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, 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.update7to8.postgresql; 029 030import org.opencms.setup.CmsSetupDb; 031 032import java.io.IOException; 033import java.sql.SQLException; 034import java.util.ArrayList; 035import java.util.Collections; 036import java.util.LinkedHashMap; 037import java.util.List; 038import java.util.Map; 039 040/** 041 * Oracle implementation to create the new tables for version 7 of OpenCms.<p> 042 * 043 * @since 7.0.0 044 */ 045public class CmsUpdateDBNewTables extends org.opencms.setup.db.update7to8.CmsUpdateDBNewTables { 046 047 /** Constant for the SQL query properties.<p> */ 048 private static final String QUERY_PROPERTY_FILE = "cms_new_tables_queries.properties"; 049 050 /** 051 * Constructor.<p> 052 * 053 * @throws IOException if the sql queries properties file could not be read 054 */ 055 public CmsUpdateDBNewTables() 056 throws IOException { 057 058 super(); 059 loadQueryProperties(getPropertyFileLocation() + QUERY_PROPERTY_FILE); 060 } 061 062 /** 063 * @see org.opencms.setup.db.A_CmsUpdateDBPart#internalExecute(org.opencms.setup.CmsSetupDb) 064 */ 065 @Override 066 protected void internalExecute(CmsSetupDb dbCon) throws SQLException { 067 068 System.out.println(new Exception().getStackTrace()[0].toString()); 069 Map<String, List<String>> elements = new LinkedHashMap<String, List<String>>(); 070 List<String> indexes = new ArrayList<String>(); 071 elements.put("CMS_LOG", indexes); 072 indexes.add("CREATE_INDEX_CMS_LOG_01_IDX"); 073 indexes.add("CREATE_INDEX_CMS_LOG_02_IDX"); 074 indexes.add("CREATE_INDEX_CMS_LOG_03_IDX"); 075 indexes.add("CREATE_INDEX_CMS_LOG_04_IDX"); 076 indexes.add("CREATE_INDEX_CMS_LOG_05_IDX"); 077 indexes.add("CREATE_INDEX_CMS_LOG_06_IDX"); 078 indexes.add("CREATE_INDEX_CMS_LOG_07_IDX"); 079 indexes.add("CREATE_INDEX_CMS_LOG_08_IDX"); 080 indexes.add("CREATE_INDEX_CMS_LOG_09_IDX"); 081 082 indexes = new ArrayList<String>(); 083 elements.put("CMS_SUBSCRIPTION_VISIT", indexes); 084 indexes.add("CREATE_INDEX_CMS_SUBSCRIPTION_VISIT_01_IDX"); 085 indexes.add("CREATE_INDEX_CMS_SUBSCRIPTION_VISIT_02_IDX"); 086 indexes.add("CREATE_INDEX_CMS_SUBSCRIPTION_VISIT_03_IDX"); 087 indexes.add("CREATE_INDEX_CMS_SUBSCRIPTION_VISIT_04_IDX"); 088 indexes.add("CREATE_INDEX_CMS_SUBSCRIPTION_VISIT_05_IDX"); 089 090 indexes = new ArrayList<String>(); 091 elements.put("CMS_SUBSCRIPTION", indexes); 092 indexes.add("CREATE_INDEX_CMS_SUBSCRIPTION_01_IDX"); 093 indexes.add("CREATE_INDEX_CMS_SUBSCRIPTION_02_IDX"); 094 indexes.add("CREATE_INDEX_CMS_SUBSCRIPTION_03_IDX"); 095 indexes.add("CREATE_INDEX_CMS_SUBSCRIPTION_04_IDX"); 096 097 indexes = new ArrayList<String>(); 098 elements.put("CMS_COUNTERS", indexes); 099 100 indexes = new ArrayList<String>(); 101 elements.put("CMS_OFFLINE_URLNAME_MAPPINGS", indexes); 102 indexes.add("CREATE_INDEX_CMS_OFFLINE_URLNAME_MAPPINGS_01_IDX"); 103 indexes.add("CREATE_INDEX_CMS_OFFLINE_URLNAME_MAPPINGS_02_IDX"); 104 105 indexes = new ArrayList<String>(); 106 elements.put("CMS_ONLINE_URLNAME_MAPPINGS", indexes); 107 indexes.add("CREATE_INDEX_CMS_ONLINE_URLNAME_MAPPINGS_01_IDX"); 108 indexes.add("CREATE_INDEX_CMS_ONLINE_URLNAME_MAPPINGS_02_IDX"); 109 110 indexes = new ArrayList<String>(); 111 elements.put("CMS_ALIASES", indexes); 112 indexes.add("CMS_ALIASES_IDX_1"); 113 114 indexes = new ArrayList<String>(); 115 elements.put("CMS_USER_PUBLISH_LIST", indexes); 116 indexes.add("CMS_USERPUBLIST_IDX_01"); 117 indexes.add("CMS_USERPUBLIST_IDX_02"); 118 119 indexes = new ArrayList<String>(); 120 elements.put("CMS_REWRITES", indexes); 121 indexes.add("CMS_REWRITES_IDX_01"); 122 123 Map<String, String> replacer = Collections.emptyMap(); 124 for (Map.Entry<String, List<String>> entry : elements.entrySet()) { 125 String table = entry.getKey(); 126 if (!dbCon.hasTableOrColumn(table, null)) { 127 String query = readQuery(table); 128 if (query == null) { 129 System.out.println("Query not found: " + table); 130 } 131 dbCon.updateSqlStatement(query, replacer, null); 132 for (String index : entry.getValue()) { 133 query = readQuery(index); 134 if (query == null) { 135 System.out.println("Query not found: " + index); 136 } 137 dbCon.updateSqlStatement(query, replacer, null); 138 } 139 } else { 140 System.out.println("table " + table + " already exists"); 141 } 142 } 143 144 } 145}