Source Code Cross Referenced for CmsUserDriver.java in  » Content-Management-System » opencms » org » opencms » db » oracle » 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 » Content Management System » opencms » org.opencms.db.oracle 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/db/oracle/CmsUserDriver.java,v $
003:         * Date   : $Date: 2008-02-27 12:05:43 $
004:         * Version: $Revision: 1.59 $
005:         *
006:         * This library is part of OpenCms -
007:         * the Open Source Content Management System
008:         *
009:         * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010:         *
011:         * This library is free software; you can redistribute it and/or
012:         * modify it under the terms of the GNU Lesser General Public
013:         * License as published by the Free Software Foundation; either
014:         * version 2.1 of the License, or (at your option) any later version.
015:         *
016:         * This library is distributed in the hope that it will be useful,
017:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
018:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019:         * Lesser General Public License for more details.
020:         *
021:         * For further information about Alkacon Software GmbH, please see the
022:         * company website: http://www.alkacon.com
023:         *
024:         * For further information about OpenCms, please see the
025:         * project website: http://www.opencms.org
026:         * 
027:         * You should have received a copy of the GNU Lesser General Public
028:         * License along with this library; if not, write to the Free Software
029:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
030:         */
031:
032:        package org.opencms.db.oracle;
033:
034:        import org.opencms.db.CmsDbContext;
035:        import org.opencms.db.CmsDbEntryNotFoundException;
036:        import org.opencms.db.CmsDbIoException;
037:        import org.opencms.db.CmsDbSqlException;
038:        import org.opencms.db.generic.CmsSqlManager;
039:        import org.opencms.db.generic.Messages;
040:        import org.opencms.file.CmsDataAccessException;
041:        import org.opencms.util.CmsDataTypeUtil;
042:        import org.opencms.util.CmsUUID;
043:
044:        import java.io.IOException;
045:        import java.io.OutputStream;
046:        import java.sql.Blob;
047:        import java.sql.Connection;
048:        import java.sql.PreparedStatement;
049:        import java.sql.ResultSet;
050:        import java.sql.SQLException;
051:
052:        import org.apache.commons.dbcp.DelegatingResultSet;
053:
054:        /**
055:         * Oracle implementation of the user driver methods.<p>
056:         * 
057:         * @author Thomas Weckert  
058:         * @author Carsten Weinholz 
059:         * 
060:         * @version $Revision: 1.59 $
061:         * 
062:         * @since 6.0.0 
063:         */
064:        public class CmsUserDriver extends org.opencms.db.generic.CmsUserDriver {
065:
066:            /**
067:             * Generates an Output stream that writes to a blob, also truncating the existing blob if required.<p>
068:             * 
069:             * Apparently Oracle requires some non-standard handling here.<p>
070:             * 
071:             * @param res the result set where the blob is located in 
072:             * @param name the name of the database column where the blob is located
073:             * @return an Output stream from a blob
074:             * @throws SQLException if something goes wring
075:             */
076:            public static OutputStream getOutputStreamFromBlob(ResultSet res,
077:                    String name) throws SQLException {
078:
079:                // TODO: perform blob check only once and store Oracle version in a static private member 
080:                // TODO: best do this during system startup / db init phase once
081:                Blob blob = res.getBlob(name);
082:                try {
083:                    // jdbc standard
084:                    blob.truncate(0);
085:                    return blob.setBinaryStream(0L);
086:                } catch (SQLException e) {
087:                    // oracle 9 & 8 (if using the same jdbc driver as provided by oracle9: ojdbc14.jar)
088:                    ((oracle.sql.BLOB) blob).trim(0);
089:                    return ((oracle.sql.BLOB) blob).getBinaryOutputStream();
090:                }
091:            }
092:
093:            /**
094:             * @see org.opencms.db.I_CmsUserDriver#initSqlManager(String)
095:             */
096:            public org.opencms.db.generic.CmsSqlManager initSqlManager(
097:                    String classname) {
098:
099:                return CmsSqlManager.getInstance(classname);
100:            }
101:
102:            /**
103:             * @see org.opencms.db.I_CmsUserDriver#writeUserInfo(CmsDbContext, CmsUUID, String, Object)
104:             */
105:            public void writeUserInfo(CmsDbContext dbc, CmsUUID userId,
106:                    String key, Object value) throws CmsDataAccessException {
107:
108:                PreparedStatement stmt = null;
109:                Connection conn = null;
110:
111:                try {
112:
113:                    // get connection
114:                    conn = m_sqlManager.getConnection(dbc);
115:
116:                    // write data to database
117:                    stmt = m_sqlManager.getPreparedStatement(conn,
118:                            "C_ORACLE_USERDATA_WRITE_3");
119:                    stmt.setString(1, userId.toString());
120:                    stmt.setString(2, key);
121:                    stmt.setString(3, value.getClass().getName());
122:                    stmt.executeUpdate();
123:                } catch (SQLException e) {
124:                    throw new CmsDbSqlException(
125:                            org.opencms.db.generic.Messages
126:                                    .get()
127:                                    .container(
128:                                            org.opencms.db.generic.Messages.ERR_GENERIC_SQL_1,
129:                                            CmsDbSqlException
130:                                                    .getErrorQuery(stmt)), e);
131:                } finally {
132:                    m_sqlManager.closeAll(dbc, conn, stmt, null);
133:                }
134:                internalUpdateUserInfo(dbc, userId, key, value);
135:            }
136:
137:            /**
138:             * Updates the given user information entry.<p>
139:             * 
140:             * @param dbc the current database context
141:             * @param userId the id of the user to update
142:             * @param key the user info entry key
143:             * @param value the user info entry value
144:             * 
145:             * @throws CmsDataAccessException if something goes wrong
146:             */
147:            protected void internalUpdateUserInfo(CmsDbContext dbc,
148:                    CmsUUID userId, String key, Object value)
149:                    throws CmsDataAccessException {
150:
151:                PreparedStatement stmt = null;
152:                PreparedStatement commit = null;
153:                ResultSet res = null;
154:                Connection conn = null;
155:
156:                boolean wasInTransaction = false;
157:
158:                try {
159:                    // get connection
160:                    conn = m_sqlManager.getConnection(dbc);
161:                    wasInTransaction = !conn.getAutoCommit();
162:                    if (!wasInTransaction) {
163:                        conn.setAutoCommit(false);
164:                    }
165:
166:                    // update user_info in this special way because of using blob
167:                    stmt = m_sqlManager.getPreparedStatement(conn,
168:                            "C_ORACLE_USERDATA_UPDATE_2");
169:                    stmt.setString(1, userId.toString());
170:                    stmt.setString(2, key);
171:                    res = ((DelegatingResultSet) stmt.executeQuery())
172:                            .getInnermostDelegate();
173:                    if (!res.next()) {
174:                        throw new CmsDbEntryNotFoundException(Messages.get()
175:                                .container(Messages.ERR_NO_USER_WITH_ID_1,
176:                                        userId));
177:                    }
178:                    // write serialized user info 
179:                    OutputStream output = getOutputStreamFromBlob(res,
180:                            "DATA_VALUE");
181:                    output.write(CmsDataTypeUtil.dataSerialize(value));
182:                    output.close();
183:                    value = null;
184:
185:                    if (!wasInTransaction) {
186:                        commit = m_sqlManager.getPreparedStatement(conn,
187:                                "C_COMMIT");
188:                        commit.execute();
189:                        m_sqlManager.closeAll(dbc, null, commit, null);
190:                    }
191:                    m_sqlManager.closeAll(dbc, null, stmt, res);
192:
193:                    // this is needed so the finally block works correctly
194:                    commit = null;
195:                    stmt = null;
196:                    res = null;
197:
198:                    if (!wasInTransaction) {
199:                        conn.setAutoCommit(true);
200:                    }
201:                } catch (SQLException e) {
202:                    throw new CmsDbSqlException(
203:                            org.opencms.db.generic.Messages
204:                                    .get()
205:                                    .container(
206:                                            org.opencms.db.generic.Messages.ERR_GENERIC_SQL_1,
207:                                            CmsDbSqlException
208:                                                    .getErrorQuery(stmt)), e);
209:                } catch (IOException e) {
210:                    throw new CmsDbIoException(Messages.get().container(
211:                            Messages.ERR_SERIALIZING_USER_DATA_1, userId), e);
212:                } finally {
213:                    org.opencms.db.oracle.CmsSqlManager.closeAllInTransaction(
214:                            m_sqlManager, dbc, conn, stmt, res, commit,
215:                            wasInTransaction);
216:                }
217:            }
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.