1 21 22 package org.apache.derby.impl.sql.conn; 23 24 import org.apache.derby.iapi.reference.JDBC20Translation; 25 import org.apache.derby.iapi.reference.JDBC30Translation; 26 27 import org.apache.derby.iapi.sql.conn.LanguageConnectionFactory; 28 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 29 import org.apache.derby.iapi.sql.compile.CompilerContext; 30 31 import org.apache.derby.iapi.sql.LanguageFactory; 32 import org.apache.derby.impl.sql.GenericStatement; 33 34 import org.apache.derby.impl.sql.conn.CachedStatement; 35 36 import org.apache.derby.iapi.services.uuid.UUIDFactory; 37 import org.apache.derby.iapi.services.compiler.JavaFactory; 38 import org.apache.derby.iapi.services.loader.ClassFactory; 39 40 import org.apache.derby.iapi.db.Database; 41 42 import org.apache.derby.iapi.store.access.TransactionController; 43 44 import org.apache.derby.iapi.sql.compile.TypeCompilerFactory; 45 46 import org.apache.derby.iapi.error.StandardException; 47 48 import org.apache.derby.iapi.sql.compile.NodeFactory; 49 import org.apache.derby.iapi.sql.compile.Parser; 50 51 import org.apache.derby.iapi.sql.Activation; 52 53 import org.apache.derby.iapi.store.access.AccessFactory; 54 import org.apache.derby.iapi.services.property.PropertyFactory; 55 56 import org.apache.derby.iapi.sql.Statement; 57 import org.apache.derby.iapi.sql.compile.OptimizerFactory; 58 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 59 import org.apache.derby.iapi.types.DataValueFactory; 60 import org.apache.derby.iapi.sql.execute.ExecutionFactory; 61 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 62 63 import org.apache.derby.iapi.services.sanity.SanityManager; 64 65 import org.apache.derby.iapi.services.monitor.Monitor; 66 import org.apache.derby.iapi.services.monitor.ModuleControl; 67 import org.apache.derby.iapi.services.monitor.ModuleSupportable; 68 import org.apache.derby.iapi.services.monitor.ModuleFactory; 69 import org.apache.derby.iapi.services.context.ContextManager; 70 71 import org.apache.derby.iapi.services.cache.CacheFactory; 72 import org.apache.derby.iapi.services.cache.CacheManager; 73 import org.apache.derby.iapi.services.cache.CacheableFactory; 74 import org.apache.derby.iapi.services.cache.Cacheable; 75 76 import org.apache.derby.iapi.services.property.PropertyUtil; 77 import org.apache.derby.iapi.services.property.PropertySetCallback; 78 79 import org.apache.derby.iapi.services.i18n.LocaleFinder; 80 import org.apache.derby.iapi.reference.SQLState; 81 import org.apache.derby.iapi.reference.Property; 82 import org.apache.derby.iapi.reference.EngineType; 83 84 import java.util.Properties ; 85 import java.util.Locale ; 86 import java.util.Dictionary ; 87 import java.io.Serializable ; 88 import org.apache.derby.iapi.util.IdUtil; 89 import org.apache.derby.iapi.services.daemon.Serviceable; 90 import org.apache.derby.iapi.util.StringUtil; 91 92 99 public class GenericLanguageConnectionFactory 100 implements LanguageConnectionFactory, CacheableFactory, PropertySetCallback, ModuleControl, ModuleSupportable { 101 102 105 protected DataDictionary dd; 106 private ExecutionFactory ef; 107 private OptimizerFactory of; 108 private TypeCompilerFactory tcf; 109 private DataValueFactory dvf; 110 private UUIDFactory uuidFactory; 111 private JavaFactory javaFactory; 112 private ClassFactory classFactory; 113 private NodeFactory nodeFactory; 114 private AccessFactory af; 115 private PropertyFactory pf; 116 117 private int nextLCCInstanceNumber; 118 119 122 private int cacheSize = org.apache.derby.iapi.reference.Property.STATEMENT_CACHE_SIZE_DEFAULT; 123 private CacheManager singleStatementCache; 124 125 128 public GenericLanguageConnectionFactory() { 129 } 130 131 134 135 138 139 146 public Statement getStatement(SchemaDescriptor compilationSchema, String statementText, boolean forReadOnly) 147 { 148 return new GenericStatement(compilationSchema, statementText, forReadOnly); 149 } 150 151 152 164 165 public LanguageConnectionContext newLanguageConnectionContext( 166 ContextManager cm, 167 TransactionController tc, 168 LanguageFactory lf, 169 Database db, 170 String userName, 171 String drdaID, 172 String dbname) throws StandardException { 173 174 pushDataDictionaryContext(cm); 175 176 return new GenericLanguageConnectionContext(cm, 177 tc, 178 lf, 179 this, 180 db, 181 userName, 182 getNextLCCInstanceNumber(), 183 drdaID, 184 dbname); 185 } 186 187 public Cacheable newCacheable(CacheManager cm) { 188 return new CachedStatement(); 189 } 190 191 194 195 200 public UUIDFactory getUUIDFactory() 201 { 202 return uuidFactory; 203 } 204 205 208 public ClassFactory getClassFactory() 209 { 210 return classFactory; 211 } 212 213 218 public JavaFactory getJavaFactory() 219 { 220 return javaFactory; 221 } 222 223 227 public NodeFactory getNodeFactory() 228 { 229 return nodeFactory; 230 } 231 232 235 public ExecutionFactory getExecutionFactory() { 236 return ef; 237 } 238 239 242 public AccessFactory getAccessFactory() 243 { 244 return af; 245 } 246 247 250 public PropertyFactory getPropertyFactory() 251 { 252 return pf; 253 } 254 255 258 public OptimizerFactory getOptimizerFactory() { 259 return of; 260 } 261 264 public TypeCompilerFactory getTypeCompilerFactory() { 265 return tcf; 266 } 267 268 271 public DataValueFactory getDataValueFactory() { 272 return dvf; 273 } 274 275 protected void pushDataDictionaryContext(ContextManager cm) { 276 dd.pushDataDictionaryContext(cm); 278 } 279 280 283 284 287 public boolean canSupport(Properties startParams) { 288 289 return Monitor.isDesiredType( startParams, EngineType.STANDALONE_DB); 290 } 291 292 private int statementCacheSize(Properties startParams) 293 { 294 String wantCacheProperty = null; 295 296 wantCacheProperty = 297 PropertyUtil.getPropertyFromSet(startParams, org.apache.derby.iapi.reference.Property.STATEMENT_CACHE_SIZE); 298 299 if (SanityManager.DEBUG) 300 SanityManager.DEBUG("StatementCacheInfo", "Cacheing implementation chosen if null or 0<"+wantCacheProperty); 301 302 if (wantCacheProperty != null) { 303 try { 304 cacheSize = Integer.parseInt(wantCacheProperty); 305 } catch (NumberFormatException nfe) { 306 cacheSize = org.apache.derby.iapi.reference.Property.STATEMENT_CACHE_SIZE_DEFAULT; 307 } 308 } 309 310 return cacheSize; 311 } 312 313 321 public void boot(boolean create, Properties startParams) 322 throws StandardException { 323 324 dvf = (DataValueFactory) Monitor.bootServiceModule(create, this, org.apache.derby.iapi.reference.ClassName.DataValueFactory, startParams); 325 javaFactory = (JavaFactory) Monitor.startSystemModule(org.apache.derby.iapi.reference.Module.JavaFactory); 326 uuidFactory = Monitor.getMonitor().getUUIDFactory(); 327 classFactory = (ClassFactory) Monitor.getServiceModule(this, org.apache.derby.iapi.reference.Module.ClassFactory); 328 if (classFactory == null) 329 classFactory = (ClassFactory) Monitor.findSystemModule(org.apache.derby.iapi.reference.Module.ClassFactory); 330 331 bootDataDictionary(create, startParams); 332 333 setValidation(); 336 337 setStore(); 338 339 ef = (ExecutionFactory) Monitor.bootServiceModule(create, this, ExecutionFactory.MODULE, startParams); 340 of = (OptimizerFactory) Monitor.bootServiceModule(create, this, OptimizerFactory.MODULE, startParams); 341 tcf = 342 (TypeCompilerFactory) Monitor.startSystemModule(TypeCompilerFactory.MODULE); 343 nodeFactory = (NodeFactory) Monitor.bootServiceModule(create, this, NodeFactory.MODULE, startParams); 344 345 int cacheSize = statementCacheSize(startParams); 347 if (cacheSize > 0) { 348 CacheFactory cacheFactory = (CacheFactory) Monitor.startSystemModule(org.apache.derby.iapi.reference.Module.CacheFactory); 349 singleStatementCache = cacheFactory.newCacheManager(this, 350 "StatementCache", 351 cacheSize/4, 352 cacheSize); 353 } 354 355 } 356 357 protected void bootDataDictionary(boolean create, Properties startParams) throws StandardException { 358 dd = (DataDictionary) Monitor.bootServiceModule(create, this, DataDictionary.MODULE, startParams); 359 } 360 361 365 366 367 public CacheManager getStatementCache() 368 { 369 return singleStatementCache; 370 } 371 372 375 public void stop() { 376 } 377 378 381 382 public void init(boolean dbOnly, Dictionary p) { 383 } 385 386 390 public boolean validate(String key, 391 Serializable value, 392 Dictionary p) 393 throws StandardException { 394 if (value == null) 395 return true; 396 else if (key.equals(Property.DEFAULT_CONNECTION_MODE_PROPERTY)) 397 { 398 String value_s = (String )value; 399 if (value_s != null && 400 !StringUtil.SQLEqualsIgnoreCase(value_s, Property.NO_ACCESS) && 401 !StringUtil.SQLEqualsIgnoreCase(value_s, Property.READ_ONLY_ACCESS) && 402 !StringUtil.SQLEqualsIgnoreCase(value_s, Property.FULL_ACCESS)) 403 throw StandardException.newException(SQLState.AUTH_INVALID_AUTHORIZATION_PROPERTY, key, value_s); 404 405 return true; 406 } 407 else if (key.equals(Property.READ_ONLY_ACCESS_USERS_PROPERTY) || 408 key.equals(Property.FULL_ACCESS_USERS_PROPERTY)) 409 { 410 String value_s = (String )value; 411 412 413 String [] newList_a; 414 try {newList_a = IdUtil.parseIdList(value_s);} 415 catch (StandardException se) { 416 throw StandardException.newException(SQLState.AUTH_INVALID_AUTHORIZATION_PROPERTY, se, key,value_s); 417 } 418 419 420 String dups = IdUtil.dups(newList_a); 421 if (dups != null) throw StandardException.newException(SQLState.AUTH_DUPLICATE_USERS, key,dups); 422 423 424 String [] otherList_a; 425 String otherList; 426 if (key.equals(Property.READ_ONLY_ACCESS_USERS_PROPERTY)) 427 otherList = (String )p.get(Property.FULL_ACCESS_USERS_PROPERTY); 428 else 429 otherList = (String )p.get(Property.READ_ONLY_ACCESS_USERS_PROPERTY); 430 otherList_a = IdUtil.parseIdList(otherList); 431 String both = IdUtil.intersect(newList_a,otherList_a); 432 if (both != null) throw StandardException.newException(SQLState.AUTH_USER_IN_READ_AND_WRITE_LISTS, both); 433 434 return true; 435 } 436 437 return false; 438 } 439 440 public Serviceable apply(String key, 441 Serializable value, 442 Dictionary p) 443 { 444 return null; 445 } 446 447 public Serializable map(String key, Serializable value, Dictionary p) 448 { 449 return null; 450 } 451 452 protected void setValidation() throws StandardException { 453 pf = (PropertyFactory) Monitor.findServiceModule(this, 454 org.apache.derby.iapi.reference.Module.PropertyFactory); 455 pf.addPropertySetNotification(this); 456 } 457 458 protected void setStore() throws StandardException { 459 af = (AccessFactory) Monitor.findServiceModule(this,AccessFactory.MODULE); 460 } 461 462 public Parser newParser(CompilerContext cc) 463 { 464 return new org.apache.derby.impl.sql.compile.ParserImpl(cc); 465 } 466 467 469 475 protected synchronized int getNextLCCInstanceNumber() 476 { 477 return nextLCCInstanceNumber++; 478 } 479 } 480 | Popular Tags |