Source Code Cross Referenced for DatabaseInfo.java in  » J2EE » Enhydra-Application-Framework » org » enhydra » server » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Enhydra Application Framework » org.enhydra.server 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Title:        AdminGui
003:         * Description:  Obtaining DatabaseManager parameters from DatabaseManager and
004:         * configuration file.
005:         * @Author       tufeX, tufex@uns.ns.ac.yu & Vladimir Radisic
006:         * @Version      1.1.1
007:         */package org.enhydra.server;
008:
009:        import java.util.Date;
010:
011:        import com.lutris.appserver.server.Application;
012:        import com.lutris.appserver.server.sql.DatabaseManager;
013:        import com.lutris.appserver.server.sql.DatabaseManagerException;
014:        import com.lutris.util.Config;
015:        import com.lutris.util.KeywordValueException;
016:
017:        /**
018:         * This class is used for obtaining information about particular application
019:         * connected to its database properties. Information are provided from the
020:         * DatabaseManager instance associated to specified application.
021:         */
022:        public class DatabaseInfo {
023:
024:            /**
025:             * Array of database names used within application.
026:             */
027:            private String[] logicalDbNames = null;
028:
029:            /**
030:             * Current database. This variable points to database, which parmeters are
031:             * currently holding in the temporary private variables of the object.
032:             */
033:            private String currentDatabase = null;
034:
035:            /**
036:             * Temporary storage for current database parameters obtained from
037:             * DatabaseManager.
038:             */
039:            private String defaultLogicalDbName = "N/A";
040:            private String type = "N/A";
041:            private String dbType = "N/A";
042:            private String activeConnections = "N/A";
043:            private String peakConnections = "N/A";
044:            private Date maxConnectionCountDate = null;;
045:            private String totalRequests = "N/A";
046:
047:            /**
048:             * Application databaseManager reference
049:             */
050:            private DatabaseManager dm;
051:
052:            /**
053:             * Storage for application configure parameters represented as Config object
054:             */
055:            private Config config;
056:
057:            /**
058:             * Construction with asociated application and coresponded configuration
059:             * parameters represented via Config object.
060:             * @param app associate aplication
061:             * @param appConfig cofiguration file parameters represented as Config object
062:             * @exceptions DatabaseManagerException
063:             * @exceptions KeywordValueException
064:             */
065:            public DatabaseInfo(Application app, Config appConfig)
066:                    throws DatabaseManagerException, KeywordValueException {
067:
068:                if (app != null) {
069:                    dm = app.getDatabaseManager(); // getting DatabaseManager
070:                    if (dm != null) {
071:                        this .logicalDbNames = dm.getLogicalDatabaseNames();
072:                        if (logicalDbNames == null
073:                                || logicalDbNames.length == 0)
074:                            return;
075:                        else if (appConfig != null
076:                                && appConfig
077:                                        .containsKey("DatabaseManager.DefaultDatabase")) {
078:                            this .config = appConfig;
079:
080:                            String tempDefaultDb = (String) appConfig
081:                                    .get("DatabaseManager.DefaultDatabase");
082:                            if (this .existDbName(tempDefaultDb)) {
083:                                this .defaultLogicalDbName = tempDefaultDb;
084:                                this .currentDatabase = tempDefaultDb;
085:                            } else {
086:                                this .defaultLogicalDbName = logicalDbNames[0];
087:                                this .currentDatabase = logicalDbNames[0];
088:                            }
089:                        } else {
090:                            this .defaultLogicalDbName = logicalDbNames[0];
091:                            this .currentDatabase = logicalDbNames[0];
092:                        }
093:
094:                        //        if(dm instanceof com.lutris.appserver.server.sql.StandardDatabaseManager)
095:                        if (dm
096:                                .getClass()
097:                                .getName()
098:                                .equals(
099:                                        "com.lutris.appserver.server.sql.StandardDatabaseManager"))
100:                            this .type = "Enhydra Standard Database Manager"; //FIXME, hard coded
101:                        else
102:                            this .type = "N/A";
103:
104:                        this .getDatabaseManagerParameters(currentDatabase);
105:                    } else
106:                        log("WARNING: DatabaseManager = null !");
107:                } else
108:                    log("WARNING: app = null !");
109:            }
110:
111:            /**
112:             * Fills the private arguments with parameters obtained from application
113:             * Databasemanager for specified database name.
114:             * @param dbName given database name.
115:             * @exceptions DatabaseManagerException
116:             */
117:            private void getDatabaseManagerParameters(String dbName)
118:                    throws DatabaseManagerException {
119:                if (this .existDbName(dbName) && dm != null) {
120:                    this .currentDatabase = dbName;
121:
122:                    long temp = dm.getActiveConnectionCount(dbName);
123:                    if (temp == -1)
124:                        this .activeConnections = "N/A";
125:                    else
126:                        this .activeConnections = String.valueOf(temp);
127:
128:                    temp = dm.getRequestCount(dbName);
129:                    if (temp == -1)
130:                        this .totalRequests = "N/A";
131:                    else
132:                        this .totalRequests = String.valueOf(temp);
133:
134:                    temp = dm.getMaxConnectionCount(dbName);
135:                    if (temp == -1)
136:                        this .peakConnections = "N/A";
137:                    else
138:                        this .peakConnections = String.valueOf(temp);
139:
140:                    this .maxConnectionCountDate = dm
141:                            .getMaxConnectionCountDate(dbName);
142:
143:                    String tempString = dm.getType(dbName);
144:                    if (tempString == null)
145:                        this .dbType = "N/A";
146:                    else
147:                        this .dbType = tempString;
148:                } else {
149:                    this .currentDatabase = null;
150:                    this .activeConnections = "N/A";
151:                    this .totalRequests = "N/A";
152:                    this .peakConnections = "N/A";
153:                    this .maxConnectionCountDate = null;
154:                    this .dbType = "N/A";
155:                }
156:            }
157:
158:            /**
159:             * Checks existence of given database name in the list of databases which
160:             * correspond to application and which are obtained from DatabaseManager.
161:             * @param dBname the name of the database which is checked.
162:             * @return true = database name exists, false = database name does not exist.
163:             */
164:            private boolean existDbName(String dBname) {
165:                if (dBname == null || logicalDbNames == null)
166:                    return false;
167:                for (int i = 0; i < this .logicalDbNames.length; i++) {
168:                    if (logicalDbNames[i].equalsIgnoreCase(dBname))
169:                        return true;
170:                }
171:                return false;
172:            }
173:
174:            /**
175:             * Returns list of logical database names obtained from application DatabaseManager
176:             * object.
177:             * @return list of logical database names represented as array of Strings, or null
178:             * if application has no corresponding databases.
179:             */
180:            public String[] getLogicalDbNames() {
181:                return logicalDbNames;
182:            }
183:
184:            /**
185:             * Gets the type of DatabaseManager instance.
186:             * @return type of DatabaseManager instance represented as String, or N/A if
187:             * this property is not available.
188:             */
189:            public String getDbManagerType() {
190:                return this .type;
191:            }
192:
193:            /**
194:             * Gets database type for given database name from DatabaseManager instance.
195:             * @param dBname name of database.
196:             * @return database type represented as String, or N/A if this property is not
197:             * available.
198:             * @exceptions DatabaseManagerException
199:             */
200:            public String getDbType(String dBname)
201:                    throws DatabaseManagerException {
202:                if (this .existDbName(dBname)) {
203:                    if (this .currentDatabase == null
204:                            || !dBname.equalsIgnoreCase(this .currentDatabase))
205:                        this .getDatabaseManagerParameters(dBname);
206:                    return this .dbType;
207:                } else
208:                    return "N/A";
209:            }
210:
211:            /**
212:             * Gets the number of currently active connections for the supplied logical
213:             * database name.
214:             * @param dBname name of database.
215:             * @return  number of currently active connections represented as String, or
216:             * N/A if this property is not available.
217:             * @exceptions DatabaseManagerException
218:             */
219:            public String getActiveConnections(String dBname)
220:                    throws DatabaseManagerException {
221:                if (this .existDbName(dBname)) {
222:                    if (this .currentDatabase == null
223:                            || !dBname.equalsIgnoreCase(this .currentDatabase))
224:                        this .getDatabaseManagerParameters(dBname);
225:                    return this .activeConnections;
226:                } else
227:                    return "N/A";
228:            }
229:
230:            /**
231:             * Gets the maximum number of concurent connections that existed at any time
232:             * since this object was created.
233:             * @param dBname name of database.
234:             * @return  maximum number of concurent connections represented as String, or
235:             * N/A if this property is not available.
236:             * @exceptions DatabaseManagerException
237:             */
238:            public String getPeakConnections(String dBname)
239:                    throws DatabaseManagerException {
240:                if (this .existDbName(dBname)) {
241:                    if (this .currentDatabase == null
242:                            || !dBname.equalsIgnoreCase(this .currentDatabase))
243:                        this .getDatabaseManagerParameters(dBname);
244:                    return this .peakConnections;
245:                } else
246:                    return "N/A";
247:            }
248:
249:            /**
250:             * Gets the date and time when maximum number of concurent connections occurs
251:             * since this object was created.
252:             * @param dBname name of database.
253:             * @return  date and time when maximum number of concurent connections occurs
254:             * represented as Date object, or null if this property is not implemented
255:             * @exceptions DatabaseManagerException
256:             */
257:            public Date getPeakConnectionsDate(String dBname)
258:                    throws DatabaseManagerException {
259:                if (this .existDbName(dBname)) {
260:                    if (this .currentDatabase == null
261:                            || !dBname.equalsIgnoreCase(this .currentDatabase))
262:                        this .getDatabaseManagerParameters(dBname);
263:                    return this .maxConnectionCountDate;
264:                } else
265:                    return null;
266:            }
267:
268:            /**
269:             * Gets the number of requests made to the database since startup time
270:             * @param dBname name of database.
271:             * @return  number of requests made to the database represented as String, or
272:             * N/A if this property is not available.
273:             * @exceptions DatabaseManagerException
274:             */
275:            public String getTotalRequests(String dBname)
276:                    throws DatabaseManagerException {
277:                if (this .existDbName(dBname)) {
278:                    if (this .currentDatabase == null
279:                            || !dBname.equalsIgnoreCase(this .currentDatabase))
280:                        this .getDatabaseManagerParameters(dBname);
281:                    return this .totalRequests;
282:                } else
283:                    return null;
284:            }
285:
286:            /**
287:             * Sets the default logical database name.
288:             * @param dBname name of database which will be set as default.
289:             * @exceptions DatabaseManagerException
290:             * @exception KeywordValueException
291:             */
292:            public void setDefaultLogicalDbName(String dBname)
293:                    throws DatabaseManagerException, KeywordValueException {
294:                if (this .existDbName(dBname)) {
295:                    this .dm.setDefaultDatabase(dBname);
296:                    this .defaultLogicalDbName = dBname;
297:                    this .config.set("DatabaseManager.DefaultDatabase", dBname);
298:                }
299:            }
300:
301:            /**
302:             * Gets the default logical database name.
303:             * @return name of database which is set as default.
304:             */
305:            public String getDefaultLogicalDbName() {
306:                return this .defaultLogicalDbName;
307:            }
308:
309:            /**
310:             * Reset the maximum connection count for the given logical database name.
311:             * @param dBname name of database which connection count will be reset.
312:             * @exceptions DatabaseManagerException
313:             */
314:            public void resetMaxConnectionCount(String dBname)
315:                    throws DatabaseManagerException {
316:                if (this .existDbName(dBname)) {
317:                    this .dm.resetMaxConnectionCount(dBname);
318:                    this .getDatabaseManagerParameters(dBname);
319:                }
320:            }
321:
322:            /**
323:             * Used for logging of messages.
324:             * @param msg message for logging represented as String.
325:             */
326:            private void log(String msg) {
327:                // FIXME.DEBUG.Log to file
328:                System.err.println("EnhydraServer, Database Info: " + msg);
329:            }
330:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.