Search in sources :

Example 21 with FilterPredicate

use of com.google.appengine.api.datastore.Query.FilterPredicate in project Cached-Datastore by Emperorlou.

the class QueryHelper method getFilteredList.

public List<CachedEntity> getFilteredList(String kind, int limit, Cursor cursor, String fieldName, FilterOperator operator, Object equalToValue, String fieldName2, FilterOperator operator2, Object equalToValue2, String fieldName3, FilterOperator operator3, Object equalToValue3, String fieldName4, FilterOperator operator4, Object equalToValue4) {
    FilterPredicate f1 = new FilterPredicate(fieldName, operator, equalToValue);
    FilterPredicate f2 = new FilterPredicate(fieldName2, operator2, equalToValue2);
    FilterPredicate f3 = new FilterPredicate(fieldName3, operator3, equalToValue3);
    FilterPredicate f4 = new FilterPredicate(fieldName4, operator4, equalToValue4);
    Filter filter = CompositeFilterOperator.and(f1, f2, f3, f4);
    return ds.fetchAsList(kind, filter, limit, cursor);
}
Also used : CompositeFilter(com.google.appengine.api.datastore.Query.CompositeFilter) Filter(com.google.appengine.api.datastore.Query.Filter) FilterPredicate(com.google.appengine.api.datastore.Query.FilterPredicate)

Example 22 with FilterPredicate

use of com.google.appengine.api.datastore.Query.FilterPredicate in project getting-started-java by GoogleCloudPlatform.

the class DatastoreSessionFilter method deleteSessionWithValue.

// [END deleteSessionVariables]
protected void deleteSessionWithValue(String varName, String varValue) {
    Transaction transaction = datastore.beginTransaction();
    try {
        Query query = new Query(SESSION_KIND).setFilter(new FilterPredicate(varName, FilterOperator.EQUAL, varValue));
        Iterator<Entity> results = datastore.prepare(transaction, query).asIterator();
        while (results.hasNext()) {
            Entity stateEntity = results.next();
            datastore.delete(transaction, stateEntity.getKey());
        }
        transaction.commit();
    } finally {
        if (transaction.isActive()) {
            transaction.rollback();
        }
    }
}
Also used : Entity(com.google.appengine.api.datastore.Entity) Transaction(com.google.appengine.api.datastore.Transaction) Query(com.google.appengine.api.datastore.Query) FilterPredicate(com.google.appengine.api.datastore.Query.FilterPredicate)

Example 23 with FilterPredicate

use of com.google.appengine.api.datastore.Query.FilterPredicate in project codeu-2018-team12 by codeu-2018-team12.

the class PersistentDataStore method setUpConversationEntity.

/**
 * Retrieves a Conversation Entity object
 *
 * @param conversation user in application
 * @return Conversation Entity
 */
private Entity setUpConversationEntity(Conversation conversation) {
    Query query = new Query("chat-conversations").setFilter(new FilterPredicate("uuid", FilterOperator.EQUAL, conversation.getId().toString()));
    PreparedQuery preparedQuery = datastore.prepare(query);
    return preparedQuery.asSingleEntity();
}
Also used : FilterPredicate(com.google.appengine.api.datastore.Query.FilterPredicate)

Example 24 with FilterPredicate

use of com.google.appengine.api.datastore.Query.FilterPredicate in project codeu-2018-team12 by codeu-2018-team12.

the class PersistentDataStore method updateEntity.

/**
 * Updates a User object in the Datstore service
 */
public void updateEntity(User user) {
    Query query = new Query("chat-users").setFilter(new FilterPredicate("uuid", FilterOperator.EQUAL, user.getId().toString()));
    PreparedQuery preparedQuery = datastore.prepare(query);
    Entity resultEntity = preparedQuery.asSingleEntity();
    resultEntity.setProperty("biography", user.getBio());
    datastore.put(resultEntity);
}
Also used : FilterPredicate(com.google.appengine.api.datastore.Query.FilterPredicate)

Example 25 with FilterPredicate

use of com.google.appengine.api.datastore.Query.FilterPredicate in project java-docs-samples by GoogleCloudPlatform.

the class MetadataPropertiesTest method representationsOfProperty.

// [START property_representation_query_example]
Collection<String> representationsOfProperty(DatastoreService ds, String kind, String property) {
    // Start with unrestricted non-keys-only property query
    Query q = new Query(Entities.PROPERTY_METADATA_KIND);
    // Limit to specified kind and property
    q.setFilter(new FilterPredicate("__key__", Query.FilterOperator.EQUAL, Entities.createPropertyKey(kind, property)));
    // Get query result
    Entity propInfo = ds.prepare(q).asSingleEntity();
    // Return collection of property representations
    return (Collection<String>) propInfo.getProperty("property_representation");
}
Also used : Entity(com.google.appengine.api.datastore.Entity) Query(com.google.appengine.api.datastore.Query) Collection(java.util.Collection) FilterPredicate(com.google.appengine.api.datastore.Query.FilterPredicate)

Aggregations

FilterPredicate (com.google.appengine.api.datastore.Query.FilterPredicate)38 Query (com.google.appengine.api.datastore.Query)31 Entity (com.google.appengine.api.datastore.Entity)26 Filter (com.google.appengine.api.datastore.Query.Filter)24 Test (org.junit.Test)21 PreparedQuery (com.google.appengine.api.datastore.PreparedQuery)20 CompositeFilter (com.google.appengine.api.datastore.Query.CompositeFilter)20 Key (com.google.appengine.api.datastore.Key)6 DatastoreService (com.google.appengine.api.datastore.DatastoreService)3 PrintWriter (java.io.PrintWriter)3 ArrayList (java.util.ArrayList)3 StringWriter (java.io.StringWriter)2 FetchOptions (com.google.appengine.api.datastore.FetchOptions)1 Transaction (com.google.appengine.api.datastore.Transaction)1 Collection (java.util.Collection)1 List (java.util.List)1 DateTime (org.joda.time.DateTime)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1