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 ...
my opinion would be nice to a relative path to the AppServer with the definition here is in the source code (XML configuration, there really is enough already ...)

Attached to define a few ways the path for Hibernate Search:






\u0026lt;property name = "hibernate.search.default.indexBase" value = "luceneIdx "/>





start parameters



-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


\u0026lt;mbean code = "org.jboss.varia.property.SystemPropertiesService"


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><JBOSS_HOME>/server/provobis/data/luceneIdx</i>

* </p>

  * <p>   * To use the FSRelativePathDirectoryProvider put following line in <code>persistence.xml</code><br>    *  
* <pre>
* <property name="hibernate.search.default.directory_provider"
* value="com.nobiscum.provobis.search.FSRelativePathDirectoryProvider" />
* </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) keys.nextElement ();

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