001: /**
002: * Title: AdminGui
003: * Description: Edit DatabaseManager parameters from configuration file.
004: * @Author tufeX, tufex@uns.ns.ac.yu & Vladimir Radisic
005: * @Version 1.1.0
006: */package org.enhydra.server;
007:
008: import org.enhydra.util.ConfigFileInterface;
009:
010: import com.lutris.util.Config;
011: import com.lutris.util.ConfigException;
012: import com.lutris.util.KeywordValueException;
013:
014: /**
015: * Instances of this class are used in manipulation and editing of DatabaseManager
016: * section parameters, defined in application configuration file. Also this class
017: * contains method saveState which provides saving changed configuration onto disk.
018: */
019: public class DatabaseEdit {
020:
021: /**
022: * Array of database names used within application.
023: */
024: private String[] databases = null;
025:
026: /**
027: * Current database. This variable points to database, which parmeters are
028: * currently holding in the temporary private variables of the object.
029: */
030: private String currentDatabase = null;
031:
032: /**
033: * Temporary storage for current database parameters. This parameters are an image
034: * of parameters from the configuration file of the application, which are led
035: * width DatabaseManager section. Parameters are invoked only in aim of faster
036: * response in getter methods (otherwise they can be found fromConfig object).
037: */
038: private String defaultDatabase = "N/A";
039: private String debug = "N/A";
040: private String dBnameClassType = "N/A";
041: private String dBnameJdbcDriver = "N/A";
042: private String dBnameConnectionUrl = "N/A";
043: private String dBnameConnectionUser = "N/A";
044: private String dBnameConnectionPassword = "N/A";
045: private String dBnameConnectionMaxPoolSize = "N/A";
046: private String dBnameConnectionAllocationTimeout = "N/A";
047: private String dBnameConnectionLogging = "N/A";
048: private String dBnameObjectIdCacheSize = "N/A";
049: private String dBnameObjectIdMinValue = "N/A";
050:
051: /**
052: * Storage for application configure parameters represented as Config object
053: */
054: private Config configTemp;
055:
056: /**
057: * Storage for application configure parameters represented as Config object. this
058: * is reference to original application configuration file.
059: */
060: private Config configOriginal;
061:
062: /**
063: * Construction of DatabaseEdit object for particular application with given
064: * configuration file.
065: * @param config configuration file of the application represented as Config
066: * object.
067: * @exception ConfigException
068: * @exception KeywordValueException
069: */
070: public DatabaseEdit(Config config) throws ConfigException,
071: KeywordValueException {
072: this .configOriginal = config; // saving reference to original Config object
073: this .configTemp = config.getClonedConfig(); // template Config file used for manipulation
074:
075: if (configTemp.containsKey("DatabaseManager.Databases"))
076: databases = configTemp
077: .getStrings("DatabaseManager.Databases");
078: if (configTemp.containsKey("DatabaseManager.DefaultDatabase")) {
079: defaultDatabase = configTemp
080: .getString("DatabaseManager.DefaultDatabase");
081: currentDatabase = defaultDatabase;
082: }
083: if (configTemp.containsKey("DatabaseManager.Debug"))
084: debug = configTemp.getString("DatabaseManager.Debug");
085: if (currentDatabase == null && databases != null)
086: currentDatabase = databases[0];
087:
088: this .refreshAllDbParameters(currentDatabase);
089: }
090:
091: /**
092: * Finds all parameters for specified database in configuration file and sets
093: * they to temporary object arguments.
094: * @param dBname name of database which parameters are searched.
095: * @exception KeywordValueException
096: */
097: public void refreshAllDbParameters(String dBname)
098: throws KeywordValueException {
099:
100: this .databases = null;
101: this .currentDatabase = null;
102:
103: this .defaultDatabase = "N/A";
104: this .debug = "N/A";
105: this .dBnameClassType = "N/A";
106: this .dBnameJdbcDriver = "N/A";
107: this .dBnameConnectionUrl = "N/A";
108: this .dBnameConnectionUser = "N/A";
109: this .dBnameConnectionPassword = "N/A";
110: this .dBnameConnectionMaxPoolSize = "N/A";
111: this .dBnameConnectionAllocationTimeout = "N/A";
112: this .dBnameConnectionLogging = "N/A";
113: this .dBnameObjectIdCacheSize = "N/A";
114: this .dBnameObjectIdMinValue = "N/A";
115:
116: Config tempParentConfig = null;
117: // Config tempConfig = (Config) configTemp.getSection("DatabaseManager.");
118: Config tempConfig = (Config) configTemp
119: .getSection("DatabaseManager");
120: if (tempConfig != null) {
121: if (tempConfig.containsKey("Databases")) {
122: this .databases = tempConfig.getStrings("Databases");
123: // checks given parameter (dBname) for existing in configTemp file
124: if (this .existDbName(dBname))
125: this .currentDatabase = dBname;
126: }
127: if (tempConfig.containsKey("DefaultDatabase"))
128: defaultDatabase = tempConfig
129: .getString("DefaultDatabase");
130:
131: if (tempConfig.containsKey("Debug"))
132: debug = tempConfig.getString("Debug");
133:
134: if (currentDatabase == null)
135: return;
136:
137: // Finds parameters for specified database
138: tempParentConfig = tempConfig;
139: tempConfig = (Config) tempConfig.getSection("DB." + dBname);
140: if (tempConfig != null) {
141: if (tempConfig.containsKey("ClassType"))
142: dBnameClassType = tempConfig.getString("ClassType");
143: if (tempConfig.containsKey("JdbcDriver"))
144: dBnameJdbcDriver = tempConfig
145: .getString("JdbcDriver");
146:
147: tempParentConfig = tempConfig;
148: tempConfig = (Config) tempConfig
149: .getSection("Connection");
150: if (tempConfig != null) {
151: if (tempConfig.containsKey("Url"))
152: dBnameConnectionUrl = tempConfig
153: .getString("Url");
154: if (tempConfig.containsKey("User"))
155: dBnameConnectionUser = tempConfig
156: .getString("User");
157: if (tempConfig.containsKey("Password"))
158: dBnameConnectionPassword = tempConfig
159: .getString("Password");
160: if (tempConfig.containsKey("MaxPoolSize"))
161: dBnameConnectionMaxPoolSize = tempConfig
162: .getString("MaxPoolSize");
163: if (tempConfig.containsKey("AllocationTimeout"))
164: dBnameConnectionAllocationTimeout = tempConfig
165: .getString("AllocationTimeout");
166: if (tempConfig.containsKey("Logging"))
167: dBnameConnectionLogging = tempConfig
168: .getString("Logging");
169: }
170: tempConfig = tempParentConfig;
171: tempConfig = (Config) tempConfig.getSection("ObjectId");
172: if (tempConfig != null) {
173: if (tempConfig.containsKey("CacheSize"))
174: dBnameObjectIdCacheSize = tempConfig
175: .getString("CacheSize");
176: if (tempConfig.containsKey("MinValue"))
177: dBnameObjectIdMinValue = tempConfig
178: .getString("MinValue");
179: }
180: }
181: }
182: }
183:
184: /**
185: * Checks existence of given database name in the list of already defined
186: * databases for application.
187: * @param dBname the name of the database.
188: * @return true = database name already exists, false = database name does not
189: * exist.
190: */
191: public boolean existDbName(String dBname) {
192: if (dBname == null || databases == null)
193: return false;
194: for (int i = 0; i < this .databases.length; i++) {
195: if (databases[i].equalsIgnoreCase(dBname))
196: return true;
197: }
198: return false;
199:
200: }
201:
202: /**
203: * Adds database name to list of databases used by application. This list is
204: * represented by "Datasbase" parameter in configuration file of the application.
205: * @param dBname the name of the database.
206: * @return true = database name is sucessfuly added, false = database name is
207: * not added.
208: * @exception KeywordValueException
209: */
210: public boolean addDatabase(String dBname)
211: throws KeywordValueException {
212: if (this .existDbName(dBname))
213: return false;
214:
215: String[] newDbString = null;
216: if (this .databases == null) //handles adding of first item in database list
217: newDbString = new String[1];
218: else
219: newDbString = new String[this .databases.length + 1];
220:
221: newDbString[newDbString.length - 1] = dBname;
222:
223: for (int i = 0; i < newDbString.length - 1; i++)
224: newDbString[i] = this .databases[i];
225:
226: this .configTemp.set("DatabaseManager.Databases", newDbString);
227: this .databases = newDbString;
228:
229: // sets initial values for all parameters. This values should be later changed
230: // width real values
231: this .setDBnameClassType("Standard", dBname);
232: this
233: .setDBnameJdbcDriver("sun.jdbc.odbc.JdbcOdbcDriver",
234: dBname);
235: this .setDBnameConnectionAllocationTimeout("10000", dBname);
236: this .setDBnameConnectionLogging("false", dBname);
237: this .setDBnameConnectionMaxPoolSize("30", dBname);
238: this .setDBnameConnectionUrl("jdbc:odbc:" + dBname, dBname);
239: this .setDBnameConnectionPassword("tiger", dBname);
240: this .setDBnameConnectionUser("miga", dBname);
241: this .setDBnameObjectIdCacheSize("20", dBname);
242: this .setDBnameObjectIdMinValue("1000000", dBname);
243:
244: return true;
245: }
246:
247: /**
248: * Removes database name from array of databases used by application. This list is
249: * represented by "Datasbase" parameter in configuration file of the application.
250: * @param dBname the name of the database.
251: * @return true = database name is sucessfuly removed, false = database name is
252: * not removed.
253: * @exception KeywordValueException
254: */
255: public boolean removeDatabase(String dBname)
256: throws KeywordValueException {
257: if (!this .existDbName(dBname))
258: return false;
259: String[] newDbString = new String[this .databases.length - 1];
260:
261: for (int i = 0, j = 0; i < newDbString.length; i++) {
262: if (!this .databases[j].equalsIgnoreCase(dBname))
263: newDbString[i] = this .databases[j];
264: else
265: i--;
266: j++;
267: }
268:
269: if (this .currentDatabase != null
270: && this .currentDatabase.equalsIgnoreCase(dBname)) {
271: this .currentDatabase = null;
272: }
273:
274: // remowes all keys connected with removed database;
275: String testDefaultDb = null;
276: if (configTemp.containsKey("DatabaseManager.DefaultDatabase"))
277: testDefaultDb = (String) configTemp
278: .get("DatabaseManager.DefaultDatabase");
279: if ((testDefaultDb != null && !testDefaultDb.trim().equals(""))
280: && testDefaultDb.equalsIgnoreCase(dBname)) {
281: this .configTemp.remove("DatabaseManager.DefaultDatabase");
282: this .defaultDatabase = "N/A";
283: }
284:
285: this .configTemp.remove("DatabaseManager.DB." + dBname
286: + ".ClassType");
287: this .configTemp.remove("DatabaseManager.DB." + dBname
288: + ".JdbcDriver");
289: this .configTemp.remove("DatabaseManager.DB." + dBname
290: + ".Connection.AllocationTimeout");
291: this .configTemp.remove("DatabaseManager.DB." + dBname
292: + ".Connection.Logging");
293: this .configTemp.remove("DatabaseManager.DB." + dBname
294: + ".Connection.MaxPoolSize");
295: this .configTemp.remove("DatabaseManager.DB." + dBname
296: + ".Connection.Url");
297: this .configTemp.remove("DatabaseManager.DB." + dBname
298: + ".Connection.Password");
299: this .configTemp.remove("DatabaseManager.DB." + dBname
300: + ".Connection.User");
301: this .configTemp.remove("DatabaseManager.DB." + dBname
302: + ".ObjectId.CacheSize");
303: this .configTemp.remove("DatabaseManager.DB." + dBname
304: + ".ObjectId.MinValue");
305:
306: if (newDbString.length == 0) { //handles removing of last item in database list
307: this .configTemp.remove("DatabaseManager.Databases");
308: this .databases = null;
309: this .currentDatabase = null;
310: } else {
311: this .configTemp.set("DatabaseManager.Databases",
312: newDbString);
313: this .databases = newDbString;
314: }
315: return true;
316: }
317:
318: /**
319: * Sets list of database names. Old settings are remowed and are swapped with
320: * given new list. All corresponding database parameters, for given database names
321: * in list, with its default initial values will be added too
322: * @param databases list of database names.
323: * @exception KeywordValueException
324: */
325: public void setDatabases(String[] databases)
326: throws KeywordValueException {
327: String newDbParam = "";
328: StringBuffer newDbParamBuffer = new StringBuffer(newDbParam);
329: for (int i = 0; i < databases.length; i++) {
330: if (i == 0)
331: newDbParamBuffer = new StringBuffer("\""
332: + this .databases[i] + "\"");
333: else
334: newDbParamBuffer.append(", \"" + this .databases[i]
335: + "\"");
336: }
337: newDbParam = newDbParamBuffer.toString();
338: // removes all keys connected width old database parameters
339: for (int i = 0; i < this .databases.length; i++) {
340: this .removeDatabase(databases[i]);
341: }
342:
343: this .configTemp.set("DatabaseManager.Databases", newDbParam);
344: this .databases = databases;
345:
346: // adds keys for new database parameters
347: for (int i = 0; i < this .databases.length; i++) {
348: this .addDatabase(databases[i]);
349: }
350:
351: }
352:
353: /**
354: * Gets list of available database names.
355: * @return list of available databases represented as String array
356: * @exception KeywordValueException
357: */
358: public String[] getDatabases() {
359: return this .databases;
360: }
361:
362: /**
363: * Sets value of ClassType parameter for given database name in Config
364: * object of application.
365: * @param value given value of ClassType parameter represented as String
366: * @param dBname name of database which parameter's value is changed or set.
367: * @throws KeywordValueException
368: */
369: public void setDBnameClassType(String value, String dBname)
370: throws KeywordValueException {
371: if (this .existDbName(dBname)) {
372: if (this .currentDatabase == null
373: || !dBname.equalsIgnoreCase(this .currentDatabase))
374: this .refreshAllDbParameters(dBname);
375: if (value == null || value.trim().equals("")) {
376: this .dBnameClassType = "N/A";
377: configTemp.set("DatabaseManager.DB." + dBname
378: + ".ClassType", "");
379: } else {
380: this .dBnameClassType = value;
381: configTemp.set("DatabaseManager.DB." + dBname
382: + ".ClassType", value);
383: }
384: }
385: }
386:
387: /**
388: * Gets value of ClassType parameter for given database name from Config
389: * object of application.
390: * @param dBname name of database which parameter's value is changed or set.
391: * @return value of parameter represented as String
392: * @throws KeywordValueException
393: */
394: public String getDBnameClassType(String dBname)
395: throws KeywordValueException {
396: if (this .existDbName(dBname)) {
397: if (this .currentDatabase == null
398: || !dBname.equalsIgnoreCase(this .currentDatabase))
399: this .refreshAllDbParameters(dBname);
400: return this .dBnameClassType;
401: } else
402: return "N/A";
403: }
404:
405: /**
406: * Sets value of Connection.AllocationTimeout parameter for given database name
407: * in Config object of application.
408: * @param value given value of Connection.AllocationTimeout parameter represented
409: * as String.
410: * @param dBname name of database which parameter's value is changed or set.
411: * @throws KeywordValueException
412: */
413: public void setDBnameConnectionAllocationTimeout(String value,
414: String dBname) throws KeywordValueException {
415: if (this .existDbName(dBname)) {
416: if (this .currentDatabase == null
417: || !dBname.equalsIgnoreCase(this .currentDatabase))
418: this .refreshAllDbParameters(dBname);
419: if (value == null || value.trim().equals("")) {
420: this .dBnameConnectionAllocationTimeout = "N/A";
421: configTemp.set("DatabaseManager.DB." + dBname
422: + ".Connection.AllocationTimeout", "");
423: } else {
424: this .dBnameConnectionAllocationTimeout = value;
425: configTemp.set("DatabaseManager.DB." + dBname
426: + ".Connection.AllocationTimeout", value);
427: }
428: }
429: }
430:
431: /**
432: * Gets value of Connection. AllocationTimeout parameter for given database name
433: * from Config 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
436: * @throws KeywordValueException
437: */
438: public String getDBnameConnectionAllocationTimeout(String dBname)
439: throws KeywordValueException {
440: if (this .existDbName(dBname)) {
441: if (this .currentDatabase == null
442: || !dBname.equalsIgnoreCase(this .currentDatabase))
443: this .refreshAllDbParameters(dBname);
444: return this .dBnameConnectionAllocationTimeout;
445: } else
446: return "N/A";
447: }
448:
449: /**
450: * Sets value of Connection.Logging parameter for given database name in Config
451: * object of application.
452: * @param value given value of Connection.Logging parameter represented as String.
453: * Allowable values for this parameter are "true" and "false". Any other value
454: * will be treated as N/A (not available).
455: * @param dBname name of database which parameter's value is changed or set.
456: * @throws KeywordValueException
457: */
458: public void setDBnameConnectionLogging(String value, String dBname)
459: throws KeywordValueException {
460: if (this .existDbName(dBname)) {
461: if (this .currentDatabase == null
462: || !dBname.equalsIgnoreCase(this .currentDatabase))
463: this .refreshAllDbParameters(dBname);
464: if (value == null
465: || value.trim().equals("")
466: || !(value.equalsIgnoreCase("true") || value
467: .equalsIgnoreCase("false"))) {
468: this .dBnameConnectionLogging = "N/A";
469: configTemp.set("DatabaseManager.DB." + dBname
470: + ".Connection.Logging", "");
471: } else {
472: this .dBnameConnectionLogging = value;
473: configTemp.set("DatabaseManager.DB." + dBname
474: + ".Connection.Logging", value);
475: }
476: }
477: }
478:
479: /**
480: * Gets value of Connection.Logging parameter for given database name from Config
481: * object of application.
482: * @param dBname name of database which parameter's value is changed or set.
483: * @return value of parameter represented as String. It could has values "true",
484: * "false" or "N/A" in case of parameter absence.
485: * @throws KeywordValueException
486: */
487: public String getDBnameConnectionLogging(String dBname)
488: throws KeywordValueException {
489: if (this .existDbName(dBname)) {
490: if (this .currentDatabase == null
491: || !dBname.equalsIgnoreCase(this .currentDatabase))
492: this .refreshAllDbParameters(dBname);
493: return this .dBnameConnectionLogging;
494: } else
495: return "N/A";
496: }
497:
498: /**
499: * Sets value of Connection.MaxPoolSize parameter for given database name in Config
500: * object of application.
501: * @param value given value of Connection.MaxPoolSize parameter represented as String
502: * @param dBname name of database which parameter's value is changed or set.
503: * @throws KeywordValueException
504: */
505: public void setDBnameConnectionMaxPoolSize(String value,
506: String dBname) throws KeywordValueException {
507: if (this .existDbName(dBname)) {
508: if (this .currentDatabase == null
509: || !dBname.equalsIgnoreCase(this .currentDatabase))
510: this .refreshAllDbParameters(dBname);
511: if (value == null || value.trim().equals("")) {
512: this .dBnameConnectionMaxPoolSize = "N/A";
513: configTemp.set("DatabaseManager.DB." + dBname
514: + ".Connection.MaxPoolSize", "");
515: } else {
516: this .dBnameConnectionMaxPoolSize = value;
517: configTemp.set("DatabaseManager.DB." + dBname
518: + ".Connection.MaxPoolSize", value);
519: }
520: }
521: }
522:
523: /**
524: * Gets value of Connection.MaxPoolSize parameter for given database name from Config
525: * object of application.
526: * @param dBname name of database which parameter's value is changed or set.
527: * @return value of parameter represented as String
528: * @throws KeywordValueException
529: */
530: public String getDBnameConnectionMaxPoolSize(String dBname)
531: throws KeywordValueException {
532: if (this .existDbName(dBname)) {
533: if (this .currentDatabase == null
534: || !dBname.equalsIgnoreCase(this .currentDatabase))
535: this .refreshAllDbParameters(dBname);
536: return this .dBnameConnectionMaxPoolSize;
537: } else
538: return "N/A";
539: }
540:
541: /**
542: * Sets value of Connection.Password parameter for given database name in Config
543: * object of application.
544: * @param value given value of Connection.Password parameter represented as String
545: * @param dBname name of database which parameter's value is changed or set.
546: * @throws KeywordValueException
547: */
548: public void setDBnameConnectionPassword(String value, String dBname)
549: throws KeywordValueException {
550: if (this .existDbName(dBname)) {
551: if (this .currentDatabase == null
552: || !dBname.equalsIgnoreCase(this .currentDatabase))
553: this .refreshAllDbParameters(dBname);
554: if (value == null || value.trim().equals("")) {
555: this .dBnameConnectionPassword = "N/A";
556: configTemp.set("DatabaseManager.DB." + dBname
557: + ".Connection.Password", "");
558: } else {
559: this .dBnameConnectionPassword = value;
560: configTemp.set("DatabaseManager.DB." + dBname
561: + ".Connection.Password", value);
562: }
563: }
564: }
565:
566: /**
567: * Gets value of Connection.Password parameter for given database name from Config
568: * object of application.
569: * @param dBname name of database which parameter's value is changed or set.
570: * @return value of parameter represented as String
571: * @throws KeywordValueException
572: */
573: public String getDBnameConnectionPassword(String dBname)
574: throws KeywordValueException {
575: if (this .existDbName(dBname)) {
576: if (this .currentDatabase == null
577: || !dBname.equalsIgnoreCase(this .currentDatabase))
578: this .refreshAllDbParameters(dBname);
579: return this .dBnameConnectionPassword;
580: } else
581: return "N/A";
582: }
583:
584: /**
585: * Sets value of Connection.Url parameter for given database name in Config
586: * object of application.
587: * @param value given value of Connection.Url parameter represented as String
588: * @param dBname name of database which parameter's value is changed or set.
589: * @throws KeywordValueException
590: */
591: public void setDBnameConnectionUrl(String value, String dBname)
592: throws KeywordValueException {
593: if (this .existDbName(dBname)) {
594: if (this .currentDatabase == null
595: || !dBname.equalsIgnoreCase(this .currentDatabase))
596: this .refreshAllDbParameters(dBname);
597: if (value == null || value.trim().equals("")) {
598: this .dBnameConnectionUrl = "N/A";
599: configTemp.set("DatabaseManager.DB." + dBname
600: + ".Connection.Url", "");
601: } else {
602: this .dBnameConnectionUrl = value;
603: configTemp.set("DatabaseManager.DB." + dBname
604: + ".Connection.Url", value);
605: }
606: }
607: }
608:
609: /**
610: * Gets value of Connection.Url parameter for given database name from Config
611: * object of application.
612: * @param dBname name of database which parameter's value is changed or set.
613: * @return value of parameter represented as String
614: * @throws KeywordValueException
615: */
616: public String getDBnameConnectionUrl(String dBname)
617: throws KeywordValueException {
618: if (this .existDbName(dBname)) {
619: if (this .currentDatabase == null
620: || !dBname.equalsIgnoreCase(this .currentDatabase))
621: this .refreshAllDbParameters(dBname);
622: return this .dBnameConnectionUrl;
623: } else
624: return "N/A";
625: }
626:
627: /**
628: * Sets value of Connection.User parameter for given database name in Config
629: * object of application.
630: * @param value given value of Connection.User parameter represented as String
631: * @param dBname name of database which parameter's value is changed or set.
632: * @throws KeywordValueException
633: */
634: public void setDBnameConnectionUser(String value, String dBname)
635: throws KeywordValueException {
636: if (this .existDbName(dBname)) {
637: if (this .currentDatabase == null
638: || !dBname.equalsIgnoreCase(this .currentDatabase))
639: this .refreshAllDbParameters(dBname);
640: if (value == null || value.trim().equals("")) {
641: this .dBnameConnectionUser = "N/A";
642: configTemp.set("DatabaseManager.DB." + dBname
643: + ".Connection.User", "");
644: } else {
645: this .dBnameConnectionUser = value;
646: configTemp.set("DatabaseManager.DB." + dBname
647: + ".Connection.User", value);
648: }
649: }
650: }
651:
652: /**
653: * Gets value of Connection.User parameter for given database name from Config
654: * object of application.
655: * @param dBname name of database which parameter's value is changed or set.
656: * @return value of parameter represented as String
657: * @throws KeywordValueException
658: */
659: public String getDBnameConnectionUser(String dBname)
660: throws KeywordValueException {
661: if (this .existDbName(dBname)) {
662: if (this .currentDatabase == null
663: || !dBname.equalsIgnoreCase(this .currentDatabase))
664: this .refreshAllDbParameters(dBname);
665: return this .dBnameConnectionUser;
666: } else
667: return "N/A";
668: }
669:
670: /**
671: * Sets value of JdbcDriver parameter for given database name in Config
672: * object of application.
673: * @param value given value of JdbcDriver parameter represented as String.
674: * @param dBname name of database which parameter's value is changed or set.
675: * @throws KeywordValueException
676: */
677: public void setDBnameJdbcDriver(String value, String dBname)
678: throws KeywordValueException {
679: if (this .existDbName(dBname)) {
680: if (this .currentDatabase == null
681: || !dBname.equalsIgnoreCase(this .currentDatabase))
682: this .refreshAllDbParameters(dBname);
683: if (value == null || value.trim().equals("")) {
684: this .dBnameJdbcDriver = "N/A";
685: configTemp.set("DatabaseManager.DB." + dBname
686: + ".JdbcDriver", "");
687: } else {
688: this .dBnameJdbcDriver = value;
689: configTemp.set("DatabaseManager.DB." + dBname
690: + ".JdbcDriver", value);
691: }
692: }
693: }
694:
695: /**
696: * Gets value of JdbcDriver parameter for given database name from Config
697: * object of application.
698: * @param dBname name of database which parameter's value is changed or set.
699: * @return value of parameter represented as String
700: * @throws KeywordValueException
701: */
702: public String getDBnameJdbcDriver(String dBname)
703: throws KeywordValueException {
704: if (this .existDbName(dBname)) {
705: if (this .currentDatabase == null
706: || !dBname.equalsIgnoreCase(this .currentDatabase))
707: this .refreshAllDbParameters(dBname);
708: return this .dBnameJdbcDriver;
709: } else
710: return "N/A";
711: }
712:
713: /**
714: * Sets value of ObjectId.CacheSize parameter for given database name in Config
715: * object of application.
716: * @param value given value of ObjectId.CacheSize parameter represented as String.
717: * @param dBname name of database which parameter's value is changed or set.
718: * @throws KeywordValueException
719: */
720: public void setDBnameObjectIdCacheSize(String value, String dBname)
721: throws KeywordValueException {
722: if (this .existDbName(dBname)) {
723: if (this .currentDatabase == null
724: || !dBname.equalsIgnoreCase(this .currentDatabase))
725: this .refreshAllDbParameters(dBname);
726: if (value == null || value.trim().equals("")) {
727: this .dBnameObjectIdCacheSize = "N/A";
728: configTemp.set("DatabaseManager.DB." + dBname
729: + ".ObjectId.CacheSize", "");
730: } else {
731: this .dBnameObjectIdCacheSize = value;
732: configTemp.set("DatabaseManager.DB." + dBname
733: + ".ObjectId.CacheSize", value);
734: }
735: }
736: }
737:
738: /**
739: * Gets value of ObjectId.CacheSize parameter for given database name from Config
740: * object of application.
741: * @param dBname name of database which parameter's value is changed or set.
742: * @return value of parameter represented as String
743: * @throws KeywordValueException
744: */
745: public String getDBnameObjectIdCacheSize(String dBname)
746: throws KeywordValueException {
747: if (this .existDbName(dBname)) {
748: if (this .currentDatabase == null
749: || !dBname.equalsIgnoreCase(this .currentDatabase))
750: this .refreshAllDbParameters(dBname);
751: return this .dBnameObjectIdCacheSize;
752: } else
753: return "N/A";
754: }
755:
756: /**
757: * Sets value of ObjectId.MinValue parameter for given database name in Config
758: * object of application.
759: * @param value given value of ObjectId.MinValue parameter represented as String
760: * @param dBname name of database which parameter's value is changed or set.
761: * @throws KeywordValueException
762: */
763: public void setDBnameObjectIdMinValue(String value, String dBname)
764: throws KeywordValueException {
765: if (this .existDbName(dBname)) {
766: if (this .currentDatabase == null
767: || !dBname.equalsIgnoreCase(this .currentDatabase))
768: this .refreshAllDbParameters(dBname);
769: if (value == null || value.trim().equals("")) {
770: this .dBnameObjectIdMinValue = "N/A";
771: configTemp.set("DatabaseManager.DB." + dBname
772: + ".ObjectId.MinValue", "");
773: } else {
774: this .dBnameObjectIdMinValue = value;
775: configTemp.set("DatabaseManager.DB." + dBname
776: + ".ObjectId.MinValue", value);
777: }
778: }
779: }
780:
781: /**
782: * Gets value of ObjectId.MinValue parameter for given database name from Config
783: * object of application.
784: * @param dBname name of database which parameter's value is changed or set.
785: * @return value of parameter represented as String
786: * @throws KeywordValueException
787: */
788: public String getDBnameObjectIdMinValue(String dBname)
789: throws KeywordValueException {
790: if (this .existDbName(dBname)) {
791: if (this .currentDatabase == null
792: || !dBname.equalsIgnoreCase(this .currentDatabase))
793: this .refreshAllDbParameters(dBname);
794: return this .dBnameObjectIdMinValue;
795: } else
796: return "N/A";
797: }
798:
799: /**
800: * Sets value of Debug parameter in Config object of application.
801: * @param debug value of parameter represented as String. It can takes values
802: * "true" or "false". If wrong value is specified, it will be treated as "false".
803: * Also if values are null or empty String, or "N/A" DatabaseManager.Debug parameter
804: * will be removed.
805: * @throws KeywordValueException
806: */
807: public void setDebug(String debug) throws KeywordValueException {
808: if (debug == null || debug.trim().equals("")
809: || debug.equalsIgnoreCase("N/A")) {
810: this .debug = "N/A";
811: configTemp.remove("DatabaseManager.Debug");
812: } else if (debug.equalsIgnoreCase("true")) {
813: this .debug = debug;
814: configTemp.set("DatabaseManager.Debug", debug);
815: } else {
816: this .debug = "false";
817: configTemp.set("DatabaseManager.Debug", "false");
818: }
819: }
820:
821: /**
822: * Gets value of Debug parameter in Config object of application.
823: * @return value of parameter represented as String. It could has values
824: * "true", "false" or "N/A" in case of parameter absence.
825: * @throws KeywordValueException
826: */
827: public String getDebug() throws KeywordValueException {
828: this .refreshAllDbParameters(null);
829: return this .debug;
830: }
831:
832: /**
833: * Sets value of DefaultDatabase parameter in Config object of application.
834: * @param dBname given value of parameter DefaultDatabase represented as String.
835: * @throws KeywordValueException
836: */
837: public void setDefaultDatabase(String dBname)
838: throws KeywordValueException {
839: if (this .existDbName(dBname)) {
840: configTemp.set("DatabaseManager.DefaultDatabase", dBname);
841: this .defaultDatabase = dBname;
842: } else if (dBname == null || dBname.trim().equals(""))
843: configTemp.remove("DatabaseManager.DefaultDatabase");
844: this .defaultDatabase = "N/A";
845: }
846:
847: /**
848: * Gets value of DefaultDatabase parameter in Config object of application.
849: * @return value of parameter represented as String.
850: * @throws KeywordValueException
851: */
852: public String getDefaultDatabase() throws KeywordValueException {
853: this .refreshAllDbParameters(null);
854: return this .defaultDatabase;
855: }
856:
857: /**
858: * Save state of DatabaseManager configuration parameters into application
859: * configuration file.
860: * @return true = state is successfully saved, false = otherwise
861: */
862: public boolean saveState() {
863: try {
864: this .configOriginal.importConfig(this .configTemp);
865: ConfigFileInterface confFile = configOriginal
866: .getConfigFile();
867: confFile.write();
868: } catch (Exception e) {
869: return false;
870: }
871: return true;
872: }
873:
874: }
|