KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > server > DatabaseEdit


1 /**
2  * Title: AdminGui
3  * Description: Edit DatabaseManager parameters from configuration file.
4  * @Author tufeX, tufex@uns.ns.ac.yu & Vladimir Radisic
5  * @Version 1.1.0
6  */

7
8 package org.enhydra.server;
9
10 import org.enhydra.util.ConfigFileInterface;
11
12 import com.lutris.util.Config;
13 import com.lutris.util.ConfigException;
14 import com.lutris.util.KeywordValueException;
15
16 /**
17  * Instances of this class are used in manipulation and editing of DatabaseManager
18  * section parameters, defined in application configuration file. Also this class
19  * contains method saveState which provides saving changed configuration onto disk.
20  */

21 public class DatabaseEdit {
22
23 /**
24  * Array of database names used within application.
25  */

26   private String JavaDoc [] databases = null;
27
28 /**
29  * Current database. This variable points to database, which parmeters are
30  * currently holding in the temporary private variables of the object.
31  */

32   private String JavaDoc currentDatabase = null;
33
34 /**
35  * Temporary storage for current database parameters. This parameters are an image
36  * of parameters from the configuration file of the application, which are led
37  * width DatabaseManager section. Parameters are invoked only in aim of faster
38  * response in getter methods (otherwise they can be found fromConfig object).
39  */

40   private String JavaDoc defaultDatabase = "N/A";
41   private String JavaDoc debug = "N/A";
42   private String JavaDoc dBnameClassType = "N/A";
43   private String JavaDoc dBnameJdbcDriver = "N/A";
44   private String JavaDoc dBnameConnectionUrl = "N/A";
45   private String JavaDoc dBnameConnectionUser = "N/A";
46   private String JavaDoc dBnameConnectionPassword = "N/A";
47   private String JavaDoc dBnameConnectionMaxPoolSize = "N/A";
48   private String JavaDoc dBnameConnectionAllocationTimeout = "N/A";
49   private String JavaDoc dBnameConnectionLogging = "N/A";
50   private String JavaDoc dBnameObjectIdCacheSize = "N/A";
51   private String JavaDoc dBnameObjectIdMinValue = "N/A";
52
53 /**
54  * Storage for application configure parameters represented as Config object
55  */

56   private Config configTemp;
57
58 /**
59  * Storage for application configure parameters represented as Config object. this
60  * is reference to original application configuration file.
61  */

62   private Config configOriginal;
63
64 /**
65  * Construction of DatabaseEdit object for particular application with given
66  * configuration file.
67  * @param config configuration file of the application represented as Config
68  * object.
69  * @exception ConfigException
70  * @exception KeywordValueException
71  */

72   public DatabaseEdit (Config config) throws ConfigException, KeywordValueException {
73     this.configOriginal = config; // saving reference to original Config object
74
this.configTemp = config.getClonedConfig(); // template Config file used for manipulation
75

76     if(configTemp.containsKey("DatabaseManager.Databases"))
77       databases = configTemp.getStrings("DatabaseManager.Databases");
78     if(configTemp.containsKey("DatabaseManager.DefaultDatabase")) {
79       defaultDatabase = configTemp.getString("DatabaseManager.DefaultDatabase");
80       currentDatabase = new String JavaDoc(defaultDatabase);
81     }
82     if (configTemp.containsKey("DatabaseManager.Debug"))
83       debug = configTemp.getString("DatabaseManager.Debug");
84     if (currentDatabase == null && databases != null)
85       currentDatabase = new String JavaDoc(databases[0]);
86
87     this.refreshAllDbParameters(currentDatabase);
88   }
89
90 /**
91  * Finds all parameters for specified database in configuration file and sets
92  * they to temporary object arguments.
93  * @param dBname name of database which parameters are searched.
94  * @exception KeywordValueException
95  */

96   public void refreshAllDbParameters(String JavaDoc dBname) throws KeywordValueException {
97
98     this.databases = null;
99     this.currentDatabase = null;
100
101     this.defaultDatabase = "N/A";
102     this.debug = "N/A";
103     this.dBnameClassType = "N/A";
104     this.dBnameJdbcDriver = "N/A";
105     this.dBnameConnectionUrl = "N/A";
106     this.dBnameConnectionUser = "N/A";
107     this.dBnameConnectionPassword = "N/A";
108     this.dBnameConnectionMaxPoolSize = "N/A";
109     this.dBnameConnectionAllocationTimeout = "N/A";
110     this.dBnameConnectionLogging = "N/A";
111     this.dBnameObjectIdCacheSize = "N/A";
112     this.dBnameObjectIdMinValue = "N/A";
113
114     Config tempParentConfig = null;
115 // Config tempConfig = (Config) configTemp.getSection("DatabaseManager.");
116
Config tempConfig = (Config) configTemp.getSection("DatabaseManager");
117     if (tempConfig != null) {
118       if(tempConfig.containsKey("Databases")) {
119         this.databases = tempConfig.getStrings("Databases");
120 // checks given parameter (dBname) for existing in configTemp file
121
if(this.existDbName(dBname))
122           this.currentDatabase = dBname;
123       }
124       if(tempConfig.containsKey("DefaultDatabase"))
125         defaultDatabase = tempConfig.getString("DefaultDatabase");
126
127       if (tempConfig.containsKey("Debug"))
128         debug = tempConfig.getString("Debug");
129
130       if(currentDatabase == null)
131         return;
132
133 // Finds parameters for specified database
134
tempParentConfig = tempConfig;
135       tempConfig = (Config) tempConfig.getSection("DB." + dBname);
136       if(tempConfig!=null) {
137         if (tempConfig.containsKey("ClassType"))
138           dBnameClassType = tempConfig.getString("ClassType");
139         if (tempConfig.containsKey("JdbcDriver"))
140           dBnameJdbcDriver = tempConfig.getString("JdbcDriver");
141
142         tempParentConfig = tempConfig;
143         tempConfig = (Config) tempConfig.getSection("Connection");
144         if(tempConfig!=null) {
145           if (tempConfig.containsKey("Url"))
146             dBnameConnectionUrl = tempConfig.getString("Url");
147           if (tempConfig.containsKey("User"))
148             dBnameConnectionUser = tempConfig.getString("User");
149           if (tempConfig.containsKey("Password"))
150             dBnameConnectionPassword = tempConfig.getString("Password");
151           if (tempConfig.containsKey("MaxPoolSize"))
152             dBnameConnectionMaxPoolSize = tempConfig.getString("MaxPoolSize");
153           if (tempConfig.containsKey("AllocationTimeout"))
154             dBnameConnectionAllocationTimeout = tempConfig.getString("AllocationTimeout");
155           if (tempConfig.containsKey("Logging"))
156             dBnameConnectionLogging = tempConfig.getString("Logging");
157         }
158         tempConfig = tempParentConfig;
159         tempConfig = (Config) tempConfig.getSection("ObjectId");
160         if(tempConfig!=null) {
161           if (tempConfig.containsKey("CacheSize"))
162             dBnameObjectIdCacheSize = tempConfig.getString("CacheSize");
163           if (tempConfig.containsKey("MinValue"))
164             dBnameObjectIdMinValue = tempConfig.getString("MinValue");
165         }
166       }
167     }
168   }
169
170 /**
171  * Checks existence of given database name in the list of already defined
172  * databases for application.
173  * @param dBname the name of the database.
174  * @return true = database name already exists, false = database name does not
175  * exist.
176  */

177 public boolean existDbName(String JavaDoc dBname) {
178   if(dBname == null || databases == null)
179     return false;
180   for (int i = 0; i < this.databases.length; i++) {
181     if (databases[i].equalsIgnoreCase(dBname))
182       return true;
183   }
184   return false;
185
186 }
187
188 /**
189  * Adds database name to list of databases used by application. This list is
190  * represented by "Datasbase" parameter in configuration file of the application.
191  * @param dBname the name of the database.
192  * @return true = database name is sucessfuly added, false = database name is
193  * not added.
194  * @exception KeywordValueException
195  */

196   public boolean addDatabase(String JavaDoc dBname) throws KeywordValueException{
197     if(this.existDbName(dBname))
198       return false;
199
200     String JavaDoc[] newDbString = null;
201     if(this.databases == null) //handles adding of first item in database list
202
newDbString = new String JavaDoc[1];
203     else
204       newDbString = new String JavaDoc[this.databases.length+1];
205
206     newDbString[newDbString.length-1] = dBname;
207
208     for (int i = 0; i < newDbString.length-1; i++)
209       newDbString[i] = this.databases[i];
210
211     this.configTemp.set("DatabaseManager.Databases", newDbString);
212     this.databases = newDbString;
213
214 // sets initial values for all parameters. This values should be later changed
215
// width real values
216
this.setDBnameClassType("Standard", dBname);
217     this.setDBnameJdbcDriver("sun.jdbc.odbc.JdbcOdbcDriver", dBname);
218     this.setDBnameConnectionAllocationTimeout("10000", dBname);
219     this.setDBnameConnectionLogging("false", dBname);
220     this.setDBnameConnectionMaxPoolSize("30", dBname);
221     this.setDBnameConnectionUrl("jdbc:odbc:"+dBname, dBname);
222     this.setDBnameConnectionPassword("tiger", dBname);
223     this.setDBnameConnectionUser("miga", dBname);
224     this.setDBnameObjectIdCacheSize("20", dBname);
225     this.setDBnameObjectIdMinValue("1000000", dBname);
226
227     return true;
228   }
229
230 /**
231  * Removes database name from array of databases used by application. This list is
232  * represented by "Datasbase" parameter in configuration file of the application.
233  * @param dBname the name of the database.
234  * @return true = database name is sucessfuly removed, false = database name is
235  * not removed.
236  * @exception KeywordValueException
237  */

238   public boolean removeDatabase(String JavaDoc dBname) throws KeywordValueException {
239     if(!this.existDbName(dBname))
240       return false;
241     String JavaDoc[] newDbString = new String JavaDoc[this.databases.length-1];
242
243     for (int i=0,j=0; i < newDbString.length; i++) {
244       if(!this.databases[j].equalsIgnoreCase(dBname))
245         newDbString[i] = this.databases[j];
246       else
247         i--;
248       j++;
249     }
250
251     if(this.currentDatabase!=null && this.currentDatabase.equalsIgnoreCase(dBname)) {
252       this.currentDatabase = null;
253     }
254
255 // remowes all keys connected with removed database;
256
String JavaDoc testDefaultDb = null;
257     if(configTemp.containsKey("DatabaseManager.DefaultDatabase"))
258       testDefaultDb = (String JavaDoc)configTemp.get("DatabaseManager.DefaultDatabase");
259     if( (testDefaultDb!=null && !testDefaultDb.trim().equals("")) &&
260         testDefaultDb.equalsIgnoreCase(dBname)) {
261       this.configTemp.remove("DatabaseManager.DefaultDatabase");
262       this.defaultDatabase = "N/A";
263     }
264
265     this.configTemp.remove("DatabaseManager.DB." + dBname + ".ClassType");
266     this.configTemp.remove("DatabaseManager.DB." + dBname + ".JdbcDriver");
267     this.configTemp.remove("DatabaseManager.DB." + dBname + ".Connection.AllocationTimeout");
268     this.configTemp.remove("DatabaseManager.DB." + dBname + ".Connection.Logging");
269     this.configTemp.remove("DatabaseManager.DB." + dBname + ".Connection.MaxPoolSize");
270     this.configTemp.remove("DatabaseManager.DB." + dBname + ".Connection.Url");
271     this.configTemp.remove("DatabaseManager.DB." + dBname + ".Connection.Password");
272     this.configTemp.remove("DatabaseManager.DB." + dBname + ".Connection.User");
273     this.configTemp.remove("DatabaseManager.DB." + dBname + ".ObjectId.CacheSize");
274     this.configTemp.remove("DatabaseManager.DB." + dBname + ".ObjectId.MinValue");
275
276     if(newDbString.length == 0) { //handles removing of last item in database list
277
this.configTemp.remove("DatabaseManager.Databases");
278       this.databases = null;
279       this.currentDatabase = null;
280     }
281     else {
282       this.configTemp.set("DatabaseManager.Databases", newDbString);
283       this.databases = newDbString;
284     }
285     return true;
286   }
287
288 /**
289  * Sets list of database names. Old settings are remowed and are swapped with
290  * given new list. All corresponding database parameters, for given database names
291  * in list, with its default initial values will be added too
292  * @param databases list of database names.
293  * @exception KeywordValueException
294  */

295   public void setDatabases(String JavaDoc [] databases) throws KeywordValueException {
296     String JavaDoc newDbParam = "";
297     for (int i = 0; i < databases.length; i++) {
298       if(i==0)
299         newDbParam = "\"" + this.databases[i] + "\"";
300       else
301         newDbParam = newDbParam + ", \"" + this.databases[i] + "\"";
302     }
303 // removes all keys connected width old database parameters
304
for (int i = 0; i < this.databases.length; i++) {
305       this.removeDatabase(databases[i]);
306     }
307
308     this.configTemp.set("DatabaseManager.Databases", newDbParam);
309     this.databases = databases;
310
311 // adds keys for new database parameters
312
for (int i = 0; i < this.databases.length; i++) {
313       this.addDatabase(databases[i]);
314     }
315
316   }
317
318 /**
319  * Gets list of available database names.
320  * @return list of available databases represented as String array
321  * @exception KeywordValueException
322  */

323   public String JavaDoc[] getDatabases() {
324     return this.databases;
325   }
326
327 /**
328  * Sets value of ClassType parameter for given database name in Config
329  * object of application.
330  * @param value given value of ClassType parameter represented as String
331  * @param dBname name of database which parameter's value is changed or set.
332  * @throws KeywordValueException
333  */

334   public void setDBnameClassType(String JavaDoc value, String JavaDoc dBname) throws KeywordValueException{
335     if(this.existDbName(dBname)) {
336       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
337         this.refreshAllDbParameters(dBname);
338       if(value==null || value.trim().equals("")) {
339         this.dBnameClassType = "N/A";
340         configTemp.set("DatabaseManager.DB." + dBname + ".ClassType", "");
341       }
342       else {
343         this.dBnameClassType = value;
344         configTemp.set("DatabaseManager.DB." + dBname + ".ClassType", value);
345       }
346     }
347   }
348
349 /**
350  * Gets value of ClassType parameter for given database name from Config
351  * object of application.
352  * @param dBname name of database which parameter's value is changed or set.
353  * @return value of parameter represented as String
354  * @throws KeywordValueException
355  */

356   public String JavaDoc getDBnameClassType( String JavaDoc dBname) throws KeywordValueException {
357     if(this.existDbName(dBname)) {
358       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
359         this.refreshAllDbParameters(dBname);
360       return this.dBnameClassType;
361     }
362     else
363       return "N/A";
364   }
365
366 /**
367  * Sets value of Connection.AllocationTimeout parameter for given database name
368  * in Config object of application.
369  * @param value given value of Connection.AllocationTimeout parameter represented
370  * as String.
371  * @param dBname name of database which parameter's value is changed or set.
372  * @throws KeywordValueException
373  */

374   public void setDBnameConnectionAllocationTimeout(String JavaDoc value, String JavaDoc dBname) throws KeywordValueException {
375     if(this.existDbName(dBname)) {
376       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
377         this.refreshAllDbParameters(dBname);
378       if(value==null || value.trim().equals("")) {
379         this.dBnameConnectionAllocationTimeout = "N/A";
380         configTemp.set("DatabaseManager.DB." + dBname + ".Connection.AllocationTimeout", "");
381       }
382       else {
383         this.dBnameConnectionAllocationTimeout = value;
384         configTemp.set("DatabaseManager.DB." + dBname + ".Connection.AllocationTimeout", value);
385       }
386     }
387   }
388
389   /**
390    * Gets value of Connection. AllocationTimeout parameter for given database name
391    * from Config object of application.
392    * @param dBname name of database which parameter's value is changed or set.
393    * @return value of parameter represented as String
394    * @throws KeywordValueException
395    */

396   public String JavaDoc getDBnameConnectionAllocationTimeout( String JavaDoc dBname) throws KeywordValueException{
397     if(this.existDbName(dBname)) {
398       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
399         this.refreshAllDbParameters(dBname);
400       return this.dBnameConnectionAllocationTimeout;
401     }
402     else
403       return "N/A";
404   }
405
406 /**
407  * Sets value of Connection.Logging parameter for given database name in Config
408  * object of application.
409  * @param value given value of Connection.Logging parameter represented as String.
410  * Allowable values for this parameter are "true" and "false". Any other value
411  * will be treated as N/A (not available).
412  * @param dBname name of database which parameter's value is changed or set.
413  * @throws KeywordValueException
414  */

415   public void setDBnameConnectionLogging(String JavaDoc value, String JavaDoc dBname) throws KeywordValueException{
416     if(this.existDbName(dBname)) {
417       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
418         this.refreshAllDbParameters(dBname);
419       if(value==null || value.trim().equals("") ||
420         !(value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) ) {
421         this.dBnameConnectionLogging = "N/A";
422         configTemp.set("DatabaseManager.DB." + dBname + ".Connection.Logging", "");
423       }
424       else {
425         this.dBnameConnectionLogging = value;
426         configTemp.set("DatabaseManager.DB." + dBname + ".Connection.Logging", value);
427       }
428     }
429   }
430
431 /**
432  * Gets value of Connection.Logging parameter for given database name from Config
433  * object of application.
434  * @param dBname name of database which parameter's value is changed or set.
435  * @return value of parameter represented as String. It could has values "true",
436  * "false" or "N/A" in case of parameter absence.
437  * @throws KeywordValueException
438  */

439   public String JavaDoc getDBnameConnectionLogging( String JavaDoc dBname) throws KeywordValueException{
440     if(this.existDbName(dBname)) {
441       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
442         this.refreshAllDbParameters(dBname);
443       return this.dBnameConnectionLogging;
444     }
445     else
446       return "N/A";
447   }
448
449 /**
450  * Sets value of Connection.MaxPoolSize parameter for given database name in Config
451  * object of application.
452  * @param value given value of Connection.MaxPoolSize parameter represented as String
453  * @param dBname name of database which parameter's value is changed or set.
454  * @throws KeywordValueException
455  */

456   public void setDBnameConnectionMaxPoolSize(String JavaDoc value, String JavaDoc dBname) throws KeywordValueException{
457     if(this.existDbName(dBname)) {
458       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
459         this.refreshAllDbParameters(dBname);
460       if(value==null || value.trim().equals("")) {
461         this.dBnameConnectionMaxPoolSize = "N/A";
462         configTemp.set("DatabaseManager.DB." + dBname + ".Connection.MaxPoolSize", "");
463       }
464       else {
465         this.dBnameConnectionMaxPoolSize = value;
466         configTemp.set("DatabaseManager.DB." + dBname + ".Connection.MaxPoolSize", value);
467       }
468     }
469   }
470
471 /**
472  * Gets value of Connection.MaxPoolSize parameter for given database name from Config
473  * object of application.
474  * @param dBname name of database which parameter's value is changed or set.
475  * @return value of parameter represented as String
476  * @throws KeywordValueException
477  */

478   public String JavaDoc getDBnameConnectionMaxPoolSize( String JavaDoc dBname) throws KeywordValueException{
479     if(this.existDbName(dBname)) {
480       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
481         this.refreshAllDbParameters(dBname);
482       return this.dBnameConnectionMaxPoolSize;
483     }
484     else
485       return "N/A";
486   }
487
488 /**
489  * Sets value of Connection.Password parameter for given database name in Config
490  * object of application.
491  * @param value given value of Connection.Password parameter represented as String
492  * @param dBname name of database which parameter's value is changed or set.
493  * @throws KeywordValueException
494  */

495   public void setDBnameConnectionPassword(String JavaDoc value, String JavaDoc dBname) throws KeywordValueException{
496     if(this.existDbName(dBname)) {
497       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
498         this.refreshAllDbParameters(dBname);
499       if(value==null || value.trim().equals("")) {
500         this.dBnameConnectionPassword = "N/A";
501         configTemp.set("DatabaseManager.DB." + dBname + ".Connection.Password", "");
502       }
503       else {
504         this.dBnameConnectionPassword = value;
505         configTemp.set("DatabaseManager.DB." + dBname + ".Connection.Password", value);
506       }
507     }
508   }
509
510 /**
511  * Gets value of Connection.Password parameter for given database name from Config
512  * object of application.
513  * @param dBname name of database which parameter's value is changed or set.
514  * @return value of parameter represented as String
515  * @throws KeywordValueException
516  */

517   public String JavaDoc getDBnameConnectionPassword( String JavaDoc dBname) throws KeywordValueException{
518     if(this.existDbName(dBname)) {
519       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
520         this.refreshAllDbParameters(dBname);
521       return this.dBnameConnectionPassword;
522     }
523     else
524       return "N/A";
525   }
526
527 /**
528  * Sets value of Connection.Url parameter for given database name in Config
529  * object of application.
530  * @param value given value of Connection.Url parameter represented as String
531  * @param dBname name of database which parameter's value is changed or set.
532  * @throws KeywordValueException
533  */

534   public void setDBnameConnectionUrl(String JavaDoc value, String JavaDoc dBname) throws KeywordValueException{
535     if(this.existDbName(dBname)) {
536       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
537         this.refreshAllDbParameters(dBname);
538       if(value==null || value.trim().equals("")) {
539         this.dBnameConnectionUrl = "N/A";
540         configTemp.set("DatabaseManager.DB." + dBname + ".Connection.Url", "");
541       }
542       else {
543         this.dBnameConnectionUrl = value;
544         configTemp.set("DatabaseManager.DB." + dBname + ".Connection.Url", value);
545       }
546     }
547   }
548
549 /**
550  * Gets value of Connection.Url parameter for given database name from Config
551  * object of application.
552  * @param dBname name of database which parameter's value is changed or set.
553  * @return value of parameter represented as String
554  * @throws KeywordValueException
555  */

556   public String JavaDoc getDBnameConnectionUrl( String JavaDoc dBname) throws KeywordValueException{
557     if(this.existDbName(dBname)) {
558       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
559         this.refreshAllDbParameters(dBname);
560       return this.dBnameConnectionUrl;
561     }
562     else
563       return "N/A";
564   }
565
566 /**
567  * Sets value of Connection.User parameter for given database name in Config
568  * object of application.
569  * @param value given value of Connection.User parameter represented as String
570  * @param dBname name of database which parameter's value is changed or set.
571  * @throws KeywordValueException
572  */

573   public void setDBnameConnectionUser(String JavaDoc value, String JavaDoc dBname) throws KeywordValueException{
574     if(this.existDbName(dBname)) {
575       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
576         this.refreshAllDbParameters(dBname);
577       if(value==null || value.trim().equals("")) {
578         this.dBnameConnectionUser = "N/A";
579         configTemp.set("DatabaseManager.DB." + dBname + ".Connection.User", "");
580       }
581       else {
582         this.dBnameConnectionUser = value;
583         configTemp.set("DatabaseManager.DB." + dBname + ".Connection.User", value);
584       }
585     }
586   }
587
588 /**
589  * Gets value of Connection.User parameter for given database name from Config
590  * object of application.
591  * @param dBname name of database which parameter's value is changed or set.
592  * @return value of parameter represented as String
593  * @throws KeywordValueException
594  */

595   public String JavaDoc getDBnameConnectionUser( String JavaDoc dBname) throws KeywordValueException{
596     if(this.existDbName(dBname)) {
597       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
598         this.refreshAllDbParameters(dBname);
599       return this.dBnameConnectionUser;
600     }
601     else
602       return "N/A";
603   }
604
605 /**
606  * Sets value of JdbcDriver parameter for given database name in Config
607  * object of application.
608  * @param value given value of JdbcDriver parameter represented as String.
609  * @param dBname name of database which parameter's value is changed or set.
610  * @throws KeywordValueException
611  */

612   public void setDBnameJdbcDriver(String JavaDoc value, String JavaDoc dBname) throws KeywordValueException{
613     if(this.existDbName(dBname)) {
614       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
615         this.refreshAllDbParameters(dBname);
616       if(value==null || value.trim().equals("")) {
617         this.dBnameJdbcDriver = "N/A";
618         configTemp.set("DatabaseManager.DB." + dBname + ".JdbcDriver", "");
619       }
620       else {
621         this.dBnameJdbcDriver = value;
622         configTemp.set("DatabaseManager.DB." + dBname + ".JdbcDriver", value);
623       }
624     }
625   }
626
627 /**
628  * Gets value of JdbcDriver parameter for given database name from Config
629  * object of application.
630  * @param dBname name of database which parameter's value is changed or set.
631  * @return value of parameter represented as String
632  * @throws KeywordValueException
633  */

634   public String JavaDoc getDBnameJdbcDriver( String JavaDoc dBname) throws KeywordValueException{
635     if(this.existDbName(dBname)) {
636       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
637         this.refreshAllDbParameters(dBname);
638       return this.dBnameJdbcDriver;
639     }
640     else
641       return "N/A";
642   }
643
644 /**
645  * Sets value of ObjectId.CacheSize parameter for given database name in Config
646  * object of application.
647  * @param value given value of ObjectId.CacheSize parameter represented as String.
648  * @param dBname name of database which parameter's value is changed or set.
649  * @throws KeywordValueException
650  */

651   public void setDBnameObjectIdCacheSize(String JavaDoc value, String JavaDoc dBname) throws KeywordValueException{
652     if(this.existDbName(dBname)) {
653       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
654         this.refreshAllDbParameters(dBname);
655       if(value==null || value.trim().equals("")) {
656         this.dBnameObjectIdCacheSize = "N/A";
657         configTemp.set("DatabaseManager.DB." + dBname + ".ObjectId.CacheSize", "");
658       }
659       else {
660         this.dBnameObjectIdCacheSize = value;
661         configTemp.set("DatabaseManager.DB." + dBname + ".ObjectId.CacheSize", value);
662       }
663     }
664   }
665
666 /**
667  * Gets value of ObjectId.CacheSize parameter for given database name from Config
668  * object of application.
669  * @param dBname name of database which parameter's value is changed or set.
670  * @return value of parameter represented as String
671  * @throws KeywordValueException
672  */

673   public String JavaDoc getDBnameObjectIdCacheSize( String JavaDoc dBname) throws KeywordValueException{
674     if(this.existDbName(dBname)) {
675       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
676         this.refreshAllDbParameters(dBname);
677       return this.dBnameObjectIdCacheSize;
678     }
679     else
680       return "N/A";
681   }
682
683 /**
684  * Sets value of ObjectId.MinValue parameter for given database name in Config
685  * object of application.
686  * @param value given value of ObjectId.MinValue parameter represented as String
687  * @param dBname name of database which parameter's value is changed or set.
688  * @throws KeywordValueException
689  */

690   public void setDBnameObjectIdMinValue(String JavaDoc value, String JavaDoc dBname) throws KeywordValueException{
691     if(this.existDbName(dBname)) {
692       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
693         this.refreshAllDbParameters(dBname);
694       if(value==null || value.trim().equals("")) {
695         this.dBnameObjectIdMinValue = "N/A";
696         configTemp.set("DatabaseManager.DB." + dBname + ".ObjectId.MinValue", "");
697       }
698       else {
699         this.dBnameObjectIdMinValue = value;
700         configTemp.set("DatabaseManager.DB." + dBname + ".ObjectId.MinValue", value);
701       }
702     }
703   }
704
705 /**
706  * Gets value of ObjectId.MinValue parameter for given database name from Config
707  * object of application.
708  * @param dBname name of database which parameter's value is changed or set.
709  * @return value of parameter represented as String
710  * @throws KeywordValueException
711  */

712   public String JavaDoc getDBnameObjectIdMinValue( String JavaDoc dBname) throws KeywordValueException{
713     if(this.existDbName(dBname)) {
714       if(this.currentDatabase==null || !dBname.equalsIgnoreCase(this.currentDatabase))
715         this.refreshAllDbParameters(dBname);
716       return this.dBnameObjectIdMinValue;
717     }
718     else
719       return "N/A";
720   }
721
722 /**
723  * Sets value of Debug parameter in Config object of application.
724  * @param debug value of parameter represented as String. It can takes values
725  * "true" or "false". If wrong value is specified, it will be treated as "false".
726  * Also if values are null or empty String, or "N/A" DatabaseManager.Debug parameter
727  * will be removed.
728  * @throws KeywordValueException
729  */

730   public void setDebug(String JavaDoc debug) throws KeywordValueException{
731     if(debug==null || debug.trim().equals("") || debug.equalsIgnoreCase("N/A")) {
732       this.debug = "N/A";
733       configTemp.remove("DatabaseManager.Debug");
734     }
735     else if(debug.equalsIgnoreCase("true")) {
736       this.debug = debug;
737       configTemp.set("DatabaseManager.Debug", debug);
738     }
739     else {
740       this.debug = "false";
741       configTemp.set("DatabaseManager.Debug", "false");
742     }
743   }
744
745 /**
746  * Gets value of Debug parameter in Config object of application.
747  * @return value of parameter represented as String. It could has values
748  * "true", "false" or "N/A" in case of parameter absence.
749  * @throws KeywordValueException
750  */

751   public String JavaDoc getDebug() throws KeywordValueException {
752     this.refreshAllDbParameters(null);
753     return this.debug;
754   }
755
756 /**
757  * Sets value of DefaultDatabase parameter in Config object of application.
758  * @param dBname given value of parameter DefaultDatabase represented as String.
759  * @throws KeywordValueException
760  */

761   public void setDefaultDatabase(String JavaDoc dBname) throws KeywordValueException {
762     if(this.existDbName(dBname)) {
763       configTemp.set("DatabaseManager.DefaultDatabase",dBname);
764       this.defaultDatabase = dBname;
765     }
766     else if(dBname==null || dBname.trim().equals(""))
767       configTemp.remove("DatabaseManager.DefaultDatabase");
768       this.defaultDatabase = "N/A";
769   }
770
771 /**
772  * Gets value of DefaultDatabase parameter in Config object of application.
773  * @return value of parameter represented as String.
774  * @throws KeywordValueException
775  */

776   public String JavaDoc getDefaultDatabase() throws KeywordValueException {
777     this.refreshAllDbParameters(null);
778     return this.defaultDatabase;
779   }
780
781 /**
782  * Save state of DatabaseManager configuration parameters into application
783  * configuration file.
784  * @return true = state is successfully saved, false = otherwise
785  */

786   public boolean saveState(){
787     try{
788       this.configOriginal.importConfig(this.configTemp);
789       ConfigFileInterface confFile = configOriginal.getConfigFile();
790       confFile.write();
791     }
792     catch(Exception JavaDoc e) {
793       return false;
794     }
795     return true;
796   }
797
798
799 }
Popular Tags