X-Git-Url: http://secure.phpeclipse.com diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/adapters/AdapterFactory.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/adapters/AdapterFactory.java index 909198c..90effd8 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/adapters/AdapterFactory.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/adapters/AdapterFactory.java @@ -2,14 +2,22 @@ package net.sourceforge.phpdt.sql.adapters; import java.util.ArrayList; +import net.sourceforge.phpdt.sql.Messages; + +/** + * @author root + * Basically this Factory is a Singleton that is used to return the proper adapter + */ public class AdapterFactory { - public static final String GENERIC = "GENERIC"; - public static final String ORACLE = "ORACLE"; - public static final String POSTGRES = "POSTGRES"; - public static final String MYSQL = "MYSQL"; - public static final String DB2 = "DB2"; - public static final String DB2AS400 = "DB2AS400"; - public static final String ADABASD = "ADABASD"; + public static final String GENERIC = "GENERIC"; //$NON-NLS-1$ + public static final String ORACLE = "ORACLE"; //$NON-NLS-1$ + public static final String POSTGRES = "POSTGRES"; //$NON-NLS-1$ + public static final String MYSQL = "MYSQL"; //$NON-NLS-1$ + public static final String DB2 = "DB2"; //$NON-NLS-1$ + public static final String DB2AS400 = "DB2AS400"; //$NON-NLS-1$ + public static final String ADABASD = "ADABASD"; //$NON-NLS-1$ + public static final String INFORMIX = "INFORMIX"; //$NON-NLS-1$ + public static final String REDBRICK = "REDBRICK"; //$NON-NLS-1$ private static AdapterFactory instance; @@ -31,13 +39,15 @@ public class AdapterFactory { private void loadDrivers() { drivers = new ArrayList(); - DriverInfo generic = new DriverInfo(GENERIC, Messages.getString("adapters.generic"), new GenericAdapter()); - DriverInfo oracle = new DriverInfo(ORACLE, Messages.getString("adapters.oracle"), new OracleAdapter()); - DriverInfo db2 = new DriverInfo(DB2, Messages.getString("adapters.db2"), new DB2Adapter()); - DriverInfo db2as400 = new DriverInfo(DB2AS400, Messages.getString("adapters.db2as400"), new DB2AS400Adapter()); - DriverInfo postgres = new DriverInfo(POSTGRES, Messages.getString("adapters.postgres"), new PostgresAdapter()); - DriverInfo mysql = new DriverInfo(MYSQL, Messages.getString("adapters.mysql"), new MySQLAdapter()); - DriverInfo adabasd = new DriverInfo(ADABASD, Messages.getString("adapters.adabasd"), new AdabasDAdapter()); + DriverInfo generic = new DriverInfo(GENERIC, Messages.getString("adapters.generic"), new GenericAdapter()); //$NON-NLS-1$ + DriverInfo oracle = new DriverInfo(ORACLE, Messages.getString("adapters.oracle"), new OracleAdapter()); //$NON-NLS-1$ + DriverInfo db2 = new DriverInfo(DB2, Messages.getString("adapters.db2"), new DB2Adapter()); //$NON-NLS-1$ + DriverInfo db2as400 = new DriverInfo(DB2AS400, Messages.getString("adapters.db2as400"), new DB2AS400Adapter()); //$NON-NLS-1$ + DriverInfo postgres = new DriverInfo(POSTGRES, Messages.getString("adapters.postgres"), new PostgresAdapter()); //$NON-NLS-1$ + DriverInfo mysql = new DriverInfo(MYSQL, Messages.getString("adapters.mysql"), new MySQLAdapter()); //$NON-NLS-1$ + DriverInfo adabasd = new DriverInfo(ADABASD, Messages.getString("adapters.adabasd"), new AdabasDAdapter()); //$NON-NLS-1$ + DriverInfo informix = new DriverInfo(INFORMIX, Messages.getString("adapters.informix"), new GenericAdapter()); //$NON-NLS-1$ + DriverInfo redbrick = new DriverInfo(REDBRICK, Messages.getString("adapters.redbrick"), new RedBrickAdapter()); //$NON-NLS-1$ drivers.add(generic); drivers.add(oracle); @@ -46,19 +56,28 @@ public class AdapterFactory { drivers.add(postgres); drivers.add(mysql); drivers.add(adabasd); + drivers.add(informix); + drivers.add(redbrick); } - public synchronized DatabaseAdapter getAdapter(String type) throws NoSuchAdapterException { + public synchronized DatabaseAdapter getAdapter(String type){ if (drivers == null) { loadDrivers(); } for (int i = 0; i < drivers.size(); i++) { DriverInfo info = (DriverInfo) drivers.get(i); if (type.equals(info.getDriverType())) { - return info.getAdapter().getInstance(); + return info.getAdapter(); } } - throw new NoSuchAdapterException(type); + // If its not a recognized driver, we return the generic one + for (int i = 0; i < drivers.size(); i++) { + DriverInfo info = (DriverInfo) drivers.get(i); + if (type.equals(GENERIC)) { + return info.getAdapter(); + } + } + return null; } public synchronized DriverInfo[] getDriverList() {