Java Code Examples for org.mongodb.morphia.Datastore#createQuery()

The following examples show how to use org.mongodb.morphia.Datastore#createQuery() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DBMongoImpl.java    From heimdall with Apache License 2.0 6 votes vote down vote up
private <T> Query<T> prepareQuery(Object criteria, Datastore dataStore) {

          Query<T> query = (Query<T>) dataStore.createQuery(criteria.getClass());

          List<Field> fields = this.getAllModelFields(criteria.getClass());
          for (Field field : fields) {
               field.setAccessible(true);
               Object value = null;
               try {
                    value = field.get(criteria);
               } catch (IllegalArgumentException | IllegalAccessException e) {
                    log.error(e.getMessage(), e);
               }
               if (value != null) {
                    query.criteria(field.getName()).equal(value);
               }
          }

          return query;
     }
 
Example 2
Source File: DBMockImpl.java    From heimdall with Apache License 2.0 6 votes vote down vote up
private <T> Query<T> prepareQuery(Object criteria, Datastore dataStore) {

        Query<T> query = (Query<T>) dataStore.createQuery(criteria.getClass());

        List<Field> fields = this.getAllModelFields(criteria.getClass());
        for (Field field : fields) {
            field.setAccessible(true);
            Object value = null;
            try {
                value = field.get(criteria);
            } catch (IllegalArgumentException | IllegalAccessException ignored) {}

            if (value != null) {
                query.criteria(field.getName()).equal(value);
            }
        }

        return query;
    }