Adding in new phpeclipse-projectSet_1.2.x.psf for svn export.
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / adapters / AdapterFactory.java
index 37f05c4..bd05994 100644 (file)
@@ -31,6 +31,26 @@ public class AdapterFactory {
                }
        }
        
+       static class DriverInfo {
+               private final String type;
+               private final String urlPattern;
+
+               DriverInfo(String type) {
+                       this(type, null);
+               }
+               DriverInfo(String type, String urlPattern) {
+                       this.type = type;
+                       this.urlPattern = urlPattern;
+                       
+               }
+               public String getType() {
+                       return this.type;
+               }
+               public String getURLPattern() {
+                       return this.urlPattern;
+               }
+       }
+       
        public static final String GENERIC = "GENERIC"; //$NON-NLS-1$
        public static final String HSQLDB = "HSQLDB"; //$NON-NLS-1$
     public static final String ORACLE = "ORACLE"; //$NON-NLS-1$
@@ -43,33 +63,45 @@ public class AdapterFactory {
        public static final String REDBRICK = "REDBRICK"; //$NON-NLS-1$
        public static final String POINTBASE = "POINTBASE"; //$NON-NLS-1$
     public static final String SYBASE = "SYBASE"; //$NON-NLS-1$
+    public static final String JDBC_ODBC_BRIDGE = "JDBC_ODBC_BRIDGE"; //$NON-NLS-1$
+    public static final String MS_SQL_SERVER = "MS_SQL_SERVER"; //$NON-NLS-1$
+    public static final String DERBY = "DERBY"; //$NON-NLS-1$
 
        private static final Map DRIVER_MAP = Collections.synchronizedMap(new HashMap());
        
        static {
-               DRIVER_MAP.put("com.ddtek.jdbc.informix.InformixDriver", AdapterFactory.INFORMIX);
-               DRIVER_MAP.put("com.ddtek.jdbc.db2.DB2Driver", AdapterFactory.DB2);
-               DRIVER_MAP.put("com.ddtek.jdbc.oracle.OracleDriver", AdapterFactory.ORACLE);
-               DRIVER_MAP.put("com.ddtek.jdbc.sqlserver.SQLServerDriver", AdapterFactory.GENERIC);
-               DRIVER_MAP.put("com.ddtek.jdbc.sybase.SybaseDriver", AdapterFactory.SYBASE);
-               DRIVER_MAP.put("com.ibm.as400.access.AS400JDBCDriver", AdapterFactory.DB2AS400);
-               DRIVER_MAP.put("COM.ibm.db2.jdbc.app.DB2Driver", AdapterFactory.DB2);
-               DRIVER_MAP.put("COM.ibm.db2.jdbc.net.DB2Driver", AdapterFactory.DB2);
-               DRIVER_MAP.put("com.inet.ora.OraDriver", AdapterFactory.ORACLE);
-               DRIVER_MAP.put("com.inet.drda.DRDADriver", AdapterFactory.DB2);
-               DRIVER_MAP.put("com.inet.syb.SybDriver", AdapterFactory.SYBASE);
-               DRIVER_MAP.put("com.inet.tds.TdsDriver", AdapterFactory.GENERIC);
-               DRIVER_MAP.put("com.informix.jdbc.IfxDriver", AdapterFactory.INFORMIX);
-               DRIVER_MAP.put("com.microsoft.jdbc.sqlserver.SQLServerDriver", AdapterFactory.GENERIC);
-               DRIVER_MAP.put("com.mysql.jdbc.Driver", AdapterFactory.MYSQL);
-               DRIVER_MAP.put("com.pointbase.jdbc.jdbcUniversalDriver", AdapterFactory.POINTBASE);
-               DRIVER_MAP.put("com.sybase.jdbcx.SybDriver", AdapterFactory.SYBASE);
-               DRIVER_MAP.put("oracle.jdbc.driver.OracleDriver", AdapterFactory.ORACLE);
-               DRIVER_MAP.put("org.gjt.mm.mysql.Driver", AdapterFactory.MYSQL);
-               DRIVER_MAP.put("org.hsqldb.jdbcDriver", AdapterFactory.HSQLDB);
-               DRIVER_MAP.put("org.postgresql.Driver", AdapterFactory.POSTGRES);
-               DRIVER_MAP.put("weblogic.jdbc.informix.InformixDriver", AdapterFactory.INFORMIX);
-               DRIVER_MAP.put("weblogic.jdbc.sqlserver.SybaseDriver", AdapterFactory.SYBASE);
+               DRIVER_MAP.put("com.ddtek.jdbc.informix.InformixDriver", new DriverInfo(INFORMIX));
+               DRIVER_MAP.put("com.ddtek.jdbc.db2.DB2Driver", new DriverInfo(DB2, "jdbc:datadirect:db2://${hostname}:${port};DatabaseName=${dbname}"));
+               DRIVER_MAP.put("com.ddtek.jdbc.oracle.OracleDriver", new DriverInfo(ORACLE ,"jdbc:oracle:thin:@{hostname}:{port}:{dbname}"));
+               DRIVER_MAP.put("com.ddtek.jdbc.sqlserver.SQLServerDriver", new DriverInfo(GENERIC));
+               DRIVER_MAP.put("com.ddtek.jdbc.sybase.SybaseDriver", new DriverInfo(SYBASE));
+               DRIVER_MAP.put("com.ibm.as400.access.AS400JDBCDriver", new DriverInfo(DB2AS400));
+               DRIVER_MAP.put("COM.ibm.db2.jdbc.app.DB2Driver", new DriverInfo(DB2, "jdbc:db2:{dbname}"));
+               DRIVER_MAP.put("COM.ibm.db2.jdbc.net.DB2Driver", new DriverInfo(DB2, "jdbc:db2://{hostname}:{port}/{dbname}"));
+               DRIVER_MAP.put("com.inet.ora.OraDriver", new DriverInfo(ORACLE ,"jdbc:oracle:thin:@{hostname}:{port}:{dbname}"));
+               DRIVER_MAP.put("com.inet.drda.DRDADriver", new DriverInfo(DB2, "jdbc:inetdb2:{hostname}:{port}?database={dbname}"));
+               DRIVER_MAP.put("com.inet.syb.SybDriver", new DriverInfo(SYBASE));
+               DRIVER_MAP.put("com.inet.tds.TdsDriver", new DriverInfo(MS_SQL_SERVER));
+               DRIVER_MAP.put("com.informix.jdbc.IfxDriver", new DriverInfo(INFORMIX, "jdbc:informix-sqli://{hostname}:{port}/{dbname}:INFORMIXSERVER={informixserver}"));
+               DRIVER_MAP.put("com.microsoft.jdbc.sqlserver.SQLServerDriver", new DriverInfo(MS_SQL_SERVER));
+               DRIVER_MAP.put("com.mysql.jdbc.Driver", new DriverInfo(MYSQL, "jdbc:mysql://{hostname}:{port}/{dbname}"));
+               DRIVER_MAP.put("com.pointbase.jdbc.jdbcUniversalDriver", new DriverInfo(POINTBASE, "jdbc:pointbase:server://{hostname}:{port}/{dbname}"));
+               DRIVER_MAP.put("com.sybase.jdbc.SybDriver", new DriverInfo(SYBASE, "jdbc:sybase:Tds:{hostname}:{port}/{dbname}"));
+               DRIVER_MAP.put("com.sybase.jdbc2.jdbc.SybDriver", new DriverInfo(SYBASE, "jdbc:sybase:Tds:{hostname}:{port}/{dbname}"));
+               DRIVER_MAP.put("com.sybase.jdbcx.SybDriver", new DriverInfo(SYBASE, "jdbc:sybase:Tds:{hostname}:{port}/{dbname}"));
+               DRIVER_MAP.put("net.sourceforge.jtds.jdbc.Driver", new DriverInfo(MS_SQL_SERVER));
+               DRIVER_MAP.put("oracle.jdbc.driver.OracleDriver", new DriverInfo(ORACLE ,"jdbc:oracle:thin:@{hostname}:{port}:{dbname}"));
+               DRIVER_MAP.put("oracle.jdbc.OracleDriver", new DriverInfo(ORACLE ,"jdbc:oracle:thin:@{hostname}:{port}:{dbname}"));
+               DRIVER_MAP.put("org.gjt.mm.mysql.Driver", new DriverInfo(MYSQL, "jdbc:mysql://{hostname}:{port}/{dbname}"));
+               DRIVER_MAP.put("org.hsqldb.jdbcDriver", new DriverInfo(HSQLDB));
+               DRIVER_MAP.put("org.postgresql.Driver", new DriverInfo(POSTGRES, "jdbc:postgresql://{hostname}:{port}/{dbname}"));
+               DRIVER_MAP.put("sun.jdbc.odbc.JdbcOdbcDriver", new DriverInfo(JDBC_ODBC_BRIDGE, "jdbc:odbc:{datasource}"));
+               DRIVER_MAP.put("weblogic.jdbc.informix.InformixDriver", new DriverInfo(INFORMIX));
+               DRIVER_MAP.put("weblogic.jdbc.sqlserver.SybaseDriver", new DriverInfo(SYBASE));
+               DRIVER_MAP.put("org.apache.derby.jdbc.driver20", new DriverInfo(DERBY, "jdbc:derby:{dbname}"));
+               DRIVER_MAP.put("org.apache.derby.jdbc.driver30", new DriverInfo(DERBY, "jdbc:derby:{dbname}"));
+               DRIVER_MAP.put("org.apache.derby.jdbc.EmbeddedDriver", new DriverInfo(DERBY, "jdbc:derby:{dbname}"));
+               
        }
        
     private static AdapterFactory instance;
@@ -83,12 +115,15 @@ public class AdapterFactory {
        addAdapter(new DB2Adapter());
        addAdapter(new DB2AS400Adapter());
        addAdapter(new PostgresAdapter());
-       addAdapter(new GenericAdapter(MYSQL));
+       addAdapter(new MySQLAdapter());
        addAdapter(new AdabasDAdapter());
-       addAdapter(new GenericAdapter(INFORMIX));
+       addAdapter(new InformixAdapter());
        addAdapter(new RedBrickAdapter());
        addAdapter(new GenericAdapter(SYBASE));
        addAdapter(new GenericAdapter(POINTBASE));
+       addAdapter(new GenericAdapter(JDBC_ODBC_BRIDGE));
+       addAdapter(new MSSQLServerAdapter());
+       addAdapter(new GenericAdapter(DERBY));
     }
     private void addAdapter(DatabaseAdapter adapter) {
        this.adapters.put(adapter.getType(), adapter);
@@ -121,6 +156,15 @@ public class AdapterFactory {
      * @return the adapter type, or null if the adapter type is not known
      */
     public String getAdapterType(String driverClassName) {
-       return (String) DRIVER_MAP.get(driverClassName);
+       DriverInfo driverInfo = (DriverInfo) DRIVER_MAP.get(driverClassName);
+               return driverInfo == null ? null : driverInfo.getType();
     }
+       /**
+        * @param type
+        * @return
+        */
+       public String getURLPattern(String driverClassName) {
+       DriverInfo driverInfo = (DriverInfo) DRIVER_MAP.get(driverClassName);
+               return driverInfo == null ? null : driverInfo.getURLPattern();
+       }
 }
\ No newline at end of file