001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-setup/org/opencms/setup/update6to7/generic/CmsUpdateDBDropUnusedTables.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.CmsSetupDb;
035: import org.opencms.setup.update6to7.A_CmsUpdateDBPart;
036:
037: import java.io.IOException;
038: import java.sql.SQLException;
039: import java.util.Arrays;
040: import java.util.Collections;
041: import java.util.HashMap;
042: import java.util.Iterator;
043: import java.util.List;
044:
045: /**
046: * This class drops the outdated tables from the OpenCms database.<p>
047: *
048: * These tables are
049: * CMS_SYSTEMID
050: * CMS_TASK
051: * CMS_TASKLOG
052: * CMS_TASKPAR
053: * CMS_TASKTYPE
054: * TEMP_PROJECT_UUIDS
055: *
056: * @author Roland Metzler
057: *
058: * @version $Revision: 1.2 $
059: *
060: * @since 7.0.0
061: */
062: public class CmsUpdateDBDropUnusedTables extends A_CmsUpdateDBPart {
063:
064: /** Constant for the SQL query to drop a table.<p> */
065: private static final String QUERY_DROP_TABLE = "Q_DROP_TABLE";
066:
067: /** Constant for the SQL query properties.<p> */
068: private static final String QUERY_PROPERTY_FILE = "generic/cms_drop_unused_tables_queries.properties";
069:
070: /** Constant for the replacement of the tablename in the sql query.<p> */
071: private static final String REPLACEMENT_TABLENAME = "${tablename}";
072:
073: /** Constant array with the unused tables.<p> */
074: private static final String[] UNUSED_TABLES = { "CMS_SYSTEMID",
075: "CMS_TASK", "CMS_TASKLOG", "CMS_TASKPAR", "CMS_TASKTYPE",
076: "TEMP_PROJECT_UUIDS" };
077:
078: /** Constant ArrayList of the unused tables that are to be dropped.<p> */
079: private static final List UNUSED_TABLES_LIST = Collections
080: .unmodifiableList(Arrays.asList(UNUSED_TABLES));
081:
082: /**
083: * Constructor.<p>
084: *
085: * @throws IOException if the sql queries properties file could not be read
086: */
087: public CmsUpdateDBDropUnusedTables() throws IOException {
088:
089: super ();
090: loadQueryProperties(QUERY_PROPERTIES_PREFIX
091: + QUERY_PROPERTY_FILE);
092: }
093:
094: /**
095: * @see org.opencms.setup.update6to7.A_CmsUpdateDBPart#internalExecute(org.opencms.setup.CmsSetupDb)
096: */
097: protected void internalExecute(CmsSetupDb dbCon)
098: throws SQLException {
099:
100: System.out.println(new Exception().getStackTrace()[0]
101: .toString());
102: for (Iterator it = UNUSED_TABLES_LIST.iterator(); it.hasNext();) {
103: String table = (String) it.next();
104: // Check if the table to drop exists
105: if (dbCon.hasTableOrColumn(table, null)) {
106: HashMap replacer = new HashMap();
107: replacer.put(REPLACEMENT_TABLENAME, table);
108: dbCon.updateSqlStatement(readQuery(QUERY_DROP_TABLE),
109: replacer, null);
110: } else {
111: System.out.println("table " + table + " not found");
112: }
113: }
114: }
115: }
|