1 package org.objectstyle.cayenne.modeler; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 6 import org.objectstyle.cayenne.dba.db2.DB2Adapter; 7 import org.objectstyle.cayenne.dba.derby.DerbyAdapter; 8 import org.objectstyle.cayenne.dba.firebird.FirebirdAdapter; 9 import org.objectstyle.cayenne.dba.hsqldb.HSQLDBAdapter; 10 import org.objectstyle.cayenne.dba.mysql.MySQLAdapter; 11 import org.objectstyle.cayenne.dba.openbase.OpenBaseAdapter; 12 import org.objectstyle.cayenne.dba.oracle.OracleAdapter; 13 import org.objectstyle.cayenne.dba.postgres.PostgresAdapter; 14 import org.objectstyle.cayenne.dba.sqlserver.SQLServerAdapter; 15 import org.objectstyle.cayenne.dba.sybase.SybaseAdapter; 16 17 22 public class AdapterMapping { 23 24 protected Map adapterToJDBCDriverMap; 25 protected Map adapterToJDBCURLMap; 26 protected Map jdbcDriverToAdapterMap; 27 protected Map eofPluginToAdapterMap; 28 29 public AdapterMapping() { 30 this.adapterToJDBCDriverMap = new HashMap (); 31 this.adapterToJDBCURLMap = new HashMap (); 32 this.jdbcDriverToAdapterMap = new HashMap (); 33 this.eofPluginToAdapterMap = new HashMap (); 34 35 initDefaults(); 36 } 37 38 protected void initDefaults() { 39 41 jdbcDriverToAdapterMap.put("oracle.jdbc.driver.OracleDriver", OracleAdapter.class 43 .getName()); 44 jdbcDriverToAdapterMap.put("com.sybase.jdbc2.jdbc.SybDriver", SybaseAdapter.class 45 .getName()); 46 jdbcDriverToAdapterMap.put("com.mysql.jdbc.Driver", MySQLAdapter.class.getName()); 47 jdbcDriverToAdapterMap.put("com.ibm.db2.jcc.DB2Driver", DB2Adapter.class 48 .getName()); 49 jdbcDriverToAdapterMap 50 .put("org.hsqldb.jdbcDriver", HSQLDBAdapter.class.getName()); 51 jdbcDriverToAdapterMap.put("org.postgresql.Driver", PostgresAdapter.class 52 .getName()); 53 jdbcDriverToAdapterMap.put("org.firebirdsql.jdbc.FBDriver", FirebirdAdapter.class 54 .getName()); 55 jdbcDriverToAdapterMap.put("com.openbase.jdbc.ObDriver", OpenBaseAdapter.class 56 .getName()); 57 jdbcDriverToAdapterMap.put("com.microsoft.jdbc.sqlserver.SQLServerDriver", 58 SQLServerAdapter.class.getName()); 59 jdbcDriverToAdapterMap.put("org.apache.derby.jdbc.EmbeddedDriver", 60 DerbyAdapter.class.getName()); 61 62 adapterToJDBCURLMap.put(OracleAdapter.class.getName(), 64 "jdbc:oracle:thin:@host:1521:database"); 65 adapterToJDBCURLMap.put(SybaseAdapter.class.getName(), 66 "jdbc:sybase:Tds:host:port/database"); 67 adapterToJDBCURLMap.put(MySQLAdapter.class.getName(), 68 "jdbc:mysql://host/database"); 69 adapterToJDBCURLMap.put(DB2Adapter.class.getName(), 70 "jdbc:db2://host:port/database"); 71 adapterToJDBCURLMap.put(HSQLDBAdapter.class.getName(), 72 "jdbc:hsqldb:hsql://host/database"); 73 adapterToJDBCURLMap.put(PostgresAdapter.class.getName(), 74 "jdbc:postgresql://host:5432/database"); 75 adapterToJDBCURLMap.put(FirebirdAdapter.class.getName(), 76 "jdbc:firebirdsql:host/port:/path/to/file.gdb"); 77 adapterToJDBCURLMap.put(OpenBaseAdapter.class.getName(), 78 "jdbc:openbase://host/database"); 79 adapterToJDBCURLMap 80 .put(SQLServerAdapter.class.getName(), 81 "jdbc:microsoft:sqlserver://host;databaseName=database;SelectMethod=cursor"); 82 83 adapterToJDBCURLMap.put(DerbyAdapter.class.getName(), 85 "jdbc:derby:testdb;create=true"); 86 87 adapterToJDBCDriverMap.put(OracleAdapter.class.getName(), 89 "oracle.jdbc.driver.OracleDriver"); 90 adapterToJDBCDriverMap.put(SybaseAdapter.class.getName(), 91 "com.sybase.jdbc2.jdbc.SybDriver"); 92 adapterToJDBCDriverMap.put(MySQLAdapter.class.getName(), "com.mysql.jdbc.Driver"); 93 adapterToJDBCDriverMap.put(DB2Adapter.class.getName(), 94 "com.ibm.db2.jcc.DB2Driver"); 95 adapterToJDBCDriverMap 96 .put(HSQLDBAdapter.class.getName(), "org.hsqldb.jdbcDriver"); 97 adapterToJDBCDriverMap.put(PostgresAdapter.class.getName(), 98 "org.postgresql.Driver"); 99 adapterToJDBCDriverMap.put(FirebirdAdapter.class.getName(), 100 "org.firebirdsql.jdbc.FBDriver"); 101 adapterToJDBCDriverMap.put(OpenBaseAdapter.class.getName(), 102 "com.openbase.jdbc.ObDriver"); 103 adapterToJDBCDriverMap.put(SQLServerAdapter.class.getName(), 104 "com.microsoft.jdbc.sqlserver.SQLServerDriver"); 105 adapterToJDBCDriverMap.put(DerbyAdapter.class.getName(), 106 "org.apache.derby.jdbc.EmbeddedDriver"); 107 108 eofPluginToAdapterMap.put("com.webobjects.jdbcadaptor.SybasePlugIn", 110 SybaseAdapter.class.getName()); 111 eofPluginToAdapterMap.put("com.webobjects.jdbcadaptor.MerantPlugIn", 112 SQLServerAdapter.class.getName()); 113 eofPluginToAdapterMap.put("com.webobjects.jdbcadaptor.MicrosoftPlugIn", 114 SQLServerAdapter.class.getName()); 115 eofPluginToAdapterMap.put("com.webobjects.jdbcadaptor.MySQLPlugIn", 116 MySQLAdapter.class.getName()); 117 eofPluginToAdapterMap.put("com.webobjects.jdbcadaptor.OraclePlugIn", 118 OracleAdapter.class.getName()); 119 eofPluginToAdapterMap.put("PostgresqlPlugIn", PostgresAdapter.class.getName()); 120 } 121 122 public String jdbcURLForAdapter(String adapterClass) { 123 return (String ) adapterToJDBCURLMap.get(adapterClass); 124 } 125 126 public String jdbcDriverForAdapter(String adapterClass) { 127 return (String ) adapterToJDBCDriverMap.get(adapterClass); 128 } 129 130 public String adapterForJDBCDriver(String driverClass) { 131 return (String ) jdbcDriverToAdapterMap.get(driverClass); 132 } 133 134 public String adapterForEOFPlugin(String eofPlugin) { 135 return (String ) eofPluginToAdapterMap.get(eofPlugin); 136 } 137 138 public String adapterForEOFPluginOrDriver(String eofPlugin, String jdbcDriver) { 139 String adapter = adapterForEOFPlugin(eofPlugin); 140 return (adapter != null) ? adapter : adapterForJDBCDriver(jdbcDriver); 141 } 142 } | Popular Tags |