Package com.google.appengine.api.datastore

Examples of com.google.appengine.api.datastore.PreparedQuery.asSingleEntity()


        pid = (String)current.entity.getProperty(ID_PROP);
        q.addFilter( PID_PROP, Query.FilterOperator.EQUAL, pid);

      }
      PreparedQuery pq = this.datastore.prepare(q);
      Entity e = pq.asSingleEntity();

      if ( e == null && autoinsert ) {
        e = new Entity( KIND_NAME);
        Date now = new Date();
        e.setProperty(NAME_PROP, name );
View Full Code Here


      // Get the Datastore Service
      DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
      Filter nomFilter =  new Query.FilterPredicate("nomusuari", Query.FilterOperator.EQUAL, usuari.getNomusuari() );
      Query q2 = new Query("Usuaris").setFilter(nomFilter);
      PreparedQuery pq = datastore.prepare(q2);
      Entity usEntity = pq.asSingleEntity();
           
      Query query = new Query("Usuaris");
      query.addFilter("nom", FilterOperator.EQUAL, usuari.getNomusuari());
      usEntity = UtilCache.getDatastoreServiceInstance().prepare(query).asSingleEntity();
View Full Code Here

            .setAncestor(key)
            .setKeysOnly();

        PreparedQuery preparedQuery = service.prepare(query);

        Entity entity = preparedQuery.asSingleEntity();
        assertEquals(john.getKey(), entity.getKey());
        assertNull(entity.getProperty("name"));
        assertNull(entity.getProperty("surname"));
    }
View Full Code Here

            .addProjection(new PropertyProjection("percent", Double.class))
            .addProjection(new PropertyProjection("x", Double.class))
            .addProjection(new PropertyProjection("diff", Long.class));

        PreparedQuery preparedQuery = service.prepare(query);
        Entity result = preparedQuery.asSingleEntity();
        assertEquals(e.getKey(), result.getKey());
        assertEquals(e.getProperty("price"), result.getProperty("price"));
        assertEquals(e.getProperty("percent"), result.getProperty("percent"));
        assertEquals(e.getProperty("x"), result.getProperty("x"));
        assertEquals(e.getProperty("diff"), result.getProperty("diff"));
View Full Code Here

        Query query = new Query("Product")
            .setAncestor(key)
            .addProjection(new PropertyProjection("long", null));

        PreparedQuery preparedQuery = service.prepare(query);
        Entity result = preparedQuery.asSingleEntity();
        assertEquals(e.getKey(), result.getKey());

        RawValue rawValue = (RawValue) result.getProperty("long");
        assertEquals(Long.valueOf(123L), rawValue.asType(Long.class));
        assertEquals(Long.valueOf(123L), rawValue.asStrictType(Long.class));
View Full Code Here

        createEntity("Person", parentKey).store();
        createEntity("Person", parentKey).store();

        PreparedQuery preparedQuery = service.prepare(new Query("Person"));
        try {
            preparedQuery.asSingleEntity();
            fail("Expected PreparedQuery.TooManyResultsException");
        } catch (PreparedQuery.TooManyResultsException e) {
            // pass
        }
    }
View Full Code Here

    protected void assertSingleResult(Entity expectedEntity, Query query) {
        PreparedQuery preparedQuery = service.prepare(query);
        assertEquals("number of results", 1, preparedQuery.countEntities(withDefaults()));

        Entity entityFromQuery = preparedQuery.asSingleEntity();
        assertEquals(expectedEntity, entityFromQuery);
    }

    protected void assertNoResults(Query query) {
        PreparedQuery preparedQuery = service.prepare(query);
View Full Code Here

        final Key key = ds.put(client);
        try {
            Query query = new Query("Client");
            query.setFilter(new Query.FilterPredicate("username", Query.FilterOperator.EQUAL, "alesj"));
            PreparedQuery pq = ds.prepare(query);
            Entity result = pq.asSingleEntity();
            Assert.assertNotNull(result);
            Assert.assertEquals(key, result.getKey());
            Assert.assertEquals("alesj", result.getProperty("username"));
            Assert.assertEquals("password", result.getProperty("password"));
        } finally {
View Full Code Here

        Query query = new Query("foo").setAncestor(fooTwo.getKey()); // query created in namespace "two"

        NamespaceManager.set("one");
        PreparedQuery preparedQuery = service.prepare(query);
        assertEquals(fooTwo, preparedQuery.asSingleEntity());

        service.delete(fooOne.getKey());
        service.delete(fooTwo.getKey());
    }
View Full Code Here

        Key keyInNamespaceOne = KeyFactory.createKey("kind", 1);

        NamespaceManager.set("two");
        Query query = new Query("kind").setFilter(new Query.FilterPredicate("someProperty", EQUAL, keyInNamespaceOne));
        PreparedQuery preparedQuery = service.prepare(query);
        preparedQuery.asSingleEntity();    // should not throw IllegalArgumentException as in previous test
        preparedQuery.asIterator().hasNext();    // should not throw IllegalArgumentException as in previous test
        preparedQuery.asList(withDefaults()).size();    // should not throw IllegalArgumentException as in previous test
    }
}
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.