1 33 34 package com.internetcds.jdbc.tds; 35 36 37 38 public class Constructors 39 { 40 public static final String cvsVersion = "$Id: Constructors.java,v 1.1 2006/06/23 10:39:04 sinisa Exp $"; 41 42 static boolean dejavu = false; 43 44 static final int JDBC2_0 = 2; 45 static final int JDBC1_0 = 1; 46 47 private static int jdbcVersion = JDBC1_0; 48 private static String jdbcVersionName = null; 49 50 private static java.lang.reflect.Constructor resultSetCtor = null; 51 private static java.lang.reflect.Constructor preparedStatementCtor = null; 52 private static java.lang.reflect.Constructor callableStatementCtor = null; 53 private static java.lang.reflect.Constructor connectionCtor = null; 54 55 56 static private java.lang.reflect.Constructor getCtor( 57 String classNamePrefix, 58 Class paramTypes[]) 59 throws java.lang.ClassNotFoundException , java.lang.NoSuchMethodException 60 { 61 java.lang.reflect.Constructor result = null; 62 String className = null; 63 Class theClass = null; 64 65 className = (classNamePrefix + "_" + jdbcVersionName); 66 theClass = java.lang.Class.forName(className); 67 68 result = theClass.getConstructor(paramTypes); 69 70 return result; 71 } 72 73 74 static private void init() 75 throws java.sql.SQLException 76 { 77 try 78 { 79 Class resultSetParamTypes[] = 80 { 81 java.lang.Class.forName("com.internetcds.jdbc.tds.Tds"), 82 java.lang.Class.forName("com.internetcds.jdbc.tds.Statement"), 83 java.lang.Class.forName("com.internetcds.jdbc.tds.Columns") 84 }; 85 Class preparedStatementParamTypes[] = 86 { 87 java.lang.Class.forName("java.sql.Connection"), 88 java.lang.Class.forName("com.internetcds.jdbc.tds.Tds"), 89 java.lang.Class.forName("java.lang.String") 90 }; 91 Class callableStatementParamTypes[] = 92 { 93 java.lang.Class.forName("java.sql.Connection"), 94 java.lang.Class.forName("com.internetcds.jdbc.tds.Tds"), 95 java.lang.Class.forName("java.lang.String") 96 }; 97 Class connectionParamTypes[] = 98 { 99 java.lang.Class.forName("java.util.Properties") 100 }; 101 102 103 try 104 { 105 Class statement = java.lang.Class.forName("java.sql.Statement"); 106 java.lang.reflect.Method execBatch = 107 statement.getDeclaredMethod("executeBatch", new Class [0]); 108 109 jdbcVersion = JDBC2_0; 110 jdbcVersionName = "2_0"; 111 } 112 catch (NoSuchMethodException nsme) 113 { 114 jdbcVersion = JDBC1_0; 115 jdbcVersionName = "1_0"; 116 } 117 118 try 119 { 120 resultSetCtor = getCtor("com.internetcds.jdbc.tds.ResultSet", 121 resultSetParamTypes); 122 preparedStatementCtor = getCtor("com.internetcds.jdbc.tds.PreparedStatement", 123 preparedStatementParamTypes); 124 callableStatementCtor = getCtor("com.internetcds.jdbc.tds.CallableStatement", 125 callableStatementParamTypes); 126 connectionCtor = getCtor("com.internetcds.jdbc.tds.Connection", 127 connectionParamTypes); 128 } 129 catch(java.lang.ClassNotFoundException e) 130 { 131 if (jdbcVersion == JDBC2_0) 132 { 133 jdbcVersion = JDBC1_0; 138 jdbcVersionName = "1_0"; 139 resultSetCtor = getCtor("com.internetcds.jdbc.tds.ResultSet", 140 resultSetParamTypes); 141 preparedStatementCtor = getCtor("com.internetcds.jdbc.tds.PreparedStatement", 142 preparedStatementParamTypes); 143 callableStatementCtor = getCtor("com.internetcds.jdbc.tds.CallableStatement", 144 callableStatementParamTypes); 145 connectionCtor = getCtor("com.internetcds.jdbc.tds.Connection", 146 connectionParamTypes); 147 } 148 } 149 } 150 catch(java.lang.ClassNotFoundException e) 151 { 152 System.err.println("Couldn't find the class"); throw new java.sql.SQLException (e.getMessage()); 154 } 155 catch(java.lang.NoSuchMethodException e) 156 { 157 System.err.println("Couldn't find a constructor"); 158 throw new java.sql.SQLException (e.getMessage()); 159 } 160 161 dejavu = true; 162 } 163 164 165 166 public static java.sql.ResultSet newResultSet( 167 Tds tds_, 168 java.sql.Statement stmt_, 169 Columns columns_) throws java.sql.SQLException 170 { 171 if (!dejavu) 172 { 173 init(); 174 } 175 176 java.sql.ResultSet result = null; 177 try 178 { 179 Object params[] = {tds_, stmt_, columns_}; 180 181 result = (java.sql.ResultSet )resultSetCtor.newInstance(params); 182 } 183 catch (java.lang.reflect.InvocationTargetException e) 184 { 185 throw new java.sql.SQLException (e.getTargetException().getMessage()); 186 } 187 catch (Throwable e) 188 { 189 e.printStackTrace(); 190 throw new java.sql.SQLException (e.getMessage()); 191 } 192 return result; 193 } 194 195 public static java.sql.CallableStatement newCallableStatement( 196 Object cx_, 197 com.internetcds.jdbc.tds.Tds tds_, 198 java.lang.String sql_) throws java.sql.SQLException 199 { 200 if (!dejavu) 201 { 202 init(); 203 } 204 205 try 206 { 207 Object params[] = {cx_, tds_, sql_}; 208 209 return (java.sql.CallableStatement )callableStatementCtor.newInstance(params); 210 } 211 catch (java.lang.reflect.InvocationTargetException e) 212 { 213 throw new java.sql.SQLException (e.getTargetException().getMessage()); 214 } 215 catch (Throwable e) 216 { 217 throw new java.sql.SQLException (e.getMessage()); 218 } 219 } 220 221 222 public static java.sql.PreparedStatement newPreparedStatement( 223 Object cx_, 224 com.internetcds.jdbc.tds.Tds tds_, 225 java.lang.String sql_) throws java.sql.SQLException 226 { 227 if (!dejavu) 228 { 229 init(); 230 } 231 232 try 233 { 234 Object params[] = {cx_, tds_, sql_}; 235 236 return (java.sql.PreparedStatement )preparedStatementCtor.newInstance(params); 237 } 238 catch (java.lang.reflect.InvocationTargetException e) 239 { 240 throw new java.sql.SQLException (e.getTargetException().getMessage()); 241 } 242 catch (Throwable e) 243 { 244 throw new java.sql.SQLException (e.getMessage()); 245 } 246 } 247 248 249 public static java.sql.Connection newConnection( 250 java.util.Properties props_) 251 throws java.sql.SQLException , com.internetcds.jdbc.tds.TdsException 252 { 253 if (!dejavu) 254 { 255 init(); 256 } 257 258 try 259 { 260 Object params[] = 261 { 262 props_, 263 }; 264 265 return (java.sql.Connection )connectionCtor.newInstance(params); 266 } 267 catch (java.lang.reflect.InvocationTargetException e) 268 { 269 throw new java.sql.SQLException (e.getTargetException().getMessage()); 270 } 271 catch (Throwable e) 272 { 273 throw new java.sql.SQLException (e.getMessage()); 274 } 275 } 276 277 } 278 279 | Popular Tags |