1 4 package org.hibernate.eclipse.console.utils; 5 6 import java.util.ArrayList ; 7 import java.util.Collections ; 8 import java.util.HashMap ; 9 import java.util.HashSet ; 10 import java.util.List ; 11 import java.util.Map ; 12 import java.util.Set ; 13 14 17 public class DriverClassHelpers { 18 19 private Map dialectNames = new HashMap (); 20 private Map connectionUrls = new HashMap (); 21 private Map driverClasses = new HashMap (); 22 23 public DriverClassHelpers() { 24 dialectNames.put("DB2", "org.hibernate.dialect.DB2Dialect"); 26 dialectNames.put("DB2390", "org.hibernate.dialect.DB2390Dialect"); 27 dialectNames.put("DB2400", "org.hibernate.dialect.DB2400Dialect"); 28 dialectNames.put("Derby", "org.hibernate.dialect.DerbyDialect"); 29 dialectNames.put("FrontBase", "org.hibernate.dialect.FrontbaseDialect"); 30 dialectNames.put("Generic", "org.hibernate.dialect.GenericDialect"); 31 dialectNames.put("HSQL", "org.hibernate.dialect.HSQLDialect"); 32 dialectNames.put("Informix", "org.hibernate.dialect.InformixDialect"); 33 dialectNames.put("Ingres", "org.hibernate.dialect.IngresDialect"); 34 dialectNames.put("Interbase", "org.hibernate.dialect.InterbaseDialect"); 35 dialectNames.put("Firebird", "org.hibernate.dialect.FirebirdDialect"); 36 dialectNames.put("Mckoi SQL", "org.hibernate.dialect.MckoiDialect"); 37 dialectNames.put("MySQL", "org.hibernate.dialect.MySQLDialect"); 38 dialectNames.put("MySQLInnoDB", "org.hibernate.dialect.MySQLInnoDBDialect"); 39 dialectNames.put("MySQLISAMDB", "org.hibernate.dialect.MySQLISAMDBDialect"); 40 dialectNames.put("Oracle9", "org.hibernate.dialect.Oracle9Dialect"); 41 dialectNames.put("Oracle","org.hibernate.dialect.OracleDialect"); 42 dialectNames.put("Pointbase", "org.hibernate.dialect.PointbaseDialect"); 43 dialectNames.put("PostgreSQL", "org.hibernate.dialect.PostgreSQLDialect"); 44 dialectNames.put("Postgress", "org.hibernate.dialect.PostgressDialect"); 45 dialectNames.put("SAP DB", "org.hibernate.dialect.SAPDBDialect"); 46 dialectNames.put("Sybase", "org.hibernate.dialect.SybaseDialect"); 47 dialectNames.put("Sybase11", "org.hibernate.dialect.Sybase11Dialect"); 48 dialectNames.put("SybaseAnywhere", "org.hibernate.dialect.SybaseAnywhereDialect"); 49 dialectNames.put("SQLServer", "org.hibernate.dialect.SQLServerDialect"); 50 51 addDriverAndURLS("org.hibernate.dialect.HSQLDialect", 52 "org.hsqldb.jdbcDriver", 53 new String [] { 54 "jdbc:hsqldb:hsql://<host>", 55 "jdbc:hsqldb:<dbname>", 56 "jdbc:hsqldb:." } 57 ); 58 59 addDriverAndURLS("org.hibernate.dialect.OracleDialect", 60 "oracle.jdbc.driver.OracleDriver", 61 new String [] { 62 "jdbc:oracle:thin:@localhost:1521:orcl", 63 "jdbc:oracle:thin:@<host>:<port1521>:<sid>" } 64 ); 65 66 addDriverAndURLS("org.hibernate.dialect.Oracle9Dialect", 67 "oracle.jdbc.driver.OracleDriver", 68 new String [] { 69 "jdbc:oracle:thin:@localhost:1521:orcl", 70 "jdbc:oracle:thin:@<host>:<port1521>:<sid>" } 71 ); 72 73 addDriverAndURLS("org.hibernate.dialect.MySQLDialect", 74 "org.gjt.mm.mysql.Driver", 75 new String [] { 76 "jdbc:mysql://<hostname>/<database>", 77 "jdbc:mysql:///test", 78 "jdbc:mysql:///<name>", 79 } 80 ); 81 82 addDriverAndURLS("org.hibernate.dialect.MySQLInnoDBDialect", 83 "org.gjt.mm.mysql.Driver", 84 new String [] { 85 "jdbc:mysql://<hostname>/<database>", 86 "jdbc:mysql:///test", 87 "jdbc:mysql:///<name>" } 88 ); 89 90 91 addDriverAndURLS("org.hibernate.dialect.MySQLMyISAMDBDialect", 92 "org.gjt.mm.mysql.Driver", 93 new String [] { 94 "jdbc:mysql://<hostname>/<database>", 95 "jdbc:mysql:///test", 96 "jdbc:mysql:///<name>" } 97 ); 98 99 addDriverAndURLS("org.hibernate.dialect.PostgreSQLDialect", 100 "org.postgresql.Driver", 101 new String [] { 102 "jdbc:postgresql:template1", 103 "jdbc:postgresql:<name>" } 104 ); 105 106 addDriverAndURLS("org.hibernate.dialect.DB2Dialect", "COM.ibm.db2.jdbc.app.DB2Driver", 107 new String [] { "jdbc:db2:test", "jdbc:db2:<name>" }); 108 109 addDriverAndURLS("org.hibernate.dialect.DB2400Dialect", "COM.ibm.db2.jdbc.app.DB2Driver", 110 new String [] { "jdbc:as400://<systemname>", "jdbc:db2:<name>" }); 111 112 addDriverAndURLS("org.hibernate.dialect.DerbyDialect", "org.apache.derby.jdbc.EmbeddedDriver", 113 new String [] { "jdbc:derby:/test;create=true" }); 114 115 addDriverAndURLS("org.hibernate.dialect.SybaseDialect", "com.sybase.jdbc2.jdbc.SybDriver", 116 new String [] { "jdbc:sybase:Tds:co3061835-a:5000/tempdb" }); 117 118 addDriverAndURLS("org.hibernate.dialect.MckoiDialect", "com.mckoi.JDBCDriver", 119 new String [] { "jdbc:mckoi:///", "jdbc:mckoi:local://C:/mckoi1.00/db.conf" }); 120 121 addDriverAndURLS("org.hibernate.dialect.SAPDBDialect", "com.sap.dbtech.jdbc.DriverSapDB", 122 new String [] { "jdbc:sapdb://localhost/TST" }); 123 124 addDriverAndURLS("org.hibernate.dialect.SQLServerDialect", "com.jnetdirect.jsql.JSQLDriver", 125 new String [] { "jdbc:JSQLConnect://1E1/test" }); 126 127 addDriverAndURLS("org.hibernate.dialect.SQLServerDialect", "com.newatlanta.jturbo.driver.Driver", 128 new String [] { "jdbc:JTurbo://1E1:1433/test" }); 129 130 addDriverAndURLS("org.hibernate.dialect.SQLServerDialect", "weblogic.jdbc.mssqlserver4.Driver", 131 new String [] { "jdbc:weblogic:mssqlserver4:1E1:1433" }); 132 133 addDriverAndURLS("org.hibernate.dialect.SQLServerDialect", "com.microsoft.jdbc.sqlserver.SQLServerDriver", 134 new String [] { "jdbc:microsoft:sqlserver://1E1;DatabaseName=test;SelectMethod=cursor" }); 135 136 addDriverAndURLS("org.hibernate.dialect.SQLServerDialect", "net.sourceforge.jtds.jdbc.Driver", 137 new String [] { "jdbc:jtds:sqlserver://1E1/test" }); 138 139 addDriverAndURLS("org.hibernate.dialect.InterbaseDialect", "interbase.interclient.Driver", 140 new String [] { "jdbc:interbase://localhost:3060/C:/firebird/test.gdb" }); 141 142 addDriverAndURLS("org.hibernate.dialect.InterbaseDialect", "org.firebirdsql.jdbc.FBDriver", 143 new String [] { "jdbc:interbase://localhost:3060/C:/firebird/test.gdb" }); 144 145 addDriverAndURLS("org.hibernate.dialect.PointbaseDialect", "com.pointbase.jdbc.jdbcUniversalDriver", 146 new String [] { "jdbc:pointbase:embedded:sample" }); 147 } 148 149 153 private void addDriverAndURLS(String dialect, String driverclass, String [] urls) { 154 add(driverClasses, dialect, driverclass); 155 for (int i = 0; i < urls.length; i++) { 156 String url = urls[i]; 157 add(connectionUrls, driverclass, url); 158 } 159 } 160 161 166 private void add(Map map, String key, String value) { 167 Set existing = (Set ) map.get(key); 168 if(existing==null) { 169 existing = new HashSet (); 170 map.put(key,existing); 171 } 172 existing.add(value); 173 } 174 175 public String [] getDialectNames() { 176 List list = new ArrayList (dialectNames.keySet()); 177 Collections.sort(list); 178 return (String []) list.toArray(new String [list.size()]); 179 } 180 181 186 public String getDialectClass(String dialectName) { 187 if(dialectNames.containsKey(dialectName)) { 188 return (String ) dialectNames.get(dialectName); 189 } else { 190 return dialectName; 191 } 192 } 193 194 public String [] getDriverClasses(String dialectName) { 195 Set result = (Set ) (driverClasses.get(dialectName)); 196 if(result!=null) { 197 return (String []) result.toArray(new String [result.size()]); 198 } else { 199 return new String [0]; 200 } 201 } 202 203 public String [] getConnectionURLS(String driverclass) { 204 Set result = (Set ) (connectionUrls.get(driverclass)); 205 if(result!=null) { 206 return (String []) result.toArray(new String [result.size()]); 207 } else { 208 return new String [0]; 209 } 210 } 211 } 212 | Popular Tags |