001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-setup/org/opencms/setup/update6to7/generic/CmsUpdateDBHistoryTables.java,v $
003: * Date : $Date: 2008-02-27 12:05:34 $
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.generic;
033:
034: import org.opencms.setup.CmsSetupDBWrapper;
035: import org.opencms.setup.CmsSetupDb;
036: import org.opencms.setup.update6to7.A_CmsUpdateDBPart;
037:
038: import java.io.IOException;
039: import java.sql.SQLException;
040: import java.util.ArrayList;
041: import java.util.HashMap;
042: import java.util.Iterator;
043: import java.util.List;
044:
045: /**
046: * This class converts the backup tables to history tables.<p>
047: *
048: * The following tables are converted
049: * CMS_BACKUP_PROJECTRESOURCES
050: * CMS_BACKUP_PROPERTIES
051: * CMS_BACKUP_PROPERTYDEF
052: * CMS_BACKUP_RESOURCES
053: * CMS_BACKUP_STRUCTURE
054: *
055: * The tables CMS_HISTORY_PRINCIPALS and CMS_HISTORY_PROJECTS are created in other classes.
056: *
057: * CMS_HISTORY_PRINCIPALS is a completely new table and is therefor handled by its own class.
058: *
059: * CMS_HISTORY_PROJECTS needs extra conversion beyond the execution of SQL statements and is
060: * also handled by a special class.
061: *
062: * @author Roland Metzler
063: *
064: * @version $Revision: 1.2 $
065: *
066: * @since 7.0.0
067: */
068: public class CmsUpdateDBHistoryTables extends A_CmsUpdateDBPart {
069:
070: /** Constant for the SQL query properties.<p> */
071: private static final String QUERY_PROPERTY_FILE = "generic/cms_history_queries.properties";
072:
073: /** Constant for the sql query to count the contents of a table.<p> */
074: private static final String QUERY_SELECT_COUNT_HISTORY_TABLE = "Q_SELECT_COUNT_HISTORY_TABLE";
075:
076: /** Constant for the replacement of the tablename in the sql query. */
077: private static final String REPLACEMENT_TABLENAME = "${tablename}";
078:
079: /**
080: * Constructor.<p>
081: *
082: * @throws IOException if the sql queries properties file could not be read
083: */
084: public CmsUpdateDBHistoryTables() throws IOException {
085:
086: super ();
087: loadQueryProperties(QUERY_PROPERTIES_PREFIX
088: + QUERY_PROPERTY_FILE);
089: }
090:
091: /**
092: * @see org.opencms.setup.update6to7.A_CmsUpdateDBPart#internalExecute(org.opencms.setup.CmsSetupDb)
093: */
094: protected void internalExecute(CmsSetupDb dbCon)
095: throws SQLException {
096:
097: System.out.println(new Exception().getStackTrace()[0]
098: .toString());
099:
100: List elements = new ArrayList();
101: elements.add("CMS_HISTORY_PROPERTYDEF");
102: if (isKeepHistory()) {
103: elements.add("CMS_HISTORY_PROJECTRESOURCES");
104: elements.add("CMS_HISTORY_PROPERTIES");
105: elements.add("CMS_HISTORY_RESOURCES");
106: elements.add("CMS_HISTORY_STRUCTURE");
107: }
108: for (Iterator it = elements.iterator(); it.hasNext();) {
109: String table = (String) it.next();
110: System.out.println("Updating table " + table);
111: if (dbCon.hasTableOrColumn(table, null)) {
112: HashMap replacer = new HashMap();
113: replacer.put(REPLACEMENT_TABLENAME, table);
114: CmsSetupDBWrapper db = null;
115: boolean update = false;
116: try {
117: db = dbCon
118: .executeSqlStatement(
119: readQuery(QUERY_SELECT_COUNT_HISTORY_TABLE),
120: replacer);
121:
122: if (db.getResultSet().next()) {
123: if (db.getResultSet().getInt("COUNT") <= 0) {
124: update = true;
125: }
126: }
127: } finally {
128: if (db != null) {
129: db.close();
130: }
131: }
132: if (update) {
133: String query = readQuery(table);
134: dbCon.updateSqlStatement(query, null, null);
135: } else {
136: System.out.println("table " + table
137: + " already has data");
138: }
139: } else {
140: System.out.println("table " + table
141: + " does not exists");
142: }
143: }
144: }
145: }
|