1 23 24 package org.xquark.jdbc.typing; 25 26 import java.net.URL ; 27 import java.sql.Connection ; 28 import java.sql.DatabaseMetaData ; 29 import java.sql.SQLException ; 30 import java.util.HashMap ; 31 import java.util.Map ; 32 33 34 39 public class DBMSInfoMap implements DBMSConstants 40 { 41 private static final String RCSRevision = "$Revision: 1.1 $"; 42 private static final String RCSName = "$Name: $"; 43 44 private static String RESOURCES_FOLDER = "resources/"; 48 49 private static DBMSInfoLoader dbInfoLoader; 53 private static Map dbmsInfos; 54 55 static 56 { 57 dbInfoLoader = new DBMSInfoLoader(); 58 dbmsInfos = new HashMap (); 59 } 60 61 private DBMSInfoMap() {} 62 63 public static synchronized DBMSInfo getDBMSInfo(short DBMS) 67 { 68 Short key = new Short (DBMS); 69 DBMSInfo ret = (DBMSInfo) dbmsInfos.get(key); 70 if (ret == null) 71 { 72 String filename; 73 switch (DBMS) 74 { 75 case ORACLE8I : case ORACLE8 : case ORACLE : 76 filename = ORACLE_FILE; 77 break; 78 case TIMESTEN40 : case TIMESTEN : 79 filename = TIMESTEN_FILE; 80 break; 81 case SYBASE_ASE_11_9 : case SYBASE : 82 filename = SYBASE_FILE; 83 break; 84 case SQL_SERVER_2000 : case SQL_SERVER : 85 filename = SQL_SERVER_FILE; 86 break; 87 case MYSQL : case MYSQL323 : 88 filename = MYSQL_FILE; 89 break; 90 default : 91 throw new RuntimeException ("Your RDBMS is not supported in the current version of XQuark products (basing on your JDBC driver informations)."); 92 } 93 URL specsURL = DBMSInfoMap.class.getResource(RESOURCES_FOLDER + filename); 94 ret = (DBMSInfo) dbInfoLoader.fromXML(specsURL.toString()); 95 ret.setDbms(DBMS); 96 dbmsInfos.put(key, ret); 97 } 98 return ret; 99 } 100 101 public static synchronized DBMSInfo getDBMSInfo(Connection conn) throws SQLException 102 { 103 return getDBMSInfo(getDatabaseVendor(conn)); 104 } 105 106 108 public static short getDatabaseVendor(Connection conn) throws SQLException 109 { 110 short databaseVendor = -1; 111 DatabaseMetaData dbmeta = conn.getMetaData(); 112 String productName = dbmeta.getDatabaseProductName(); 113 String version = dbmeta.getDatabaseProductVersion(); 114 115 if (productName.equalsIgnoreCase("TimesTen")) { 117 if (version.startsWith("04.00")) 118 databaseVendor = TIMESTEN40; 119 else 120 databaseVendor = TIMESTEN; 121 } 122 else if (productName.equalsIgnoreCase("Oracle")) { 124 if (version.startsWith("Oracle8i") || version.startsWith("Personal Oracle8i")) 125 databaseVendor = ORACLE8I; 126 else if (version.startsWith("Oracle8")) 127 databaseVendor = ORACLE8; 128 else 129 databaseVendor = ORACLE; 130 } 131 else if (productName.equalsIgnoreCase("MYSQL")) { 133 if (version.startsWith("3.23")) 134 databaseVendor = MYSQL323; 135 else 136 databaseVendor = MYSQL; 137 } 138 else if (productName.equalsIgnoreCase("Adaptive Server Enterprise")) { 140 if (version.startsWith("Adaptive Server Enterprise/11.9")) 141 databaseVendor = SYBASE_ASE_11_9; 142 else 143 databaseVendor = SYBASE; 144 } 145 else if (productName.equalsIgnoreCase("Microsoft SQL Server")) 146 { 147 if (version.indexOf("2000") >= 0) 148 databaseVendor = SQL_SERVER_2000; 149 else 150 databaseVendor = SQL_SERVER; 151 } 152 else if (isJDBC2(conn)) 153 databaseVendor = JDBC2; 154 else 155 databaseVendor = JDBC1; 156 return databaseVendor; 157 } 158 159 private static boolean isJDBC2(Connection conn) throws SQLException 160 { 161 try { 162 conn.getTypeMap(); 163 } 164 catch (AbstractMethodError e) { 165 return false; 166 } 167 return true; 168 } 169 } 170 | Popular Tags |