Permalink
Browse files

Merge pull request #7 from robintaylor/master

[DS-1156] Refactor Browse related code out of InitializeDatabase into InitializeBrowseDatabase
  • Loading branch information...
2 parents 14f9066 + 3d4f40f commit 67558c447a3d8cee65bc72123add9fffb90135ec @robintaylor robintaylor committed May 3, 2012
@@ -0,0 +1,80 @@
+/**
+ * The contents of this file are subject to the license and copyright
+ * detailed in the LICENSE and NOTICE files at the root of the source
+ * tree and available online at
+ *
+ * http://www.dspace.org/license/
+ */
+package org.dspace.browse;
+
+import org.apache.log4j.Logger;
+import org.dspace.core.ConfigurationManager;
+
+/**
+ * Command-line executed class for initializing the Browse tables of the DSpace database.
+ *
+ * @author Robert Tansley
+ * @version $Revision$
+ */
+public class InitializeBrowseDatabase
+{
+ /** log4j category */
+ private static Logger log = Logger.getLogger(InitializeBrowseDatabase.class);
+
+ public static void main(String[] argv)
+ {
+
+ // Usage checks
+ if (argv.length != 1)
+ {
+ log.warn("Schema file not specified");
+ System.exit(1);
+ }
+
+ ConfigurationManager.loadConfig(null);
+ log.info("Initializing Browse Database");
+
+ try
+ {
+ if("clean-database.sql".equals(argv[0]))
+ {
+ try
+ {
+ IndexBrowse browse = new IndexBrowse();
+ browse.setDelete(true);
+ browse.setExecute(true);
+ browse.clearDatabase();
+ }
+ catch (BrowseException e)
+ {
+ log.error(e.getMessage(),e);
+ throw new IllegalStateException(e.getMessage(),e);
+ }
+ }
+ else
+ {
+ try
+ {
+ IndexBrowse browse = new IndexBrowse();
+ browse.setRebuild(true);
+ browse.setExecute(true);
+ browse.initBrowse();
+ }
+ catch (BrowseException e)
+ {
+ log.error(e.getMessage(),e);
+ throw new IllegalStateException(e.getMessage(),e);
+ }
+ }
+
+ System.exit(0);
+ }
+ catch (Exception e)
+ {
+ log.fatal("Caught exception:", e);
+ System.exit(1);
+ }
+ }
+
+
+}
@@ -13,8 +13,6 @@
import java.io.IOException;
import org.apache.log4j.Logger;
-import org.dspace.browse.BrowseException;
-import org.dspace.browse.IndexBrowse;
import org.dspace.core.ConfigurationManager;
/**
@@ -46,39 +44,11 @@ public static void main(String[] argv)
{
if("clean-database.sql".equals(argv[0]))
{
- try
- {
- IndexBrowse browse = new IndexBrowse();
- browse.setDelete(true);
- browse.setExecute(true);
- browse.clearDatabase();
- }
- catch (BrowseException e)
- {
- log.error(e.getMessage(),e);
- throw new IllegalStateException(e.getMessage(),e);
- }
-
- DatabaseManager.loadSql(getScript(argv[0]));
-
+ DatabaseManager.loadSql(getScript(argv[0]));
}
else
{
-
- DatabaseManager.loadSql(getScript(argv[0]));
-
- try
- {
- IndexBrowse browse = new IndexBrowse();
- browse.setRebuild(true);
- browse.setExecute(true);
- browse.initBrowse();
- }
- catch (BrowseException e)
- {
- log.error(e.getMessage(),e);
- throw new IllegalStateException(e.getMessage(),e);
- }
+ DatabaseManager.loadSql(getScript(argv[0]));
}
System.exit(0);
@@ -787,12 +787,13 @@ Common usage:
</java>
<!-- Add the browse tables -->
- <java classname="org.dspace.browse.IndexBrowse" classpathref="class.path" fork="yes" failonerror="yes">
+ <java classname="org.dspace.browse.InitializeBrowseDatabase" classpathref="class.path" fork="yes" failonerror="yes">
<sysproperty key="log4j.configuration" value="file:config/log4j-console.properties" />
<sysproperty key="dspace.log.init.disable" value="true" />
<sysproperty key="dspace.configuration" value="${config}" />
- <arg line="-t -x" />
+ <arg value="database_schema.sql" />
</java>
+
</target>
@@ -805,6 +806,13 @@ Common usage:
- properties -->
<target name="clean_database" description="Removes DSpace database tables, destroying data">
+ <java classname="org.dspace.browse.InitializeBrowseDatabase" classpathref="class.path" fork="yes" failonerror="yes">
+ <sysproperty key="log4j.configuration" value="file:config/log4j-console.properties" />
+ <sysproperty key="dspace.log.init.disable" value="true" />
+ <sysproperty key="dspace.configuration" value="${config}" />
+ <arg value="clean-database.sql" />
+ </java>
+
<java classname="org.dspace.storage.rdbms.InitializeDatabase" classpathref="class.path" fork="yes" failonerror="yes">
<sysproperty key="log4j.configuration" value="file:config/log4j-console.properties" />
<sysproperty key="dspace.log.init.disable" value="true" />

0 comments on commit 67558c4

Please sign in to comment.