Source Code Cross Referenced for WebSession.java in  » Database-DBMS » h2database » org » h2 » server » web » 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 » Database DBMS » h2database » org.h2.server.web 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
003:         * (http://h2database.com/html/license.html).
004:         * Initial Developer: H2 Group
005:         */
006:        package org.h2.server.web;
007:
008:        import java.sql.Connection;
009:        import java.sql.DatabaseMetaData;
010:        import java.sql.ResultSet;
011:        import java.sql.SQLException;
012:        import java.sql.Statement;
013:        import java.sql.Timestamp;
014:        import java.util.ArrayList;
015:        import java.util.HashMap;
016:        import java.util.Locale;
017:
018:        import org.h2.bnf.Bnf;
019:        import org.h2.message.TraceSystem;
020:
021:        /**
022:         * The web session keeps all data of a user session.
023:         * This class is used by the H2 Console.
024:         */
025:        public class WebSession {
026:            long lastAccess;
027:            HashMap map = new HashMap();
028:            Locale locale;
029:            WebServer server;
030:
031:            private static final int MAX_HISTORY = 1000;
032:            private ArrayList commandHistory = new ArrayList();
033:
034:            private Connection conn;
035:            private DatabaseMetaData meta;
036:            private DbContents contents = new DbContents();
037:            private DbContextRule columnRule;
038:            private DbContextRule newAliasRule;
039:            private DbContextRule tableRule;
040:            private DbContextRule aliasRule;
041:            private DbContextRule columnAliasRule;
042:            private Bnf bnf;
043:            Statement executingStatement;
044:            ResultSet result;
045:
046:            WebSession(WebServer server) {
047:                this .server = server;
048:            }
049:
050:            public void put(String key, Object value) {
051:                map.put(key, value);
052:            }
053:
054:            public Object get(String key) {
055:                if ("sessions".equals(key)) {
056:                    return server.getSessions();
057:                }
058:                return map.get(key);
059:            }
060:
061:            public void remove(String key) {
062:                map.remove(key);
063:            }
064:
065:            public Bnf getBnf() {
066:                return bnf;
067:            }
068:
069:            void loadBnf() {
070:                try {
071:                    Bnf newBnf = Bnf.getInstance(null);
072:                    columnRule = new DbContextRule(contents,
073:                            DbContextRule.COLUMN);
074:                    newAliasRule = new DbContextRule(contents,
075:                            DbContextRule.NEW_TABLE_ALIAS);
076:                    aliasRule = new DbContextRule(contents,
077:                            DbContextRule.TABLE_ALIAS);
078:                    tableRule = new DbContextRule(contents, DbContextRule.TABLE);
079:                    columnAliasRule = new DbContextRule(contents,
080:                            DbContextRule.COLUMN_ALIAS);
081:                    //            bnf.updateTopic("newTableName", new String[]{"TEST"});
082:                    //            String[] schemas;
083:                    //            if(contents.isMySQL) {
084:                    //                schemas = new String[0];
085:                    //            } else {
086:                    //                schemas = new String[contents.schemas.length];
087:                    //                for(int i=0; i<contents.schemas.length; i++) {
088:                    //                    schemas[i] = contents.schemas[i].quotedName + ".";
089:                    //                }
090:                    //            }
091:                    //            bnf.updateTopic("schemaName", schemas);
092:                    newBnf.updateTopic("columnName", columnRule);
093:                    newBnf.updateTopic("newTableAlias", newAliasRule);
094:                    newBnf.updateTopic("tableAlias", aliasRule);
095:                    newBnf.updateTopic("columnAlias", columnAliasRule);
096:                    newBnf.updateTopic("tableName", tableRule);
097:                    // bnf.updateTopic("name", new String[]{""});
098:                    newBnf.linkStatements();
099:                    bnf = newBnf;
100:                } catch (Exception e) {
101:                    // ok we don't have the bnf
102:                    e.printStackTrace();
103:                }
104:            }
105:
106:            String getCommand(int id) {
107:                return (String) commandHistory.get(id);
108:            }
109:
110:            void addCommand(String sql) {
111:                if (sql == null) {
112:                    return;
113:                }
114:                sql = sql.trim();
115:                if (sql.length() == 0) {
116:                    return;
117:                }
118:                if (commandHistory.size() > MAX_HISTORY) {
119:                    commandHistory.remove(0);
120:                }
121:                int idx = commandHistory.indexOf(sql);
122:                if (idx >= 0) {
123:                    commandHistory.remove(idx);
124:                }
125:                commandHistory.add(sql);
126:            }
127:
128:            ArrayList getCommands() {
129:                return commandHistory;
130:            }
131:
132:            public HashMap getInfo() {
133:                HashMap m = new HashMap();
134:                m.putAll(map);
135:                m.put("lastAccess", new Timestamp(lastAccess).toString());
136:                try {
137:                    m.put("url", conn == null ? "not connected" : conn
138:                            .getMetaData().getURL());
139:                    m.put("user", conn == null ? "-" : conn.getMetaData()
140:                            .getUserName());
141:                    m.put("lastQuery", commandHistory.size() == 0 ? ""
142:                            : commandHistory.get(0));
143:                    m.put("executing", executingStatement == null ? "no"
144:                            : "yes");
145:                } catch (SQLException e) {
146:                    TraceSystem.traceThrowable(e);
147:                }
148:                return m;
149:            }
150:
151:            void setConnection(Connection conn) throws SQLException {
152:                this .conn = conn;
153:                if (conn == null) {
154:                    meta = null;
155:                } else {
156:                    meta = conn.getMetaData();
157:                }
158:                contents = new DbContents();
159:            }
160:
161:            DatabaseMetaData getMetaData() {
162:                return meta;
163:            }
164:
165:            Connection getConnection() {
166:                return conn;
167:            }
168:
169:            public DbContents getContents() {
170:                return contents;
171:            }
172:
173:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.