001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.setup.db.update6to7; 029 030import org.opencms.setup.CmsSetupDb; 031import org.opencms.setup.db.A_CmsUpdateDBPart; 032 033import java.io.IOException; 034import java.sql.SQLException; 035import java.util.Arrays; 036import java.util.Collections; 037import java.util.HashMap; 038import java.util.Iterator; 039import java.util.List; 040import java.util.Map; 041 042/** 043 * This class drops the CMS_BACKUP tables that are no longer used after all the transfers are finished.<p> 044 * 045 * The tables to drop are 046 * <ul> 047 * <li>CMS_BACKUP_PROJECTRESOURCES</li> 048 * <li>CMS_BACKUP_PROJECTS</li> 049 * <li>CMS_BACKUP_PROPERTIES</li> 050 * <li>CMS_BACKUP_PROPERTYDEF</li> 051 * <li>CMS_BACKUP_RESOURCES</li> 052 * <li>CMS_BACKUP_STRUCTURE</li> 053 * </ul> 054 * 055 * @since 7.0.0 056 */ 057public class CmsUpdateDBDropBackupTables extends A_CmsUpdateDBPart { 058 059 /** Array of the BACKUP tables that are to be dropped.<p> */ 060 protected static final String[] BACKUP_TABLES = { 061 "CMS_BACKUP_PROJECTRESOURCES", 062 "CMS_BACKUP_PROJECTS", 063 "CMS_BACKUP_PROPERTIES", 064 "CMS_BACKUP_PROPERTYDEF", 065 "CMS_BACKUP_RESOURCES", 066 "CMS_BACKUP_STRUCTURE"}; 067 068 /** Constant ArrayList of the BACKUP_TABLES that are to be dropped.<p> */ 069 protected static final List<String> BACKUP_TABLES_LIST = Collections.unmodifiableList(Arrays.asList(BACKUP_TABLES)); 070 071 /** Constant for the replacement of the tablename in the sql query.<p> */ 072 protected static final String REPLACEMENT_TABLENAME = "${tablename}"; 073 074 /** Constant for the sql query to drop a table.<p> */ 075 private static final String QUERY_DROP_TABLE = "Q_DROP_TABLE"; 076 077 /** Constant for the SQL query properties.<p> */ 078 private static final String QUERY_PROPERTY_FILE = "cms_drop_backup_tables_queries.properties"; 079 080 /** 081 * Constructor.<p> 082 * 083 * @throws IOException if the query properties cannot be read 084 */ 085 public CmsUpdateDBDropBackupTables() 086 throws IOException { 087 088 super(); 089 loadQueryProperties(getPropertyFileLocation() + QUERY_PROPERTY_FILE); 090 } 091 092 /** 093 * @see org.opencms.setup.db.A_CmsUpdateDBPart#internalExecute(org.opencms.setup.CmsSetupDb) 094 */ 095 @Override 096 protected void internalExecute(CmsSetupDb dbCon) { 097 098 System.out.println(new Exception().getStackTrace()[0].toString()); 099 String dropQuery = readQuery(QUERY_DROP_TABLE); 100 for (Iterator<String> it = BACKUP_TABLES_LIST.iterator(); it.hasNext();) { 101 String table = it.next(); 102 Map<String, String> replacer = new HashMap<String, String>(); 103 replacer.put(REPLACEMENT_TABLENAME, table); 104 try { 105 dbCon.updateSqlStatement(dropQuery, replacer, null); 106 } catch (SQLException e) { 107 e.printStackTrace(); 108 } 109 } 110 } 111}