Java Examples for com.googlecode.objectify.Query

The following java examples will help you to understand the usage of com.googlecode.objectify.Query. These source code samples are taken from different open source projects.

Example 1
Project: Prendamigo-master  File: QueryTests.java View source code
/** */
@Test
public void testKeysOnly() throws Exception {
    Objectify ofy = this.fact.begin();
    Query<Trivial> q = ofy.query(Trivial.class);
    int count = 0;
    for (Key<Trivial> k : q.fetchKeys()) {
        assert keys.contains(k);
        count++;
    }
    assert count == keys.size();
    // Just for the hell of it, test the other methods
    assert q.countAll() == keys.size();
    q.limit(2);
    for (Key<Trivial> k : q.fetchKeys()) assert keys.contains(k);
    Key<Trivial> first = q.getKey();
    assert first.equals(this.keys.get(0));
    q.offset(1);
    Key<Trivial> second = q.getKey();
    assert second.equals(this.keys.get(1));
}
Example 2
Project: FeedThisToThat-master  File: DataAccessObject.java View source code
public static List<Long> getFeedsForUpdate() {
    Vector<Long> outputList = new Vector<Long>();
    Query<FeedParameters> query = objectify.query(FeedParameters.class).filter("inPostingQueue", true).filter("postingTime <", new Date());
    for (Key<FeedParameters> feedKey : query.fetchKeys()) {
        outputList.add(feedKey.getId());
    }
    return outputList;
}
Example 3
Project: viaja-facil-master  File: Dao.java View source code
@SuppressWarnings("unchecked")
public static synchronized HashMap<String, Set<TrainNode>> getTrainNodes() {
    String functionName = "getTrainNodes()";
    if (trainNodes == null || trainNodes.size() == 0) {
        trainNodes = new HashMap<String, Set<TrainNode>>();
        Objectify ofy = ObjectifyService.begin();
        Query<TrainNode> q = ofy.query(TrainNode.class);
        List<Key<TrainNode>> keys;
        try {
            Cache cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
            keys = (List<Key<TrainNode>>) cache.get(q.toString());
            if (keys == null) {
                keys = q.listKeys();
                cache.put(q.toString(), keys);
            }
        } catch (CacheException e) {
            keys = q.listKeys();
            Logger.getLogger(location).log(Level.SEVERE, functionName + ": Cache error: " + e);
            e.printStackTrace();
        }
        Map<Key<TrainNode>, TrainNode> res = ofy.get(keys);
        Collection<TrainNode> tns = res.values();
        Logger.getLogger(location).log(Level.INFO, functionName + ": Got " + res.size() + " TrainNodes. keys.size(): " + keys.size());
        //			String m = "";
        for (TrainNode tn : tns) {
            if (!trainNodes.containsKey(tn.getGeoCell())) {
                trainNodes.put(tn.getGeoCell(), new HashSet<TrainNode>());
            }
            trainNodes.get(tn.getGeoCell()).add(tn);
        /*				if(tn.getLineKey().equals(new Key<Line>(Line.class, 155))) {
//				if(tn.getLineType() == 11) {
					System.err.print("\"" + tn.getGeoCell() + "\", ");
				}*/
        }
    //			Utils.eMailGeneric(m, "DaoTemp");
    }
    return trainNodes;
}
Example 4
Project: gwt-marketplace-master  File: ProductManager.java View source code
public SearchResults<Product> search(HashMap<String, String> namedParameters, ArrayList<String> generalParameters, int startIndex, int limit, String ordering, boolean ascending, Integer knownRowCount) {
    Query<Product> query = noTx().query(Product.class);
    addOrdering(query, ordering, ascending, "name", true);
    if (null != namedParameters && namedParameters.size() > 0) {
        for (Map.Entry<String, String> param : namedParameters.entrySet()) {
            if (param.getKey().equals("category")) {
                query.filter("categoryId", param.getValue());
            } else if (param.getKey().equals("status")) {
                query.filter("status", param.getValue());
            } else if (param.getKey().equals("license")) {
                query.filter("license", param.getValue());
            } else if (param.getKey().equals("name")) {
                query.filter("name", param.getValue());
            } else if (param.getKey().equals("tag")) {
                query.filter("tags", param.getValue());
            }
        }
    }
    if (null != generalParameters && generalParameters.size() > 0) {
        query.filter("searchFields in", generalParameters);
    }
    return toSearchResults(query, knownRowCount);
}
Example 5
Project: gwt-voices-master  File: ResultsServiceImpl.java View source code
private HashMap<UserAgent, TestResults> getResultsImpl() {
    HashMap<UserAgent, TestResults> map = new HashMap<UserAgent, TestResults>();
    Objectify ofy = ObjectifyService.begin();
    Query<TestResultSummary> q = ofy.query(TestResultSummary.class).chunkSize(5000);
    for (TestResultSummary summary : q) {
        TestResults testResults = summary.getTestResults();
        map.put(new UserAgent(summary.getUserAgent()), testResults);
    }
    return map;
}
Example 6
Project: volinfoman-master  File: DaoGaeDatastore.java View source code
/* (non-Javadoc)
	 * @see com.lisedex.volinfoman.server.Dao#expireCodesBefore(java.util.Calendar)
	 */
@Override
public void expireCodesBefore(long now) {
    Query<ConfirmationCode> oldCodes = ofy().query(ConfirmationCode.class).filter("expires <", now);
    for (ConfirmationCode code : oldCodes) {
        User user = getUser(code.getUsername());
        if (user != null) {
            // make sure user is still in unconfirmed state
            if (user.getStatus() == User.STATUS_UNCONFIRMED) {
                deleteUser(user.getId());
            }
        }
        deleteConfirmationCode(code);
    }
}
Example 7
Project: gwt.svn-master  File: Task.java View source code
/**
   * Find all tasks for the current user.
   */
@SuppressWarnings("unchecked")
public static List<Task> findAllTasks() {
    // TODO: move this method to a service object and get rid of EMF (e.g. use a ServiceLocator)
    EMF emf = EMF.get();
    Query<Task> q = emf.ofy().query(Task.class).filter("userId", currentUserId());
    List<Task> list = q.list();
    /*
     * If this is the first time running the app, populate the datastore with
     * some default tasks and re-query the datastore for them.
     */
    if (list.size() == 0) {
        populateDatastore();
        q = emf.ofy().query(Task.class).filter("userId", currentUserId());
        list = q.list();
    }
    return list;
}
Example 8
Project: TheSocialOS-master  File: ContactsServiceimpl.java View source code
@Override
public List<User> getFriendsSuggestionList(String text) throws FriendNotFoundException {
    Objectify ofy = ObjectifyService.begin();
    StringTokenizer tokens = new StringTokenizer(text);
    List<String> userNames = new ArrayList<String>();
    User user = UserHelper.getUserSession(perThreadRequest.get().getSession(), ofy);
    while (tokens.hasMoreTokens()) userNames.add(tokens.nextToken());
    Query<User> queryContact;
    if (userNames.isEmpty())
        throw new FriendNotFoundException("Not contacts found with these codes");
    if (userNames.size() == 1)
        queryContact = ofy.query(User.class).filter("firstName >=", userNames.get(0)).filter("firstName <", userNames.get(0) + "�");
    else
        queryContact = ofy.query(User.class).filter("firstName >=", userNames.get(0)).filter("firstName <", userNames.get(0) + "�");
    List<User> SearchContacts = new ArrayList<User>();
    for (User contact : queryContact) {
        Key<User> userKey = ObjectifyService.factory().getKey(contact);
        if (user.getContacts().contains(userKey))
            SearchContacts.add(contact);
    }
    return SearchContacts;
}
Example 9
Project: appinventor-sources-master  File: ObjectifyStorageIo.java View source code
@Override
public void run(Objectify datastore) {
    Key<ProjectData> projectKey = projectKey(projectId);
    Query<FileData> fdq = datastore.query(FileData.class).ancestor(projectKey);
    for (FileData fd : fdq) {
        if (isTrue(fd.isGCS)) {
            gcsPaths.add(fd.gcsName);
        } else if (fd.isBlob) {
            blobKeys.add(fd.blobKey);
        }
    }
    datastore.delete(fdq);
    // finally, delete the ProjectData object
    datastore.delete(projectKey);
}
Example 10
Project: gwt-sandbox-master  File: Task.java View source code
/**
   * Find all tasks for the current user.
   */
@SuppressWarnings("unchecked")
public static List<Task> findAllTasks() {
    // TODO: move this method to a service object and get rid of EMF (e.g. use a ServiceLocator)
    EMF emf = EMF.get();
    Query<Task> q = emf.ofy().query(Task.class).filter("userId", currentUserId());
    List<Task> list = q.list();
    /*
     * If this is the first time running the app, populate the datastore with
     * some default tasks and re-query the datastore for them.
     */
    if (list.size() == 0) {
        populateDatastore();
        q = emf.ofy().query(Task.class).filter("userId", currentUserId());
        list = q.list();
    }
    return list;
}
Example 11
Project: google-web-toolkit-svnmirror-master  File: Task.java View source code
/**
   * Find all tasks for the current user.
   */
@SuppressWarnings("unchecked")
public static List<Task> findAllTasks() {
    // TODO: move this method to a service object and get rid of EMF (e.g. use a ServiceLocator)
    EMF emf = EMF.get();
    Query<Task> q = emf.ofy().query(Task.class).filter("userId", currentUserId());
    List<Task> list = q.list();
    /*
     * If this is the first time running the app, populate the datastore with
     * some default tasks and re-query the datastore for them.
     */
    if (list.size() == 0) {
        populateDatastore();
        q = emf.ofy().query(Task.class).filter("userId", currentUserId());
        list = q.list();
    }
    return list;
}
Example 12
Project: scalagwt-gwt-master  File: Task.java View source code
/**
   * Find all tasks for the current user.
   */
@SuppressWarnings("unchecked")
public static List<Task> findAllTasks() {
    // TODO: move this method to a service object and get rid of EMF (e.g. use a ServiceLocator)
    EMF emf = EMF.get();
    Query<Task> q = emf.ofy().query(Task.class).filter("userId", currentUserId());
    List<Task> list = q.list();
    /*
     * If this is the first time running the app, populate the datastore with
     * some default tasks and re-query the datastore for them.
     */
    if (list.size() == 0) {
        populateDatastore();
        q = emf.ofy().query(Task.class).filter("userId", currentUserId());
        list = q.list();
    }
    return list;
}
Example 13
Project: objectify-master  File: QueryImpl.java View source code
/** @return the underlying datastore query object */
private com.google.appengine.api.datastore.Query getActualQuery() {
    return this.actual;
}