KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > controller > xml > DatabasesParser


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Emmanuel Cecchet.
22  * Contributor(s): Mathieu Peltier, Sara Bouchenakm Nicolas Modrzyk
23  */

24
25 package org.objectweb.cjdbc.controller.xml;
26
27 import java.io.IOException JavaDoc;
28 import java.io.InputStream JavaDoc;
29 import java.io.StringReader JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import java.util.Hashtable JavaDoc;
32
33 import javax.management.NotCompliantMBeanException JavaDoc;
34 import javax.management.ObjectName JavaDoc;
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 JavaDoc;
127 import org.xml.sax.InputSource JavaDoc;
128 import org.xml.sax.SAXException JavaDoc;
129 import org.xml.sax.SAXParseException JavaDoc;
130 import org.xml.sax.XMLReader JavaDoc;
131 import org.xml.sax.helpers.DefaultHandler JavaDoc;
132 import org.xml.sax.helpers.XMLReaderFactory JavaDoc;
133
134 /**
135  * Parses an XML content conforming to C-JDBC.dtd and configure the given C-JDBC
136  * Controller accordingly.
137  *
138  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
139  * @author <a HREF="mailto:Mathieu.Peltier@inrialpes.fr">Mathieu Peltier </a>
140  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
141  * @version 1.0
142  */

143 public class DatabasesParser extends DefaultHandler JavaDoc
144 {
145
146   /** XML parser. */
147   private XMLReader JavaDoc parser;
148
149   /** Logger instance. */
150   static Trace logger = Trace
151                                                              .getLogger(DatabasesParser.class
152                                                                  .getName());
153
154   /** C-JDBC controller to setup. */
155   private Controller controller;
156
157   /** dbToPrepare is used if only a specified database has to be loaded */
158   private Hashtable JavaDoc dbToPrepare = null;
159   /** setter for jumping from one VirtualDatabase definition to the next one */
160   private boolean skipDatabase = false;
161
162   /**
163    * Parsing of Users are only defined in Admin at the moment, but may be
164    * defined somewhere else in the future.
165    */

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 JavaDoc 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 JavaDoc backendNameList;
200   private ErrorCheckingPolicy currentErrorCheckingPolicy;
201
202   private int currentNbOfConcurrentReads;
203
204   /**
205    * Creates a new <code>DatabasesParser</code> instance. This method
206    * Instanciates also a new <code>DatabasesParser</code>.
207    *
208    * @param controller <code>Controller</code> to load the Virtual Database
209    * into
210    * @throws SAXException if an error occurs
211    */

212   public DatabasesParser(Controller controller) throws SAXException JavaDoc
213   {
214     prepareHandler(controller);
215   }
216
217   /**
218    * Creates a new <code>DatabasesParser</code> instance. This method
219    * Instanciates also a new <code>DatabasesParser</code>. This instance will
220    * look only for the specified database.
221    *
222    * @param controller <code>Controller</code> to load the Virtual Database
223    * into
224    * @param virtualName the specified <code>VirtualDatabase</code> to load.
225    * @param autoLoad autoenable switch
226    * @param checkPoint checkpoint information
227    * @throws SAXException if an error occurs
228    */

229   public DatabasesParser(Controller controller, String JavaDoc virtualName,
230       int autoLoad, String JavaDoc checkPoint) throws SAXException JavaDoc
231   {
232     prepareHandler(controller);
233     // Test if a name has been specified. Otherwise skip.
234
if (virtualName != null)
235       prepareDB(virtualName, autoLoad, checkPoint);
236   }
237
238   private void prepareHandler(Controller controller) throws SAXException JavaDoc
239   {
240     // Instantiate a new parser
241
parser = XMLReaderFactory.createXMLReader();
242
243     this.controller = controller;
244
245     // Activate validation
246
parser.setFeature("http://xml.org/sax/features/validation", true);
247
248     // Install error handler
249
parser.setErrorHandler(this);
250
251     // Install document handler
252
parser.setContentHandler(this);
253
254     // Install local entity resolver
255
parser.setEntityResolver(this);
256   }
257
258   /**
259    * Parses an XML content according to C-JDBC DTD.
260    *
261    * @param xml a <code>String</code> containing the XML content to parse
262    * @exception SAXException if an error occurs
263    * @exception IOException if an error occurs
264    */

265   public void readXML(String JavaDoc xml) throws IOException JavaDoc, SAXException JavaDoc
266   {
267     InputSource JavaDoc input = new InputSource JavaDoc(new StringReader JavaDoc(xml));
268     parser.parse(input);
269   }
270
271   /**
272    * Validate an XML content according to C-JDBC DTD.
273    *
274    * @param xml content
275    * @param validateBeforeParsing if true validate the document before the
276    * parsing
277    * @throws IOException if an error occurs
278    * @throws SAXException if an error occurs
279    */

280   public void readXML(String JavaDoc xml, boolean validateBeforeParsing)
281       throws IOException JavaDoc, SAXException JavaDoc
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 JavaDoc 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 JavaDoc errors = validator.getExceptions();
309       for (int i = 0; i < errors.size(); i++)
310         logger.error(((Exception JavaDoc) errors.get(i)).getMessage());
311
312       if (!validator.isValid())
313         throw new SAXException JavaDoc(Translate
314             .get("virtualdatabase.xml.document.not.valid"));
315     }
316     this.readXML(xml);
317   }
318
319   /**
320    * Handles notification of a non-recoverable parser error.
321    *
322    * @param e the warning information encoded as an exception.
323    * @exception SAXException any SAX exception, possibly wrapping another
324    * exception.
325    */

326   public void fatalError(SAXParseException JavaDoc e) throws SAXException JavaDoc
327   {
328     logger.error(Translate.get("virtualdatabase.xml.parsing.fatal",
329         new String JavaDoc[]{e.getPublicId(), String.valueOf(e.getLineNumber()),
330             String.valueOf(e.getColumnNumber()), e.getMessage()}));
331     throw e;
332   }
333
334   /**
335    * Handles notification of a recoverable parser error.
336    *
337    * @param e the warning information encoded as an exception.
338    * @exception SAXException any SAX exception, possibly wrapping another
339    * exception
340    */

341   public void error(SAXParseException JavaDoc e) throws SAXException JavaDoc
342   {
343     logger.error(Translate.get("virtualdatabase.xml.parsing.error",
344         new String JavaDoc[]{e.getPublicId(), String.valueOf(e.getLineNumber()),
345             String.valueOf(e.getColumnNumber()), e.getMessage()}));
346     throw e;
347   }
348
349   /**
350    * Allows to parse the document with a local copy of the DTD whatever the
351    * original <code>DOCTYPE</code> found. Warning, this method is called only
352    * if the XML document contains a <code>DOCTYPE</code>.
353    *
354    * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String,
355    * java.lang.String)
356    */

357   public InputSource JavaDoc resolveEntity(String JavaDoc publicId, String JavaDoc systemId)
358       throws SAXException JavaDoc
359   {
360     InputStream JavaDoc stream = DatabasesXmlTags.class.getResourceAsStream("/"
361         + Constants.C_JDBC_DTD_FILE);
362     if (stream == null)
363       throw new SAXException JavaDoc("Cannot find C-JDBC DTD file '"
364           + Constants.C_JDBC_DTD_FILE + "' in classpath");
365
366     return new InputSource JavaDoc(stream);
367   }
368
369   /**
370    * If this method is called. Only the specified DB of the Xml file will be
371    * loaded.
372    *
373    * @param virtualName <code>VirtualDatabase</code> name
374    * @param autoLoad autoenable switch
375    * @param checkPoint checkpoint for recovery
376    */

377   public void prepareDB(String JavaDoc virtualName, int autoLoad, String JavaDoc checkPoint)
378   {
379     dbToPrepare = new Hashtable JavaDoc(3);
380     dbToPrepare.put("virtualName", virtualName);
381     dbToPrepare.put("autoEnable", String.valueOf(autoLoad));
382     dbToPrepare.put("checkPoint", checkPoint);
383   }
384
385   /**
386    * Initializes parsing of a document.
387    *
388    * @exception SAXException unspecialized error
389    */

390   public void startDocument() throws SAXException JavaDoc
391   {
392     logger.info(Translate.get("virtualdatabase.xml.start"));
393   }
394
395   /**
396    * Finalizes parsing of a document.
397    *
398    * @exception SAXException unspecialized error
399    */

400   public void endDocument() throws SAXException JavaDoc
401   {
402     logger.info(Translate.get("virtualdatabase.xml.done"));
403   }
404
405   /**
406    * Analyzes an element first line.
407    *
408    * @param uri name space URI
409    * @param localName local name
410    * @param name element raw name
411    * @param atts element attributes
412    * @exception SAXException if an error occurs
413    */

414   public void startElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc name,
415       Attributes JavaDoc atts) throws SAXException JavaDoc
416   {
417     logger.debug(Translate.get("virtualdatabase.xml.parsing.start", name));
418
419     // Virtual database
420
if (name.equals(DatabasesXmlTags.ELT_VirtualDatabase))
421     {
422       if (dbToPrepare == null)
423       {
424         // Prepare all databases
425
newVirtualDatabase(atts);
426       }
427       else
428       {
429         // Only prepare one database
430
String JavaDoc virtualName = atts.getValue(DatabasesXmlTags.ATT_name);
431         if (virtualName.equalsIgnoreCase((String JavaDoc) dbToPrepare
432             .get("virtualName")))
433         {
434           // This is the database that we want to prepare
435
skipDatabase = false;
436           newVirtualDatabase(atts);
437         }
438         else
439         {
440           // Skip to next one
441
skipDatabase = true;
442         }
443       }
444     }
445     // Skip to next definition of a virtualDatabase ?
446
if (skipDatabase)
447       return;
448
449     // Distribution
450
else if (name.equals(DatabasesXmlTags.ELT_Distribution))
451       newDistribution(atts);
452
453     // Monitoring
454
else if (name.equals(DatabasesXmlTags.ELT_SQLMonitoring))
455       newSQLMonitoring(atts);
456     else if (name.equals(DatabasesXmlTags.ELT_SQLMonitoringRule))
457       newSQLMonitoringRule(atts);
458
459     // Backup
460
else if (name.equals(DatabasesXmlTags.ELT_Backup))
461       newBackupManager();
462     else if (name.equals(DatabasesXmlTags.ELT_Backuper))
463       newBackuper(atts);
464
465     // Database backend
466
else if (name.equals(DatabasesXmlTags.ELT_DatabaseBackend))
467       newDatabaseBackend(atts);
468     else if (name.equals(DatabasesXmlTags.ELT_RewritingRule))
469       newRewritingRule(atts);
470
471     // Authentication manager
472
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     // Request manager
482
else if (name.equals(DatabasesXmlTags.ELT_RequestManager))
483       newRequestManager(atts);
484
485     // Macro Handler
486
else if (name.equals(DatabasesXmlTags.ELT_MacroHandling))
487       newMacroHandler(atts);
488
489     // Request schedulers
490
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     // Request caches
500
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     // Request load balancers
519
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     // Policies
560
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     // Recovery log
572
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     // Connection managers
584
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     // Database schema
596
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 JavaDoc msg = Translate.get(
603             "virtualdatabase.xml.schema.static.incompatible.dynamic",
604             currentBackend.getName());
605         logger.error(msg);
606         throw new SAXException JavaDoc(msg);
607       }
608       currentDatabaseSchema = new DatabaseSchema();
609     }
610
611     // Database table (inside a DatabaseSchema)
612
else if (name.equals(DatabasesXmlTags.ELT_DatabaseTable))
613       newDatabaseTable(atts);
614
615     // Table column (inside a DatabaseSchema/DatabaseTable)
616
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   /**
626    * DatabasesParser for end of element.
627    *
628    * @param uri name space URI
629    * @param localName local name
630    * @param name element raw name
631    * @exception SAXException if an error occurs
632    */

633   public void endElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc name)
634       throws SAXException JavaDoc
635   {
636     logger.debug(Translate.get("virtualdatabase.xml.parsing.end", name));
637     // Test if skip is needed
638
if (skipDatabase)
639       return;
640
641     // Virtual database
642
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 JavaDoc) dbToPrepare
660                 .get("autoEnable"));
661             String JavaDoc checkPoint = (String JavaDoc) dbToPrepare.get("checkPoint");
662             // checkPoint is store as "" in Hashtable
663
// but methods to enable backend requires checkPoint to be null
664
// if no recovery from checkpoint
665
checkPoint = checkPoint.equalsIgnoreCase("") ? null : checkPoint;
666             controller.addVirtualDatabase(currentVirtualDatabase, autoLoad,
667                 checkPoint);
668           }
669         }
670         catch (Exception JavaDoc e)
671         {
672           String JavaDoc 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     // Request manager
684
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         // We consider that SingleDB and ParallelDB balancers don't need macros
694
// handler
695
if (currentLoadBalancer == null)
696           throw new SAXException JavaDoc("virtualdatabase.xml.loadbalancer.not.set");
697         if (!(currentLoadBalancer instanceof SingleDB || currentLoadBalancer instanceof ParallelDB))
698         {
699           // If no macros handling has been specified, create a default one
700
// based one the dtd default values
701
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 JavaDoc smsg = Translate.get(
717                     "virtualdatabase.xml.no.single.distributed.requestmanager",
718                     currentLoadBalancer.getRAIDbLevel());
719                 logger.error(smsg);
720                 throw new SAXException JavaDoc(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 JavaDoc msg = Translate.get(
737                     "virtualdatabase.xml.no.distributed.requestmanager",
738                     currentLoadBalancer.getRAIDbLevel());
739                 logger.error(msg);
740                 throw new SAXException JavaDoc(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 JavaDoc e)
764         {
765           String JavaDoc msg = Translate
766               .get("virtualdatabase.xml.requestmanager.creation.failed");
767           logger.error(msg, e);
768           throw new SAXException JavaDoc(msg, e);
769         }
770       }
771     }
772
773     // Database backend
774
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 JavaDoc e)
783         {
784           String JavaDoc msg = Translate.get("virtualdatabase.xml.backend.add.failed");
785           logger.error(msg, e);
786           throw new SAXException JavaDoc(msg, e);
787         }
788       }
789       currentBackend = null;
790     }
791
792     // Authentication manager
793
else if (name.equals(DatabasesXmlTags.ELT_AuthenticationManager))
794     {
795       if (currentVirtualDatabase != null)
796       {
797         currentVirtualDatabase
798             .setAuthenticationManager(currentAuthenticationManager);
799       }
800     }
801
802     // Request cache
803
else if (name.equals(DatabasesXmlTags.ELT_RequestCache))
804     {
805       if (currentResultCache != null)
806       { // Set default result cache rule if missing
807
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     // Database schema
828
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 JavaDoc 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 JavaDoc 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     // Database table
863
else if (name.equals(DatabasesXmlTags.ELT_DatabaseTable))
864     {
865       if (currentTable != null)
866       {
867         try
868         {
869           ArrayList JavaDoc 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 JavaDoc[]{
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 JavaDoc 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 JavaDoc e)
906         {
907           logger.error(Translate
908               .get("virtualdatabase.xml.procedure.add.failed"), e);
909         }
910         currentProcedure = null;
911       }
912     }
913
914     // CreateTable rule
915
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     // RAIDb-0 load balancer
927
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 JavaDoc e)
947       {
948         String JavaDoc msg = Translate
949             .get("virtualdatabase.xml.loadbalancer.raidb0.failed");
950         logger.error(msg, e);
951         throw new SAXException JavaDoc(msg, e);
952       }
953     }
954
955     // Recovery Log
956
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 JavaDoc e)
966       {
967         String JavaDoc msg = Translate
968             .get("virtualdatabase.xml.recoverylog.cheking.tables.failed");
969         logger.error(msg, e);
970         throw new SAXException JavaDoc(msg);
971       }
972       // Set the last transaction id of the scheduler from the recovery logs
973
try
974       {
975         currentRequestScheduler.initializeTransactionId(currentRecoveryLog
976             .getLastTransactionId() + 1);
977       }
978       catch (Exception JavaDoc e)
979       {
980         String JavaDoc msg = Translate
981             .get("virtualdatabase.xml.scheduler.initialization.failed");
982         logger.error(msg, e);
983         throw new SAXException JavaDoc(msg);
984       }
985     }
986   }
987
988   /* Virtual database */
989
990   /**
991    * Sets {@link #currentVirtualDatabase}as a new <code> VirtualDatabase
992    * </code>
993    * using the parsed attributes. An exception is thrown in particular if a
994    * virtual database with the same name is already registered in the
995    * controller.
996    *
997    * @param atts parsed attributes
998    * @exception SAXException if an error occurs
999    */

1000  private void newVirtualDatabase(Attributes JavaDoc atts) throws SAXException JavaDoc
1001  {
1002    String JavaDoc name = atts.getValue(DatabasesXmlTags.ATT_name);
1003    String JavaDoc maxNbOfConnections = atts
1004        .getValue(DatabasesXmlTags.ATT_maxNbOfConnections);
1005    String JavaDoc poolThreads = atts.getValue(DatabasesXmlTags.ATT_poolThreads);
1006    String JavaDoc minNbOfThreads = atts.getValue(DatabasesXmlTags.ATT_minNbOfThreads);
1007    String JavaDoc maxNbOfThreads = atts.getValue(DatabasesXmlTags.ATT_maxNbOfThreads);
1008    String JavaDoc maxThreadIdleTime = atts
1009        .getValue(DatabasesXmlTags.ATT_maxThreadIdleTime);
1010    String JavaDoc sqlDumpLength = atts.getValue(DatabasesXmlTags.ATT_sqlDumpLength);
1011    String JavaDoc blobEncodingMethod = atts
1012        .getValue(DatabasesXmlTags.ATT_blobEncodingMethod);
1013
1014    if (controller.hasVirtualDatabase(name))
1015    {
1016      String JavaDoc msg = Translate.get(
1017          "virtualdatabase.xml.virtualdatabase.already.exists", name);
1018      logger.error(msg);
1019      throw new SAXException JavaDoc(msg);
1020    }
1021
1022    try
1023    {
1024      // Process the attributes
1025
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      // converts in ms
1030
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 JavaDoc e)
1043    {
1044      String JavaDoc msg = Translate.get("virtualdatabase.xml.virtualdatabase.failed");
1045      logger.error(msg, e);
1046      throw new SAXException JavaDoc(msg, e);
1047    }
1048  }
1049
1050  /* Distribution */
1051
1052  /**
1053   * Sets {@link #currentVirtualDatabase}as a new
1054   * <code>DistributedVirtalDatabase</code> using the parsed attributes.
1055   *
1056   * @param atts parsed attributes
1057   */

1058  private void newDistribution(Attributes JavaDoc atts) throws SAXException JavaDoc
1059  {
1060    // TODO: We do not handle macroClock
1061
String JavaDoc groupName = atts.getValue(DatabasesXmlTags.ATT_groupName);
1062    String JavaDoc 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 JavaDoc e1)
1070    {
1071      // keep default
1072
}
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 JavaDoc[]{currentVirtualDatabase.getVirtualDatabaseName(),
1081              groupName, castTimeout}));
1082    try
1083    {
1084      // we need to replace previous database mbean
1085
ObjectName JavaDoc 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 JavaDoc e)
1100    {
1101      String JavaDoc msg = Translate
1102          .get("virtualdatabase.xml.virtualdatabase.distributed.failed");
1103      logger.error(msg, e);
1104      throw new SAXException JavaDoc(msg, e);
1105    }
1106  }
1107
1108  /* Monitoring */
1109
1110  /**
1111   * Sets a new <code>SQLMonitoring</code> to the current virtual database.
1112   *
1113   * @param atts parsed attributes
1114   */

1115  private void newSQLMonitoring(Attributes JavaDoc atts)
1116  {
1117    String JavaDoc 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  /**
1132   * Add a new <code>SQLMonitoringRule</code> to the current SQL monitor.
1133   *
1134   * @param atts parsed attributes
1135   */

1136  private void newSQLMonitoringRule(Attributes JavaDoc atts)
1137  {
1138    String JavaDoc queryPattern = atts.getValue(DatabasesXmlTags.ATT_queryPattern);
1139    String JavaDoc caseSensitiveString = atts
1140        .getValue(DatabasesXmlTags.ATT_caseSensitive);
1141    String JavaDoc applyToSkeletonString = atts
1142        .getValue(DatabasesXmlTags.ATT_applyToSkeleton);
1143    String JavaDoc 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    // Create the rule and add it
1162
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 JavaDoc[]{queryPattern, String.valueOf(caseSensitive),
1168              applyToSkeletonString, String.valueOf(monitoring)}));
1169    currentVirtualDatabase.getSQLMonitor().addRule(rule);
1170  }
1171
1172  //
1173
// Backup
1174
//
1175

1176  /**
1177   * Adds a new <code>BackupManager</code>
1178   */

1179  private void newBackupManager()
1180  {
1181    currentBackupManager = new BackupManager();
1182  }
1183
1184  /**
1185   * Adds a new <code>Backuper</code> to the currentBackupManager
1186   *
1187   * @param atts parsed attributes
1188   */

1189  private void newBackuper(Attributes JavaDoc atts)
1190  {
1191    String JavaDoc name = atts.getValue(DatabasesXmlTags.ATT_backuperName);
1192    String JavaDoc className = atts.getValue(DatabasesXmlTags.ATT_className);
1193    String JavaDoc 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 JavaDoc e)
1202    {
1203      String JavaDoc 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  //
1223
// Database backend
1224
//
1225

1226  /**
1227   * Sets {@link #currentBackend}as a new <code> DatabaseBackend</code> using
1228   * the parsed attributes.
1229   *
1230   * @param atts parsed attributes
1231   * @throws SAXException
1232   */

1233  private void newDatabaseBackend(Attributes JavaDoc atts) throws SAXException JavaDoc
1234  {
1235    String JavaDoc name = atts.getValue(DatabasesXmlTags.ATT_name);
1236    String JavaDoc driverClassName = atts.getValue(DatabasesXmlTags.ATT_driver);
1237    String JavaDoc driverPath = atts.getValue(DatabasesXmlTags.ATT_driverPath);
1238    String JavaDoc url = atts.getValue(DatabasesXmlTags.ATT_url);
1239    String JavaDoc 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 JavaDoc[]{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 JavaDoc e)
1262    {
1263      logger.error("MBean is not compliant", e);
1264      throw new SAXException JavaDoc("mbean is not compliant");
1265    }
1266  }
1267
1268  /**
1269   * Adds a <code>AbstractRewritingRule</code> to the current DatabaseBackend.
1270   *
1271   * @param atts parsed attributes
1272   */

1273  private void newRewritingRule(Attributes JavaDoc atts) throws SAXException JavaDoc
1274  {
1275    String JavaDoc queryPattern = atts.getValue(DatabasesXmlTags.ATT_queryPattern);
1276    String JavaDoc rewrite = atts.getValue(DatabasesXmlTags.ATT_rewrite);
1277    String JavaDoc matchingType = atts.getValue(DatabasesXmlTags.ATT_matchingType);
1278    String JavaDoc caseSensitiveString = atts
1279        .getValue(DatabasesXmlTags.ATT_caseSensitive);
1280    String JavaDoc 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    // Create the rule and add it
1294
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 JavaDoc(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 JavaDoc[]{queryPattern, rewrite, String.valueOf(caseSensitive),
1312              String.valueOf(stopOnMatch)}));
1313    currentBackend.addRewritingRule(rule);
1314  }
1315
1316  /* Authentication manager */
1317
1318  /**
1319   * Sets {@link #currentAuthenticationManager}as a new <code>
1320   * AuthenticationManager</code>.
1321   */

1322  private void newAuthenticationManager()
1323  {
1324    currentAuthenticationManager = new AuthenticationManager();
1325  }
1326
1327  /**
1328   * Sets the administrator user of the {@link #currentAuthenticationManager}
1329   * using the parsed attributs.
1330   *
1331   * @param atts parsed attributes
1332   */

1333  private void newAdminUser(Attributes JavaDoc atts)
1334  {
1335    String JavaDoc aLogin = atts.getValue(DatabasesXmlTags.ATT_username);
1336    String JavaDoc 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 JavaDoc[]{
1341              aLogin, aPassword}));
1342    currentAuthenticationManager.addAdminUser(new AdminUser(aLogin, aPassword));
1343  }
1344
1345  /**
1346   * Sets {@link #currentVirtualUser}as a new <code> VirtualDatabaseUser
1347   * </code>
1348   * using the parsed attributes and adds this new virtual database user to the
1349   * {@link #currentAuthenticationManager}.
1350   *
1351   * @param atts parsed attributes
1352   */

1353  private void newVirtualLogin(Attributes JavaDoc atts)
1354  {
1355    String JavaDoc vLogin = atts.getValue(DatabasesXmlTags.ATT_vLogin);
1356    String JavaDoc 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 JavaDoc[]{
1362              vLogin, vPassword}));
1363    currentAuthenticationManager.addVirtualUser(currentVirtualUser);
1364  }
1365
1366  /* Request manager */
1367
1368  /**
1369   * Sets the {@link #beginTimeout},{@link #commitTimeout}and
1370   * {@link #rollbackTimeout}timeouts (in ms) using the parsed attributes.
1371   *
1372   * @param atts element attributes
1373   * @exception SAXException if an error occurs
1374   */

1375  private void newRequestManager(Attributes JavaDoc atts) throws SAXException JavaDoc
1376  {
1377    try
1378    {
1379      String JavaDoc begin = atts.getValue(DatabasesXmlTags.ATT_beginTimeout);
1380      String JavaDoc commit = atts.getValue(DatabasesXmlTags.ATT_commitTimeout);
1381      String JavaDoc rollback = atts.getValue(DatabasesXmlTags.ATT_rollbackTimeout);
1382      String JavaDoc caseSensitiveParsingString = atts
1383          .getValue(DatabasesXmlTags.ATT_caseSensitiveParsing);
1384
1385      // Convert to ms
1386
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 JavaDoc[]{
1399                String.valueOf(beginTimeout), String.valueOf(commitTimeout),
1400                String.valueOf(rollbackTimeout)}));
1401    }
1402    catch (NumberFormatException JavaDoc e)
1403    {
1404      String JavaDoc msg = Translate
1405          .get("virtualdatabase.xml.requestmanager.timeout.failed");
1406      logger.error(msg, e);
1407      throw new SAXException JavaDoc(msg, e);
1408    }
1409  }
1410
1411  /* Macro Handling */
1412
1413  /**
1414   * Adds a new <code>MacrosHandler</code> using the parsed attributes.
1415   *
1416   * @param atts parsed attributes
1417   */

1418  private void newMacroHandler(Attributes JavaDoc atts)
1419  {
1420    /**
1421     * rand (off | int | long | float | double) "float" now (off | date | time |
1422     * timestamp) "timestamp" currentDate (off | date | time | timestamp) "date"
1423     * currentTime (off | date | time | timestamp) "time" timeOfDay (off | date |
1424     * time | timestamp) "timestamp" currentTimestamp (off | date | time |
1425     * timestamp) "timestamp" timeResolution CDATA "0"
1426     */

1427    String JavaDoc rand = atts.getValue(DatabasesXmlTags.ATT_rand);
1428    String JavaDoc now = atts.getValue(DatabasesXmlTags.ATT_now);
1429    String JavaDoc currentDate = atts.getValue(DatabasesXmlTags.ATT_currentDate);
1430    String JavaDoc currentTime = atts.getValue(DatabasesXmlTags.ATT_currentTime);
1431    String JavaDoc currentTimestamp = atts
1432        .getValue(DatabasesXmlTags.ATT_currentTimestamp);
1433    String JavaDoc timeResolution = atts.getValue(DatabasesXmlTags.ATT_timeResolution);
1434    String JavaDoc 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 JavaDoc e)
1450    {
1451      logger.warn(Translate.get(
1452          "virtualdatabase.xml.invalid.macroshandler.settings", e));
1453    }
1454  }
1455
1456  /* Request scheduler */
1457
1458  /**
1459   * Sets {@link #currentRequestScheduler}as a new <code>
1460   * SingleDBPassThroughScheduler</code>
1461   * using the parsed attributes.
1462   *
1463   * @param atts parsed attributes
1464   * @exception SAXException if an error occurs
1465   */

1466  private void newSingleDBScheduler(Attributes JavaDoc atts) throws SAXException JavaDoc
1467  {
1468    String JavaDoc level = atts.getValue(DatabasesXmlTags.ATT_level);
1469
1470    // SingleDB Query Level
1471
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    // SingleDB Pessimistic Transaction Level
1480
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 JavaDoc(Translate.get(
1490          "virtualdatabase.xml.scheduler.singledb.unsupported", level));
1491    }
1492  }
1493
1494  /**
1495   * Sets {@link #currentRequestScheduler}as a new <code>
1496   * RAIDb0PassThroughLevelScheduler</code>
1497   * or <code>RAIDb0PessimisticTransactionLevelScheduler</code> using the
1498   * parsed attributes.
1499   *
1500   * @param atts parsed attributes
1501   * @exception SAXException if an error occurs
1502   */

1503  private void newRAIDb0Scheduler(Attributes JavaDoc atts) throws SAXException JavaDoc
1504  {
1505    String JavaDoc 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 JavaDoc(Translate.get(
1523          "virtualdatabase.xml.scheduler.raidb0.unsupported", level));
1524  }
1525
1526  /**
1527   * Sets {@link #currentRequestScheduler}as a new
1528   * <code>RAIDb1PassThroughScheduler</code>,<code>
1529   * RAIDb1QueryLevelScheduler</code>,
1530   * <code>RAIDb1OptimisticQueryLevelScheduler</code> or
1531   * <code>RAIDb1PessimisticTransactionLevelScheduler</code> using the parsed
1532   * attributes.
1533   *
1534   * @param atts parsed attributes
1535   * @exception SAXException if an error occurs
1536   */

1537  private void newRAIDb1Scheduler(Attributes JavaDoc atts) throws SAXException JavaDoc
1538  {
1539    String JavaDoc level = atts.getValue(DatabasesXmlTags.ATT_level);
1540
1541    // RAIDb-1 Pass Through level
1542
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    // RAIDb-1 Query level
1551
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    // RAIDb-1 Optimistic Query level
1559
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    // RAIDb-1 Optimistic Transaction level
1568
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    // RAIDb-1 Pessimistic Transaction level
1576
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 JavaDoc(Translate.get(
1586          "virtualdatabase.xml.scheduler.raidb1.unsupported", level));
1587    }
1588  }
1589
1590  /**
1591   * Sets {@link #currentRequestScheduler}as a new
1592   * <code>RAIDb2PassThroughScheduler</code>,<code>
1593   * RAIDb2QueryLevelScheduler</code>
1594   * or <code>RAIDb2PessimisticTransactionLevelScheduler</code> using the
1595   * parsed attributes.
1596   *
1597   * @param atts parsed attributes
1598   * @exception SAXException if an error occurs
1599   */

1600  private void newRAIDb2Scheduler(Attributes JavaDoc atts) throws SAXException JavaDoc
1601  {
1602    String JavaDoc level = atts.getValue(DatabasesXmlTags.ATT_level);
1603
1604    // RAIDb-2 Query level
1605
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    // RAIDb-2 Query level
1614
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    // RAIDb-2 Pessimistic Transaction level
1622
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 JavaDoc(Translate.get(
1632          "virtualdatabase.xml.scheduler.raidb2.unsupported", level));
1633    }
1634  }
1635
1636  /* ********************** */
1637  /* *** Request caches *** */
1638  /* ********************** */
1639
1640  /**
1641   * Sets {@link #currentMetadataCache}as a new <code>MetadataCache</code>
1642   * using the parsed attributes.
1643   *
1644   * @param atts parsed attributes
1645   * @exception SAXException if an error occurs
1646   */

1647  private void newMetadataCache(Attributes JavaDoc atts) throws SAXException JavaDoc
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 JavaDoc e)
1658    {
1659      String JavaDoc msg = Translate.get(
1660          "virtualdatabase.xml.metadata.cache.create.failed", e);
1661      logger.error(msg, e);
1662      throw new SAXException JavaDoc(msg, e);
1663    }
1664  }
1665
1666  /**
1667   * Sets {@link #currentParsingCache}as a new <code>ParsingCache</code>
1668   * using the parsed attributes.
1669   *
1670   * @param atts parsed attributes
1671   * @exception SAXException if an error occurs
1672   */

1673  private void newParsingCache(Attributes JavaDoc atts) throws SAXException JavaDoc
1674  {
1675    String JavaDoc 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 JavaDoc 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 JavaDoc e)
1694    {
1695      String JavaDoc msg = Translate.get(
1696          "virtualdatabase.xml.parsing.cache.create.failed", e);
1697      logger.error(msg, e);
1698      throw new SAXException JavaDoc(msg, e);
1699    }
1700  }
1701
1702  /**
1703   * Sets {@link #currentResultCache}as a new <code> ResultCache</code> using
1704   * the parsed attributes.
1705   *
1706   * @param atts parsed attributes
1707   * @exception SAXException if an error occurs
1708   */

1709  private void newResultCache(Attributes JavaDoc atts) throws SAXException JavaDoc
1710  {
1711    String JavaDoc granularity = atts.getValue(DatabasesXmlTags.ATT_granularity);
1712    String JavaDoc maxEntriesString = atts
1713        .getValue(DatabasesXmlTags.ATT_maxNbOfEntries);
1714    String JavaDoc 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 JavaDoc(Translate.get(
1737            "virtualdatabase.xml.cache.unsupported", granularity));
1738
1739      currentResultCache = ResultCacheFactory.getCacheInstance(
1740          granularityValue, maxEntries, pendingTimeout);
1741
1742    }
1743    catch (Exception JavaDoc e)
1744    {
1745      String JavaDoc msg = Translate.get("virtualdatabase.xml.cache.create.failed",
1746          granularity);
1747      logger.error(msg, e);
1748      throw new SAXException JavaDoc(msg, e);
1749    }
1750  }
1751
1752  /**
1753   * Add a new <code>ResultCacheRule</code> using the parsed attributes.
1754   *
1755   * @param atts parsed attributes
1756   * @exception SAXException if an error occurs
1757   */

1758  private void newResultCacheRule(Attributes JavaDoc atts) throws SAXException JavaDoc
1759  {
1760    String JavaDoc queryString = atts.getValue(DatabasesXmlTags.ATT_queryPattern);
1761
1762    String JavaDoc caseSensitiveString = atts
1763        .getValue(DatabasesXmlTags.ATT_caseSensitive);
1764    String JavaDoc 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 JavaDoc 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    // Create the rule
1792
try
1793    {
1794      currentResultCacheRule = new ResultCacheRule(queryString, caseSensitive,
1795          applyToSkeleton, timestampResolution);
1796    }
1797    catch (RESyntaxException e1)
1798    {
1799      String JavaDoc msg = Translate.get("virtualdatabase.xml.cache.rule.invalid", e1);
1800      logger.error(msg);
1801      throw new SAXException JavaDoc(msg);
1802    }
1803
1804    if (logger.isDebugEnabled())
1805      logger.debug(Translate.get("virtualdatabase.xml.cache.rule.add",
1806          new String JavaDoc[]{atts.getValue(DatabasesXmlTags.ATT_queryPattern),
1807              String.valueOf(caseSensitive), applyToSkeletonString,
1808              String.valueOf(timestampResolution)}));
1809    currentResultCache.addCachingRule(currentResultCacheRule);
1810  }
1811
1812  /**
1813   * Set the <code>DefaultResultCacheRule</code> using the parsed attributes.
1814   *
1815   * @param atts parsed attributes
1816   * @exception SAXException if an error occurs
1817   */

1818  private void newDefaultResultCacheRule(Attributes JavaDoc atts) throws SAXException JavaDoc
1819  {
1820    long currentTimestampResolution;
1821    try
1822    {
1823      currentTimestampResolution = Long.parseLong(atts
1824          .getValue(DatabasesXmlTags.ATT_timestampResolution)) / 1000;
1825    }
1826    catch (Exception JavaDoc e)
1827    {
1828      String JavaDoc msg = Translate
1829          .get("virtualdatabase.invalid.timestamp.resolution");
1830      logger.warn(msg);
1831      currentTimestampResolution = 1000;
1832    }
1833    // Create a fake rule
1834
try
1835    {
1836      currentResultCacheRule = new ResultCacheRule("", false, false,
1837          currentTimestampResolution);
1838    }
1839    catch (RESyntaxException e)
1840    {
1841      throw new SAXException JavaDoc(Translate.get(
1842          "virtualdatabase.xml.cache.rule.default.invalid", e));
1843    }
1844  }
1845
1846  /**
1847   * Add a new <code>EagerCaching</code> behavior to the current
1848   * <code>ResultCacheRule</code>.
1849   *
1850   * @param atts parsed attributes
1851   * @exception SAXException if an error occurs
1852   */

1853  private void newEagerCaching(Attributes JavaDoc atts)
1854  {
1855    Hashtable JavaDoc options = new Hashtable JavaDoc();
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  /**
1863   * Add a new <code>RelaxedCaching</code> behavior to the current
1864   * <code>ResultCacheRule</code>.
1865   *
1866   * @param atts parsed attributes
1867   */

1868  private void newRelaxedCaching(Attributes JavaDoc atts)
1869  {
1870    Hashtable JavaDoc options = new Hashtable JavaDoc();
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  /* Load balancers */
1879
1880  /**
1881   * Sets {@link #currentLoadBalancer}as a new <code> SingleDB</code> using
1882   * the parsed attributes.
1883   *
1884   * @exception SAXException if an error occurs
1885   */

1886  private void newSingleDBRequestLoadBalancer() throws SAXException JavaDoc
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 JavaDoc e)
1897    {
1898      String JavaDoc msg = Translate
1899          .get("virtualdatabase.xml.loadbalancer.singledb.failed");
1900      logger.error(msg, e);
1901      throw new SAXException JavaDoc(msg, e);
1902    }
1903  }
1904
1905  //
1906
// ParallelDB load balancers
1907
//
1908

1909  /**
1910   * Sets {@link #currentLoadBalancer}as a new <code>ParallelDB_RR</code>
1911   * using the parsed attributes.
1912   *
1913   * @exception SAXException if an error occurs
1914   */

1915  private void newParallelDBLeastPendingRequestsFirst() throws SAXException JavaDoc
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 JavaDoc e)
1926    {
1927      String JavaDoc msg = Translate
1928          .get("virtualdatabase.xml.loadbalancer.paralleldb_rr.failed");
1929      logger.error(msg, e);
1930      throw new SAXException JavaDoc(msg, e);
1931    }
1932  }
1933
1934  /**
1935   * Sets {@link #currentLoadBalancer}as a new <code>ParallelDB_LPRF</code>
1936   * using the parsed attributes.
1937   *
1938   * @exception SAXException if an error occurs
1939   */

1940  private void newParallelDBRoundRobinLoadBalancer() throws SAXException JavaDoc
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 JavaDoc e)
1951    {
1952      String JavaDoc msg = Translate
1953          .get("virtualdatabase.xml.loadbalancer.paralleldb_lprf.failed");
1954      logger.error(msg, e);
1955      throw new SAXException JavaDoc(msg, e);
1956    }
1957  }
1958
1959  //
1960
// RAIDb-0 load balancers
1961
//
1962

1963  /**
1964   * Sets {@link #currentLoadBalancer}as a new <code> RAIDb0</code> using the
1965   * parsed attributes.
1966   */

1967  private void newRAIDb0LoadBalancer()
1968  {
1969    currentCreateTablePolicy = new CreateTablePolicy();
1970    currentCreateTableRule = null;
1971  }
1972
1973  //
1974
// RAIDb-1 load balancers
1975
//
1976

1977  /**
1978   * Sets {@link #currentLoadBalancer}as a new <code> RAIDb1</code> using the
1979   * parsed attributes.
1980   */

1981  private void newRAIDb1LoadBalancer()
1982  {
1983    currentWaitForCompletionPolicy = null;
1984  }
1985
1986  /**
1987   * Sets {@link #currentLoadBalancer}as a new <code> RAIDb1_RR</code> using
1988   * the parsed attributes.
1989   *
1990   * @exception SAXException if an error occurs
1991   */

1992  private void newRAIDb1RoundRobinLoadBalancer() throws SAXException JavaDoc
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 JavaDoc e)
2012    {
2013      String JavaDoc msg = Translate
2014          .get("virtualdatabase.xml.loadbalancer.raidb1_rr.failed");
2015      logger.error(msg, e);
2016      throw new SAXException JavaDoc(msg, e);
2017    }
2018  }
2019
2020  /**
2021   * Sets {@link #currentLoadBalancer}as a new <code> RAIDb1_WRR</code> using
2022   * the parsed attributes.
2023   *
2024   * @exception SAXException if an error occurs
2025   */

2026  private void newRAIDb1WeightedRoundRobinLoadBalancer() throws SAXException JavaDoc
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 JavaDoc e)
2046    {
2047      String JavaDoc msg = Translate
2048          .get("virtualdatabase.xml.loadbalancer.raidb1_wrr.failed");
2049      logger.error(msg, e);
2050      throw new SAXException JavaDoc(msg, e);
2051    }
2052  }
2053
2054  /**
2055   * Sets {@link #currentLoadBalancer}as a new <code> RAIDb1_LPRF</code> using
2056   * the parsed attributes.
2057   *
2058   * @exception SAXException if an error occurs
2059   */

2060  private void newRAIDb1LeastPendingRequestsFirst() throws SAXException JavaDoc
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 JavaDoc e)
2080    {
2081      String JavaDoc msg = Translate
2082          .get("virtualdatabase.xml.loadbalancer.raidb1_lprf.failed");
2083      logger.error(msg, e);
2084      throw new SAXException JavaDoc(msg, e);
2085    }
2086  }
2087
2088  //
2089
// RAIDb-1ec load balancers
2090
//
2091

2092  /**
2093   * Sets {@link #currentLoadBalancer}as a new <code> RAIDb1ec</code> using
2094   * the parsed attributes.
2095   *
2096   * @param atts parsed attributes
2097   */

2098  private void newRAIDb1ecLoadBalancer(Attributes JavaDoc atts)
2099  {
2100    String JavaDoc nbOfConcurrentReads = atts
2101        .getValue(DatabasesXmlTags.ATT_nbOfConcurrentReads);
2102    currentNbOfConcurrentReads = Integer.parseInt(nbOfConcurrentReads);
2103    currentErrorCheckingPolicy = null;
2104    currentWaitForCompletionPolicy = null;
2105  }
2106
2107  /**
2108   * Sets {@link #currentLoadBalancer}as a new <code> RAIDb1ec_RR</code> using
2109   * the parsed attributes.
2110   *
2111   * @exception SAXException if an error occurs
2112   */

2113  private void newRAIDb1ecRoundRobinLoadBalancer() throws SAXException JavaDoc
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 JavaDoc e)
2138    {
2139      String JavaDoc msg = Translate
2140          .get("virtualdatabase.xml.loadbalancer.raidb1ec_rr.failed");
2141      logger.error(msg, e);
2142      throw new SAXException JavaDoc(msg, e);
2143    }
2144  }
2145
2146  /**
2147   * Sets {@link #currentLoadBalancer}as a new <code> RAIDb1ec_WRR</code>
2148   * using the parsed attributes.
2149   *
2150   * @exception SAXException if an error occurs
2151   */

2152  private void newRAIDb1ecWeightedRoundRobinLoadBalancer() throws SAXException JavaDoc
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 JavaDoc e)
2177    {
2178      String JavaDoc msg = Translate
2179          .get("virtualdatabase.xml.loadbalancer.raidb1ec_wrr.failed");
2180      logger.error(msg, e);
2181      throw new SAXException JavaDoc(msg, e);
2182    }
2183  }
2184
2185  //
2186
// RAIDb-2 load balancers
2187
//
2188

2189  /**
2190   * Sets {@link #currentLoadBalancer}as a new <code> RAIDb2</code> using the
2191   * parsed attributes.
2192   */

2193  private void newRAIDb2LoadBalancer()
2194  {
2195    currentWaitForCompletionPolicy = null;
2196    currentCreateTablePolicy = new CreateTablePolicy();
2197    // Add a default rule to create table on all nodes
2198
currentCreateTablePolicy.addRule(new CreateTableAll());
2199    currentCreateTableRule = null;
2200  }
2201
2202  /**
2203   * Sets {@link #currentLoadBalancer}as a new <code> RAIDb2_RR</code> using
2204   * the parsed attributes.
2205   *
2206   * @exception SAXException if an error occurs
2207   */

2208  private void newRAIDb2RoundRobinLoadBalancer() throws SAXException JavaDoc
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 JavaDoc e)
2228    {
2229      String JavaDoc msg = Translate
2230          .get("virtualdatabase.xml.loadbalancer.raidb2_rr.failed");
2231      logger.error(msg, e);
2232      throw new SAXException JavaDoc(msg, e);
2233    }
2234  }
2235
2236  /**
2237   * Sets {@link #currentLoadBalancer}as a new <code> RAIDb2_WRR</code> using
2238   * the parsed attributes.
2239   *
2240   * @exception SAXException if an error occurs
2241   */

2242  private void newRAIDb2WeightedRoundRobinLoadBalancer() throws SAXException JavaDoc
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 JavaDoc e)
2262    {
2263      String JavaDoc msg = Translate
2264          .get("virtualdatabase.xml.loadbalancer.raidb2_wrr.failed");
2265      logger.error(msg, e);
2266      throw new SAXException JavaDoc(msg, e);
2267    }
2268  }
2269
2270  /**
2271   * Sets {@link #currentLoadBalancer}as a new <code> RAIDb2_LPRF</code> using
2272   * the parsed attributes.
2273   *
2274   * @exception SAXException if an error occurs
2275   */

2276  private void newRAIDb2LeastPendingRequestsFirst() throws SAXException JavaDoc
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 JavaDoc e)
2295    {
2296      String JavaDoc msg = Translate
2297          .get("virtualdatabase.xml.loadbalancer.raidb2_lprf.failed");
2298      logger.error(msg, e);
2299      throw new SAXException JavaDoc(msg, e);
2300    }
2301  }
2302
2303  //
2304
// RAIDb-2ec load balancers
2305
//
2306

2307  /**
2308   * Sets {@link #currentLoadBalancer}as a new <code> RAIDb2ec</code> using
2309   * the parsed attributes.
2310   */

2311  private void newRAIDb2ecLoadBalancer()
2312  {
2313    currentErrorCheckingPolicy = null;
2314    currentWaitForCompletionPolicy = null;
2315    currentCreateTablePolicy = new CreateTablePolicy();
2316    currentCreateTableRule = null;
2317  }
2318
2319  /**
2320   * Sets {@link #currentLoadBalancer}as a new <code> RAIDb2ec_RR</code> using
2321   * the parsed attributes.
2322   *
2323   * @exception SAXException if an error occurs
2324   */

2325  private void newRAIDb2ecRoundRobinLoadBalancer() throws SAXException JavaDoc
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 JavaDoc e)
2350    {
2351      String JavaDoc msg = Translate
2352          .get("virtualdatabase.xml.loadbalancer.raidb2ec_rr.failed");
2353      logger.error(msg, e);
2354      throw new SAXException JavaDoc(msg, e);
2355    }
2356  }
2357
2358  /**
2359   * Sets {@link #currentLoadBalancer}as a new <code> RAIDb2ec_WRR</code>
2360   * using the parsed attributes.
2361   *
2362   * @exception SAXException if an error occurs
2363   */

2364  private void newRAIDb2ecWeightedRoundRobinLoadBalancer() throws SAXException JavaDoc
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 JavaDoc e)
2389    {
2390      String JavaDoc msg = Translate
2391          .get("virtualdatabase.xml.loadbalancer.raidb2ec_wrr.failed");
2392      logger.error(msg, e);
2393      throw new SAXException JavaDoc(msg, e);
2394    }
2395  }
2396
2397  //
2398
// Load balancer policies
2399
//
2400

2401  /**
2402   * Set the WaitForCompletion policy.
2403   *
2404   * @param atts parsed attributes
2405   * @exception SAXException if an error occurs
2406   */

2407  private void newWaitForCompletion(Attributes JavaDoc atts) throws SAXException JavaDoc
2408  {
2409    String JavaDoc 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 JavaDoc(Translate.get(
2421          "virtualdatabase.xml.loadbalancer.waitforcompletion.unsupported",
2422          policy));
2423  }
2424
2425  /**
2426   * Add an ErrorChecking policy.
2427   *
2428   * @param atts parsed attributes
2429   * @exception SAXException if an error occurs
2430   */

2431  private void newErrorChecking(Attributes JavaDoc atts) throws SAXException JavaDoc
2432  {
2433    String JavaDoc nbOfNodes = atts.getValue(DatabasesXmlTags.ATT_numberOfNodes);
2434    String JavaDoc 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 JavaDoc(Translate.get(
2445          "virtualdatabase.xml.loadbalancer.errorchecking.unsupported", policy));
2446  }
2447
2448  /**
2449   * Add a CreateTable rule.
2450   *
2451   * @param atts parsed attributes
2452   * @exception SAXException if an error occurs
2453   */

2454  private void newCreateTable(Attributes JavaDoc atts) throws SAXException JavaDoc
2455  {
2456    String JavaDoc tableName = atts.getValue(DatabasesXmlTags.ATT_tableName);
2457    String JavaDoc nbOfNodes = atts.getValue(DatabasesXmlTags.ATT_numberOfNodes);
2458    String JavaDoc policy = atts.getValue(DatabasesXmlTags.ATT_policy);
2459    backendNameList = new ArrayList JavaDoc();
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 JavaDoc(Translate.get(
2468          "virtualdatabase.xml.create.table.unsupported", policy));
2469
2470    currentCreateTableRule.setNumberOfNodes(Integer.parseInt(nbOfNodes));
2471    currentCreateTableRule.setTableName(tableName);
2472  }
2473
2474  /**
2475   * Adds a backend name to the current backendNameList.
2476   *
2477   * @param atts parsed attributes
2478   */

2479  private void newBackendName(Attributes JavaDoc atts)
2480  {
2481    String JavaDoc 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  /**
2489   * Sets the weight of the {@link #currentLoadBalancer}using the parsed
2490   * attributes.
2491   *
2492   * @param atts parsed attributes
2493   * @exception SAXException if an error occurs
2494   */

2495  private void newBackendWeight(Attributes JavaDoc atts) throws SAXException JavaDoc
2496  {
2497    String JavaDoc 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 JavaDoc[]{String.valueOf(weight), name}));
2505
2506      currentLoadBalancer.setWeight(name, weight);
2507    }
2508    catch (Exception JavaDoc e)
2509    {
2510      String JavaDoc msg = Translate.get("virtualdatabase.xml.backend.weigth.failed",
2511          name);
2512      logger.error(msg, e);
2513      throw new SAXException JavaDoc(msg, e);
2514    }
2515  }
2516
2517  /* Log recovery */
2518
2519  /**
2520   * Sets the currentRecoveryLog as new <code>RecoveryLog</code> using the
2521   * parsed attributes.
2522   *
2523   * @param atts parsed attributes
2524   * @exception SAXException if an error occurs
2525   */

2526  private void newRecoveryLog(Attributes JavaDoc atts) throws SAXException JavaDoc
2527  {
2528    try
2529    {
2530      String JavaDoc driverClassName = atts.getValue(DatabasesXmlTags.ATT_driver);
2531      String JavaDoc driverPath = atts.getValue(DatabasesXmlTags.ATT_driverPath);
2532      String JavaDoc url = atts.getValue(DatabasesXmlTags.ATT_url);
2533      String JavaDoc login = atts.getValue(DatabasesXmlTags.ATT_login);
2534      String JavaDoc password = atts.getValue(DatabasesXmlTags.ATT_password);
2535      String JavaDoc timeout = atts.getValue(DatabasesXmlTags.ATT_requestTimeout);
2536      int recoveryBatchSize = Integer.parseInt(atts
2537          .getValue(DatabasesXmlTags.ATT_recoveryBatchSize));
2538      // Convert to ms
2539
requestTimeout = Integer.parseInt(timeout) * 1000;
2540
2541      if (logger.isDebugEnabled())
2542        logger.debug(Translate.get(
2543            "virtualdatabase.xml.recoverylog.jdbc.create", new String JavaDoc[]{
2544                driverClassName, url, login, password,
2545                String.valueOf(requestTimeout)}));
2546
2547      currentRecoveryLog = new RecoveryLog(driverPath, driverClassName, url,
2548          login, password, requestTimeout, recoveryBatchSize);
2549      // currentRecoveryLog.setBackendTableCreateStatement();
2550
}
2551    catch (Exception JavaDoc e)
2552    {
2553      String JavaDoc msg = Translate.get("virtualdatabase.xml.recoverylog.jdbc.failed");
2554      logger.error(msg, e);
2555      throw new SAXException JavaDoc(msg, e);
2556    }
2557  }
2558
2559  /**
2560   * Sets the recovery log table create statement for the current
2561   * <code>RecoveryLog</code> using the <code>RecoveryLogTable</code> parsed
2562   * attributes.
2563   *
2564   * @param atts parsed attributes
2565   * @exception SAXException if an error occurs
2566   */

2567  private void newRecoveryLogTable(Attributes JavaDoc atts) throws SAXException JavaDoc
2568  {
2569    try
2570    {
2571      String JavaDoc createTable = atts.getValue(DatabasesXmlTags.ATT_createTable);
2572      String JavaDoc tableName = atts.getValue(DatabasesXmlTags.ATT_tableName);
2573      String JavaDoc idType = atts.getValue(DatabasesXmlTags.ATT_idColumnType);
2574      String JavaDoc vloginType = atts.getValue(DatabasesXmlTags.ATT_vloginColumnType);
2575      String JavaDoc sqlName = atts.getValue(DatabasesXmlTags.ATT_sqlColumnName);
2576      String JavaDoc sqlType = atts.getValue(DatabasesXmlTags.ATT_sqlColumnType);
2577      String JavaDoc transactionIdType = atts
2578          .getValue(DatabasesXmlTags.ATT_transactionIdColumnType);
2579      String JavaDoc extraStatement = atts
2580          .getValue(DatabasesXmlTags.ATT_extraStatementDefinition);
2581
2582      if (currentRecoveryLog == null)
2583      {
2584        String JavaDoc msg = Translate
2585            .get("virtualdatabase.xml.recoverylog.jdbc.recoverytable.setnull");
2586        logger.error(msg);
2587        throw new SAXException JavaDoc(msg);
2588      }
2589      else
2590        currentRecoveryLog.setLogTableCreateStatement(createTable, tableName,
2591            idType, vloginType, sqlName, sqlType, transactionIdType,
2592            extraStatement);
2593    }
2594    catch (Exception JavaDoc e)
2595    {
2596      String JavaDoc msg = Translate
2597          .get("virtualdatabase.xml.recoverylog.jdbc.recoverytable.failed");
2598      logger.error(msg, e);
2599      throw new SAXException JavaDoc(msg, e);
2600    }
2601  }
2602
2603  /**
2604   * Sets the checkpoint table create statement for the current
2605   * <code>RecoveryLog</code> using the <code>CheckpointTable</code> parsed
2606   * attributes.
2607   *
2608   * @param atts parsed attributes
2609   * @exception SAXException if an error occurs
2610   */

2611  private void newRecoveryCheckpointTable(Attributes JavaDoc atts) throws SAXException JavaDoc
2612  {
2613    try
2614    {
2615      String JavaDoc createTable = atts.getValue(DatabasesXmlTags.ATT_createTable);
2616      String JavaDoc tableName = atts.getValue(DatabasesXmlTags.ATT_tableName);
2617      String JavaDoc nameType = atts
2618          .getValue(DatabasesXmlTags.ATT_checkpointNameColumnType);
2619      String JavaDoc requestIdType = atts
2620          .getValue(DatabasesXmlTags.ATT_requestIdColumnType);
2621      String JavaDoc extraStatement = atts
2622          .getValue(DatabasesXmlTags.ATT_extraStatementDefinition);
2623
2624      if (currentRecoveryLog == null)
2625      {
2626        String JavaDoc msg = Translate
2627            .get("virtualdatabase.xml.recoverylog.jdbc.checkpointtable.setnull");
2628        logger.error(msg);
2629        throw new SAXException JavaDoc(msg);
2630      }
2631      else
2632        currentRecoveryLog.setCheckpointTableCreateStatement(createTable,
2633            tableName, nameType, requestIdType, extraStatement);
2634    }
2635    catch (Exception JavaDoc e)
2636    {
2637      String JavaDoc msg = Translate
2638          .get("virtualdatabase.xml.recoverylog.jdbc.checkpointtable.failed");
2639      logger.error(msg, e);
2640      throw new SAXException JavaDoc(msg, e);
2641    }
2642  }
2643
2644  /**
2645   * Sets the backend table create statement for the current
2646   * <code>RecoveryLog</code> using the <code>BackendTable</code> parsed
2647   * attributes.
2648   *
2649   * @param atts parsed attributes
2650   * @exception SAXException if an error occurs
2651   */

2652  private void newRecoveryBackendTable(Attributes JavaDoc atts) throws SAXException JavaDoc
2653  {
2654    try
2655    {
2656      String JavaDoc createTable = atts.getValue(DatabasesXmlTags.ATT_createTable);
2657      String JavaDoc tableName = atts.getValue(DatabasesXmlTags.ATT_tableName);
2658      String JavaDoc checkpointNameType = atts
2659          .getValue(DatabasesXmlTags.ATT_checkpointNameColumnType);
2660      String JavaDoc databaseNameType = atts
2661          .getValue(DatabasesXmlTags.ATT_databaseNameColumnType);
2662      String JavaDoc backendNameType = atts
2663          .getValue(DatabasesXmlTags.ATT_backendNameColumnType);
2664      String JavaDoc backendStateType = atts
2665          .getValue(DatabasesXmlTags.ATT_backendStateColumnType);
2666      String JavaDoc extraStatement = atts
2667          .getValue(DatabasesXmlTags.ATT_extraStatementDefinition);
2668
2669      if (currentRecoveryLog == null)
2670      {
2671        String JavaDoc msg = Translate
2672            .get("virtualdatabase.xml.recoverylog.jdbc.backendtable.setnull");
2673        logger.error(msg);
2674        throw new SAXException JavaDoc(msg);
2675      }
2676      else
2677        currentRecoveryLog.setBackendTableCreateStatement(createTable,
2678            tableName, checkpointNameType, backendNameType, backendStateType,
2679            databaseNameType, extraStatement);
2680    }
2681    catch (Exception JavaDoc e)
2682    {
2683      String JavaDoc msg = Translate
2684          .get("virtualdatabase.xml.recoverylog.jdbc.backendtable.failed");
2685      logger.error(msg, e);
2686      throw new SAXException JavaDoc(msg, e);
2687    }
2688  }
2689
2690  /**
2691   * Sets the dump table create statement for the current
2692   * <code>RecoveryLog</code> using the <code>DumpTable</code> parsed
2693   * attributes.
2694   *
2695   * @param atts parsed attributes
2696   * @exception SAXException if an error occurs
2697   */

2698  private void newRecoveryDumpTable(Attributes JavaDoc atts) throws SAXException JavaDoc
2699  {
2700    try
2701    {
2702      String JavaDoc createTable = atts.getValue(DatabasesXmlTags.ATT_createTable);
2703      String JavaDoc tableName = atts.getValue(DatabasesXmlTags.ATT_tableName);
2704      String JavaDoc dumpNameColumnType = atts
2705          .getValue(DatabasesXmlTags.ATT_dumpNameColumnType);
2706      String JavaDoc dumpDateColumnType = atts
2707          .getValue(DatabasesXmlTags.ATT_dumpDateColumnType);
2708      String JavaDoc dumpPathColumnType = atts
2709          .getValue(DatabasesXmlTags.ATT_dumpPathColumnType);
2710      String JavaDoc dumpTypeColumnType = atts
2711          .getValue(DatabasesXmlTags.ATT_dumpFormatColumnType);
2712      String JavaDoc checkpointNameColumnType = atts
2713          .getValue(DatabasesXmlTags.ATT_checkpointNameColumnType);
2714      String JavaDoc backendNameColumnType = atts
2715          .getValue(DatabasesXmlTags.ATT_backendNameColumnType);
2716      String JavaDoc tablesColumnName = atts
2717          .getValue(DatabasesXmlTags.ATT_tablesColumnName);
2718      String JavaDoc tablesColumnType = atts
2719          .getValue(DatabasesXmlTags.ATT_tablesColumnType);
2720
2721      String JavaDoc extraStatement = atts
2722          .getValue(DatabasesXmlTags.ATT_extraStatementDefinition);
2723
2724      if (currentRecoveryLog == null)
2725      {
2726        String JavaDoc msg = Translate
2727            .get("virtualdatabase.xml.recoverylog.jdbc.dumptable.setnull");
2728        logger.error(msg);
2729        throw new SAXException JavaDoc(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 JavaDoc e)
2739    {
2740      String JavaDoc msg = Translate
2741          .get("virtualdatabase.xml.recoverylog.jdbc.dumptable.failed");
2742      logger.error(msg, e);
2743      throw new SAXException JavaDoc(msg, e);
2744    }
2745  }
2746
2747  /* Connection manager */
2748
2749  /**
2750   * Sets the currentRecoveryLog as new <code>RecoveryLog</code> using the
2751   * parsed attributes.
2752   *
2753   * @param atts parsed attributes
2754   * @exception SAXException if an error occurs
2755   */

2756  private void newConnectionManager(Attributes JavaDoc atts) throws SAXException JavaDoc
2757  {
2758    connectionManagerVLogin = atts.getValue(DatabasesXmlTags.ATT_vLogin);
2759    String JavaDoc connectionManagerRLogin = atts.getValue(DatabasesXmlTags.ATT_rLogin);
2760    String JavaDoc connectionManagerRPassword = atts
2761        .getValue(DatabasesXmlTags.ATT_rPassword);
2762    String JavaDoc backendName = currentBackend.getName();
2763
2764    // Check that the virtual login has been defined
2765
if (!currentAuthenticationManager
2766        .isValidVirtualLogin(connectionManagerVLogin))
2767    {
2768      String JavaDoc msg = Translate.get(
2769          "virtualdatabase.xml.connectionmanager.vlogin.undefined",
2770          new String JavaDoc[]{connectionManagerVLogin, currentBackend.getName()});
2771      logger.error(msg);
2772      throw new SAXException JavaDoc(msg);
2773    }
2774    // Add Real user for the database
2775
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 JavaDoc[]{connectionManagerRLogin, connectionManagerRPassword,
2782                  backendName}));
2783
2784    try
2785    {
2786      currentAuthenticationManager.addRealUser(connectionManagerVLogin,
2787          currentDatabaseBackendUser);
2788    }
2789    catch (AuthenticationManagerException e)
2790    {
2791      String JavaDoc msg = Translate
2792          .get("virtualdatabase.xml.authentication.login.real.add.failed");
2793      logger.error(msg, e);
2794      throw new SAXException JavaDoc(msg, e);
2795    }
2796
2797    // // Get database real user
2798
// currentDatabaseBackendUser = currentAuthenticationManager
2799
// .getDatabaseBackendUser(connectionManagerVLogin, currentBackend
2800
// .getName());
2801
//
2802
// if (currentDatabaseBackendUser == null)
2803
// {
2804
// String msg = Translate.get(
2805
// "virtualdatabase.xml.connectionmanager.rlogin.undefined",
2806
// new String[]{currentBackend.getName(), connectionManagerVLogin});
2807
// logger.error(msg);
2808
// throw new SAXException(msg);
2809
// }
2810
}
2811
2812  /**
2813   * Adds a new <code>SimpleConnectionManager</code> to
2814   * {@link #currentBackend}using the parsed attributes.
2815   */

2816  private void newSimpleConnectionManager()
2817  {
2818    if (logger.isDebugEnabled())
2819      logger.debug(Translate.get(
2820          "virtualdatabase.xml.connectionmanager.simple.add", new String JavaDoc[]{
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  /**
2833   * Adds a new <code>FailFastPoolConnectionManager</code> to
2834   * {@link #currentBackend}using the parsed attributes.
2835   *
2836   * @param atts parsed attributes
2837   * @exception SAXException if an error occurs
2838   */

2839  private void newFailFastPoolConnectionManager(Attributes JavaDoc atts)
2840      throws SAXException JavaDoc
2841  {
2842    try
2843    {
2844      int poolSize = Integer.parseInt(atts
2845          .getValue(DatabasesXmlTags.ATT_poolSize));
2846
2847      // sanity check
2848
if (poolSize < 1)
2849        throw new IllegalArgumentException JavaDoc(
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 JavaDoc[]{
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 JavaDoc e)
2869    {
2870      String JavaDoc msg = Translate.get(
2871          "virtualdatabase.xml.connectionmanager.failfast.failed",
2872          currentBackend.getName());
2873      logger.error(msg, e);
2874      throw new SAXException JavaDoc(msg, e);
2875    }
2876  }
2877
2878  /**
2879   * Adds a new <code>RandomWaitPoolConnectionManager</code> to
2880   * {@link #currentBackend}using the parsed attributes.
2881   *
2882   * @param atts parsed attributes
2883   * @exception SAXException if an error occurs
2884   */

2885  private void newRandomWaitPoolConnectionManager(Attributes JavaDoc atts)
2886      throws SAXException JavaDoc
2887  {
2888    try
2889    {
2890      int poolSize = Integer.parseInt(atts
2891          .getValue(DatabasesXmlTags.ATT_poolSize));
2892      String JavaDoc timeoutString = atts.getValue(DatabasesXmlTags.ATT_timeout);
2893      int timeout = 0;
2894
2895      if (timeoutString != null) // Timeout is IMPLIED and
2896
// may be null
2897
timeout = Integer.parseInt(timeoutString);
2898
2899      // sanity check
2900
if (timeout < 0 || poolSize < 1)
2901        throw new IllegalArgumentException JavaDoc(
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 JavaDoc[]{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 JavaDoc e)
2921    {
2922      String JavaDoc msg = Translate.get(
2923          "virtualdatabase.xml.connectionmanager.randomwait.failed",
2924          currentBackend.getName());
2925      logger.error(msg, e);
2926      throw new SAXException JavaDoc(msg, e);
2927    }
2928  }
2929
2930  /**
2931   * Adds a new <code>VariablePoolConnectionManager</code> to
2932   * {@link #currentBackend}using the parsed attributes.
2933   *
2934   * @param atts parsed attributes
2935   * @exception SAXException if an error occurs
2936   */

2937  private void newVariablePoolConnectionManager(Attributes JavaDoc atts)
2938      throws SAXException JavaDoc
2939  {
2940    try
2941    {
2942      int initPoolSize = Integer.parseInt(atts
2943          .getValue(DatabasesXmlTags.ATT_initPoolSize));
2944
2945      int minPoolSize = initPoolSize;
2946      // minPoolSize is IMPLIED and may be null
2947
String JavaDoc attr = atts.getValue(DatabasesXmlTags.ATT_minPoolSize);
2948      if (attr != null)
2949        minPoolSize = Integer.parseInt(attr);
2950
2951      // maxPoolSize is IMPLIED and may be null
2952
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 JavaDoc timeoutString = atts.getValue(DatabasesXmlTags.ATT_idleTimeout);
2958      int idleTimeout = VariablePoolConnectionManager.DEFAULT_IDLE_TIMEOUT;
2959      if (timeoutString != null) // idleTimeout is IMPLIED
2960
// and may be null
2961
idleTimeout = Integer.parseInt(timeoutString);
2962
2963      timeoutString = atts.getValue(DatabasesXmlTags.ATT_waitTimeout);
2964      int waitTimeout = VariablePoolConnectionManager.DEFAULT_WAIT_TIMEOUT;
2965      if (timeoutString != null) // waitTimeout is IMPLIED
2966
// and may be null
2967
waitTimeout = Integer.parseInt(timeoutString);
2968
2969      // sanity checks
2970
if (minPoolSize < 0 || maxPoolSize < 0
2971          || (maxPoolSize != 0 && minPoolSize > maxPoolSize)
2972          || (maxPoolSize != 0 && initPoolSize > maxPoolSize)
2973          || initPoolSize < minPoolSize)
2974        throw new IllegalArgumentException JavaDoc(
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 JavaDoc[]{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 JavaDoc e)
2998    {
2999      String JavaDoc msg = Translate.get(
3000          "virtualdatabase.xml.connectionmanager.variable.failed",
3001          currentBackend.getName());
3002      logger.error(msg, e);
3003      throw new SAXException JavaDoc(msg, e);
3004    }
3005  }
3006
3007  /* Database schema */
3008
3009  /**
3010   * Sets {@link #currentTable}as a new <code> DatabaseTable</code> using the
3011   * parsed attributs.
3012   *
3013   * @param atts parsed attributes
3014   * @exception SAXException if error occurs
3015   */

3016  private void newDatabaseTable(Attributes JavaDoc atts) throws SAXException JavaDoc
3017  {
3018    String JavaDoc tableName = atts.getValue(DatabasesXmlTags.ATT_tableName);
3019    String JavaDoc nbOfColumns = atts.getValue(DatabasesXmlTags.ATT_nbOfColumns);
3020
3021    if (logger.isDebugEnabled())
3022      logger.debug(Translate.get("virtualdatabase.xml.schema.table.add",
3023          new String JavaDoc[]{tableName, String.valueOf(nbOfColumns)}));
3024
3025    numberOfColumns = Integer.parseInt(nbOfColumns);
3026
3027    try
3028    {
3029      currentTable = new DatabaseTable(tableName, numberOfColumns);
3030    }
3031    catch (NumberFormatException JavaDoc e)
3032    {
3033      String JavaDoc msg = Translate.get("virtualdatabase.xml.schema.table.failed",
3034          tableName);
3035      logger.error(msg, e);
3036      throw new SAXException JavaDoc(msg, e);
3037    }
3038  }
3039
3040  private void newDatabaseSchema(Attributes JavaDoc atts)
3041  {
3042    String JavaDoc dynamicLevel = atts.getValue(DatabasesXmlTags.ATT_dynamicPrecision);
3043    String JavaDoc gatherSystemTable = atts
3044        .getValue(DatabasesXmlTags.ATT_gatherSystemTables);
3045    String JavaDoc 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  /**
3057   * Adds to {@link #currentTable}a new <code> DatabaseColumn</code> using the
3058   * parsed attributes.
3059   *
3060   * @param atts parsed attributes
3061   */

3062  private void newDatabaseColumn(Attributes JavaDoc atts)
3063  {
3064    String JavaDoc columnName = atts.getValue(DatabasesXmlTags.ATT_columnName);
3065    String JavaDoc isUnique = atts.getValue(DatabasesXmlTags.ATT_isUnique);
3066
3067    if (logger.isDebugEnabled())
3068      logger.debug(Translate.get("virtualdatabase.xml.schema.column.add",
3069          new String JavaDoc[]{columnName, String.valueOf(isUnique)}));
3070
3071    currentTable.addColumn(new DatabaseColumn(columnName, isUnique
3072        .equals(DatabasesXmlTags.VAL_true)));
3073  }
3074
3075  private void newDatabaseProcedure(Attributes JavaDoc atts)
3076  {
3077    String JavaDoc procedureName = atts.getValue(DatabasesXmlTags.ATT_name);
3078    String JavaDoc returnType = atts.getValue(DatabasesXmlTags.ATT_returnType);
3079    if (logger.isDebugEnabled())
3080      logger.debug(Translate.get("virtualdatabase.xml.schema.procedure.add",
3081          new String JavaDoc[]{procedureName, returnType}));
3082
3083    currentProcedure = new DatabaseProcedure(procedureName, "",
3084        DatabaseProcedure.getTypeFromString(returnType));
3085  }
3086
3087  private void newDatabaseProcedureColumn(Attributes JavaDoc atts)
3088  {
3089    String JavaDoc paramName = atts.getValue(DatabasesXmlTags.ATT_name);
3090    String JavaDoc nullable = atts.getValue(DatabasesXmlTags.ATT_nullable);
3091    String JavaDoc type = atts.getValue(DatabasesXmlTags.ATT_paramType);
3092    if (logger.isDebugEnabled())
3093      logger.debug(Translate.get(
3094          "virtualdatabase.xml.schema.procedure.parameter.add", new String JavaDoc[]{
3095              paramName, nullable, type}));
3096    currentProcedure.addParameter(new DatabaseProcedureParameter(paramName,
3097        DatabaseProcedureParameter.getColumnTypeFromString(type),
3098        DatabaseProcedureParameter.getNullFromString(nullable)));
3099  }
3100}
Popular Tags