You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2010/05/27 15:20:48 UTC
svn commit: r948822 - in
/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core:
interfaces/DBInterfaceFactory.java system/LCF.java
Author: kwright
Date: Thu May 27 13:20:48 2010
New Revision: 948822
URL: http://svn.apache.org/viewvc?rev=948822&view=rev
Log:
Make database implementation be controllable by a configuration parameter.
Modified:
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/DBInterfaceFactory.java
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/system/LCF.java
Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/DBInterfaceFactory.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/DBInterfaceFactory.java?rev=948822&r1=948821&r2=948822&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/DBInterfaceFactory.java (original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/DBInterfaceFactory.java Thu May 27 13:20:48 2010
@@ -18,6 +18,9 @@
*/
package org.apache.lcf.core.interfaces;
+import org.apache.lcf.core.system.LCF;
+import java.lang.reflect.*;
+
/** This is the factory class for an IDBInterface.
*/
public class DBInterfaceFactory
@@ -37,10 +40,46 @@ public class DBInterfaceFactory
Object x = context.get(dbName);
if (x == null || !(x instanceof IDBInterface))
{
- // Create new database handle
- // x = new org.apache.lcf.core.database.DBInterfaceMySQL(context,databaseName,userName,password);
- x = new org.apache.lcf.core.database.DBInterfacePostgreSQL(context,databaseName,userName,password);
- context.save(dbName,x);
+ String implementationClass = LCF.getProperty(LCF.databaseImplementation);
+ if (implementationClass == null)
+ implementationClass = "org.apache.lcf.core.database.DBInterfacePostgreSQL";
+ try
+ {
+ Class c = Class.forName(implementationClass);
+ Constructor constructor = c.getConstructor(new Class[]{IThreadContext.class,String.class,String.class,String.class});
+ x = constructor.newInstance(new Object[]{context,databaseName,userName,password});
+ if (!(x instanceof IDBInterface))
+ throw new LCFException("Database implementation class "+implementationClass+" does not implement IDBInterface",LCFException.SETUP_ERROR);
+ context.save(dbName,x);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new LCFException("Database implementation class "+implementationClass+" could not be found: "+e.getMessage(),e,LCFException.SETUP_ERROR);
+ }
+ catch (ExceptionInInitializerError e)
+ {
+ throw new LCFException("Database implementation class "+implementationClass+" could not be instantiated: "+e.getMessage(),e,LCFException.SETUP_ERROR);
+ }
+ catch (LinkageError e)
+ {
+ throw new LCFException("Database implementation class "+implementationClass+" could not be linked: "+e.getMessage(),e,LCFException.SETUP_ERROR);
+ }
+ catch (InstantiationException e)
+ {
+ throw new LCFException("Database implementation class "+implementationClass+" could not be instantiated: "+e.getMessage(),e,LCFException.SETUP_ERROR);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new LCFException("Database implementation class "+implementationClass+" could not be instantiated: "+e.getMessage(),e,LCFException.SETUP_ERROR);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new LCFException("Database implementation class "+implementationClass+" had no constructor taking (IThreadContext, String, String, String): "+e.getMessage(),e,LCFException.SETUP_ERROR);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new LCFException("Database implementation class "+implementationClass+" had no public constructor taking (IThreadContext, String, String, String): "+e.getMessage(),e,LCFException.SETUP_ERROR);
+ }
}
return (IDBInterface)x;
Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/system/LCF.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/system/LCF.java?rev=948822&r1=948821&r2=948822&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/system/LCF.java (original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/system/LCF.java Thu May 27 13:20:48 2010
@@ -86,6 +86,8 @@ public class LCF
// Implementation class properties
/** Lock manager implementation class */
public static final String lockManagerImplementation = "org.apache.lcf.lockmanagerclass";
+ /** Database implementation class */
+ public static final String databaseImplementation = "org.apache.lcf.databaseimplementationclass";
// The following are system integration properties
/** Script to invoke when configuration changes, if any */