Skip to content
Snippets Groups Projects
Commit cee3849e authored by ribeaudc's avatar ribeaudc
Browse files

[LMS-634] change: - 'DatabaseCreationUtil' moved to 'sourceTest'.

- 'DatabaseCreationUtil' only does migration and no longer indexing.
add: - 'IndexCreationUtil' and 'Indexing of Database' launch configuration for indexing.

SVN: 9040
parent 6060592d
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/IndexCreationUtil.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="ch.systemsx.cisd.openbis.generic.server.dataaccess.db.IndexCreationUtil"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="migration_dump"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="openbis"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea&#13;&#10;-Xmx512M"/>
</launchConfiguration>
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication"> <launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/DatabaseCreationUtil.java"/> <listEntry value="/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/DatabaseCreationUtil.java"/>
</listAttribute> </listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/> <listEntry value="1"/>
</listAttribute> </listAttribute>
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/> <booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="ch.systemsx.cisd.openbis.generic.server.dataaccess.db.DatabaseCreationUtil"/> <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="ch.systemsx.cisd.openbis.generic.server.dataaccess.db.DatabaseCreationUtil"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="027"/> <stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="027"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="openbis"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="openbis"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea&#13;&#10;-Xmx512M"/> <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea&#13;&#10;-Xmx512M"/>
</launchConfiguration> </launchConfiguration>
...@@ -19,8 +19,6 @@ package ch.systemsx.cisd.openbis.generic.server.dataaccess.db; ...@@ -19,8 +19,6 @@ package ch.systemsx.cisd.openbis.generic.server.dataaccess.db;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.apache.commons.lang.StringUtils;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
...@@ -31,9 +29,6 @@ import ch.systemsx.cisd.dbmigration.DBMigrationEngine; ...@@ -31,9 +29,6 @@ import ch.systemsx.cisd.dbmigration.DBMigrationEngine;
import ch.systemsx.cisd.dbmigration.DatabaseConfigurationContext; import ch.systemsx.cisd.dbmigration.DatabaseConfigurationContext;
import ch.systemsx.cisd.dbmigration.ISqlScriptProvider; import ch.systemsx.cisd.dbmigration.ISqlScriptProvider;
import ch.systemsx.cisd.dbmigration.postgresql.DumpPreparator; import ch.systemsx.cisd.dbmigration.postgresql.DumpPreparator;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.FullTextIndexerRunnable;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.HibernateSearchContext;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.IndexMode;
/** /**
* Utility methods around database creation. * Utility methods around database creation.
...@@ -42,57 +37,16 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.IndexMode; ...@@ -42,57 +37,16 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.IndexMode;
*/ */
public final class DatabaseCreationUtil public final class DatabaseCreationUtil
{ {
private static final String LUCENE_INDICES = "sourceTest/lucene/indices";
private static BeanFactory beanFactory; private static BeanFactory beanFactory;
private static HibernateSearchContext hibernateSearchContext;
static static
{ {
LogInitializer.init(); LogInitializer.init();
// Deactivate the indexing in the application context loaded by Spring.
System.setProperty("hibernate.search.index-mode", "NO_INDEX");
System.setProperty("hibernate.search.index-base", LUCENE_INDICES);
} }
public static void main(final String[] args) throws Exception private DatabaseCreationUtil()
{ {
if (args.length == 0 || args.length > 2) // This class can not be instantiated.
{
System.out.println("Usage: java " + DatabaseCreationUtil.class.getName()
+ "[--reindex[=true|false]] <database version>");
System.exit(1);
}
final String databaseVersion;
boolean reindex = false;
if (args.length == 1)
{
reindex = false;
databaseVersion = args[0];
} else
{
if (args[0].startsWith("--reindex"))
{
if (args[0].indexOf('=') > -1)
{
reindex = Boolean.parseBoolean(StringUtils.split(args[0], '=')[1]);
} else
{
reindex = true;
}
}
databaseVersion = args[1];
}
// If reindexing is asked, creating a HibernateSearchContext should be done before the
// Spring application context gets loaded because HibernateSearchContext removes the whole
// indices directory.
if (reindex)
{
hibernateSearchContext = createHibernateSearchContext();
hibernateSearchContext.afterPropertiesSet();
}
createFilesFromADumpOfAMigratedDatabase(databaseVersion, reindex);
} }
private final static BeanFactory getBeanFactory() private final static BeanFactory getBeanFactory()
...@@ -110,11 +64,9 @@ public final class DatabaseCreationUtil ...@@ -110,11 +64,9 @@ public final class DatabaseCreationUtil
/** /**
* Creates all files in <code>sourceTest/sql/postgresql</code> necessary to set up a database * Creates all files in <code>sourceTest/sql/postgresql</code> necessary to set up a database
* of the current version by dumping a database migrated from the specified version. * of the current version by dumping a database migrated from the specified version.
*
* @param reindex
*/ */
private final static void createFilesFromADumpOfAMigratedDatabase(final String databaseVersion, private final static void createFilesFromADumpOfAMigratedDatabase(final String databaseVersion)
final boolean reindex) throws Exception throws Exception
{ {
final String databaseKind = "migration_dump"; final String databaseKind = "migration_dump";
final DatabaseConfigurationContext context = final DatabaseConfigurationContext context =
...@@ -130,33 +82,6 @@ public final class DatabaseCreationUtil ...@@ -130,33 +82,6 @@ public final class DatabaseCreationUtil
createDumpForJava(databaseKind, scriptProvider.getDumpFolder(DatabaseVersionHolder createDumpForJava(databaseKind, scriptProvider.getDumpFolder(DatabaseVersionHolder
.getDatabaseVersion())); .getDatabaseVersion()));
scriptProvider.markAsDumpRestorable(DatabaseVersionHolder.getDatabaseVersion()); scriptProvider.markAsDumpRestorable(DatabaseVersionHolder.getDatabaseVersion());
if (reindex)
{
performFullTextIndex(databaseKind);
}
}
/**
* Performs a full text index because the test database has been migrated.
*/
private final static void performFullTextIndex(final String databaseKind) throws Exception
{
final BeanFactory factory = getBeanFactory();
final FullTextIndexerRunnable fullTextIndexer =
new FullTextIndexerRunnable((SessionFactory) factory
.getBean("hibernate-session-factory"), hibernateSearchContext);
fullTextIndexer.run();
}
/**
* Creates a freshly new {@link HibernateSearchContext} overriding the one loaded by <i>Spring</i>.
*/
private final static HibernateSearchContext createHibernateSearchContext()
{
final HibernateSearchContext context = new HibernateSearchContext();
context.setIndexBase(LUCENE_INDICES);
context.setIndexMode(IndexMode.INDEX_FROM_SCRATCH);
return context;
} }
/** /**
...@@ -190,8 +115,18 @@ public final class DatabaseCreationUtil ...@@ -190,8 +115,18 @@ public final class DatabaseCreationUtil
return configurationContext; return configurationContext;
} }
private DatabaseCreationUtil() //
// Main method
//
public static void main(final String[] args) throws Exception
{ {
// This class can not be instantiated. if (args.length != 1)
{
System.out.println("Usage: java " + DatabaseCreationUtil.class.getName()
+ "<database version>");
System.exit(1);
}
createFilesFromADumpOfAMigratedDatabase(args[0]);
} }
} }
/*
* Copyright 2008 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.generic.server.dataaccess.db;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import ch.systemsx.cisd.common.logging.LogInitializer;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.FullTextIndexerRunnable;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.HibernateSearchContext;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.IndexMode;
/**
* Utility methods around database indexing with <i>Hibernate</i>.
*
* @author Christian Ribeaud
*/
public final class IndexCreationUtil
{
private static final String LUCENE_INDICES = "sourceTest/lucene/indices";
static
{
LogInitializer.init();
// Deactivate the indexing in the application context loaded by Spring.
System.setProperty("hibernate.search.index-mode", "NO_INDEX");
System.setProperty("hibernate.search.index-base", LUCENE_INDICES);
}
private static HibernateSearchContext hibernateSearchContext;
private static BeanFactory beanFactory;
private IndexCreationUtil()
{
// Can not be instantiated.
}
private final static BeanFactory getBeanFactory()
{
if (beanFactory == null)
{
final AbstractApplicationContext applicationContext =
new ClassPathXmlApplicationContext(new String[]
{ "applicationContext.xml" }, true);
IndexCreationUtil.beanFactory = applicationContext;
}
return beanFactory;
}
/**
* Performs a full text index because the test database has been migrated.
*/
private final static void performFullTextIndex() throws Exception
{
final BeanFactory factory = getBeanFactory();
final FullTextIndexerRunnable fullTextIndexer =
new FullTextIndexerRunnable((SessionFactory) factory
.getBean("hibernate-session-factory"), hibernateSearchContext);
fullTextIndexer.run();
}
/**
* Creates a freshly new {@link HibernateSearchContext} overriding the one loaded by <i>Spring</i>.
*/
private final static HibernateSearchContext createHibernateSearchContext()
{
final HibernateSearchContext context = new HibernateSearchContext();
context.setIndexBase(LUCENE_INDICES);
context.setIndexMode(IndexMode.INDEX_FROM_SCRATCH);
return context;
}
//
// Main method
//
public static void main(final String[] args) throws Exception
{
if (args.length != 1)
{
System.out.println("Usage: java " + DatabaseCreationUtil.class.getName()
+ "<database kind>");
System.exit(1);
}
System.setProperty("database.kind", args[0]);
hibernateSearchContext = createHibernateSearchContext();
hibernateSearchContext.afterPropertiesSet();
performFullTextIndex();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment