KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectstyle > cayenne > modeler > AdapterMapping


1 package org.objectstyle.cayenne.modeler;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
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 /**
18  * Contains mappings for guessing defaults for various adapter and JDBC settings.
19  *
20  * @author Andrei Adamchik
21  */

22 public class AdapterMapping {
23
24     protected Map JavaDoc adapterToJDBCDriverMap;
25     protected Map JavaDoc adapterToJDBCURLMap;
26     protected Map JavaDoc jdbcDriverToAdapterMap;
27     protected Map JavaDoc eofPluginToAdapterMap;
28
29     public AdapterMapping() {
30         this.adapterToJDBCDriverMap = new HashMap JavaDoc();
31         this.adapterToJDBCURLMap = new HashMap JavaDoc();
32         this.jdbcDriverToAdapterMap = new HashMap JavaDoc();
33         this.eofPluginToAdapterMap = new HashMap JavaDoc();
34
35         initDefaults();
36     }
37
38     protected void initDefaults() {
39         // TODO: make configuration external...
40

41         // drivers
42
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         // urls
63
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         // TODO: embedded Derby Mode... change to client-server once we figure it out
84
adapterToJDBCURLMap.put(DerbyAdapter.class.getName(),
85                 "jdbc:derby:testdb;create=true");
86
87         // adapters
88
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         // EOF plugins...
109
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 JavaDoc jdbcURLForAdapter(String JavaDoc adapterClass) {
123         return (String JavaDoc) adapterToJDBCURLMap.get(adapterClass);
124     }
125
126     public String JavaDoc jdbcDriverForAdapter(String JavaDoc adapterClass) {
127         return (String JavaDoc) adapterToJDBCDriverMap.get(adapterClass);
128     }
129
130     public String JavaDoc adapterForJDBCDriver(String JavaDoc driverClass) {
131         return (String JavaDoc) jdbcDriverToAdapterMap.get(driverClass);
132     }
133
134     public String JavaDoc adapterForEOFPlugin(String JavaDoc eofPlugin) {
135         return (String JavaDoc) eofPluginToAdapterMap.get(eofPlugin);
136     }
137
138     public String JavaDoc adapterForEOFPluginOrDriver(String JavaDoc eofPlugin, String JavaDoc jdbcDriver) {
139         String JavaDoc adapter = adapterForEOFPlugin(eofPlugin);
140         return (adapter != null) ? adapter : adapterForJDBCDriver(jdbcDriver);
141     }
142 }
Popular Tags