Tuesday, April 28, 2009
Mirena Softened Cervix
When the Hibernate Search index in the file system stores (FSDirectoryProvider), this typically is defined in the persistence.xml (in the use of JPA). Here you can only use a relative path to the index directory from which the Java application was started specify (eg $ TOMCAT_HOME / bin) or you are an absolute path. After the persistence.xml is normally part of the delivered application, an absolute path is not really in question (a typical scenario: Development on Windows - C: \\ app \\ luceneIdx; Livedeployment Linux - / usr / local / app / luceneIdx). A relative path is however not necessarily beautiful - / usr/share/jboss/jboss-4.2.3GA/bin/luceneIdx ...
\u0026lt;property name = "hibernate.search.default.indexBase" value = "luceneIdx "/>
-Dhibernate.search.default.indexBase = D: / luceneIdx
When starting the VM can also specify the index, Hibernate Search will then use this. Thus, for each environment (Windows, Linux) defines an absolute directory
JBoss MBean SystemProperties
name = "jboss.util: type = Service, name = SystemProperties>
<!-- Load properties from each of the given comma separated URLs -->
<attribute name="URLList">
./conf/lucene.properties
</attribute>
</mbean>
Lucene.properties
hibernate.search.default.indexBase=D:/luceneIdx3
The definition of Hibernate Search Index Directory is being held in a property file (accessed through the System Properties JBoss MBean) that may be different style for each server environment. The configuration is in the application, the property file can be different on each server.
Self directory provider
package com.nobiscum.provobis.search;
import java.io.File; import java.util.Enumeration; import java.util.Properties; import org.hibernate.search.backend.configuration.MaskedProperty;
import org.hibernate.search.engine.SearchFactoryImplementor; import org.hibernate.search.store.FSDirectoryProvider;
/** * <p> * This DirectoryProvider use the <i><jboss.server.data.dir>/luceneIdx</i> directory to store the * Apache Lucene filesystem index.<br> * For example the path looks like <i>&lt;JBOSS_HOME&gt;/server/provobis/data/luceneIdx</i> * </p>
* <p> * To use the FSRelativePathDirectoryProvider put following line in <code>persistence.xml</code><br> *
* <pre> * &lt;property name=&quot;hibernate.search.default.directory_provider&quot; * value=&quot;com.nobiscum.provobis.search.FSRelativePathDirectoryProvider&quot; /&gt; * </pre> * * </p>
* * @author mre * @see FSDirectoryProvider
*/ public class FSRelativePathDirectoryProvider extends FSDirectoryProvider { @Override public void initialize(String directoryProviderName, Properties properties, SearchFactoryImplementor searchFactoryImplementor) {
// copy is necessary, see method description. Properties p = copyProperties(properties);
// XXX AppServer dependency String indexBase = System.getProperty("jboss.server.data.dir"); indexBase += File.separator + "luceneIdx"; p.put("indexBase", indexBase); super.initialize(directoryProviderName, p, searchFactoryImplementor);
}
/**
* The <code>properties</code> parameter is not a {@link Properties} themselve, but rather a * subclass ({@link MaskedProperty}. The {@link MaskedProperty} is read-only, less methods are * implemented, the most throw an UnsupportedOperationException.
* <p> * To manipulate the properties, a new <i>normal</i> {@link Properties} object is created. The * values from the given properties are all copied into the new one. * * @param properties * existing properties object
* @return new properties object, that contains all values from <code>properties</code>
private Properties copyProperties(Properties properties) { newProperties Properties = new Properties ();
\u0026lt;Object> Enumeration keys = properties.keys (); if (keys.hasMoreElements ()) {String key
String newProperties return
};; properties.getProperty value = (key); newProperties.put (key, value)
}}
Here is the path relative to the JBoss data directory.
find a nice solution as I ;-)
0 comments:
Post a Comment