1 21 22 package org.apache.derby.jdbc; 23 24 import org.apache.derby.iapi.reference.Attribute; 25 import org.apache.derby.iapi.reference.MessageId; 26 import org.apache.derby.iapi.reference.Property; 27 import org.apache.derby.iapi.reference.SQLState; 28 29 import org.apache.derby.impl.jdbc.EmbedConnection; 30 31 import org.apache.derby.iapi.services.sanity.SanityManager; 32 import org.apache.derby.iapi.error.StandardException; 33 import org.apache.derby.iapi.sql.ResultSet; 34 import org.apache.derby.iapi.jdbc.BrokeredConnection; 35 import org.apache.derby.iapi.jdbc.BrokeredConnectionControl; 36 import org.apache.derby.iapi.services.i18n.MessageService; 37 import org.apache.derby.iapi.services.monitor.Monitor; 38 import org.apache.derby.iapi.services.io.FormatableProperties; 39 40 import org.apache.derby.impl.jdbc.*; 41 42 import java.sql.Connection ; 43 import java.sql.SQLException ; 44 import java.sql.Driver ; 45 import java.sql.DriverManager ; 46 import java.sql.DriverPropertyInfo ; 47 48 import java.util.Properties ; 49 50 56 57 public class Driver20 extends InternalDriver implements Driver { 58 59 private static final String [] BOOLEAN_CHOICES = {"false", "true"}; 60 61 private Class antiGCDriverManager; 62 63 66 67 public void boot(boolean create, Properties properties) throws StandardException { 68 69 super.boot(create, properties); 70 71 AutoloadedDriver.registerDriverModule( this ); 73 74 antiGCDriverManager = java.sql.DriverManager .class; 77 } 78 79 public void stop() { 80 81 super.stop(); 82 83 AutoloadedDriver.unregisterDriverModule(); 84 } 85 86 94 public Connection getNewNestedConnection(EmbedConnection conn) 95 { 96 return new EmbedConnection(conn); 97 } 98 99 103 public EmbedConnection getNewEmbedConnection(String url, Properties info) 104 throws SQLException 105 { 106 return new EmbedConnection(this, url, info); 108 } 109 110 113 public java.sql.PreparedStatement 114 newEmbedPreparedStatement (EmbedConnection conn, 115 String stmt, 116 boolean forMetaData, 117 int resultSetType, 118 int resultSetConcurrency, 119 int resultSetHoldability, 120 int autoGeneratedKeys, 121 int[] columnIndexes, 122 String [] columnNames) 123 throws SQLException 124 { 125 return new EmbedPreparedStatement20(conn, stmt, forMetaData, 126 resultSetType, resultSetConcurrency, resultSetHoldability, 127 autoGeneratedKeys, columnIndexes, columnNames); 128 } 129 130 133 public java.sql.CallableStatement newEmbedCallableStatement( 134 EmbedConnection conn, 135 String stmt, 136 int resultSetType, 137 int resultSetConcurrency, 138 int resultSetHoldability) 139 throws SQLException 140 { 141 return new EmbedCallableStatement20(conn, stmt, 142 resultSetType, resultSetConcurrency, resultSetHoldability); 143 } 144 145 public org.apache.derby.impl.jdbc.EmbedResultSet 146 newEmbedResultSet(EmbedConnection conn, ResultSet results, boolean forMetaData, org.apache.derby.impl.jdbc.EmbedStatement statement, boolean isAtomic) 147 throws SQLException 148 { 149 return new EmbedResultSet20(conn, results, forMetaData, statement, 150 isAtomic); 151 } 152 public BrokeredConnection newBrokeredConnection(BrokeredConnectionControl control) { 153 154 return new BrokeredConnection(control); 155 } 156 172 public DriverPropertyInfo [] getPropertyInfo(String url, Properties info) throws SQLException { 173 174 176 if (info != null) { 177 if (Boolean.valueOf(info.getProperty(Attribute.SHUTDOWN_ATTR)).booleanValue()) { 178 179 return new DriverPropertyInfo [0]; 181 } 182 } 183 184 186 String dbname = InternalDriver.getDatabaseName(url, info); 187 188 FormatableProperties finfo = getAttributes(url, info); 191 info = null; boolean encryptDB = Boolean.valueOf(finfo.getProperty(Attribute.DATA_ENCRYPTION)).booleanValue(); 193 String encryptpassword = finfo.getProperty(Attribute.BOOT_PASSWORD); 194 195 if (dbname.length() == 0 || (encryptDB = true && encryptpassword == null)) { 196 197 199 203 String [][] connStringAttributes = { 204 {Attribute.DBNAME_ATTR, MessageId.CONN_DATABASE_IDENTITY}, 205 {Attribute.CRYPTO_PROVIDER, MessageId.CONN_CRYPTO_PROVIDER}, 206 {Attribute.CRYPTO_ALGORITHM, MessageId.CONN_CRYPTO_ALGORITHM}, 207 {Attribute.CRYPTO_KEY_LENGTH, MessageId.CONN_CRYPTO_KEY_LENGTH}, 208 {Attribute.CRYPTO_EXTERNAL_KEY, MessageId.CONN_CRYPTO_EXTERNAL_KEY}, 209 {Attribute.TERRITORY, MessageId.CONN_LOCALE}, 210 {Attribute.USERNAME_ATTR, MessageId.CONN_USERNAME_ATTR}, 211 {Attribute.LOG_DEVICE, MessageId.CONN_LOG_DEVICE}, 212 {Attribute.ROLL_FORWARD_RECOVERY_FROM, MessageId.CONN_ROLL_FORWARD_RECOVERY_FROM}, 213 {Attribute.CREATE_FROM, MessageId.CONN_CREATE_FROM}, 214 {Attribute.RESTORE_FROM, MessageId.CONN_RESTORE_FROM}, 215 }; 216 217 String [][] connBooleanAttributes = { 218 {Attribute.SHUTDOWN_ATTR, MessageId.CONN_SHUT_DOWN_CLOUDSCAPE}, 219 {Attribute.CREATE_ATTR, MessageId.CONN_CREATE_DATABASE}, 220 {Attribute.DATA_ENCRYPTION, MessageId.CONN_DATA_ENCRYPTION}, 221 {Attribute.UPGRADE_ATTR, MessageId.CONN_UPGRADE_DATABASE}, 222 }; 223 224 String [][] connStringSecretAttributes = { 225 {Attribute.BOOT_PASSWORD, MessageId.CONN_BOOT_PASSWORD}, 226 {Attribute.PASSWORD_ATTR, MessageId.CONN_PASSWORD_ATTR}, 227 }; 228 229 230 DriverPropertyInfo [] optionsNoDB = new DriverPropertyInfo [connStringAttributes.length+ 231 connBooleanAttributes.length+ 232 connStringSecretAttributes.length]; 233 234 int attrIndex = 0; 235 for( int i = 0; i < connStringAttributes.length; i++, attrIndex++ ) 236 { 237 optionsNoDB[attrIndex] = new DriverPropertyInfo (connStringAttributes[i][0], 238 finfo.getProperty(connStringAttributes[i][0])); 239 optionsNoDB[attrIndex].description = MessageService.getTextMessage(connStringAttributes[i][1]); 240 } 241 242 optionsNoDB[0].choices = Monitor.getMonitor().getServiceList(Property.DATABASE_MODULE); 243 optionsNoDB[0].value = dbname; 246 247 for( int i = 0; i < connStringSecretAttributes.length; i++, attrIndex++ ) 248 { 249 optionsNoDB[attrIndex] = new DriverPropertyInfo (connStringSecretAttributes[i][0], 250 (finfo.getProperty(connStringSecretAttributes[i][0]) == null? "" : "****")); 251 optionsNoDB[attrIndex].description = MessageService.getTextMessage(connStringSecretAttributes[i][1]); 252 } 253 254 for( int i = 0; i < connBooleanAttributes.length; i++, attrIndex++ ) 255 { 256 optionsNoDB[attrIndex] = new DriverPropertyInfo (connBooleanAttributes[i][0], 257 Boolean.valueOf(finfo == null? "" : finfo.getProperty(connBooleanAttributes[i][0])).toString()); 258 optionsNoDB[attrIndex].description = MessageService.getTextMessage(connBooleanAttributes[i][1]); 259 optionsNoDB[attrIndex].choices = BOOLEAN_CHOICES; 260 } 261 262 return optionsNoDB; 263 } 264 265 return new DriverPropertyInfo [0]; 266 } 267 } 268 | Popular Tags |