001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-setup/org/opencms/setup/update6to7/oracle/CmsUpdateDBCmsUsers.java,v $
003: * Date : $Date: 2008-02-27 12:05:48 $
004: * Version: $Revision: 1.2 $
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.setup.update6to7.oracle;
033:
034: import org.opencms.db.oracle.CmsUserDriver;
035: import org.opencms.setup.CmsSetupDBWrapper;
036: import org.opencms.setup.CmsSetupDb;
037: import org.opencms.util.CmsDataTypeUtil;
038:
039: import java.io.IOException;
040: import java.io.OutputStream;
041: import java.sql.SQLException;
042: import java.util.ArrayList;
043: import java.util.HashMap;
044: import java.util.Iterator;
045: import java.util.List;
046:
047: /**
048: * Oracle implementation of the generic update class for the Users.<p>
049: *
050: * @author Roland Metzler
051: * @author Peter Bonrad
052: *
053: * @version $Revision: 1.2 $
054: *
055: * @since 7.0.0
056: */
057: public class CmsUpdateDBCmsUsers extends
058: org.opencms.setup.update6to7.generic.CmsUpdateDBCmsUsers {
059:
060: /** Constant for the query to insert the new user data into the new table CMS_USERDATA.<p> */
061: private static final String QUERY_ORACLE_USERDATA_UPDATE = "Q_ORACLE_USERDATA_UPDATE";
062:
063: /** Constant for the SQL query properties.<p> */
064: private static final String QUERY_PROPERTY_FILE = "oracle/cms_users_queries.properties";
065:
066: /** Constant for the replacement in the sql query. */
067: private static final String REPLACEMENT_TABLEINDEX_SPACE = "${indexTablespace}";
068:
069: /**
070: * Constructor.<p>
071: *
072: * @throws IOException if the sql queries properties file could not be read
073: */
074: public CmsUpdateDBCmsUsers() throws IOException {
075:
076: super ();
077: loadQueryProperties(QUERY_PROPERTIES_PREFIX
078: + QUERY_PROPERTY_FILE);
079: }
080:
081: /**
082: * @see org.opencms.setup.update6to7.generic.CmsUpdateDBCmsUsers#createUserDataTable(org.opencms.setup.CmsSetupDb)
083: */
084: protected void createUserDataTable(CmsSetupDb dbCon)
085: throws SQLException {
086:
087: String indexTablespace = (String) m_poolData
088: .get("indexTablespace");
089:
090: HashMap replacer = new HashMap();
091: replacer.put(REPLACEMENT_TABLEINDEX_SPACE, indexTablespace);
092:
093: String createStatement = readQuery(QUERY_CREATE_TABLE_USERDATA);
094: dbCon.updateSqlStatement(createStatement, replacer, null);
095:
096: // create indices
097: List indexElements = new ArrayList();
098: indexElements.add("CMS_USERDATA_01_IDX_INDEX");
099: indexElements.add("CMS_USERDATA_02_IDX_INDEX");
100:
101: Iterator iter = indexElements.iterator();
102: while (iter.hasNext()) {
103: String stmt = readQuery((String) iter.next());
104:
105: try {
106:
107: // Create the index
108: dbCon.updateSqlStatement(stmt, replacer, null);
109: } catch (SQLException e) {
110: e.printStackTrace();
111: }
112: }
113: }
114:
115: /**
116: * @see org.opencms.setup.update6to7.generic.CmsUpdateDBCmsUsers#writeUserInfo(org.opencms.setup.CmsSetupDb, java.lang.String, java.lang.String, java.lang.Object)
117: */
118: protected void writeUserInfo(CmsSetupDb dbCon, String id,
119: String key, Object value) {
120:
121: String query = readQuery(QUERY_INSERT_CMS_USERDATA);
122:
123: try {
124: // Generate the list of parameters to add into the user info table
125: List params = new ArrayList();
126: params.add(id);
127: params.add(key);
128: params.add(value.getClass().getName());
129:
130: dbCon.updateSqlStatement(query, null, params);
131: } catch (SQLException e) {
132: e.printStackTrace();
133: }
134:
135: // update user_info in this special way because of using blob
136:
137: boolean wasInTransaction = false;
138:
139: CmsSetupDBWrapper db = null;
140:
141: try {
142:
143: wasInTransaction = !dbCon.getConnection().getAutoCommit();
144: if (!wasInTransaction) {
145: dbCon.getConnection().setAutoCommit(false);
146: }
147:
148: String stmt = readQuery(QUERY_ORACLE_USERDATA_UPDATE);
149:
150: // Generate the list of parameters to add into the user info table
151: List params = new ArrayList();
152: params.add(id);
153: params.add(key);
154:
155: db = dbCon.executeSqlStatement(stmt, null, params);
156: if (db.getResultSet().next()) {
157:
158: // write serialized user info
159: OutputStream output = CmsUserDriver
160: .getOutputStreamFromBlob(db.getResultSet(),
161: "DATA_VALUE");
162: output.write(CmsDataTypeUtil.dataSerialize(value));
163: output.close();
164:
165: } else {
166: System.out.println("Could not insert blob");
167: }
168:
169: if (!wasInTransaction) {
170: CmsSetupDBWrapper db2 = null;
171: try {
172: String commit = readQuery("Q_COMMIT");
173: db2 = dbCon.executeSqlStatement(commit, null);
174: } finally {
175: if (db2 != null) {
176: db2.close();
177: }
178: }
179: }
180:
181: } catch (Exception e) {
182: e.printStackTrace();
183: } finally {
184:
185: // close result set
186: if (db != null) {
187: db.close();
188: }
189:
190: // rollback
191: CmsSetupDBWrapper db2 = null;
192: try {
193: if (!wasInTransaction) {
194: String rollback = readQuery("Q_ROLLBACK");
195: db2 = dbCon.executeSqlStatement(rollback, null);
196: }
197: } catch (Exception e) {
198: e.printStackTrace();
199: } finally {
200: if (db2 != null) {
201: db2.close();
202: }
203: }
204:
205: // set auto commit back to original value
206: try {
207: if (!wasInTransaction) {
208: dbCon.getConnection().setAutoCommit(true);
209: }
210: } catch (Exception e) {
211: e.printStackTrace();
212: }
213: }
214: }
215: }
|