Odrin Odrin - 9 days ago 5
Java Question

Google App Engine Datastore Query (Java)

I need delete from my DB all Entitys, wich that contain "-" sign in the "name" prop.
What do I need to make a query?
P.S. Java

Answer

You can't do that in the GAE datastore with only one query, because the datastore does not support "contains" queries. Therefore, you have two options:

  1. Select all entities and iterate over the result set, checking if the name contains a "-".
  2. Add a new property, e.g. "nameContainsDash" to your entity and query all entities that have this property set to true. This property is updated every time the name is updated.
...

public void setName(String name) {
    this.name = name;
    nameContainsDash = name.contains("-");
}

public boolean isNameContainsDash() {
    return nameContainsDash;
}

...

Of course, the second option might require data migration, since the property will be null for existing entities.