org.modeshape.jcr.query.lucene.LuceneSearchConfiguration Maven / Gradle / Ivy
/*
* ModeShape (http://www.modeshape.org)
* See the COPYRIGHT.txt file distributed with this work for information
* regarding copyright ownership. Some portions may be licensed
* to Red Hat, Inc. under one or more contributor license agreements.
* See the AUTHORS.txt file in the distribution for a full listing of
* individual contributors.
*
* ModeShape is free software. Unless otherwise indicated, all code in ModeShape
* is licensed to you under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* ModeShape is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.modeshape.jcr.query.lucene;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import org.apache.lucene.util.Version;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.search.cfg.SearchMapping;
import org.hibernate.search.cfg.spi.SearchConfiguration;
import org.hibernate.search.cfg.spi.SearchConfigurationBase;
import org.hibernate.search.impl.SimpleInitializer;
import org.hibernate.search.spi.InstanceInitializer;
import org.hibernate.search.spi.ServiceProvider;
import org.modeshape.common.logging.Logger;
/**
* The Hibernate Search {@link SearchConfiguration} implementation that specifies how Hibernate Search should be configured.
*/
public abstract class LuceneSearchConfiguration extends SearchConfigurationBase {
protected static final String HIBERNATE_PROPERTY_PREFIX = "hibernate.search.";
protected static final String DEFAULT_INDEX = "default.";
protected Logger logger = Logger.getLogger(LuceneSearchConfiguration.class);
private final Map> classes = new HashMap>();
private final Map> unmodifiableClasses;
private final Properties properties = new Properties();
private final InstanceInitializer initializer = SimpleInitializer.INSTANCE;
/**
* @param annotatedAndBridgeClasses the annotated classes that will be submitted to the indexer
*/
protected LuceneSearchConfiguration( Class>... annotatedAndBridgeClasses ) {
for (Class> annotatedAndBridgeClass : annotatedAndBridgeClasses) {
classes.put(annotatedAndBridgeClass.getName(), annotatedAndBridgeClass);
}
unmodifiableClasses = Collections.unmodifiableMap(classes);
}
protected void setProperty( String name,
String value ) {
if (value != null) this.properties.setProperty(name, value);
}
protected void setProperty( String name,
String value,
String defaultValue) {
if (value != null) {
this.properties.setProperty(name, value);
} else if (defaultValue != null) {
this.properties.setProperty(name, defaultValue);
}
}
@SuppressWarnings( "deprecation" )
public Version getVersion() {
Version version = Version.valueOf(this.properties.getProperty("hibernate.search.lucene_version"));
return version != null ? version : Version.LUCENE_CURRENT;
}
@Override
public Iterator> getClassMappings() {
return unmodifiableClasses.values().iterator();
}
@Override
public Class> getClassMapping( String name ) {
return classes.get(name);
}
@Override
public String getProperty( String propertyName ) {
return properties.getProperty(propertyName);
}
@Override
public Properties getProperties() {
return properties;
}
@Override
public ReflectionManager getReflectionManager() {
return null;
}
@Override
public SearchMapping getProgrammaticMapping() {
return null;
}
@Override
public Map>, Object> getProvidedServices() {
return Collections.emptyMap();
}
@Override
public boolean isTransactionManagerExpected() {
// See MODE-1420; we use a transaction manager when updating indexes with changes made by sessions,
// but a transaction is not used when manually re-indexing
return false;
}
@Override
public InstanceInitializer getInstanceInitializer() {
return initializer;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Iterator> iter = properties.entrySet().iterator();
if (iter.hasNext()) {
Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy