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.oracle;
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        String indexTablespace = m_poolData.get("indexTablespace");
070
071        Map<String, List<String>> elements = new LinkedHashMap<String, List<String>>();
072        List<String> indexes = new ArrayList<String>();
073        elements.put("CMS_LOG", indexes);
074        indexes.add("CREATE_INDEX_CMS_LOG_01");
075        indexes.add("CREATE_INDEX_CMS_LOG_02");
076        indexes.add("CREATE_INDEX_CMS_LOG_03");
077        indexes.add("CREATE_INDEX_CMS_LOG_04");
078        indexes.add("CREATE_INDEX_CMS_LOG_05");
079        indexes.add("CREATE_INDEX_CMS_LOG_06");
080        indexes.add("CREATE_INDEX_CMS_LOG_07");
081        indexes.add("CREATE_INDEX_CMS_LOG_08");
082        indexes.add("CREATE_INDEX_CMS_LOG_09");
083
084        indexes = new ArrayList<String>();
085        elements.put("CMS_SUBSCRIPTION_VISIT", indexes);
086        indexes.add("CREATE_INDEX_CMS_SUBSCRIPTION_VISIT_01");
087        indexes.add("CREATE_INDEX_CMS_SUBSCRIPTION_VISIT_02");
088        indexes.add("CREATE_INDEX_CMS_SUBSCRIPTION_VISIT_03");
089        indexes.add("CREATE_INDEX_CMS_SUBSCRIPTION_VISIT_04");
090        indexes.add("CREATE_INDEX_CMS_SUBSCRIPTION_VISIT_05");
091
092        indexes = new ArrayList<String>();
093        elements.put("CMS_SUBSCRIPTION", indexes);
094        indexes.add("CREATE_INDEX_CMS_SUBSCRIPTION_01");
095        indexes.add("CREATE_INDEX_CMS_SUBSCRIPTION_02");
096        indexes.add("CREATE_INDEX_CMS_SUBSCRIPTION_03");
097        indexes.add("CREATE_INDEX_CMS_SUBSCRIPTION_04");
098
099        indexes = new ArrayList<String>();
100        elements.put("CMS_COUNTERS", indexes);
101
102        indexes = new ArrayList<String>();
103        elements.put("CMS_OFFLINE_URLNAME_MAPPINGS", indexes);
104        indexes.add("CREATE_INDEX_CMS_OFFLINE_MAPPINGS_01_IDX");
105        indexes.add("CREATE_INDEX_CMS_OFFLINE_MAPPINGS_02_IDX");
106
107        indexes = new ArrayList<String>();
108        elements.put("CMS_ONLINE_URLNAME_MAPPINGS", indexes);
109        indexes.add("CREATE_INDEX_CMS_ONLINE_MAPPINGS_01_IDX");
110        indexes.add("CREATE_INDEX_CMS_ONLINE_MAPPINGS_02_IDX");
111
112        indexes = new ArrayList<String>();
113        elements.put("CMS_ALIASES", indexes);
114        indexes.add("CMS_ALIASES_IDX_1");
115
116        indexes = new ArrayList<String>();
117        elements.put("CMS_USER_PUBLISH_LIST", indexes);
118        indexes.add("CMS_USERPUBLIST_IDX_01");
119        indexes.add("CMS_USERPUBLIST_IDX_02");
120
121        indexes = new ArrayList<String>();
122        elements.put("CMS_REWRITES", indexes);
123        indexes.add("CMS_REWRITES_IDX_01");
124
125        Map<String, String> replacer = Collections.singletonMap("${indexTablespace}", indexTablespace);
126        for (Map.Entry<String, List<String>> entry : elements.entrySet()) {
127            String table = entry.getKey();
128            if (!dbCon.hasTableOrColumn(table, null)) {
129                String query = readQuery(table);
130                dbCon.updateSqlStatement(query, replacer, null);
131                for (String index : entry.getValue()) {
132                    query = readQuery(index);
133                    dbCon.updateSqlStatement(query, replacer, null);
134                }
135            } else {
136                System.out.println("table " + table + " already exists");
137            }
138        }
139
140    }
141}