Source Code Cross Referenced for DBUtil.java in  » J2EE » Enhydra-Application-Framework » com » lutris » appserver » server » sessionEnhydra » persistent » 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 » com.lutris.appserver.server.sessionEnhydra.persistent 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Enhydra Java Application Server Project
003:         *
004:         * The contents of this file are subject to the Enhydra Public License
005:         * Version 1.1 (the "License"); you may not use this file except in
006:         * compliance with the License. You may obtain a copy of the License on
007:         * the Enhydra web site ( http://www.enhydra.org/ ).
008:         *
009:         * Software distributed under the License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011:         * the License for the specific terms governing rights and limitations
012:         * under the License.
013:         *
014:         * The Initial Developer of the Enhydra Application Server is Lutris
015:         * Technologies, Inc. The Enhydra Application Server and portions created
016:         * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017:         * All Rights Reserved.
018:         *
019:         * Contributor(s):
020:         *
021:         * $Id: DBUtil.java,v 1.2 2006-06-15 13:44:07 sinisa Exp $
022:         */
023:
024:        package com.lutris.appserver.server.sessionEnhydra.persistent;
025:
026:        import java.sql.SQLException;
027:
028:        import com.lutris.appserver.server.Enhydra;
029:        import com.lutris.appserver.server.session.SessionException;
030:        import com.lutris.appserver.server.sessionEnhydra.StandardSession;
031:        import com.lutris.appserver.server.sessionEnhydra.StandardSessionManager;
032:        import com.lutris.appserver.server.sql.DBQuery;
033:        import com.lutris.appserver.server.sql.DBTransaction;
034:        import com.lutris.appserver.server.sql.DatabaseManagerException;
035:        import com.lutris.appserver.server.sql.Query;
036:
037:        /**
038:         * Utilitity class for performint database operations.
039:         *
040:         * @see         StandardSession
041:         * @see         StandardSessionManager
042:         * @version	$Revision: 1.2 $
043:         * @author	Kyle Clark
044:         */
045:        class DBUtil {
046:
047:            /**
048:             * Saves a session to the database.
049:             *
050:             * @param session
051:             *   the session to save.
052:             * @param dbName the database that should be accessed.  May be
053:             *   null in which case the default database is used.
054:             * @return the number of rows that were affected
055:             *   by this update.
056:             * @exception SessionException
057:             *   if an error occurs.
058:             */
059:            static int dbUpdate(PersistentSession session, String dbName)
060:                    throws SessionException {
061:                PersistentSessionDO sessionDO = new PersistentSessionDO(session);
062:                try {
063:                    DBTransaction t = createTransaction(dbName);
064:                    try {
065:                        t.update(sessionDO);
066:                        t.commit();
067:                    } catch (Exception e) {
068:                        t.rollback();
069:                        throw e;
070:                    } finally {
071:                        t.release();
072:                    }
073:                } catch (Exception e) {
074:                    throw new SessionException(e);
075:                }
076:                return sessionDO.getTransactionRowCount();
077:            }
078:
079:            /**
080:             * Deletes a session from the database.
081:             *
082:             * @param sessionKey
083:             *   the key that identifies the session that will be deleted.
084:             * @param dbName the database that should be accessed.  May be
085:             *   null in which case the default database is used.
086:             * @exception SessionException
087:             *   if an error occurs.
088:             */
089:            static void dbDelete(String sessionKey, String dbName)
090:                    throws SessionException {
091:                try {
092:                    DBTransaction t = createTransaction(dbName);
093:                    SessionDeleteDO s = new SessionDeleteDO(sessionKey);
094:                    try {
095:                        t.delete(s);
096:                        t.commit();
097:                    } catch (Exception e) {
098:                        t.rollback();
099:                        throw e;
100:                    } finally {
101:                        t.release();
102:                    }
103:                } catch (Exception e) {
104:                    throw new SessionException(e);
105:                }
106:            }
107:
108:            /**
109:             * Inserts a session into the database.
110:             *
111:             * @param session
112:             *   the session that will be inserted.
113:             * @param dbName the database that should be accessed.  May be
114:             *   null in which case the default database is used.
115:             * @exception SessionException
116:             *   if an error occurs.
117:             */
118:            static void dbInsert(PersistentSession session, String dbName)
119:                    throws SessionException {
120:                try {
121:                    PersistentSessionDO sessionDO = new PersistentSessionDO(
122:                            session);
123:                    DBTransaction t = createTransaction(dbName);
124:                    try {
125:                        t.insert(sessionDO);
126:                        t.commit();
127:                    } catch (Exception e) {
128:                        t.rollback();
129:                        throw e;
130:                    } finally {
131:                        t.release();
132:                    }
133:                } catch (Exception e) {
134:                    throw new SessionException(e);
135:                }
136:            }
137:
138:            /**
139:             * Executes a query of the database.
140:             *
141:             * @param query
142:             *   the object containg the query statement.
143:             * @param dbName the database that should be queried.  May be
144:             *   null in which case the default database is used.
145:             * @exception SessionException
146:             *   if an erro occurs.
147:             */
148:            static Object dbQuery(Query query, String dbName)
149:                    throws SessionException {
150:                try {
151:                    DBQuery q = createQuery(dbName);
152:                    try {
153:                        q.query(query);
154:                        return q.next();
155:                    } catch (Exception e) {
156:                        throw e;
157:                    } finally {
158:                        q.release();
159:                    }
160:                } catch (Exception e) {
161:                    throw new SessionException(e);
162:                }
163:            }
164:
165:            /**
166:             * Creates a transaction for the specified DB name.
167:             *
168:             * @param dbName the database name.  May be null in
169:             *   which case the default database is used.
170:             * @exception DatabaseManagerException if an error occurs.
171:             * @exception SQLException if an error occurs.
172:             */
173:            static DBTransaction createTransaction(String dbName)
174:                    throws DatabaseManagerException, SQLException {
175:                DBTransaction t;
176:                if (dbName != null) {
177:                    t = Enhydra.getDatabaseManager().createTransaction(dbName);
178:                } else {
179:                    t = Enhydra.getDatabaseManager().createTransaction();
180:                }
181:                return t;
182:            }
183:
184:            /**
185:             * Creates a query for the specified DB name.
186:             *
187:             * @param dbName the database name.  May be null in
188:             *   which case the default database is used.
189:             * @exception DatabaseManagerException if an error occurs.
190:             * @exception SQLException if an error occurs.
191:             */
192:            static DBQuery createQuery(String dbName)
193:                    throws DatabaseManagerException, SQLException {
194:                DBQuery q;
195:                if (dbName != null) {
196:                    q = Enhydra.getDatabaseManager().createQuery(dbName);
197:                } else {
198:                    q = Enhydra.getDatabaseManager().createQuery();
199:                }
200:                return q;
201:            }
202:
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.