public void testGlobalCount() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getAccountImplClass()) .select(count("creationDate")) .build(); List<Object[]> list = q.list(); assertEquals(1, list.size()); assertEquals(1, list.get(0).length); assertEquals(3L, list.get(0)[0]); }
public void testSortByDate() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getAccountImplClass()) .orderBy("creationDate", SortOrder.DESC) .build(); List<Account> list = q.list(); assertEquals(3, list.size()); assertEquals(3, list.get(0).getId()); assertEquals(2, list.get(1).getId()); assertEquals(1, list.get(2).getId()); }
public void testStringLiteralEscape() { QueryFactory qf = getQueryFactory(); // all transactions that have a given description. the description contains characters that need to be escaped. Query q = qf.from(getModelFactory().getAccountImplClass()) .having("description").eq("John Doe's first bank account") .build(); List<Account> list = q.list(); assertEquals(1, list.size()); assertEquals(1, list.get(0).getId()); }
public void testEqSentence() { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getAccountImplClass()) .having("description").eq("John Doe's first bank account") .build(); List<Account> list = q.list(); assertEquals(1, list.size()); assertEquals(1, list.get(0).getId()); }
public void testSampleDomainQuery28() throws Exception { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getAccountImplClass()) .orderBy("id", SortOrder.ASC) .having("creationDate").lte(makeDate("2013-01-20")) .build(); List<Account> list = q.list(); assertEquals(3, list.size()); assertEquals(1, list.get(0).getId()); assertEquals(2, list.get(1).getId()); assertEquals(3, list.get(2).getId()); }
public void testSampleDomainQuery26() throws Exception { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getAccountImplClass()) .having("creationDate").eq(makeDate("2013-01-20")) .build(); List<Account> list = q.list(); assertEquals(1, list.size()); assertEquals(3, list.get(0).getId()); }
public void testSampleDomainQuery29() throws Exception { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getAccountImplClass()) .having("creationDate").gt(makeDate("2013-01-04")) .build(); List<Account> list = q.list(); assertEquals(1, list.size()); assertEquals(3, list.get(0).getId()); }
public void testSampleDomainQuery27() throws Exception { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getAccountImplClass()) .orderBy("id", SortOrder.ASC) .having("creationDate").lt(makeDate("2013-01-20")) .build(); List<Account> list = q.list(); assertEquals(2, list.size()); assertEquals(1, list.get(0).getId()); assertEquals(2, list.get(1).getId()); }
public void testDateParam() throws Exception { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getAccountImplClass()) .having("creationDate").eq(param("param1")) .build().setParameter("param1", makeDate("2013-01-03")); List<Account> list = q.list(); assertEquals(1, list.size()); assertEquals(1, list.get(0).getId()); }
public void testSampleDomainQuery17() { QueryFactory qf = getQueryFactory(); // all accounts for a user. first get the user by id and then get his account. Query q1 = qf.from(getModelFactory().getUserImplClass()) .having("id").eq(1).build(); List<User> users = q1.list(); Query q2 = qf.from(getModelFactory().getAccountImplClass()) .orderBy("description", SortOrder.ASC) .having("id").in(users.get(0).getAccountIds()).build(); List<Account> list = q2.list(); assertEquals(2, list.size()); assertEquals("John Doe's first bank account", list.get(0).getDescription()); assertEquals("John Doe's second bank account", list.get(1).getDescription()); }
@Override protected void createCacheManagers() throws Throwable { Util.recursiveFileRemove(indexDirectory); boolean created = new File(indexDirectory).mkdirs(); assertTrue(created); ConfigurationBuilder cfg = TestCacheManagerFactory.getDefaultCacheConfiguration(true); cfg.indexing().index(Index.ALL) .addIndexedEntity(getModelFactory().getUserImplClass()) .addIndexedEntity(getModelFactory().getAccountImplClass()) .addIndexedEntity(getModelFactory().getTransactionImplClass()) .addProperty("default.directory_provider", "filesystem") .addProperty("default.indexBase", indexDirectory) .addProperty("lucene_version", "LUCENE_CURRENT"); createClusteredCaches(1, cfg); }
private void checkIndexPresence(Cache cache) { SearchIntegrator searchIntegrator = Search.getSearchManager(cache).unwrap(SearchIntegrator.class); verifyClassIsIndexed(searchIntegrator, getModelFactory().getUserImplClass()); verifyClassIsIndexed(searchIntegrator, getModelFactory().getAccountImplClass()); verifyClassIsIndexed(searchIntegrator, getModelFactory().getTransactionImplClass()); verifyClassIsNotIndexed(searchIntegrator, getModelFactory().getAddressImplClass()); }
public void testIndexPresence() { SearchIntegrator searchIntegrator = Search.getSearchManager((Cache) getCacheForQuery()).unwrap(SearchIntegrator.class); verifyClassIsIndexed(searchIntegrator, getModelFactory().getUserImplClass()); verifyClassIsIndexed(searchIntegrator, getModelFactory().getAccountImplClass()); verifyClassIsIndexed(searchIntegrator, getModelFactory().getTransactionImplClass()); verifyClassIsNotIndexed(searchIntegrator, getModelFactory().getAddressImplClass()); }
@Override protected void createCacheManagers() throws Throwable { ConfigurationBuilder cfg = TestCacheManagerFactory.getDefaultCacheConfiguration(true); cfg.transaction() .transactionMode(TransactionMode.TRANSACTIONAL) .indexing().index(Index.ALL) .addIndexedEntity(getModelFactory().getUserImplClass()) .addIndexedEntity(getModelFactory().getAccountImplClass()) .addIndexedEntity(getModelFactory().getTransactionImplClass()) .addProperty("default.directory_provider", "local-heap") .addProperty("lucene_version", "LUCENE_CURRENT"); createClusteredCaches(1, cfg); }
@Override protected void createCacheManagers() throws Throwable { ConfigurationBuilder cfg = TestCacheManagerFactory.getDefaultCacheConfiguration(true); cfg.transaction() .transactionMode(TransactionMode.TRANSACTIONAL) .indexing().index(Index.ALL) .addIndexedEntity(getModelFactory().getUserImplClass()) .addIndexedEntity(getModelFactory().getAccountImplClass()) .addIndexedEntity(getModelFactory().getTransactionImplClass()) .addProperty("default.directory_provider", "local-heap") .addProperty("lucene_version", "LUCENE_CURRENT"); createClusteredCaches(1, cfg); }
@Override protected void createCacheManagers() throws Throwable { ConfigurationBuilder cfg = TestCacheManagerFactory.getDefaultCacheConfiguration(true); cfg.transaction() .transactionMode(TransactionMode.TRANSACTIONAL) .indexing().index(Index.ALL) .addIndexedEntity(getModelFactory().getUserImplClass()) .addIndexedEntity(getModelFactory().getAccountImplClass()) .addIndexedEntity(getModelFactory().getTransactionImplClass()) .addProperty("default.directory_provider", "local-heap") .addProperty("lucene_version", "LUCENE_CURRENT"); createClusteredCaches(1, cfg); }
@Override protected void createCacheManagers() throws Throwable { ConfigurationBuilder defaultConfiguration = TestCacheManagerFactory.getDefaultCacheConfiguration(true); createClusteredCaches(1, defaultConfiguration); ConfigurationBuilder cfg = TestCacheManagerFactory.getDefaultCacheConfiguration(true); cfg.indexing().index(Index.ALL) .addIndexedEntity(getModelFactory().getUserImplClass()) .addIndexedEntity(getModelFactory().getAccountImplClass()) .addIndexedEntity(getModelFactory().getTransactionImplClass()) .addProperty("default.directory_provider", "infinispan") .addProperty("lucene_version", "LUCENE_CURRENT"); manager(0).defineConfiguration(TEST_CACHE_NAME, cfg.build()); cache = manager(0).getCache(TEST_CACHE_NAME); }
@Override protected void createCacheManagers() throws Throwable { ConfigurationBuilder cfg = TestCacheManagerFactory.getDefaultCacheConfiguration(true); cfg.encoding().key().mediaType(MediaType.APPLICATION_OBJECT_TYPE); cfg.encoding().value().mediaType(MediaType.APPLICATION_OBJECT_TYPE); cfg.indexing().index(Index.ALL) .addIndexedEntity(getModelFactory().getUserImplClass()) .addIndexedEntity(getModelFactory().getAccountImplClass()) .addIndexedEntity(getModelFactory().getTransactionImplClass()) .addProperty("default.directory_provider", "local-heap") .addProperty("lucene_version", "LUCENE_CURRENT"); createClusteredCaches(1, cfg); } }
@Override protected void createCacheManagers() throws Throwable { ConfigurationBuilder defaultConfiguration = getDefaultClusteredCacheConfig(CacheMode.REPL_SYNC, false); defaultConfiguration.clustering() .stateTransfer().fetchInMemoryState(true); createClusteredCaches(2, defaultConfiguration); ConfigurationBuilder cfg = initialCacheConfiguration(); IndexingConfigurationBuilder indexingConfigurationBuilder = cfg.clustering() .stateTransfer().fetchInMemoryState(true) .indexing() .index(Index.PRIMARY_OWNER) .addIndexedEntity(getModelFactory().getUserImplClass()) .addIndexedEntity(getModelFactory().getAccountImplClass()) .addIndexedEntity(getModelFactory().getTransactionImplClass()); getIndexConfig().forEach(indexingConfigurationBuilder::addProperty); manager(0).defineConfiguration(TEST_CACHE_NAME, cfg.build()); manager(1).defineConfiguration(TEST_CACHE_NAME, cfg.build()); cache1 = manager(0).getCache(TEST_CACHE_NAME); cache2 = manager(1).getCache(TEST_CACHE_NAME); }