Return-Path: Delivered-To: apmail-incubator-connectors-commits-archive@minotaur.apache.org Received: (qmail 68110 invoked from network); 27 May 2010 13:21:13 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 27 May 2010 13:21:13 -0000 Received: (qmail 94221 invoked by uid 500); 27 May 2010 13:21:13 -0000 Delivered-To: apmail-incubator-connectors-commits-archive@incubator.apache.org Received: (qmail 94189 invoked by uid 500); 27 May 2010 13:21:13 -0000 Mailing-List: contact connectors-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: connectors-dev@incubator.apache.org Delivered-To: mailing list connectors-commits@incubator.apache.org Received: (qmail 94182 invoked by uid 99); 27 May 2010 13:21:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 May 2010 13:21:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED,T_FILL_THIS_FORM_SHORT X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 May 2010 13:21:10 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 88F3C23889B3; Thu, 27 May 2010 13:20:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r948822 - in /incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core: interfaces/DBInterfaceFactory.java system/LCF.java Date: Thu, 27 May 2010 13:20:48 -0000 To: connectors-commits@incubator.apache.org From: kwright@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100527132048.88F3C23889B3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 */