public static Query fromIdentifier( Object id ) { if (id == null) { throw new IllegalArgumentException("null identifier passed in"); } Identifier objectIdentifier = Identifier.from(id); if (objectIdentifier == null) { throw new IllegalArgumentException("Supplied id results in null Identifier"); } Query q = new Query(); q.addIdentifier( Identifier.from(id) ); return q; }
public static Query fromUUID( UUID uuid ) { Query q = new Query(); q.addIdentifier( Identifier.fromUUID( uuid ) ); return q; }
@Test public void nameIdentifierTest() throws Exception { logger.debug( "nameIdentifierTest" ); EntityManager em = app.getEntityManager(); assertNotNull( em ); Map<String, Object> properties = new LinkedHashMap<String, Object>(); properties.put( "keywords", "blah,test,game" ); properties.put( "title", "Solitaire" ); properties.put( "name", "test" ); Entity game1 = em.create( "games", properties ); assertNotNull( game1 ); //we create 2 entities, otherwise this test will pass when it shouldn't properties.put( "name", "test2" ); Entity game2 = em.create( "game", properties ); assertNotNull( game2 ); app.waitForQueueDrainAndRefreshIndex(); // overlap Query query = new Query(); query.addIdentifier( Identifier.fromName( "test" ) ); Results r = em.searchCollection( em.getApplicationRef(), "games", query ); assertEquals( "We should only get 1 result", 1, r.size() ); assertNull( "No cursor should be present", r.getCursor() ); assertEquals( "Saved entity returned", game1, r.getEntity() ); }
query.setQl("select * where username ='"+pathToken.getIdentifier().getName()+"'"); }else{ query.addIdentifier(pathToken.getIdentifier());
query.setEntityType( eType ); if ( id != null ) { query.addIdentifier( Identifier.fromUUID( id ) ); query.addIdentifier( Identifier.from( name ) );
@Test public void uuidIdentifierTest() throws Exception { logger.debug( "uuidIdentifierTest" ); EntityManager em = app.getEntityManager(); assertNotNull( em ); Map<String, Object> properties = new LinkedHashMap<String, Object>(); properties.put( "keywords", "blah,test,game" ); properties.put( "title", "Solitaire" ); Entity game1 = em.create( "game", properties ); assertNotNull( game1 ); //we create 2 entities, otherwise this test will pass when it shouldn't Entity game2 = em.create( "game", properties ); assertNotNull( game2 ); app.waitForQueueDrainAndRefreshIndex(); // overlap Query query = new Query(); query.addIdentifier( Identifier.fromUUID( game1.getUuid() ) ); Results r = em.searchCollection( em.getApplicationRef(), "games", query ); assertEquals( "We should only get 1 result", 1, r.size() ); assertNull( "No cursor should be present", r.getCursor() ); assertEquals( "Saved entity returned", game1, r.getEntity() ); }
@Test public void emailIdentifierTest() throws Exception { logger.debug( "emailIdentifierTest" ); EntityManager em = app.getEntityManager(); assertNotNull( em ); User user = new User(); user.setUsername( "foobar" ); user.setEmail( "foobar@usergrid.org" ); Entity createUser = em.create( user ); assertNotNull( createUser ); //we create 2 entities, otherwise this test will pass when it shouldn't User user2 = new User(); user2.setUsername( "foobar2" ); user2.setEmail( "foobar2@usergrid.org" ); Entity createUser2 = em.create( user2 ); assertNotNull( createUser2 ); app.waitForQueueDrainAndRefreshIndex(); // overlap Query query = new Query(); query.addIdentifier( Identifier.fromEmail( "foobar@usergrid.org" ) ); Results r = em.searchCollection( em.getApplicationRef(), "users", query ); assertEquals( "We should only get 1 result", 1, r.size() ); assertNull( "No cursor should be present", r.getCursor() ); assertEquals( "Saved entity returned", createUser, r.getEntity() ); }