protected void configureCache(ConfigurationBuilder builder) { builder.indexing().index(Index.ALL) .addIndexedEntity(Person.class) .addProperty("default.directory_provider", "local-heap") .addProperty("lucene_version", "LUCENE_CURRENT"); }
@Produces @ConfigureCache("faq-cache") @FaqCache() public Configuration specialCacheCfg(InjectionPoint injectionPoint) throws ClassNotFoundException, NoSuchMethodException { log.info("Configuring faq-cache..."); Class classToIndex = null; String defaultValue = (String) FaqCache.class.getMethod("classToIndex").getDefaultValue(); try { classToIndex = Class.forName(injectionPoint.getAnnotated().getAnnotation(FaqCache.class).classToIndex()); } catch (final Exception e) { log.warning("Failed to lookup the class: " + classToIndex + " --> " + e.getMessage()); log.warning("Configuring classToIndex to [" + defaultValue + "]"); classToIndex = Class.forName(defaultValue); } return new ConfigurationBuilder() .indexing() .autoConfig(true) .addIndexedEntity(classToIndex) .index(Index.ALL) .addProperty("default.directory_provider", "ram") .build(); } }
@Produces @ConfigureCache("urban-dictionary-cache") @UrbanDictionaryCache public Configuration specialCacheCfg(InjectionPoint injectionPoint) { log.info("Configuring urban-dictionary-cache..."); return new ConfigurationBuilder() .indexing() .autoConfig(true) .addProperty("default.directory_provider", "ram") .build(); } }
private ConfigurationBuilder getIndexedConfigWithCustomCaches(String lockCache, String metadataCache, String dataCache) { ConfigurationBuilder cfg = getIndexedConfig(); cfg.indexing().index(Index.ALL) .addProperty("default.locking_cachename", lockCache) .addProperty("default.data_cachename", dataCache) .addProperty("default.metadata_cachename", metadataCache) .addProperty("lucene_version", "LUCENE_CURRENT"); return cfg; }
@Test public void testOverride() { String override = "hibernate.search.default.exclusive_index_use"; IndexingConfiguration cfg = new ConfigurationBuilder() .indexing() .index(Index.ALL) .autoConfig(true) .addProperty(override, "false").create(); assertEquals(cfg.properties().get(override), "false"); }
private Configuration nonIndexed() { return new ConfigurationBuilder().indexing().index(Index.NONE) .addProperty("lucene_version", "LUCENE_CURRENT").build(); }
@Override protected EmbeddedCacheManager createCacheManager() throws Exception { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.indexing().index(Index.ALL); return TestCacheManagerFactory.createCacheManager(builder); }
@Test public void testLocalWitAutoConfig() { IndexingConfiguration cfg = new ConfigurationBuilder() .indexing().index(Index.ALL).autoConfig(true) .create(); assertFalse(cfg.properties().isEmpty()); assertEquals(cfg.properties().get("hibernate.search.default.directory_provider"), "filesystem"); }
/** * Here we show that the first test could work. */ @Test public void testWithoutSearchMapping() { final Properties properties = new Properties(); properties.put("default.directory_provider", "local-heap"); properties.put("lucene_version", "LUCENE_CURRENT"); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.indexing().index(Index.PRIMARY_OWNER).withProperties(properties); withCacheManager(new CacheManagerCallable( TestCacheManagerFactory.createCacheManager(builder)) { @Override public void call() { final Cache<Long, BondPVO2> cache = cm.getCache(); final SearchManager sm = Search.getSearchManager(cache); final BondPVO2 bond = new BondPVO2(1, "Test", "DE000123"); cache.put(bond.getId(), bond); final QueryBuilder qb = sm.buildQueryBuilderForClass(BondPVO2.class) .get(); final Query q = qb.keyword().onField("name").matching("Test") .createQuery(); final CacheQuery<?> cq = sm.getQuery(q, BondPVO2.class); Assert.assertEquals(cq.getResultSize(), 1); } }); }
.index(indexing.isEnabled() ? Index.valueOf(indexing.toString()) : Index.NONE) .withProperties(indexingProperties) .autoConfig(autoConfig)
public void testPropertyMutabilityInInheritance() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.indexing().autoConfig(true).addProperty("key", "value"); Configuration configuration = builder.build(); try { configuration.indexing().properties().setProperty("anotherKey", "anotherValue"); fail("Expecting unmodifiable properties"); } catch (UnsupportedOperationException e) { // expected } ConfigurationBuilder derived = new ConfigurationBuilder(); derived.read(configuration); builder.indexing().addProperty("anotherKey", "anotherValue"); } }
case ENABLED: if (Boolean.parseBoolean(value)) { builder.indexing().enable(); } else { builder.indexing().disable(); builder.indexing().indexLocalOnly(Boolean.parseBoolean(value)); break; default: indexing.withProperties(indexingProperties);
@Override public void inject(Module module) { try { ClassLoader moduleClassLoader = System.getSecurityManager() == null ? module.getClassLoader() : AccessController.doPrivileged((PrivilegedAction<ClassLoader>) module::getClassLoader); Class<?> entityClass = Class.forName(entityClassName, false, moduleClassLoader); builder.indexing().addIndexedEntity(entityClass); } catch (Exception e) { throw InfinispanMessages.MESSAGES.unableToInstantiateClass(className); } } };
@Override protected void configureCache(ConfigurationBuilder builder) { super.configureCache(builder); builder.indexing().index(Index.PRIMARY_OWNER) .addProperty("default.directory_provider", "infinispan") .addProperty("default.indexmanager", "org.infinispan.query.indexmanager.InfinispanIndexManager") .addProperty("lucene_version", "LUCENE_CURRENT"); } }
@Produces @ConfigureCache("jboss-books-cache") @JBossBooksCache public Configuration specialCacheCfg(InjectionPoint injectionPoint) { log.info("Configuring jboss-books-cache..."); return new ConfigurationBuilder() .indexing() .autoConfig(true) .addProperty("default.directory_provider", "ram") .build(); } }
@Test(expectedExceptions = CacheConfigurationException.class, expectedExceptionsMessageRegExp = "ISPN(\\d)*: Indexing can only be enabled if infinispan-query.jar is available on your classpath, and this jar has not been detected.") public void testIndexingRequiresOptionalModule() { ConfigurationBuilder c = new ConfigurationBuilder(); c.indexing().index(Index.ALL); c.validate(GlobalConfigurationBuilder.defaultClusteredBuilder().build()); }
@Test public void testDistWitAutoConfig() { IndexingConfiguration cfg = new ConfigurationBuilder() .clustering().cacheMode(CacheMode.DIST_SYNC) .indexing().index(Index.ALL).autoConfig(true) .create(); assertFalse(cfg.properties().isEmpty()); assertEquals(cfg.properties().get("hibernate.search.default.directory_provider"), "infinispan"); }
.index(Index.PRIMARY_OWNER).withProperties(properties);
@Override public void inject(EmbeddedCacheManager cacheManager) { try { ClassLoader classLoader = cacheManager.getCacheManagerConfiguration().classLoader(); Class<?> entityClass = Class.forName(className, false, classLoader); builder.indexing().addIndexedEntity(entityClass); } catch (Exception e) { throw InfinispanMessages.MESSAGES.unableToInstantiateClass(className); } } };