1 24 25 package org.objectweb.cjdbc.controller.xml; 26 27 import java.io.IOException ; 28 import java.io.InputStream ; 29 import java.io.StringReader ; 30 import java.util.ArrayList ; 31 import java.util.Hashtable ; 32 33 import javax.management.NotCompliantMBeanException ; 34 import javax.management.ObjectName ; 35 36 import org.apache.regexp.RESyntaxException; 37 import org.objectweb.cjdbc.common.exceptions.BackupException; 38 import org.objectweb.cjdbc.common.i18n.Translate; 39 import org.objectweb.cjdbc.common.jmx.JmxConstants; 40 import org.objectweb.cjdbc.common.log.Trace; 41 import org.objectweb.cjdbc.common.sql.filters.AbstractBlobFilter; 42 import org.objectweb.cjdbc.common.sql.filters.MacrosHandler; 43 import org.objectweb.cjdbc.common.sql.schema.DatabaseColumn; 44 import org.objectweb.cjdbc.common.sql.schema.DatabaseProcedure; 45 import org.objectweb.cjdbc.common.sql.schema.DatabaseProcedureParameter; 46 import org.objectweb.cjdbc.common.sql.schema.DatabaseSchema; 47 import org.objectweb.cjdbc.common.sql.schema.DatabaseTable; 48 import org.objectweb.cjdbc.common.users.AdminUser; 49 import org.objectweb.cjdbc.common.users.DatabaseBackendUser; 50 import org.objectweb.cjdbc.common.users.VirtualDatabaseUser; 51 import org.objectweb.cjdbc.common.util.Constants; 52 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags; 53 import org.objectweb.cjdbc.common.xml.XmlValidator; 54 import org.objectweb.cjdbc.controller.authentication.AuthenticationManager; 55 import org.objectweb.cjdbc.controller.authentication.AuthenticationManagerException; 56 import org.objectweb.cjdbc.controller.backend.DatabaseBackend; 57 import org.objectweb.cjdbc.controller.backend.DatabaseBackendSchemaConstants; 58 import org.objectweb.cjdbc.controller.backend.rewriting.AbstractRewritingRule; 59 import org.objectweb.cjdbc.controller.backend.rewriting.PatternRewritingRule; 60 import org.objectweb.cjdbc.controller.backend.rewriting.ReplaceAllRewritingRule; 61 import org.objectweb.cjdbc.controller.backend.rewriting.SimpleRewritingRule; 62 import org.objectweb.cjdbc.controller.backup.BackupManager; 63 import org.objectweb.cjdbc.controller.backup.Backuper; 64 import org.objectweb.cjdbc.controller.cache.metadata.MetadataCache; 65 import org.objectweb.cjdbc.controller.cache.parsing.ParsingCache; 66 import org.objectweb.cjdbc.controller.cache.result.AbstractResultCache; 67 import org.objectweb.cjdbc.controller.cache.result.CachingGranularities; 68 import org.objectweb.cjdbc.controller.cache.result.ResultCacheFactory; 69 import org.objectweb.cjdbc.controller.cache.result.ResultCacheRule; 70 import org.objectweb.cjdbc.controller.cache.result.rules.EagerCaching; 71 import org.objectweb.cjdbc.controller.connection.FailFastPoolConnectionManager; 72 import org.objectweb.cjdbc.controller.connection.RandomWaitPoolConnectionManager; 73 import org.objectweb.cjdbc.controller.connection.SimpleConnectionManager; 74 import org.objectweb.cjdbc.controller.connection.VariablePoolConnectionManager; 75 import org.objectweb.cjdbc.controller.core.Controller; 76 import org.objectweb.cjdbc.controller.jmx.MBeanServerManager; 77 import org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer; 78 import org.objectweb.cjdbc.controller.loadbalancer.paralleldb.ParallelDB; 79 import org.objectweb.cjdbc.controller.loadbalancer.paralleldb.ParallelDB_LPRF; 80 import org.objectweb.cjdbc.controller.loadbalancer.paralleldb.ParallelDB_RR; 81 import org.objectweb.cjdbc.controller.loadbalancer.policies.WaitForCompletionPolicy; 82 import org.objectweb.cjdbc.controller.loadbalancer.policies.createtable.CreateTableAll; 83 import org.objectweb.cjdbc.controller.loadbalancer.policies.createtable.CreateTablePolicy; 84 import org.objectweb.cjdbc.controller.loadbalancer.policies.createtable.CreateTableRandom; 85 import org.objectweb.cjdbc.controller.loadbalancer.policies.createtable.CreateTableRoundRobin; 86 import org.objectweb.cjdbc.controller.loadbalancer.policies.createtable.CreateTableRule; 87 import org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingAll; 88 import org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingPolicy; 89 import org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingRandom; 90 import org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingRoundRobin; 91 import org.objectweb.cjdbc.controller.loadbalancer.raidb0.RAIDb0; 92 import org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1_LPRF; 93 import org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1_RR; 94 import org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1_WRR; 95 import org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1ec_RR; 96 import org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1ec_WRR; 97 import org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2_LPRF; 98 import org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2_RR; 99 import org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2_WRR; 100 import org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2ec_RR; 101 import org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2ec_WRR; 102 import org.objectweb.cjdbc.controller.loadbalancer.singledb.SingleDB; 103 import org.objectweb.cjdbc.controller.monitoring.SQLMonitoring; 104 import org.objectweb.cjdbc.controller.monitoring.SQLMonitoringRule; 105 import org.objectweb.cjdbc.controller.recoverylog.RecoveryLog; 106 import org.objectweb.cjdbc.controller.requestmanager.RAIDbLevels; 107 import org.objectweb.cjdbc.controller.requestmanager.RequestManager; 108 import org.objectweb.cjdbc.controller.requestmanager.distributed.RAIDb1DistributedRequestManager; 109 import org.objectweb.cjdbc.controller.requestmanager.distributed.RAIDb2DistributedRequestManager; 110 import org.objectweb.cjdbc.controller.scheduler.AbstractScheduler; 111 import org.objectweb.cjdbc.controller.scheduler.raidb0.RAIDb0PassThroughLevelScheduler; 112 import org.objectweb.cjdbc.controller.scheduler.raidb0.RAIDb0PessimisticTransactionLevelScheduler; 113 import org.objectweb.cjdbc.controller.scheduler.raidb1.RAIDb1OptimisticQueryLevelScheduler; 114 import org.objectweb.cjdbc.controller.scheduler.raidb1.RAIDb1OptimisticTransactionLevelScheduler; 115 import org.objectweb.cjdbc.controller.scheduler.raidb1.RAIDb1PassThroughScheduler; 116 import org.objectweb.cjdbc.controller.scheduler.raidb1.RAIDb1PessimisticTransactionLevelScheduler; 117 import org.objectweb.cjdbc.controller.scheduler.raidb1.RAIDb1QueryLevelScheduler; 118 import org.objectweb.cjdbc.controller.scheduler.raidb2.RAIDb2PassThroughScheduler; 119 import org.objectweb.cjdbc.controller.scheduler.raidb2.RAIDb2PessimisticTransactionLevelScheduler; 120 import org.objectweb.cjdbc.controller.scheduler.raidb2.RAIDb2QueryLevelScheduler; 121 import org.objectweb.cjdbc.controller.scheduler.singledb.SingleDBPassThroughScheduler; 122 import org.objectweb.cjdbc.controller.scheduler.singledb.SingleDBPessimisticTransactionLevelScheduler; 123 import org.objectweb.cjdbc.controller.virtualdatabase.DistributedVirtualDatabase; 124 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase; 125 import org.objectweb.cjdbc.controller.virtualdatabase.protocol.CJDBCGroupMessage; 126 import org.xml.sax.Attributes ; 127 import org.xml.sax.InputSource ; 128 import org.xml.sax.SAXException ; 129 import org.xml.sax.SAXParseException ; 130 import org.xml.sax.XMLReader ; 131 import org.xml.sax.helpers.DefaultHandler ; 132 import org.xml.sax.helpers.XMLReaderFactory ; 133 134 143 public class DatabasesParser extends DefaultHandler 144 { 145 146 147 private XMLReader parser; 148 149 150 static Trace logger = Trace 151 .getLogger(DatabasesParser.class 152 .getName()); 153 154 155 private Controller controller; 156 157 158 private Hashtable dbToPrepare = null; 159 160 private boolean skipDatabase = false; 161 162 166 private boolean parsingAdminUsers = false; 167 168 private VirtualDatabase currentVirtualDatabase = null; 169 private BackupManager currentBackupManager = null; 170 private DatabaseBackend currentBackend; 171 private DatabaseBackendUser currentDatabaseBackendUser; 172 private AuthenticationManager currentAuthenticationManager; 173 private AbstractScheduler currentRequestScheduler; 174 private AbstractResultCache currentResultCache; 175 private MetadataCache currentMetadataCache = null; 176 private ParsingCache currentParsingCache = null; 177 private ResultCacheRule currentResultCacheRule; 178 private MacrosHandler currentMacroHandler; 179 private AbstractLoadBalancer currentLoadBalancer; 180 private RecoveryLog currentRecoveryLog; 181 private VirtualDatabaseUser currentVirtualUser; 182 private DatabaseSchema currentDatabaseSchema; 183 private DatabaseTable currentTable; 184 private DatabaseProcedure currentProcedure; 185 private int numberOfColumns; 186 187 private String connectionManagerVLogin; 188 private WaitForCompletionPolicy currentWaitForCompletionPolicy; 189 190 private long beginTimeout; 191 private long commitTimeout; 192 private long rollbackTimeout; 193 private int requestTimeout; 194 195 private boolean caseSensitiveParsing; 196 197 private CreateTablePolicy currentCreateTablePolicy; 198 private CreateTableRule currentCreateTableRule; 199 private ArrayList backendNameList; 200 private ErrorCheckingPolicy currentErrorCheckingPolicy; 201 202 private int currentNbOfConcurrentReads; 203 204 212 public DatabasesParser(Controller controller) throws SAXException 213 { 214 prepareHandler(controller); 215 } 216 217 229 public DatabasesParser(Controller controller, String virtualName, 230 int autoLoad, String checkPoint) throws SAXException 231 { 232 prepareHandler(controller); 233 if (virtualName != null) 235 prepareDB(virtualName, autoLoad, checkPoint); 236 } 237 238 private void prepareHandler(Controller controller) throws SAXException 239 { 240 parser = XMLReaderFactory.createXMLReader(); 242 243 this.controller = controller; 244 245 parser.setFeature("http://xml.org/sax/features/validation", true); 247 248 parser.setErrorHandler(this); 250 251 parser.setContentHandler(this); 253 254 parser.setEntityResolver(this); 256 } 257 258 265 public void readXML(String xml) throws IOException , SAXException 266 { 267 InputSource input = new InputSource (new StringReader (xml)); 268 parser.parse(input); 269 } 270 271 280 public void readXML(String xml, boolean validateBeforeParsing) 281 throws IOException , SAXException 282 { 283 if (validateBeforeParsing) 284 { 285 XmlValidator validator = new XmlValidator(Constants.C_JDBC_DTD_FILE, xml); 286 if (logger.isDebugEnabled()) 287 { 288 if (validator.isDtdValid()) 289 logger.debug(Translate.get("virtualdatabase.xml.dtd.validated")); 290 if (validator.isXmlValid()) 291 logger.debug(Translate.get("virtualdatabase.xml.document.validated")); 292 } 293 294 if (validator.getWarnings().size() > 0) 295 { 296 ArrayList warnings = validator.getWarnings(); 297 for (int i = 0; i < warnings.size(); i++) 298 logger.warn(Translate.get("virtualdatabase.xml.parsing.warning", 299 warnings.get(i))); 300 } 301 302 if (!validator.isDtdValid()) 303 logger.error(Translate.get("virtualdatabase.xml.dtd.not.validated")); 304 if (!validator.isXmlValid()) 305 logger.error(Translate 306 .get("virtualdatabase.xml.document.not.validated")); 307 308 ArrayList errors = validator.getExceptions(); 309 for (int i = 0; i < errors.size(); i++) 310 logger.error(((Exception ) errors.get(i)).getMessage()); 311 312 if (!validator.isValid()) 313 throw new SAXException (Translate 314 .get("virtualdatabase.xml.document.not.valid")); 315 } 316 this.readXML(xml); 317 } 318 319 326 public void fatalError(SAXParseException e) throws SAXException 327 { 328 logger.error(Translate.get("virtualdatabase.xml.parsing.fatal", 329 new String []{e.getPublicId(), String.valueOf(e.getLineNumber()), 330 String.valueOf(e.getColumnNumber()), e.getMessage()})); 331 throw e; 332 } 333 334 341 public void error(SAXParseException e) throws SAXException 342 { 343 logger.error(Translate.get("virtualdatabase.xml.parsing.error", 344 new String []{e.getPublicId(), String.valueOf(e.getLineNumber()), 345 String.valueOf(e.getColumnNumber()), e.getMessage()})); 346 throw e; 347 } 348 349 357 public InputSource resolveEntity(String publicId, String systemId) 358 throws SAXException 359 { 360 InputStream stream = DatabasesXmlTags.class.getResourceAsStream("/" 361 + Constants.C_JDBC_DTD_FILE); 362 if (stream == null) 363 throw new SAXException ("Cannot find C-JDBC DTD file '" 364 + Constants.C_JDBC_DTD_FILE + "' in classpath"); 365 366 return new InputSource (stream); 367 } 368 369 377 public void prepareDB(String virtualName, int autoLoad, String checkPoint) 378 { 379 dbToPrepare = new Hashtable (3); 380 dbToPrepare.put("virtualName", virtualName); 381 dbToPrepare.put("autoEnable", String.valueOf(autoLoad)); 382 dbToPrepare.put("checkPoint", checkPoint); 383 } 384 385 390 public void startDocument() throws SAXException 391 { 392 logger.info(Translate.get("virtualdatabase.xml.start")); 393 } 394 395 400 public void endDocument() throws SAXException 401 { 402 logger.info(Translate.get("virtualdatabase.xml.done")); 403 } 404 405 414 public void startElement(String uri, String localName, String name, 415 Attributes atts) throws SAXException 416 { 417 logger.debug(Translate.get("virtualdatabase.xml.parsing.start", name)); 418 419 if (name.equals(DatabasesXmlTags.ELT_VirtualDatabase)) 421 { 422 if (dbToPrepare == null) 423 { 424 newVirtualDatabase(atts); 426 } 427 else 428 { 429 String virtualName = atts.getValue(DatabasesXmlTags.ATT_name); 431 if (virtualName.equalsIgnoreCase((String ) dbToPrepare 432 .get("virtualName"))) 433 { 434 skipDatabase = false; 436 newVirtualDatabase(atts); 437 } 438 else 439 { 440 skipDatabase = true; 442 } 443 } 444 } 445 if (skipDatabase) 447 return; 448 449 else if (name.equals(DatabasesXmlTags.ELT_Distribution)) 451 newDistribution(atts); 452 453 else if (name.equals(DatabasesXmlTags.ELT_SQLMonitoring)) 455 newSQLMonitoring(atts); 456 else if (name.equals(DatabasesXmlTags.ELT_SQLMonitoringRule)) 457 newSQLMonitoringRule(atts); 458 459 else if (name.equals(DatabasesXmlTags.ELT_Backup)) 461 newBackupManager(); 462 else if (name.equals(DatabasesXmlTags.ELT_Backuper)) 463 newBackuper(atts); 464 465 else if (name.equals(DatabasesXmlTags.ELT_DatabaseBackend)) 467 newDatabaseBackend(atts); 468 else if (name.equals(DatabasesXmlTags.ELT_RewritingRule)) 469 newRewritingRule(atts); 470 471 else if (name.equals(DatabasesXmlTags.ELT_AuthenticationManager)) 473 newAuthenticationManager(); 474 else if (name.equals(DatabasesXmlTags.ELT_Admin)) 475 parsingAdminUsers = true; 476 else if (name.equals(DatabasesXmlTags.ELT_User) && parsingAdminUsers) 477 newAdminUser(atts); 478 else if (name.equals(DatabasesXmlTags.ELT_VirtualLogin)) 479 newVirtualLogin(atts); 480 481 else if (name.equals(DatabasesXmlTags.ELT_RequestManager)) 483 newRequestManager(atts); 484 485 else if (name.equals(DatabasesXmlTags.ELT_MacroHandling)) 487 newMacroHandler(atts); 488 489 else if (name.equals(DatabasesXmlTags.ELT_SingleDBScheduler)) 491 newSingleDBScheduler(atts); 492 else if (name.equals(DatabasesXmlTags.ELT_RAIDb0Scheduler)) 493 newRAIDb0Scheduler(atts); 494 else if (name.equals(DatabasesXmlTags.ELT_RAIDb1Scheduler)) 495 newRAIDb1Scheduler(atts); 496 else if (name.equals(DatabasesXmlTags.ELT_RAIDb2Scheduler)) 497 newRAIDb2Scheduler(atts); 498 499 else if (name.equals(DatabasesXmlTags.ELT_MetadataCache)) 501 newMetadataCache(atts); 502 else if (name.equals(DatabasesXmlTags.ELT_ParsingCache)) 503 newParsingCache(atts); 504 else if (name.equals(DatabasesXmlTags.ELT_ResultCache)) 505 newResultCache(atts); 506 else if (name.equals(DatabasesXmlTags.ELT_DefaultResultCacheRule)) 507 newDefaultResultCacheRule(atts); 508 else if (name.equals(DatabasesXmlTags.ELT_ResultCacheRule)) 509 newResultCacheRule(atts); 510 else if (name.equals(DatabasesXmlTags.ELT_NoCaching)) 511 currentResultCacheRule.setCacheBehavior(ResultCacheFactory 512 .getCacheBehaviorInstance(DatabasesXmlTags.ELT_NoCaching, null)); 513 else if (name.equals(DatabasesXmlTags.ELT_EagerCaching)) 514 newEagerCaching(atts); 515 else if (name.equals(DatabasesXmlTags.ELT_RelaxedCaching)) 516 newRelaxedCaching(atts); 517 518 else if (name.equals(DatabasesXmlTags.ELT_SingleDB)) 520 newSingleDBRequestLoadBalancer(); 521 else if (name.equals(DatabasesXmlTags.ELT_ParallelDB_RoundRobin)) 522 newParallelDBRoundRobinLoadBalancer(); 523 else if (name 524 .equals(DatabasesXmlTags.ELT_ParallelDB_LeastPendingRequestsFirst)) 525 newParallelDBLeastPendingRequestsFirst(); 526 else if (name.equals(DatabasesXmlTags.ELT_RAIDb_0)) 527 newRAIDb0LoadBalancer(); 528 else if (name.equals(DatabasesXmlTags.ELT_RAIDb_1)) 529 newRAIDb1LoadBalancer(); 530 else if (name.equals(DatabasesXmlTags.ELT_RAIDb_1_RoundRobin)) 531 newRAIDb1RoundRobinLoadBalancer(); 532 else if (name.equals(DatabasesXmlTags.ELT_RAIDb_1_WeightedRoundRobin)) 533 newRAIDb1WeightedRoundRobinLoadBalancer(); 534 else if (name 535 .equals(DatabasesXmlTags.ELT_RAIDb_1_LeastPendingRequestsFirst)) 536 newRAIDb1LeastPendingRequestsFirst(); 537 else if (name.equals(DatabasesXmlTags.ELT_RAIDb_1ec)) 538 newRAIDb1ecLoadBalancer(atts); 539 else if (name.equals(DatabasesXmlTags.ELT_RAIDb_1ec_RoundRobin)) 540 newRAIDb1ecRoundRobinLoadBalancer(); 541 else if (name.equals(DatabasesXmlTags.ELT_RAIDb_1ec_WeightedRoundRobin)) 542 newRAIDb1ecWeightedRoundRobinLoadBalancer(); 543 else if (name.equals(DatabasesXmlTags.ELT_RAIDb_2)) 544 newRAIDb2LoadBalancer(); 545 else if (name.equals(DatabasesXmlTags.ELT_RAIDb_2_RoundRobin)) 546 newRAIDb2RoundRobinLoadBalancer(); 547 else if (name.equals(DatabasesXmlTags.ELT_RAIDb_2_WeightedRoundRobin)) 548 newRAIDb2WeightedRoundRobinLoadBalancer(); 549 else if (name 550 .equals(DatabasesXmlTags.ELT_RAIDb_2_LeastPendingRequestsFirst)) 551 newRAIDb2LeastPendingRequestsFirst(); 552 else if (name.equals(DatabasesXmlTags.ELT_RAIDb_2ec)) 553 newRAIDb2ecLoadBalancer(); 554 else if (name.equals(DatabasesXmlTags.ELT_RAIDb_2ec_RoundRobin)) 555 newRAIDb2ecRoundRobinLoadBalancer(); 556 else if (name.equals(DatabasesXmlTags.ELT_RAIDb_2ec_WeightedRoundRobin)) 557 newRAIDb2ecWeightedRoundRobinLoadBalancer(); 558 559 else if (name.equals(DatabasesXmlTags.ELT_WaitForCompletion)) 561 newWaitForCompletion(atts); 562 else if (name.equals(DatabasesXmlTags.ELT_ErrorChecking)) 563 newErrorChecking(atts); 564 else if (name.equals(DatabasesXmlTags.ELT_CreateTable)) 565 newCreateTable(atts); 566 else if (name.equals(DatabasesXmlTags.ELT_BackendName)) 567 newBackendName(atts); 568 else if (name.equals(DatabasesXmlTags.ELT_BackendWeight)) 569 newBackendWeight(atts); 570 571 else if (name.equals(DatabasesXmlTags.ELT_RecoveryLog)) 573 newRecoveryLog(atts); 574 else if (name.equals(DatabasesXmlTags.ELT_RecoveryLogTable)) 575 newRecoveryLogTable(atts); 576 else if (name.equals(DatabasesXmlTags.ELT_CheckpointTable)) 577 newRecoveryCheckpointTable(atts); 578 else if (name.equals(DatabasesXmlTags.ELT_BackendTable)) 579 newRecoveryBackendTable(atts); 580 else if (name.equals(DatabasesXmlTags.ELT_DumpTable)) 581 newRecoveryDumpTable(atts); 582 583 else if (name.equals(DatabasesXmlTags.ELT_ConnectionManager)) 585 newConnectionManager(atts); 586 else if (name.equals(DatabasesXmlTags.ELT_SimpleConnectionManager)) 587 newSimpleConnectionManager(); 588 else if (name.equals(DatabasesXmlTags.ELT_FailFastPoolConnectionManager)) 589 newFailFastPoolConnectionManager(atts); 590 else if (name.equals(DatabasesXmlTags.ELT_RandomWaitPoolConnectionManager)) 591 newRandomWaitPoolConnectionManager(atts); 592 else if (name.equals(DatabasesXmlTags.ELT_VariablePoolConnectionManager)) 593 newVariablePoolConnectionManager(atts); 594 595 else if (name.equals(DatabasesXmlTags.ELT_DatabaseSchema)) 597 newDatabaseSchema(atts); 598 else if (name.equals(DatabasesXmlTags.ELT_DatabaseStaticSchema)) 599 { 600 if (currentBackend.getDynamicPrecision() != DatabaseBackendSchemaConstants.DynamicPrecisionStatic) 601 { 602 String msg = Translate.get( 603 "virtualdatabase.xml.schema.static.incompatible.dynamic", 604 currentBackend.getName()); 605 logger.error(msg); 606 throw new SAXException (msg); 607 } 608 currentDatabaseSchema = new DatabaseSchema(); 609 } 610 611 else if (name.equals(DatabasesXmlTags.ELT_DatabaseTable)) 613 newDatabaseTable(atts); 614 615 else if (name.equals(DatabasesXmlTags.ELT_DatabaseColumn)) 617 newDatabaseColumn(atts); 618 619 else if (name.equals(DatabasesXmlTags.ELT_DatabaseProcedure)) 620 newDatabaseProcedure(atts); 621 else if (name.equals(DatabasesXmlTags.ELT_DatabaseProcedureColumn)) 622 newDatabaseProcedureColumn(atts); 623 } 624 625 633 public void endElement(String uri, String localName, String name) 634 throws SAXException 635 { 636 logger.debug(Translate.get("virtualdatabase.xml.parsing.end", name)); 637 if (skipDatabase) 639 return; 640 641 if (name.equals(DatabasesXmlTags.ELT_VirtualDatabase)) 643 { 644 if (logger.isDebugEnabled()) 645 logger.debug(Translate.get("virtualdatabase.xml.add.virtualdatabase")); 646 647 if (currentVirtualDatabase != null) 648 { 649 try 650 { 651 if (currentVirtualDatabase instanceof DistributedVirtualDatabase) 652 ((DistributedVirtualDatabase) currentVirtualDatabase).joinGroup(); 653 if (dbToPrepare == null) 654 { 655 controller.addVirtualDatabase(currentVirtualDatabase); 656 } 657 else 658 { 659 int autoLoad = Integer.parseInt((String ) dbToPrepare 660 .get("autoEnable")); 661 String checkPoint = (String ) dbToPrepare.get("checkPoint"); 662 checkPoint = checkPoint.equalsIgnoreCase("") ? null : checkPoint; 666 controller.addVirtualDatabase(currentVirtualDatabase, autoLoad, 667 checkPoint); 668 } 669 } 670 catch (Exception e) 671 { 672 String msg = Translate 673 .get("controller.add.virtualdatabase.failed", e); 674 if (logger.isDebugEnabled()) 675 logger.error(msg, e); 676 else 677 logger.error(e); 678 } 679 } 680 currentVirtualDatabase = null; 681 } 682 683 else if (name.equals(DatabasesXmlTags.ELT_RequestManager)) 685 { 686 if (logger.isDebugEnabled()) 687 logger.debug(Translate.get("virtualdatabase.xml.requestmanager.set")); 688 689 if (currentVirtualDatabase != null) 690 { 691 RequestManager requestManager = null; 692 693 if (currentLoadBalancer == null) 696 throw new SAXException ("virtualdatabase.xml.loadbalancer.not.set"); 697 if (!(currentLoadBalancer instanceof SingleDB || currentLoadBalancer instanceof ParallelDB)) 698 { 699 if (currentMacroHandler == null) 702 currentMacroHandler = new MacrosHandler(MacrosHandler.RAND_FLOAT, 703 1000, MacrosHandler.DATE_TIMESTAMP, MacrosHandler.DATE_DATE, 704 MacrosHandler.DATE_TIME, MacrosHandler.DATE_TIMESTAMP, 705 MacrosHandler.DATE_TIMESTAMP); 706 currentLoadBalancer.setMacroHandler(currentMacroHandler); 707 } 708 709 try 710 { 711 if (currentVirtualDatabase.isDistributed()) 712 { 713 switch (currentLoadBalancer.getRAIDbLevel()) 714 { 715 case RAIDbLevels.SingleDB : 716 String smsg = Translate.get( 717 "virtualdatabase.xml.no.single.distributed.requestmanager", 718 currentLoadBalancer.getRAIDbLevel()); 719 logger.error(smsg); 720 throw new SAXException (smsg); 721 case RAIDbLevels.RAIDb1 : 722 requestManager = new RAIDb1DistributedRequestManager( 723 (DistributedVirtualDatabase) currentVirtualDatabase, 724 currentRequestScheduler, currentResultCache, 725 currentLoadBalancer, currentRecoveryLog, beginTimeout, 726 commitTimeout, rollbackTimeout); 727 break; 728 case RAIDbLevels.RAIDb2 : 729 requestManager = new RAIDb2DistributedRequestManager( 730 (DistributedVirtualDatabase) currentVirtualDatabase, 731 currentRequestScheduler, currentResultCache, 732 currentLoadBalancer, currentRecoveryLog, beginTimeout, 733 commitTimeout, rollbackTimeout); 734 break; 735 default : 736 String msg = Translate.get( 737 "virtualdatabase.xml.no.distributed.requestmanager", 738 currentLoadBalancer.getRAIDbLevel()); 739 logger.error(msg); 740 throw new SAXException (msg); 741 } 742 } 743 else 744 requestManager = new RequestManager(currentVirtualDatabase, 745 currentRequestScheduler, currentResultCache, 746 currentLoadBalancer, currentRecoveryLog, beginTimeout, 747 commitTimeout, rollbackTimeout); 748 749 if (requestManager != null) 750 { 751 if (currentParsingCache != null) 752 requestManager.setParsingCache(currentParsingCache); 753 if (currentMetadataCache != null) 754 requestManager.setMetadataCache(currentMetadataCache); 755 requestManager.setCaseSensitiveParsing(caseSensitiveParsing); 756 } 757 758 currentVirtualDatabase.setRequestManager(requestManager); 759 if (currentBackupManager == null) 760 currentBackupManager = new BackupManager(); 761 requestManager.setBackupManager(currentBackupManager); 762 } 763 catch (Exception e) 764 { 765 String msg = Translate 766 .get("virtualdatabase.xml.requestmanager.creation.failed"); 767 logger.error(msg, e); 768 throw new SAXException (msg, e); 769 } 770 } 771 } 772 773 else if (name.equals(DatabasesXmlTags.ELT_DatabaseBackend)) 775 { 776 if (currentBackend != null) 777 { 778 try 779 { 780 currentVirtualDatabase.addBackend(currentBackend, false); 781 } 782 catch (Exception e) 783 { 784 String msg = Translate.get("virtualdatabase.xml.backend.add.failed"); 785 logger.error(msg, e); 786 throw new SAXException (msg, e); 787 } 788 } 789 currentBackend = null; 790 } 791 792 else if (name.equals(DatabasesXmlTags.ELT_AuthenticationManager)) 794 { 795 if (currentVirtualDatabase != null) 796 { 797 currentVirtualDatabase 798 .setAuthenticationManager(currentAuthenticationManager); 799 } 800 } 801 802 else if (name.equals(DatabasesXmlTags.ELT_RequestCache)) 804 { 805 if (currentResultCache != null) 806 { if (currentResultCache.getDefaultRule() == null) 808 { 809 ResultCacheRule defaultRule = null; 810 try 811 { 812 defaultRule = new ResultCacheRule("", false, false, 1000); 813 } 814 catch (RESyntaxException impossible) 815 { 816 } 817 defaultRule.setCacheBehavior(new EagerCaching(0)); 818 currentResultCache.setDefaultRule(defaultRule); 819 } 820 } 821 } 822 else if (name.equals(DatabasesXmlTags.ELT_DefaultResultCacheRule)) 823 { 824 currentResultCache.setDefaultRule(currentResultCacheRule); 825 } 826 827 else if (name.equals(DatabasesXmlTags.ELT_DatabaseStaticSchema)) 829 { 830 if (currentDatabaseSchema != null) 831 { 832 if (currentBackend != null) 833 { 834 try 835 { 836 currentBackend.setDatabaseSchema(currentDatabaseSchema, true); 837 } 838 catch (Exception e) 839 { 840 logger.error(Translate 841 .get("virtualdatabase.xml.backend.set.schema.failed"), e); 842 } 843 } 844 else 845 { 846 try 847 { 848 currentVirtualDatabase 849 .setStaticDatabaseSchema(currentDatabaseSchema); 850 } 851 catch (Exception e) 852 { 853 logger.error(Translate 854 .get("virtualdatabase.xml.virtualdatabase.set.schema.failed"), 855 e); 856 } 857 } 858 currentDatabaseSchema = null; 859 } 860 } 861 862 else if (name.equals(DatabasesXmlTags.ELT_DatabaseTable)) 864 { 865 if (currentTable != null) 866 { 867 try 868 { 869 ArrayList cols = currentTable.getColumns(); 870 if (cols == null) 871 logger.warn(Translate.get("virtualdatabase.xml.table.no.column", 872 currentTable.getName())); 873 else if (cols.size() != numberOfColumns) 874 logger.warn(Translate.get( 875 "virtualdatabase.xml.table.column.mismatch", new String []{ 876 String.valueOf(numberOfColumns), currentTable.getName(), 877 String.valueOf(cols.size())})); 878 879 currentDatabaseSchema.addTable(currentTable); 880 if (logger.isDebugEnabled()) 881 logger.debug(Translate.get("virtualdatabase.xml.table.add", 882 currentTable.getName())); 883 } 884 catch (Exception e) 885 { 886 logger 887 .error(Translate.get("virtualdatabase.xml.table.add.failed"), e); 888 } 889 currentTable = null; 890 } 891 } 892 893 else if (name.equals(DatabasesXmlTags.ELT_DatabaseProcedure)) 894 { 895 if (currentProcedure != null) 896 { 897 try 898 { 899 900 currentDatabaseSchema.addProcedure(currentProcedure); 901 if (logger.isDebugEnabled()) 902 logger.debug(Translate.get("virtualdatabase.xml.procedure.add", 903 currentProcedure.getName())); 904 } 905 catch (Exception e) 906 { 907 logger.error(Translate 908 .get("virtualdatabase.xml.procedure.add.failed"), e); 909 } 910 currentProcedure = null; 911 } 912 } 913 914 else if (name.equals(DatabasesXmlTags.ELT_CreateTable)) 916 { 917 if (currentCreateTablePolicy != null) 918 { 919 if (logger.isDebugEnabled()) 920 logger.debug(Translate.get("virtualdatabase.xml.create.table.add", 921 currentCreateTableRule.getInformation())); 922 currentCreateTablePolicy.addRule(currentCreateTableRule); 923 } 924 } 925 926 else if (name.equals(DatabasesXmlTags.ELT_RAIDb_0)) 928 { 929 if (logger.isDebugEnabled()) 930 logger.debug(Translate 931 .get("virtualdatabase.xml.loadbalancer.raidb0.set")); 932 933 if (currentCreateTablePolicy.getDefaultRule() == null) 934 { 935 if (logger.isDebugEnabled()) 936 logger.debug(Translate 937 .get("virtualdatabase.xml.create.table.default")); 938 CreateTableRule rule = new CreateTableRoundRobin(); 939 currentCreateTablePolicy.addRule(rule); 940 } 941 try 942 { 943 currentLoadBalancer = new RAIDb0(currentVirtualDatabase, 944 currentCreateTablePolicy); 945 } 946 catch (Exception e) 947 { 948 String msg = Translate 949 .get("virtualdatabase.xml.loadbalancer.raidb0.failed"); 950 logger.error(msg, e); 951 throw new SAXException (msg, e); 952 } 953 } 954 955 else if (name.equals(DatabasesXmlTags.ELT_RecoveryLog)) 957 { 958 if (logger.isDebugEnabled()) 959 logger.debug(Translate 960 .get("virtualdatabase.xml.recoverylog.cheking.tables")); 961 try 962 { 963 currentRecoveryLog.checkRecoveryLogTables(); 964 } 965 catch (Exception e) 966 { 967 String msg = Translate 968 .get("virtualdatabase.xml.recoverylog.cheking.tables.failed"); 969 logger.error(msg, e); 970 throw new SAXException (msg); 971 } 972 try 974 { 975 currentRequestScheduler.initializeTransactionId(currentRecoveryLog 976 .getLastTransactionId() + 1); 977 } 978 catch (Exception e) 979 { 980 String msg = Translate 981 .get("virtualdatabase.xml.scheduler.initialization.failed"); 982 logger.error(msg, e); 983 throw new SAXException (msg); 984 } 985 } 986 } 987 988 989 990 1000 private void newVirtualDatabase(Attributes atts) throws SAXException 1001 { 1002 String name = atts.getValue(DatabasesXmlTags.ATT_name); 1003 String maxNbOfConnections = atts 1004 .getValue(DatabasesXmlTags.ATT_maxNbOfConnections); 1005 String poolThreads = atts.getValue(DatabasesXmlTags.ATT_poolThreads); 1006 String minNbOfThreads = atts.getValue(DatabasesXmlTags.ATT_minNbOfThreads); 1007 String maxNbOfThreads = atts.getValue(DatabasesXmlTags.ATT_maxNbOfThreads); 1008 String maxThreadIdleTime = atts 1009 .getValue(DatabasesXmlTags.ATT_maxThreadIdleTime); 1010 String sqlDumpLength = atts.getValue(DatabasesXmlTags.ATT_sqlDumpLength); 1011 String blobEncodingMethod = atts 1012 .getValue(DatabasesXmlTags.ATT_blobEncodingMethod); 1013 1014 if (controller.hasVirtualDatabase(name)) 1015 { 1016 String msg = Translate.get( 1017 "virtualdatabase.xml.virtualdatabase.already.exists", name); 1018 logger.error(msg); 1019 throw new SAXException (msg); 1020 } 1021 1022 try 1023 { 1024 int maxConnections = Integer.parseInt(maxNbOfConnections); 1026 boolean pool = poolThreads.equals(DatabasesXmlTags.VAL_true); 1027 int minThreads = Integer.parseInt(minNbOfThreads); 1028 int maxThreads = Integer.parseInt(maxNbOfThreads); 1029 long threadIdleTime = Long.parseLong(maxThreadIdleTime) * 1000L; 1031 int dumpLength = Integer.parseInt(sqlDumpLength); 1032 AbstractBlobFilter blobFilter = AbstractBlobFilter 1033 .getBlobFilterInstance(blobEncodingMethod); 1034 if (logger.isDebugEnabled()) 1035 logger.debug(Translate.get( 1036 "virtualdatabase.xml.virtualdatabase.create", name)); 1037 currentVirtualDatabase = new VirtualDatabase(controller, name, 1038 maxConnections, pool, minThreads, maxThreads, threadIdleTime, 1039 dumpLength, blobFilter); 1040 1041 } 1042 catch (Exception e) 1043 { 1044 String msg = Translate.get("virtualdatabase.xml.virtualdatabase.failed"); 1045 logger.error(msg, e); 1046 throw new SAXException (msg, e); 1047 } 1048 } 1049 1050 1051 1052 1058 private void newDistribution(Attributes atts) throws SAXException 1059 { 1060 String groupName = atts.getValue(DatabasesXmlTags.ATT_groupName); 1062 String castTimeout = atts.getValue(DatabasesXmlTags.ATT_castTimeout); 1063 long timeout; 1064 try 1065 { 1066 timeout = Long.parseLong(castTimeout); 1067 CJDBCGroupMessage.defaultCastTimeOut = timeout; 1068 } 1069 catch (NumberFormatException e1) 1070 { 1071 } 1073 1074 if (groupName == null) 1075 groupName = currentVirtualDatabase.getVirtualDatabaseName(); 1076 1077 if (logger.isDebugEnabled()) 1078 logger.debug(Translate.get( 1079 "virtualdatabase.xml.virtualdatabase.distributed.create", 1080 new String []{currentVirtualDatabase.getVirtualDatabaseName(), 1081 groupName, castTimeout})); 1082 try 1083 { 1084 ObjectName objectName = JmxConstants 1086 .getVirtualDbObjectName(currentVirtualDatabase 1087 .getVirtualDatabaseName()); 1088 MBeanServerManager.unregister(objectName); 1089 1090 currentVirtualDatabase = new DistributedVirtualDatabase(controller, 1091 currentVirtualDatabase.getVirtualDatabaseName(), groupName, 1092 currentVirtualDatabase.getMaxNbOfConnections(), 1093 currentVirtualDatabase.isPoolConnectionThreads(), 1094 currentVirtualDatabase.getMinNbOfThreads(), currentVirtualDatabase 1095 .getMaxNbOfThreads(), currentVirtualDatabase 1096 .getMaxThreadIdleTime(), currentVirtualDatabase 1097 .getSQLShortFormLength(), currentVirtualDatabase.getBlobFilter()); 1098 } 1099 catch (Exception e) 1100 { 1101 String msg = Translate 1102 .get("virtualdatabase.xml.virtualdatabase.distributed.failed"); 1103 logger.error(msg, e); 1104 throw new SAXException (msg, e); 1105 } 1106 } 1107 1108 1109 1110 1115 private void newSQLMonitoring(Attributes atts) 1116 { 1117 String monitoringString = atts 1118 .getValue(DatabasesXmlTags.ATT_defaultMonitoring); 1119 boolean monitoring; 1120 if (monitoringString != null) 1121 monitoring = monitoringString.equals(DatabasesXmlTags.VAL_on); 1122 else 1123 monitoring = false; 1124 1125 SQLMonitoring sqlMonitor = new SQLMonitoring(currentVirtualDatabase 1126 .getVirtualDatabaseName()); 1127 sqlMonitor.setDefaultRule(monitoring); 1128 currentVirtualDatabase.setSQLMonitor(sqlMonitor); 1129 } 1130 1131 1136 private void newSQLMonitoringRule(Attributes atts) 1137 { 1138 String queryPattern = atts.getValue(DatabasesXmlTags.ATT_queryPattern); 1139 String caseSensitiveString = atts 1140 .getValue(DatabasesXmlTags.ATT_caseSensitive); 1141 String applyToSkeletonString = atts 1142 .getValue(DatabasesXmlTags.ATT_applyToSkeleton); 1143 String monitoringString = atts.getValue(DatabasesXmlTags.ATT_monitoring); 1144 1145 boolean caseSensitive; 1146 if (caseSensitiveString != null) 1147 caseSensitive = caseSensitiveString.equals(DatabasesXmlTags.VAL_true); 1148 else 1149 caseSensitive = false; 1150 boolean applyToSkeleton; 1151 if (applyToSkeletonString != null) 1152 applyToSkeleton = applyToSkeletonString.equals(DatabasesXmlTags.VAL_true); 1153 else 1154 applyToSkeleton = false; 1155 boolean monitoring; 1156 if (monitoringString != null) 1157 monitoring = monitoringString.equals(DatabasesXmlTags.VAL_on); 1158 else 1159 monitoring = false; 1160 1161 SQLMonitoringRule rule = new SQLMonitoringRule(queryPattern, caseSensitive, 1163 applyToSkeleton, monitoring); 1164 1165 if (logger.isDebugEnabled()) 1166 logger.debug(Translate.get("virtualdatabase.xml.sqlmonitoring.rule.add", 1167 new String []{queryPattern, String.valueOf(caseSensitive), 1168 applyToSkeletonString, String.valueOf(monitoring)})); 1169 currentVirtualDatabase.getSQLMonitor().addRule(rule); 1170 } 1171 1172 1176 1179 private void newBackupManager() 1180 { 1181 currentBackupManager = new BackupManager(); 1182 } 1183 1184 1189 private void newBackuper(Attributes atts) 1190 { 1191 String name = atts.getValue(DatabasesXmlTags.ATT_backuperName); 1192 String className = atts.getValue(DatabasesXmlTags.ATT_className); 1193 String options = atts.getValue(DatabasesXmlTags.ATT_options); 1194 1195 Backuper backuper = null; 1196 try 1197 { 1198 backuper = (Backuper) Class.forName(className).newInstance(); 1199 backuper.setOptions(options); 1200 } 1201 catch (Exception e) 1202 { 1203 String msg = "Failed to load backuper " + name + " from class " 1204 + className + " (" + e + ")"; 1205 if (logger.isDebugEnabled()) 1206 logger.error(msg, e); 1207 else 1208 logger.error(e); 1209 return; 1210 } 1211 1212 try 1213 { 1214 currentBackupManager.registerBackuper(name, backuper); 1215 } 1216 catch (BackupException e) 1217 { 1218 logger.error("Failed to load backuper" + name + "(" + e + ")"); 1219 } 1220 } 1221 1222 1226 1233 private void newDatabaseBackend(Attributes atts) throws SAXException 1234 { 1235 String name = atts.getValue(DatabasesXmlTags.ATT_name); 1236 String driverClassName = atts.getValue(DatabasesXmlTags.ATT_driver); 1237 String driverPath = atts.getValue(DatabasesXmlTags.ATT_driverPath); 1238 String url = atts.getValue(DatabasesXmlTags.ATT_url); 1239 String connectionTestStatement = atts 1240 .getValue(DatabasesXmlTags.ATT_connectionTestStatement); 1241 1242 if (logger.isDebugEnabled()) 1243 { 1244 logger.debug(Translate.get("virtualdatabase.xml.backend.create", 1245 new String []{name, driverClassName, url, connectionTestStatement})); 1246 if (driverPath == null) 1247 { 1248 logger.debug("no driver path defined for backend."); 1249 } 1250 else 1251 { 1252 logger.debug("using driver path " + driverPath); 1253 } 1254 } 1255 try 1256 { 1257 currentBackend = new DatabaseBackend(name, driverPath, driverClassName, 1258 url, currentVirtualDatabase.getVirtualDatabaseName(), true, 1259 connectionTestStatement); 1260 } 1261 catch (NotCompliantMBeanException e) 1262 { 1263 logger.error("MBean is not compliant", e); 1264 throw new SAXException ("mbean is not compliant"); 1265 } 1266 } 1267 1268 1273 private void newRewritingRule(Attributes atts) throws SAXException 1274 { 1275 String queryPattern = atts.getValue(DatabasesXmlTags.ATT_queryPattern); 1276 String rewrite = atts.getValue(DatabasesXmlTags.ATT_rewrite); 1277 String matchingType = atts.getValue(DatabasesXmlTags.ATT_matchingType); 1278 String caseSensitiveString = atts 1279 .getValue(DatabasesXmlTags.ATT_caseSensitive); 1280 String stopOnMatchString = atts.getValue(DatabasesXmlTags.ATT_stopOnMatch); 1281 1282 boolean caseSensitive; 1283 if (caseSensitiveString != null) 1284 caseSensitive = caseSensitiveString.equals(DatabasesXmlTags.VAL_true); 1285 else 1286 caseSensitive = false; 1287 boolean stopOnMatch; 1288 if (stopOnMatchString != null) 1289 stopOnMatch = stopOnMatchString.equals(DatabasesXmlTags.VAL_true); 1290 else 1291 stopOnMatch = false; 1292 1293 AbstractRewritingRule rule; 1295 if (matchingType.equals(DatabasesXmlTags.VAL_simple)) 1296 rule = new SimpleRewritingRule(queryPattern, rewrite, caseSensitive, 1297 stopOnMatch); 1298 else if (matchingType.equals(DatabasesXmlTags.VAL_pattern)) 1299 rule = new PatternRewritingRule(queryPattern, rewrite, caseSensitive, 1300 stopOnMatch); 1301 else if (matchingType.equals(DatabasesXmlTags.VAL_replaceAll)) 1302 rule = new ReplaceAllRewritingRule(queryPattern, rewrite, caseSensitive, 1303 stopOnMatch); 1304 else 1305 throw new SAXException (Translate.get( 1306 "virtualdatabase.xml.rewritingrule.unsupported.matching", 1307 matchingType)); 1308 1309 if (logger.isDebugEnabled()) 1310 logger.debug(Translate.get("virtualdatabase.xml.rewritingrule.add", 1311 new String []{queryPattern, rewrite, String.valueOf(caseSensitive), 1312 String.valueOf(stopOnMatch)})); 1313 currentBackend.addRewritingRule(rule); 1314 } 1315 1316 1317 1318 1322 private void newAuthenticationManager() 1323 { 1324 currentAuthenticationManager = new AuthenticationManager(); 1325 } 1326 1327 1333 private void newAdminUser(Attributes atts) 1334 { 1335 String aLogin = atts.getValue(DatabasesXmlTags.ATT_username); 1336 String aPassword = atts.getValue(DatabasesXmlTags.ATT_password); 1337 1338 if (logger.isDebugEnabled()) 1339 logger.debug(Translate.get( 1340 "virtualdatabase.xml.authentication.login.admin.add", new String []{ 1341 aLogin, aPassword})); 1342 currentAuthenticationManager.addAdminUser(new AdminUser(aLogin, aPassword)); 1343 } 1344 1345 1353 private void newVirtualLogin(Attributes atts) 1354 { 1355 String vLogin = atts.getValue(DatabasesXmlTags.ATT_vLogin); 1356 String vPassword = atts.getValue(DatabasesXmlTags.ATT_vPassword); 1357 currentVirtualUser = new VirtualDatabaseUser(vLogin, vPassword); 1358 1359 if (logger.isDebugEnabled()) 1360 logger.debug(Translate.get( 1361 "virtualdatabase.xml.authentication.login.virtual.add", new String []{ 1362 vLogin, vPassword})); 1363 currentAuthenticationManager.addVirtualUser(currentVirtualUser); 1364 } 1365 1366 1367 1368 1375 private void newRequestManager(Attributes atts) throws SAXException 1376 { 1377 try 1378 { 1379 String begin = atts.getValue(DatabasesXmlTags.ATT_beginTimeout); 1380 String commit = atts.getValue(DatabasesXmlTags.ATT_commitTimeout); 1381 String rollback = atts.getValue(DatabasesXmlTags.ATT_rollbackTimeout); 1382 String caseSensitiveParsingString = atts 1383 .getValue(DatabasesXmlTags.ATT_caseSensitiveParsing); 1384 1385 beginTimeout = Long.parseLong(begin) * 1000L; 1387 commitTimeout = Long.parseLong(commit) * 1000L; 1388 rollbackTimeout = Long.parseLong(rollback) * 1000L; 1389 1390 if (caseSensitiveParsingString != null) 1391 caseSensitiveParsing = caseSensitiveParsingString 1392 .equals(DatabasesXmlTags.VAL_true); 1393 else 1394 caseSensitiveParsing = false; 1395 1396 if (logger.isDebugEnabled()) 1397 logger.debug(Translate.get( 1398 "virtualdatabase.xml.requestmanager.parameters", new String []{ 1399 String.valueOf(beginTimeout), String.valueOf(commitTimeout), 1400 String.valueOf(rollbackTimeout)})); 1401 } 1402 catch (NumberFormatException e) 1403 { 1404 String msg = Translate 1405 .get("virtualdatabase.xml.requestmanager.timeout.failed"); 1406 logger.error(msg, e); 1407 throw new SAXException (msg, e); 1408 } 1409 } 1410 1411 1412 1413 1418 private void newMacroHandler(Attributes atts) 1419 { 1420 1427 String rand = atts.getValue(DatabasesXmlTags.ATT_rand); 1428 String now = atts.getValue(DatabasesXmlTags.ATT_now); 1429 String currentDate = atts.getValue(DatabasesXmlTags.ATT_currentDate); 1430 String currentTime = atts.getValue(DatabasesXmlTags.ATT_currentTime); 1431 String currentTimestamp = atts 1432 .getValue(DatabasesXmlTags.ATT_currentTimestamp); 1433 String timeResolution = atts.getValue(DatabasesXmlTags.ATT_timeResolution); 1434 String timeOfDay = atts.getValue(DatabasesXmlTags.ATT_timeOfDay); 1435 1436 int icurrentDate = MacrosHandler.getIntDateLevel(currentDate); 1437 int icurrentTime = MacrosHandler.getIntDateLevel(currentTime); 1438 int icurrentTimestamp = MacrosHandler.getIntDateLevel(currentTimestamp); 1439 int itimeOfDay = MacrosHandler.getIntDateLevel(timeOfDay); 1440 int inow = MacrosHandler.getIntDateLevel(now); 1441 int irand = MacrosHandler.getIntRandLevel(rand); 1442 long ltimeResolution = Long.parseLong(timeResolution); 1443 1444 try 1445 { 1446 currentMacroHandler = new MacrosHandler(irand, ltimeResolution, inow, 1447 icurrentDate, icurrentTime, itimeOfDay, icurrentTimestamp); 1448 } 1449 catch (RuntimeException e) 1450 { 1451 logger.warn(Translate.get( 1452 "virtualdatabase.xml.invalid.macroshandler.settings", e)); 1453 } 1454 } 1455 1456 1457 1458 1466 private void newSingleDBScheduler(Attributes atts) throws SAXException 1467 { 1468 String level = atts.getValue(DatabasesXmlTags.ATT_level); 1469 1470 if (level.equals(DatabasesXmlTags.VAL_passThrough)) 1472 { 1473 if (logger.isDebugEnabled()) 1474 logger.debug(Translate 1475 .get("virtualdatabase.xml.scheduler.singledb.create.passthrough")); 1476 currentRequestScheduler = new SingleDBPassThroughScheduler(); 1477 } 1478 1479 else if (level.equals(DatabasesXmlTags.VAL_pessimisticTransaction)) 1481 { 1482 if (logger.isDebugEnabled()) 1483 logger.debug(Translate 1484 .get("virtualdatabase.xml.scheduler.singledb.create.pessimistic")); 1485 currentRequestScheduler = new SingleDBPessimisticTransactionLevelScheduler(); 1486 } 1487 else 1488 { 1489 throw new SAXException (Translate.get( 1490 "virtualdatabase.xml.scheduler.singledb.unsupported", level)); 1491 } 1492 } 1493 1494 1503 private void newRAIDb0Scheduler(Attributes atts) throws SAXException 1504 { 1505 String level = atts.getValue(DatabasesXmlTags.ATT_level); 1506 1507 if (level.equals(DatabasesXmlTags.VAL_passThrough)) 1508 { 1509 if (logger.isDebugEnabled()) 1510 logger.debug(Translate 1511 .get("virtualdatabase.xml.scheduler.raidb0.create.passthrough")); 1512 currentRequestScheduler = new RAIDb0PassThroughLevelScheduler(); 1513 } 1514 else if (level.equals(DatabasesXmlTags.VAL_pessimisticTransaction)) 1515 { 1516 if (logger.isDebugEnabled()) 1517 logger.debug(Translate 1518 .get("virtualdatabase.xml.scheduler.raidb0.create.pessimistic")); 1519 currentRequestScheduler = new RAIDb0PessimisticTransactionLevelScheduler(); 1520 } 1521 else 1522 throw new SAXException (Translate.get( 1523 "virtualdatabase.xml.scheduler.raidb0.unsupported", level)); 1524 } 1525 1526 1537 private void newRAIDb1Scheduler(Attributes atts) throws SAXException 1538 { 1539 String level = atts.getValue(DatabasesXmlTags.ATT_level); 1540 1541 if (level.equals(DatabasesXmlTags.VAL_passThrough)) 1543 { 1544 if (logger.isDebugEnabled()) 1545 logger.debug(Translate 1546 .get("virtualdatabase.xml.scheduler.raidb1.create.passthrough")); 1547 currentRequestScheduler = new RAIDb1PassThroughScheduler( 1548 currentVirtualDatabase); 1549 } 1550 else if (level.equals(DatabasesXmlTags.VAL_query)) 1552 { 1553 if (logger.isDebugEnabled()) 1554 logger.debug(Translate 1555 .get("virtualdatabase.xml.scheduler.raidb1.create.query")); 1556 currentRequestScheduler = new RAIDb1QueryLevelScheduler(); 1557 } 1558 else if (level.equals(DatabasesXmlTags.VAL_optimisticQuery)) 1560 { 1561 if (logger.isDebugEnabled()) 1562 logger 1563 .debug(Translate 1564 .get("virtualdatabase.xml.scheduler.raidb1.create.query.optimistic")); 1565 currentRequestScheduler = new RAIDb1OptimisticQueryLevelScheduler(); 1566 } 1567 else if (level.equals(DatabasesXmlTags.VAL_optimisticTransaction)) 1569 { 1570 if (logger.isDebugEnabled()) 1571 logger.debug(Translate 1572 .get("virtualdatabase.xml.scheduler.raidb1.create.optimistic")); 1573 currentRequestScheduler = new RAIDb1OptimisticTransactionLevelScheduler(); 1574 } 1575 else if (level.equals(DatabasesXmlTags.VAL_pessimisticTransaction)) 1577 { 1578 if (logger.isDebugEnabled()) 1579 logger.debug(Translate 1580 .get("virtualdatabase.xml.scheduler.raidb1.create.pessimistic")); 1581 currentRequestScheduler = new RAIDb1PessimisticTransactionLevelScheduler(); 1582 } 1583 else 1584 { 1585 throw new SAXException (Translate.get( 1586 "virtualdatabase.xml.scheduler.raidb1.unsupported", level)); 1587 } 1588 } 1589 1590 1600 private void newRAIDb2Scheduler(Attributes atts) throws SAXException 1601 { 1602 String level = atts.getValue(DatabasesXmlTags.ATT_level); 1603 1604 if (level.equals(DatabasesXmlTags.VAL_passThrough)) 1606 { 1607 if (logger.isDebugEnabled()) 1608 logger.debug(Translate 1609 .get("virtualdatabase.xml.scheduler.raidb2.create.passthrough")); 1610 currentRequestScheduler = new RAIDb2PassThroughScheduler( 1611 currentVirtualDatabase); 1612 } 1613 else if (level.equals(DatabasesXmlTags.VAL_query)) 1615 { 1616 if (logger.isDebugEnabled()) 1617 logger.debug(Translate 1618 .get("virtualdatabase.xml.scheduler.raidb2.create.query")); 1619 currentRequestScheduler = new RAIDb2QueryLevelScheduler(); 1620 } 1621 else if (level.equals(DatabasesXmlTags.VAL_pessimisticTransaction)) 1623 { 1624 if (logger.isDebugEnabled()) 1625 logger.debug(Translate 1626 .get("virtualdatabase.xml.scheduler.raidb2.create.pessimistic")); 1627 currentRequestScheduler = new RAIDb2PessimisticTransactionLevelScheduler(); 1628 } 1629 else 1630 { 1631 throw new SAXException (Translate.get( 1632 "virtualdatabase.xml.scheduler.raidb2.unsupported", level)); 1633 } 1634 } 1635 1636 1637 1638 1639 1640 1647 private void newMetadataCache(Attributes atts) throws SAXException 1648 { 1649 try 1650 { 1651 int maxMetadata = Integer.parseInt(atts 1652 .getValue(DatabasesXmlTags.ATT_maxNbOfMetadata)); 1653 int maxField = Integer.parseInt(atts 1654 .getValue(DatabasesXmlTags.ATT_maxNbOfField)); 1655 currentMetadataCache = new MetadataCache(maxMetadata, maxField); 1656 } 1657 catch (Exception e) 1658 { 1659 String msg = Translate.get( 1660 "virtualdatabase.xml.metadata.cache.create.failed", e); 1661 logger.error(msg, e); 1662 throw new SAXException (msg, e); 1663 } 1664 } 1665 1666 1673 private void newParsingCache(Attributes atts) throws SAXException 1674 { 1675 String backgroundParsingString = atts 1676 .getValue(DatabasesXmlTags.ATT_backgroundParsing); 1677 boolean backgroundParsing; 1678 1679 if (backgroundParsingString != null) 1680 backgroundParsing = backgroundParsingString 1681 .equals(DatabasesXmlTags.VAL_true); 1682 else 1683 backgroundParsing = false; 1684 1685 String maxEntriesString = atts 1686 .getValue(DatabasesXmlTags.ATT_maxNbOfEntries); 1687 int maxEntries = Integer.parseInt(maxEntriesString); 1688 1689 try 1690 { 1691 currentParsingCache = new ParsingCache(maxEntries, backgroundParsing); 1692 } 1693 catch (Exception e) 1694 { 1695 String msg = Translate.get( 1696 "virtualdatabase.xml.parsing.cache.create.failed", e); 1697 logger.error(msg, e); 1698 throw new SAXException (msg, e); 1699 } 1700 } 1701 1702 1709 private void newResultCache(Attributes atts) throws SAXException 1710 { 1711 String granularity = atts.getValue(DatabasesXmlTags.ATT_granularity); 1712 String maxEntriesString = atts 1713 .getValue(DatabasesXmlTags.ATT_maxNbOfEntries); 1714 String pendingTimeoutString = atts 1715 .getValue(DatabasesXmlTags.ATT_pendingTimeout); 1716 1717 if (logger.isDebugEnabled()) 1718 logger.debug(Translate.get("virtualdatabase.xml.cache.create", 1719 granularity)); 1720 1721 try 1722 { 1723 int maxEntries = Integer.parseInt(maxEntriesString); 1724 int pendingTimeout = Integer.parseInt(pendingTimeoutString); 1725 1726 int granularityValue; 1727 if (granularity.equals(DatabasesXmlTags.VAL_table)) 1728 granularityValue = CachingGranularities.TABLE; 1729 else if (granularity.equals(DatabasesXmlTags.VAL_database)) 1730 granularityValue = CachingGranularities.DATABASE; 1731 else if (granularity.equals(DatabasesXmlTags.VAL_column)) 1732 granularityValue = CachingGranularities.COLUMN; 1733 else if (granularity.equals(DatabasesXmlTags.VAL_columnUnique)) 1734 granularityValue = CachingGranularities.COLUMN_UNIQUE; 1735 else 1736 throw new InstantiationException (Translate.get( 1737 "virtualdatabase.xml.cache.unsupported", granularity)); 1738 1739 currentResultCache = ResultCacheFactory.getCacheInstance( 1740 granularityValue, maxEntries, pendingTimeout); 1741 1742 } 1743 catch (Exception e) 1744 { 1745 String msg = Translate.get("virtualdatabase.xml.cache.create.failed", 1746 granularity); 1747 logger.error(msg, e); 1748 throw new SAXException (msg, e); 1749 } 1750 } 1751 1752 1758 private void newResultCacheRule(Attributes atts) throws SAXException 1759 { 1760 String queryString = atts.getValue(DatabasesXmlTags.ATT_queryPattern); 1761 1762 String caseSensitiveString = atts 1763 .getValue(DatabasesXmlTags.ATT_caseSensitive); 1764 String applyToSkeletonString = atts 1765 .getValue(DatabasesXmlTags.ATT_applyToSkeleton); 1766 long timestampResolution; 1767 try 1768 { 1769 timestampResolution = Long.parseLong(atts 1770 .getValue(DatabasesXmlTags.ATT_timestampResolution)); 1771 timestampResolution *= 1000; 1772 } 1773 catch (Exception e) 1774 { 1775 logger 1776 .warn(Translate.get("virtualdatabase.invalid.timestamp.resolution")); 1777 timestampResolution = 1000; 1778 } 1779 1780 boolean caseSensitive; 1781 if (caseSensitiveString != null) 1782 caseSensitive = caseSensitiveString.equals(DatabasesXmlTags.VAL_true); 1783 else 1784 caseSensitive = false; 1785 boolean applyToSkeleton; 1786 if (applyToSkeletonString != null) 1787 applyToSkeleton = applyToSkeletonString.equals(DatabasesXmlTags.VAL_true); 1788 else 1789 applyToSkeleton = false; 1790 1791 try 1793 { 1794 currentResultCacheRule = new ResultCacheRule(queryString, caseSensitive, 1795 applyToSkeleton, timestampResolution); 1796 } 1797 catch (RESyntaxException e1) 1798 { 1799 String msg = Translate.get("virtualdatabase.xml.cache.rule.invalid", e1); 1800 logger.error(msg); 1801 throw new SAXException (msg); 1802 } 1803 1804 if (logger.isDebugEnabled()) 1805 logger.debug(Translate.get("virtualdatabase.xml.cache.rule.add", 1806 new String []{atts.getValue(DatabasesXmlTags.ATT_queryPattern), 1807 String.valueOf(caseSensitive), applyToSkeletonString, 1808 String.valueOf(timestampResolution)})); 1809 currentResultCache.addCachingRule(currentResultCacheRule); 1810 } 1811 1812 1818 private void newDefaultResultCacheRule(Attributes atts) throws SAXException 1819 { 1820 long currentTimestampResolution; 1821 try 1822 { 1823 currentTimestampResolution = Long.parseLong(atts 1824 .getValue(DatabasesXmlTags.ATT_timestampResolution)) / 1000; 1825 } 1826 catch (Exception e) 1827 { 1828 String msg = Translate 1829 .get("virtualdatabase.invalid.timestamp.resolution"); 1830 logger.warn(msg); 1831 currentTimestampResolution = 1000; 1832 } 1833 try 1835 { 1836 currentResultCacheRule = new ResultCacheRule("", false, false, 1837 currentTimestampResolution); 1838 } 1839 catch (RESyntaxException e) 1840 { 1841 throw new SAXException (Translate.get( 1842 "virtualdatabase.xml.cache.rule.default.invalid", e)); 1843 } 1844 } 1845 1846 1853 private void newEagerCaching(Attributes atts) 1854 { 1855 Hashtable options = new Hashtable (); 1856 for (int i = 0; i < atts.getLength(); i++) 1857 options.put(atts.getQName(i), atts.getValue(i)); 1858 currentResultCacheRule.setCacheBehavior(ResultCacheFactory 1859 .getCacheBehaviorInstance(DatabasesXmlTags.ELT_EagerCaching, options)); 1860 } 1861 1862 1868 private void newRelaxedCaching(Attributes atts) 1869 { 1870 Hashtable options = new Hashtable (); 1871 for (int i = 0; i < atts.getLength(); i++) 1872 options.put(atts.getQName(i), atts.getValue(i)); 1873 currentResultCacheRule 1874 .setCacheBehavior(ResultCacheFactory.getCacheBehaviorInstance( 1875 DatabasesXmlTags.ELT_RelaxedCaching, options)); 1876 } 1877 1878 1879 1880 1886 private void newSingleDBRequestLoadBalancer() throws SAXException 1887 { 1888 if (logger.isDebugEnabled()) 1889 logger.debug(Translate 1890 .get("virtualdatabase.xml.loadbalancer.singledb.set")); 1891 1892 try 1893 { 1894 currentLoadBalancer = new SingleDB(currentVirtualDatabase); 1895 } 1896 catch (Exception e) 1897 { 1898 String msg = Translate 1899 .get("virtualdatabase.xml.loadbalancer.singledb.failed"); 1900 logger.error(msg, e); 1901 throw new SAXException (msg, e); 1902 } 1903 } 1904 1905 1909 1915 private void newParallelDBLeastPendingRequestsFirst() throws SAXException 1916 { 1917 if (logger.isDebugEnabled()) 1918 logger.debug(Translate 1919 .get("virtualdatabase.xml.loadbalancer.paralleldb_rr.set")); 1920 1921 try 1922 { 1923 currentLoadBalancer = new ParallelDB_RR(currentVirtualDatabase); 1924 } 1925 catch (Exception e) 1926 { 1927 String msg = Translate 1928 .get("virtualdatabase.xml.loadbalancer.paralleldb_rr.failed"); 1929 logger.error(msg, e); 1930 throw new SAXException (msg, e); 1931 } 1932 } 1933 1934 1940 private void newParallelDBRoundRobinLoadBalancer() throws SAXException 1941 { 1942 if (logger.isDebugEnabled()) 1943 logger.debug(Translate 1944 .get("virtualdatabase.xml.loadbalancer.paralleldb_lprf.set")); 1945 1946 try 1947 { 1948 currentLoadBalancer = new ParallelDB_LPRF(currentVirtualDatabase); 1949 } 1950 catch (Exception e) 1951 { 1952 String msg = Translate 1953 .get("virtualdatabase.xml.loadbalancer.paralleldb_lprf.failed"); 1954 logger.error(msg, e); 1955 throw new SAXException (msg, e); 1956 } 1957 } 1958 1959 1963 1967 private void newRAIDb0LoadBalancer() 1968 { 1969 currentCreateTablePolicy = new CreateTablePolicy(); 1970 currentCreateTableRule = null; 1971 } 1972 1973 1977 1981 private void newRAIDb1LoadBalancer() 1982 { 1983 currentWaitForCompletionPolicy = null; 1984 } 1985 1986 1992 private void newRAIDb1RoundRobinLoadBalancer() throws SAXException 1993 { 1994 if (currentWaitForCompletionPolicy == null) 1995 currentWaitForCompletionPolicy = new WaitForCompletionPolicy(); 1996 1997 if (logger.isDebugEnabled()) 1998 { 1999 logger.debug(Translate 2000 .get("virtualdatabase.xml.loadbalancer.raidb1_rr.set")); 2001 logger.debug(Translate.get( 2002 "virtualdatabase.xml.loadbalancer.waitforcompletion.rule", 2003 currentWaitForCompletionPolicy.getInformation())); 2004 } 2005 2006 try 2007 { 2008 currentLoadBalancer = new RAIDb1_RR(currentVirtualDatabase, 2009 currentWaitForCompletionPolicy); 2010 } 2011 catch (Exception e) 2012 { 2013 String msg = Translate 2014 .get("virtualdatabase.xml.loadbalancer.raidb1_rr.failed"); 2015 logger.error(msg, e); 2016 throw new SAXException (msg, e); 2017 } 2018 } 2019 2020 2026 private void newRAIDb1WeightedRoundRobinLoadBalancer() throws SAXException 2027 { 2028 if (currentWaitForCompletionPolicy == null) 2029 currentWaitForCompletionPolicy = new WaitForCompletionPolicy(); 2030 2031 if (logger.isDebugEnabled()) 2032 { 2033 logger.debug(Translate 2034 .get("virtualdatabase.xml.loadbalancer.raidb1_wrr.set")); 2035 logger.debug(Translate.get( 2036 "virtualdatabase.xml.loadbalancer.waitforcompletion.rule", 2037 currentWaitForCompletionPolicy.getInformation())); 2038 } 2039 2040 try 2041 { 2042 currentLoadBalancer = new RAIDb1_WRR(currentVirtualDatabase, 2043 currentWaitForCompletionPolicy); 2044 } 2045 catch (Exception e) 2046 { 2047 String msg = Translate 2048 .get("virtualdatabase.xml.loadbalancer.raidb1_wrr.failed"); 2049 logger.error(msg, e); 2050 throw new SAXException (msg, e); 2051 } 2052 } 2053 2054 2060 private void newRAIDb1LeastPendingRequestsFirst() throws SAXException 2061 { 2062 if (currentWaitForCompletionPolicy == null) 2063 currentWaitForCompletionPolicy = new WaitForCompletionPolicy(); 2064 2065 if (logger.isDebugEnabled()) 2066 { 2067 logger.debug(Translate 2068 .get("virtualdatabase.xml.loadbalancer.raidb1_lprf.set")); 2069 logger.debug(Translate.get( 2070 "virtualdatabase.xml.loadbalancer.waitforcompletion.rule", 2071 currentWaitForCompletionPolicy.getInformation())); 2072 } 2073 2074 try 2075 { 2076 currentLoadBalancer = new RAIDb1_LPRF(currentVirtualDatabase, 2077 currentWaitForCompletionPolicy); 2078 } 2079 catch (Exception e) 2080 { 2081 String msg = Translate 2082 .get("virtualdatabase.xml.loadbalancer.raidb1_lprf.failed"); 2083 logger.error(msg, e); 2084 throw new SAXException (msg, e); 2085 } 2086 } 2087 2088 2092 2098 private void newRAIDb1ecLoadBalancer(Attributes atts) 2099 { 2100 String nbOfConcurrentReads = atts 2101 .getValue(DatabasesXmlTags.ATT_nbOfConcurrentReads); 2102 currentNbOfConcurrentReads = Integer.parseInt(nbOfConcurrentReads); 2103 currentErrorCheckingPolicy = null; 2104 currentWaitForCompletionPolicy = null; 2105 } 2106 2107 2113 private void newRAIDb1ecRoundRobinLoadBalancer() throws SAXException 2114 { 2115 if (currentWaitForCompletionPolicy == null) 2116 currentWaitForCompletionPolicy = new WaitForCompletionPolicy(); 2117 2118 if (logger.isDebugEnabled()) 2119 { 2120 logger.debug(Translate 2121 .get("virtualdatabase.xml.loadbalancer.raidb1ec_rr.set")); 2122 logger.debug(Translate.get( 2123 "virtualdatabase.xml.loadbalancer.waitforcompletion.rule", 2124 currentWaitForCompletionPolicy.getInformation())); 2125 } 2126 2127 try 2128 { 2129 currentLoadBalancer = new RAIDb1ec_RR(currentVirtualDatabase, 2130 currentWaitForCompletionPolicy, currentErrorCheckingPolicy, 2131 currentNbOfConcurrentReads); 2132 if (logger.isDebugEnabled()) 2133 logger.debug(Translate.get( 2134 "virtualdatabase.xml.loadbalancer.errorchecking.policy", 2135 currentErrorCheckingPolicy.getInformation())); 2136 } 2137 catch (Exception e) 2138 { 2139 String msg = Translate 2140 .get("virtualdatabase.xml.loadbalancer.raidb1ec_rr.failed"); 2141 logger.error(msg, e); 2142 throw new SAXException (msg, e); 2143 } 2144 } 2145 2146 2152 private void newRAIDb1ecWeightedRoundRobinLoadBalancer() throws SAXException 2153 { 2154 if (currentWaitForCompletionPolicy == null) 2155 currentWaitForCompletionPolicy = new WaitForCompletionPolicy(); 2156 2157 if (logger.isDebugEnabled()) 2158 { 2159 logger.debug(Translate 2160 .get("virtualdatabase.xml.loadbalancer.raidb1ec_wrr.set")); 2161 logger.debug(Translate.get( 2162 "virtualdatabase.xml.loadbalancer.waitforcompletion.rule", 2163 currentWaitForCompletionPolicy.getInformation())); 2164 } 2165 2166 try 2167 { 2168 currentLoadBalancer = new RAIDb1ec_WRR(currentVirtualDatabase, 2169 currentWaitForCompletionPolicy, currentErrorCheckingPolicy, 2170 currentNbOfConcurrentReads); 2171 if (logger.isDebugEnabled()) 2172 logger.debug(Translate.get( 2173 "virtualdatabase.xml.loadbalancer.errorchecking.policy", 2174 currentErrorCheckingPolicy.getInformation())); 2175 } 2176 catch (Exception e) 2177 { 2178 String msg = Translate 2179 .get("virtualdatabase.xml.loadbalancer.raidb1ec_wrr.failed"); 2180 logger.error(msg, e); 2181 throw new SAXException (msg, e); 2182 } 2183 } 2184 2185 2189 2193 private void newRAIDb2LoadBalancer() 2194 { 2195 currentWaitForCompletionPolicy = null; 2196 currentCreateTablePolicy = new CreateTablePolicy(); 2197 currentCreateTablePolicy.addRule(new CreateTableAll()); 2199 currentCreateTableRule = null; 2200 } 2201 2202 2208 private void newRAIDb2RoundRobinLoadBalancer() throws SAXException 2209 { 2210 if (currentWaitForCompletionPolicy == null) 2211 currentWaitForCompletionPolicy = new WaitForCompletionPolicy(); 2212 2213 if (logger.isDebugEnabled()) 2214 { 2215 logger.debug(Translate 2216 .get("virtualdatabase.xml.loadbalancer.raidb2_rr.set")); 2217 logger.debug(Translate.get( 2218 "virtualdatabase.xml.loadbalancer.waitforcompletion.rule", 2219 currentWaitForCompletionPolicy.getInformation())); 2220 } 2221 2222 try 2223 { 2224 currentLoadBalancer = new RAIDb2_RR(currentVirtualDatabase, 2225 currentWaitForCompletionPolicy, currentCreateTablePolicy); 2226 } 2227 catch (Exception e) 2228 { 2229 String msg = Translate 2230 .get("virtualdatabase.xml.loadbalancer.raidb2_rr.failed"); 2231 logger.error(msg, e); 2232 throw new SAXException (msg, e); 2233 } 2234 } 2235 2236 2242 private void newRAIDb2WeightedRoundRobinLoadBalancer() throws SAXException 2243 { 2244 if (currentWaitForCompletionPolicy == null) 2245 currentWaitForCompletionPolicy = new WaitForCompletionPolicy(); 2246 2247 if (logger.isDebugEnabled()) 2248 { 2249 logger.debug(Translate 2250 .get("virtualdatabase.xml.loadbalancer.raidb2_wrr.set")); 2251 logger.debug(Translate.get( 2252 "virtualdatabase.xml.loadbalancer.waitforcompletion.rule", 2253 currentWaitForCompletionPolicy.getInformation())); 2254 } 2255 2256 try 2257 { 2258 currentLoadBalancer = new RAIDb2_WRR(currentVirtualDatabase, 2259 currentWaitForCompletionPolicy, currentCreateTablePolicy); 2260 } 2261 catch (Exception e) 2262 { 2263 String msg = Translate 2264 .get("virtualdatabase.xml.loadbalancer.raidb2_wrr.failed"); 2265 logger.error(msg, e); 2266 throw new SAXException (msg, e); 2267 } 2268 } 2269 2270 2276 private void newRAIDb2LeastPendingRequestsFirst() throws SAXException 2277 { 2278 if (currentWaitForCompletionPolicy == null) 2279 currentWaitForCompletionPolicy = new WaitForCompletionPolicy(); 2280 if (logger.isDebugEnabled()) 2281 { 2282 logger.debug(Translate 2283 .get("virtualdatabase.xml.loadbalancer.raidb2_lprf.set")); 2284 logger.debug(Translate.get( 2285 "virtualdatabase.xml.loadbalancer.waitforcompletion.rule", 2286 currentWaitForCompletionPolicy.getInformation())); 2287 } 2288 2289 try 2290 { 2291 currentLoadBalancer = new RAIDb2_LPRF(currentVirtualDatabase, 2292 currentWaitForCompletionPolicy, currentCreateTablePolicy); 2293 } 2294 catch (Exception e) 2295 { 2296 String msg = Translate 2297 .get("virtualdatabase.xml.loadbalancer.raidb2_lprf.failed"); 2298 logger.error(msg, e); 2299 throw new SAXException (msg, e); 2300 } 2301 } 2302 2303 2307 2311 private void newRAIDb2ecLoadBalancer() 2312 { 2313 currentErrorCheckingPolicy = null; 2314 currentWaitForCompletionPolicy = null; 2315 currentCreateTablePolicy = new CreateTablePolicy(); 2316 currentCreateTableRule = null; 2317 } 2318 2319 2325 private void newRAIDb2ecRoundRobinLoadBalancer() throws SAXException 2326 { 2327 if (currentWaitForCompletionPolicy == null) 2328 currentWaitForCompletionPolicy = new WaitForCompletionPolicy(); 2329 2330 if (logger.isDebugEnabled()) 2331 { 2332 logger.debug(Translate 2333 .get("virtualdatabase.xml.loadbalancer.raidb2_rr.set")); 2334 logger.debug(Translate.get( 2335 "virtualdatabase.xml.loadbalancer.waitforcompletion.rule", 2336 currentWaitForCompletionPolicy.getInformation())); 2337 } 2338 2339 try 2340 { 2341 currentLoadBalancer = new RAIDb2ec_RR(currentVirtualDatabase, 2342 currentWaitForCompletionPolicy, currentCreateTablePolicy, 2343 currentErrorCheckingPolicy, currentNbOfConcurrentReads); 2344 if (logger.isDebugEnabled()) 2345 logger.debug(Translate.get( 2346 "virtualdatabase.xml.loadbalancer.errorchecking.policy", 2347 currentErrorCheckingPolicy.getInformation())); 2348 } 2349 catch (Exception e) 2350 { 2351 String msg = Translate 2352 .get("virtualdatabase.xml.loadbalancer.raidb2ec_rr.failed"); 2353 logger.error(msg, e); 2354 throw new SAXException (msg, e); 2355 } 2356 } 2357 2358 2364 private void newRAIDb2ecWeightedRoundRobinLoadBalancer() throws SAXException 2365 { 2366 if (currentWaitForCompletionPolicy == null) 2367 currentWaitForCompletionPolicy = new WaitForCompletionPolicy(); 2368 2369 if (logger.isDebugEnabled()) 2370 { 2371 logger.debug(Translate 2372 .get("virtualdatabase.xml.loadbalancer.raidb2_wrr.set")); 2373 logger.debug(Translate.get( 2374 "virtualdatabase.xml.loadbalancer.waitforcompletion.rule", 2375 currentWaitForCompletionPolicy.getInformation())); 2376 } 2377 2378 try 2379 { 2380 currentLoadBalancer = new RAIDb2ec_WRR(currentVirtualDatabase, 2381 currentWaitForCompletionPolicy, currentCreateTablePolicy, 2382 currentErrorCheckingPolicy, currentNbOfConcurrentReads); 2383 if (logger.isDebugEnabled()) 2384 logger.debug(Translate.get( 2385 "virtualdatabase.xml.loadbalancer.errorchecking.policy", 2386 currentErrorCheckingPolicy.getInformation())); 2387 } 2388 catch (Exception e) 2389 { 2390 String msg = Translate 2391 .get("virtualdatabase.xml.loadbalancer.raidb2ec_wrr.failed"); 2392 logger.error(msg, e); 2393 throw new SAXException (msg, e); 2394 } 2395 } 2396 2397 2401 2407 private void newWaitForCompletion(Attributes atts) throws SAXException 2408 { 2409 String policy = atts.getValue(DatabasesXmlTags.ATT_policy); 2410 currentWaitForCompletionPolicy = new WaitForCompletionPolicy(); 2411 2412 if (policy.equals(DatabasesXmlTags.VAL_first)) 2413 currentWaitForCompletionPolicy.setPolicy(WaitForCompletionPolicy.FIRST); 2414 else if (policy.equals(DatabasesXmlTags.VAL_majority)) 2415 currentWaitForCompletionPolicy 2416 .setPolicy(WaitForCompletionPolicy.MAJORITY); 2417 else if (policy.equals(DatabasesXmlTags.VAL_all)) 2418 currentWaitForCompletionPolicy.setPolicy(WaitForCompletionPolicy.ALL); 2419 else 2420 throw new SAXException (Translate.get( 2421 "virtualdatabase.xml.loadbalancer.waitforcompletion.unsupported", 2422 policy)); 2423 } 2424 2425 2431 private void newErrorChecking(Attributes atts) throws SAXException 2432 { 2433 String nbOfNodes = atts.getValue(DatabasesXmlTags.ATT_numberOfNodes); 2434 String policy = atts.getValue(DatabasesXmlTags.ATT_policy); 2435 if (policy.equals(DatabasesXmlTags.VAL_random)) 2436 currentErrorCheckingPolicy = new ErrorCheckingRandom(Integer 2437 .parseInt(nbOfNodes)); 2438 else if (policy.equals(DatabasesXmlTags.VAL_roundRobin)) 2439 currentErrorCheckingPolicy = new ErrorCheckingRoundRobin(Integer 2440 .parseInt(nbOfNodes)); 2441 else if (policy.equals(DatabasesXmlTags.VAL_all)) 2442 currentErrorCheckingPolicy = new ErrorCheckingAll(); 2443 else 2444 throw new SAXException (Translate.get( 2445 "virtualdatabase.xml.loadbalancer.errorchecking.unsupported", policy)); 2446 } 2447 2448 2454 private void newCreateTable(Attributes atts) throws SAXException 2455 { 2456 String tableName = atts.getValue(DatabasesXmlTags.ATT_tableName); 2457 String nbOfNodes = atts.getValue(DatabasesXmlTags.ATT_numberOfNodes); 2458 String policy = atts.getValue(DatabasesXmlTags.ATT_policy); 2459 backendNameList = new ArrayList (); 2460 if (policy.equals(DatabasesXmlTags.VAL_random)) 2461 currentCreateTableRule = new CreateTableRandom(backendNameList); 2462 else if (policy.equals(DatabasesXmlTags.VAL_roundRobin)) 2463 currentCreateTableRule = new CreateTableRoundRobin(backendNameList); 2464 else if (policy.equals(DatabasesXmlTags.VAL_all)) 2465 currentCreateTableRule = new CreateTableAll(backendNameList); 2466 else 2467 throw new SAXException (Translate.get( 2468 "virtualdatabase.xml.create.table.unsupported", policy)); 2469 2470 currentCreateTableRule.setNumberOfNodes(Integer.parseInt(nbOfNodes)); 2471 currentCreateTableRule.setTableName(tableName); 2472 } 2473 2474 2479 private void newBackendName(Attributes atts) 2480 { 2481 String name = atts.getValue(DatabasesXmlTags.ATT_name); 2482 if (logger.isDebugEnabled()) 2483 logger.debug(Translate 2484 .get("virtualdatabase.xml.backend.policy.add", name)); 2485 backendNameList.add(name); 2486 } 2487 2488 2495 private void newBackendWeight(Attributes atts) throws SAXException 2496 { 2497 String name = atts.getValue(DatabasesXmlTags.ATT_name); 2498 try 2499 { 2500 int weight = Integer.parseInt(atts.getValue(DatabasesXmlTags.ATT_weight)); 2501 2502 if (logger.isDebugEnabled()) 2503 logger.debug(Translate.get("virtualdatabase.xml.backend.weigth.set", 2504 new String []{String.valueOf(weight), name})); 2505 2506 currentLoadBalancer.setWeight(name, weight); 2507 } 2508 catch (Exception e) 2509 { 2510 String msg = Translate.get("virtualdatabase.xml.backend.weigth.failed", 2511 name); 2512 logger.error(msg, e); 2513 throw new SAXException (msg, e); 2514 } 2515 } 2516 2517 2518 2519 2526 private void newRecoveryLog(Attributes atts) throws SAXException 2527 { 2528 try 2529 { 2530 String driverClassName = atts.getValue(DatabasesXmlTags.ATT_driver); 2531 String driverPath = atts.getValue(DatabasesXmlTags.ATT_driverPath); 2532 String url = atts.getValue(DatabasesXmlTags.ATT_url); 2533 String login = atts.getValue(DatabasesXmlTags.ATT_login); 2534 String password = atts.getValue(DatabasesXmlTags.ATT_password); 2535 String timeout = atts.getValue(DatabasesXmlTags.ATT_requestTimeout); 2536 int recoveryBatchSize = Integer.parseInt(atts 2537 .getValue(DatabasesXmlTags.ATT_recoveryBatchSize)); 2538 requestTimeout = Integer.parseInt(timeout) * 1000; 2540 2541 if (logger.isDebugEnabled()) 2542 logger.debug(Translate.get( 2543 "virtualdatabase.xml.recoverylog.jdbc.create", new String []{ 2544 driverClassName, url, login, password, 2545 String.valueOf(requestTimeout)})); 2546 2547 currentRecoveryLog = new RecoveryLog(driverPath, driverClassName, url, 2548 login, password, requestTimeout, recoveryBatchSize); 2549 } 2551 catch (Exception e) 2552 { 2553 String msg = Translate.get("virtualdatabase.xml.recoverylog.jdbc.failed"); 2554 logger.error(msg, e); 2555 throw new SAXException (msg, e); 2556 } 2557 } 2558 2559 2567 private void newRecoveryLogTable(Attributes atts) throws SAXException 2568 { 2569 try 2570 { 2571 String createTable = atts.getValue(DatabasesXmlTags.ATT_createTable); 2572 String tableName = atts.getValue(DatabasesXmlTags.ATT_tableName); 2573 String idType = atts.getValue(DatabasesXmlTags.ATT_idColumnType); 2574 String vloginType = atts.getValue(DatabasesXmlTags.ATT_vloginColumnType); 2575 String sqlName = atts.getValue(DatabasesXmlTags.ATT_sqlColumnName); 2576 String sqlType = atts.getValue(DatabasesXmlTags.ATT_sqlColumnType); 2577 String transactionIdType = atts 2578 .getValue(DatabasesXmlTags.ATT_transactionIdColumnType); 2579 String extraStatement = atts 2580 .getValue(DatabasesXmlTags.ATT_extraStatementDefinition); 2581 2582 if (currentRecoveryLog == null) 2583 { 2584 String msg = Translate 2585 .get("virtualdatabase.xml.recoverylog.jdbc.recoverytable.setnull"); 2586 logger.error(msg); 2587 throw new SAXException (msg); 2588 } 2589 else 2590 currentRecoveryLog.setLogTableCreateStatement(createTable, tableName, 2591 idType, vloginType, sqlName, sqlType, transactionIdType, 2592 extraStatement); 2593 } 2594 catch (Exception e) 2595 { 2596 String msg = Translate 2597 .get("virtualdatabase.xml.recoverylog.jdbc.recoverytable.failed"); 2598 logger.error(msg, e); 2599 throw new SAXException (msg, e); 2600 } 2601 } 2602 2603 2611 private void newRecoveryCheckpointTable(Attributes atts) throws SAXException 2612 { 2613 try 2614 { 2615 String createTable = atts.getValue(DatabasesXmlTags.ATT_createTable); 2616 String tableName = atts.getValue(DatabasesXmlTags.ATT_tableName); 2617 String nameType = atts 2618 .getValue(DatabasesXmlTags.ATT_checkpointNameColumnType); 2619 String requestIdType = atts 2620 .getValue(DatabasesXmlTags.ATT_requestIdColumnType); 2621 String extraStatement = atts 2622 .getValue(DatabasesXmlTags.ATT_extraStatementDefinition); 2623 2624 if (currentRecoveryLog == null) 2625 { 2626 String msg = Translate 2627 .get("virtualdatabase.xml.recoverylog.jdbc.checkpointtable.setnull"); 2628 logger.error(msg); 2629 throw new SAXException (msg); 2630 } 2631 else 2632 currentRecoveryLog.setCheckpointTableCreateStatement(createTable, 2633 tableName, nameType, requestIdType, extraStatement); 2634 } 2635 catch (Exception e) 2636 { 2637 String msg = Translate 2638 .get("virtualdatabase.xml.recoverylog.jdbc.checkpointtable.failed"); 2639 logger.error(msg, e); 2640 throw new SAXException (msg, e); 2641 } 2642 } 2643 2644 2652 private void newRecoveryBackendTable(Attributes atts) throws SAXException 2653 { 2654 try 2655 { 2656 String createTable = atts.getValue(DatabasesXmlTags.ATT_createTable); 2657 String tableName = atts.getValue(DatabasesXmlTags.ATT_tableName); 2658 String checkpointNameType = atts 2659 .getValue(DatabasesXmlTags.ATT_checkpointNameColumnType); 2660 String databaseNameType = atts 2661 .getValue(DatabasesXmlTags.ATT_databaseNameColumnType); 2662 String backendNameType = atts 2663 .getValue(DatabasesXmlTags.ATT_backendNameColumnType); 2664 String backendStateType = atts 2665 .getValue(DatabasesXmlTags.ATT_backendStateColumnType); 2666 String extraStatement = atts 2667 .getValue(DatabasesXmlTags.ATT_extraStatementDefinition); 2668 2669 if (currentRecoveryLog == null) 2670 { 2671 String msg = Translate 2672 .get("virtualdatabase.xml.recoverylog.jdbc.backendtable.setnull"); 2673 logger.error(msg); 2674 throw new SAXException (msg); 2675 } 2676 else 2677 currentRecoveryLog.setBackendTableCreateStatement(createTable, 2678 tableName, checkpointNameType, backendNameType, backendStateType, 2679 databaseNameType, extraStatement); 2680 } 2681 catch (Exception e) 2682 { 2683 String msg = Translate 2684 .get("virtualdatabase.xml.recoverylog.jdbc.backendtable.failed"); 2685 logger.error(msg, e); 2686 throw new SAXException (msg, e); 2687 } 2688 } 2689 2690 2698 private void newRecoveryDumpTable(Attributes atts) throws SAXException 2699 { 2700 try 2701 { 2702 String createTable = atts.getValue(DatabasesXmlTags.ATT_createTable); 2703 String tableName = atts.getValue(DatabasesXmlTags.ATT_tableName); 2704 String dumpNameColumnType = atts 2705 .getValue(DatabasesXmlTags.ATT_dumpNameColumnType); 2706 String dumpDateColumnType = atts 2707 .getValue(DatabasesXmlTags.ATT_dumpDateColumnType); 2708 String dumpPathColumnType = atts 2709 .getValue(DatabasesXmlTags.ATT_dumpPathColumnType); 2710 String dumpTypeColumnType = atts 2711 .getValue(DatabasesXmlTags.ATT_dumpFormatColumnType); 2712 String checkpointNameColumnType = atts 2713 .getValue(DatabasesXmlTags.ATT_checkpointNameColumnType); 2714 String backendNameColumnType = atts 2715 .getValue(DatabasesXmlTags.ATT_backendNameColumnType); 2716 String tablesColumnName = atts 2717 .getValue(DatabasesXmlTags.ATT_tablesColumnName); 2718 String tablesColumnType = atts 2719 .getValue(DatabasesXmlTags.ATT_tablesColumnType); 2720 2721 String extraStatement = atts 2722 .getValue(DatabasesXmlTags.ATT_extraStatementDefinition); 2723 2724 if (currentRecoveryLog == null) 2725 { 2726 String msg = Translate 2727 .get("virtualdatabase.xml.recoverylog.jdbc.dumptable.setnull"); 2728 logger.error(msg); 2729 throw new SAXException (msg); 2730 } 2731 else 2732 currentRecoveryLog.setDumpTableCreateStatement(createTable, tableName, 2733 dumpNameColumnType, dumpDateColumnType, dumpPathColumnType, 2734 dumpTypeColumnType, checkpointNameColumnType, 2735 backendNameColumnType, tablesColumnName, tablesColumnType, 2736 extraStatement); 2737 } 2738 catch (Exception e) 2739 { 2740 String msg = Translate 2741 .get("virtualdatabase.xml.recoverylog.jdbc.dumptable.failed"); 2742 logger.error(msg, e); 2743 throw new SAXException (msg, e); 2744 } 2745 } 2746 2747 2748 2749 2756 private void newConnectionManager(Attributes atts) throws SAXException 2757 { 2758 connectionManagerVLogin = atts.getValue(DatabasesXmlTags.ATT_vLogin); 2759 String connectionManagerRLogin = atts.getValue(DatabasesXmlTags.ATT_rLogin); 2760 String connectionManagerRPassword = atts 2761 .getValue(DatabasesXmlTags.ATT_rPassword); 2762 String backendName = currentBackend.getName(); 2763 2764 if (!currentAuthenticationManager 2766 .isValidVirtualLogin(connectionManagerVLogin)) 2767 { 2768 String msg = Translate.get( 2769 "virtualdatabase.xml.connectionmanager.vlogin.undefined", 2770 new String []{connectionManagerVLogin, currentBackend.getName()}); 2771 logger.error(msg); 2772 throw new SAXException (msg); 2773 } 2774 currentDatabaseBackendUser = new DatabaseBackendUser(backendName, 2776 connectionManagerRLogin, connectionManagerRPassword); 2777 2778 if (logger.isDebugEnabled()) 2779 logger.debug(Translate 2780 .get("virtualdatabase.xml.authentication.login.real.add", 2781 new String []{connectionManagerRLogin, connectionManagerRPassword, 2782 backendName})); 2783 2784 try 2785 { 2786 currentAuthenticationManager.addRealUser(connectionManagerVLogin, 2787 currentDatabaseBackendUser); 2788 } 2789 catch (AuthenticationManagerException e) 2790 { 2791 String msg = Translate 2792 .get("virtualdatabase.xml.authentication.login.real.add.failed"); 2793 logger.error(msg, e); 2794 throw new SAXException (msg, e); 2795 } 2796 2797 } 2811 2812 2816 private void newSimpleConnectionManager() 2817 { 2818 if (logger.isDebugEnabled()) 2819 logger.debug(Translate.get( 2820 "virtualdatabase.xml.connectionmanager.simple.add", new String []{ 2821 currentBackend.getName(), connectionManagerVLogin, 2822 currentDatabaseBackendUser.getLogin(), 2823 currentDatabaseBackendUser.getPassword()})); 2824 2825 currentBackend.addConnectionManager(connectionManagerVLogin, 2826 new SimpleConnectionManager(currentBackend.getURL(), currentBackend 2827 .getName(), currentDatabaseBackendUser.getLogin(), 2828 currentDatabaseBackendUser.getPassword(), currentBackend 2829 .getDriverPath(), currentBackend.getDriverClassName())); 2830 } 2831 2832 2839 private void newFailFastPoolConnectionManager(Attributes atts) 2840 throws SAXException 2841 { 2842 try 2843 { 2844 int poolSize = Integer.parseInt(atts 2845 .getValue(DatabasesXmlTags.ATT_poolSize)); 2846 2847 if (poolSize < 1) 2849 throw new IllegalArgumentException ( 2850 Translate 2851 .get("virtualdatabase.xml.connectionmanager.failfast.failed.parameter")); 2852 2853 if (logger.isDebugEnabled()) 2854 logger.debug(Translate.get( 2855 "virtualdatabase.xml.connectionmanager.failfast.add", new String []{ 2856 currentBackend.getName(), connectionManagerVLogin, 2857 String.valueOf(poolSize), 2858 currentDatabaseBackendUser.getLogin(), 2859 currentDatabaseBackendUser.getPassword()})); 2860 2861 currentBackend.addConnectionManager(connectionManagerVLogin, 2862 new FailFastPoolConnectionManager(currentBackend.getURL(), 2863 currentBackend.getName(), currentDatabaseBackendUser.getLogin(), 2864 currentDatabaseBackendUser.getPassword(), currentBackend 2865 .getDriverPath(), currentBackend.getDriverClassName(), 2866 poolSize)); 2867 } 2868 catch (Exception e) 2869 { 2870 String msg = Translate.get( 2871 "virtualdatabase.xml.connectionmanager.failfast.failed", 2872 currentBackend.getName()); 2873 logger.error(msg, e); 2874 throw new SAXException (msg, e); 2875 } 2876 } 2877 2878 2885 private void newRandomWaitPoolConnectionManager(Attributes atts) 2886 throws SAXException 2887 { 2888 try 2889 { 2890 int poolSize = Integer.parseInt(atts 2891 .getValue(DatabasesXmlTags.ATT_poolSize)); 2892 String timeoutString = atts.getValue(DatabasesXmlTags.ATT_timeout); 2893 int timeout = 0; 2894 2895 if (timeoutString != null) timeout = Integer.parseInt(timeoutString); 2898 2899 if (timeout < 0 || poolSize < 1) 2901 throw new IllegalArgumentException ( 2902 Translate 2903 .get("virtualdatabase.xml.connectionmanager.randomwait.failed.parameter")); 2904 2905 if (logger.isDebugEnabled()) 2906 logger.debug(Translate.get( 2907 "virtualdatabase.xml.connectionmanager.randomwait.add", 2908 new String []{currentBackend.getName(), connectionManagerVLogin, 2909 String.valueOf(poolSize), String.valueOf(timeout), 2910 currentDatabaseBackendUser.getLogin(), 2911 currentDatabaseBackendUser.getPassword()})); 2912 2913 currentBackend.addConnectionManager(connectionManagerVLogin, 2914 new RandomWaitPoolConnectionManager(currentBackend.getURL(), 2915 currentBackend.getName(), currentDatabaseBackendUser.getLogin(), 2916 currentDatabaseBackendUser.getPassword(), currentBackend 2917 .getDriverPath(), currentBackend.getDriverClassName(), 2918 poolSize, timeout)); 2919 } 2920 catch (Exception e) 2921 { 2922 String msg = Translate.get( 2923 "virtualdatabase.xml.connectionmanager.randomwait.failed", 2924 currentBackend.getName()); 2925 logger.error(msg, e); 2926 throw new SAXException (msg, e); 2927 } 2928 } 2929 2930 2937 private void newVariablePoolConnectionManager(Attributes atts) 2938 throws SAXException 2939 { 2940 try 2941 { 2942 int initPoolSize = Integer.parseInt(atts 2943 .getValue(DatabasesXmlTags.ATT_initPoolSize)); 2944 2945 int minPoolSize = initPoolSize; 2946 String attr = atts.getValue(DatabasesXmlTags.ATT_minPoolSize); 2948 if (attr != null) 2949 minPoolSize = Integer.parseInt(attr); 2950 2951 int maxPoolSize = VariablePoolConnectionManager.DEFAULT_MAX_POOL_SIZE; 2953 attr = atts.getValue(DatabasesXmlTags.ATT_maxPoolSize); 2954 if (attr != null) 2955 maxPoolSize = Integer.parseInt(attr); 2956 2957 String timeoutString = atts.getValue(DatabasesXmlTags.ATT_idleTimeout); 2958 int idleTimeout = VariablePoolConnectionManager.DEFAULT_IDLE_TIMEOUT; 2959 if (timeoutString != null) idleTimeout = Integer.parseInt(timeoutString); 2962 2963 timeoutString = atts.getValue(DatabasesXmlTags.ATT_waitTimeout); 2964 int waitTimeout = VariablePoolConnectionManager.DEFAULT_WAIT_TIMEOUT; 2965 if (timeoutString != null) waitTimeout = Integer.parseInt(timeoutString); 2968 2969 if (minPoolSize < 0 || maxPoolSize < 0 2971 || (maxPoolSize != 0 && minPoolSize > maxPoolSize) 2972 || (maxPoolSize != 0 && initPoolSize > maxPoolSize) 2973 || initPoolSize < minPoolSize) 2974 throw new IllegalArgumentException ( 2975 Translate 2976 .get("virtualdatabase.xml.connectionmanager.variable.failed.parameter")); 2977 2978 if (logger.isDebugEnabled()) 2979 logger.debug(Translate.get( 2980 "virtualdatabase.xml.connectionmanager.randomwait.add", 2981 new String []{currentBackend.getName(), connectionManagerVLogin, 2982 String.valueOf(initPoolSize), String.valueOf(minPoolSize), 2983 String.valueOf(maxPoolSize), String.valueOf(idleTimeout), 2984 String.valueOf(waitTimeout), 2985 currentDatabaseBackendUser.getLogin(), 2986 currentDatabaseBackendUser.getPassword()})); 2987 2988 currentBackend 2989 .addConnectionManager(connectionManagerVLogin, 2990 new VariablePoolConnectionManager(currentBackend.getURL(), 2991 currentBackend.getName(), currentDatabaseBackendUser 2992 .getLogin(), currentDatabaseBackendUser.getPassword(), 2993 currentBackend.getDriverPath(), currentBackend 2994 .getDriverClassName(), initPoolSize, minPoolSize, 2995 maxPoolSize, idleTimeout, waitTimeout)); 2996 } 2997 catch (Exception e) 2998 { 2999 String msg = Translate.get( 3000 "virtualdatabase.xml.connectionmanager.variable.failed", 3001 currentBackend.getName()); 3002 logger.error(msg, e); 3003 throw new SAXException (msg, e); 3004 } 3005 } 3006 3007 3008 3009 3016 private void newDatabaseTable(Attributes atts) throws SAXException 3017 { 3018 String tableName = atts.getValue(DatabasesXmlTags.ATT_tableName); 3019 String nbOfColumns = atts.getValue(DatabasesXmlTags.ATT_nbOfColumns); 3020 3021 if (logger.isDebugEnabled()) 3022 logger.debug(Translate.get("virtualdatabase.xml.schema.table.add", 3023 new String []{tableName, String.valueOf(nbOfColumns)})); 3024 3025 numberOfColumns = Integer.parseInt(nbOfColumns); 3026 3027 try 3028 { 3029 currentTable = new DatabaseTable(tableName, numberOfColumns); 3030 } 3031 catch (NumberFormatException e) 3032 { 3033 String msg = Translate.get("virtualdatabase.xml.schema.table.failed", 3034 tableName); 3035 logger.error(msg, e); 3036 throw new SAXException (msg, e); 3037 } 3038 } 3039 3040 private void newDatabaseSchema(Attributes atts) 3041 { 3042 String dynamicLevel = atts.getValue(DatabasesXmlTags.ATT_dynamicPrecision); 3043 String gatherSystemTable = atts 3044 .getValue(DatabasesXmlTags.ATT_gatherSystemTables); 3045 String schemaName = atts.getValue(DatabasesXmlTags.ATT_schemaName); 3046 3047 if (dynamicLevel == null) 3048 dynamicLevel = DatabasesXmlTags.VAL_all; 3049 if (gatherSystemTable == null) 3050 gatherSystemTable = DatabasesXmlTags.VAL_false; 3051 currentBackend.setDynamicPrecision(DatabaseBackendSchemaConstants 3052 .getDynamicSchemaLevel(dynamicLevel), DatabasesXmlTags.VAL_true 3053 .equals(gatherSystemTable), schemaName); 3054 } 3055 3056 3062 private void newDatabaseColumn(Attributes atts) 3063 { 3064 String columnName = atts.getValue(DatabasesXmlTags.ATT_columnName); 3065 String isUnique = atts.getValue(DatabasesXmlTags.ATT_isUnique); 3066 3067 if (logger.isDebugEnabled()) 3068 logger.debug(Translate.get("virtualdatabase.xml.schema.column.add", 3069 new String []{columnName, String.valueOf(isUnique)})); 3070 3071 currentTable.addColumn(new DatabaseColumn(columnName, isUnique 3072 .equals(DatabasesXmlTags.VAL_true))); 3073 } 3074 3075 private void newDatabaseProcedure(Attributes atts) 3076 { 3077 String procedureName = atts.getValue(DatabasesXmlTags.ATT_name); 3078 String returnType = atts.getValue(DatabasesXmlTags.ATT_returnType); 3079 if (logger.isDebugEnabled()) 3080 logger.debug(Translate.get("virtualdatabase.xml.schema.procedure.add", 3081 new String []{procedureName, returnType})); 3082 3083 currentProcedure = new DatabaseProcedure(procedureName, "", 3084 DatabaseProcedure.getTypeFromString(returnType)); 3085 } 3086 3087 private void newDatabaseProcedureColumn(Attributes atts) 3088 { 3089 String paramName = atts.getValue(DatabasesXmlTags.ATT_name); 3090 String nullable = atts.getValue(DatabasesXmlTags.ATT_nullable); 3091 String type = atts.getValue(DatabasesXmlTags.ATT_paramType); 3092 if (logger.isDebugEnabled()) 3093 logger.debug(Translate.get( 3094 "virtualdatabase.xml.schema.procedure.parameter.add", new String []{ 3095 paramName, nullable, type})); 3096 currentProcedure.addParameter(new DatabaseProcedureParameter(paramName, 3097 DatabaseProcedureParameter.getColumnTypeFromString(type), 3098 DatabaseProcedureParameter.getNullFromString(nullable))); 3099 } 3100} | Popular Tags |