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.oracle;
029
030import org.opencms.setup.CmsSetupDb;
031
032import java.io.IOException;
033import java.sql.SQLException;
034import java.util.ArrayList;
035import java.util.HashMap;
036import java.util.List;
037import java.util.Map;
038
039/**
040 * Oracle implementation to create the new tables for version 7 of OpenCms.<p>
041 *
042 * @since 7.0.0
043 */
044public class CmsUpdateDBNewTables extends org.opencms.setup.db.update6to7.CmsUpdateDBNewTables {
045
046    /** Constant for the SQL query properties.<p> */
047    private static final String QUERY_PROPERTY_FILE = "cms_new_tables_queries.properties";
048
049    /** Constant for the replacement in the sql query. */
050    private static final String REPLACEMENT_TABLEINDEX_SPACE = "${indexTablespace}";
051
052    /**
053     * Constructor.<p>
054     *
055     * @throws IOException if the sql queries properties file could not be read
056     */
057    public CmsUpdateDBNewTables()
058    throws IOException {
059
060        super();
061        loadQueryProperties(getPropertyFileLocation() + QUERY_PROPERTY_FILE);
062    }
063
064    /**
065     * @see org.opencms.setup.db.update6to7.CmsUpdateDBNewTables#internalExecute(org.opencms.setup.CmsSetupDb)
066     */
067    @Override
068    protected void internalExecute(CmsSetupDb dbCon) throws SQLException {
069
070        System.out.println(new Exception().getStackTrace()[0].toString());
071
072        String indexTablespace = m_poolData.get("indexTablespace");
073
074        Map<String, List<String>> elements = new HashMap<String, List<String>>();
075
076        List<String> indexes = new ArrayList<String>();
077        indexes.add("CREATE_INDEX_CMS_OFFLINE_RELATIONS_01");
078        indexes.add("CREATE_INDEX_CMS_OFFLINE_RELATIONS_02");
079        indexes.add("CREATE_INDEX_CMS_OFFLINE_RELATIONS_03");
080        indexes.add("CREATE_INDEX_CMS_OFFLINE_RELATIONS_04");
081        indexes.add("CREATE_INDEX_CMS_OFFLINE_RELATIONS_05");
082        elements.put("CMS_OFFLINE_RESOURCE_RELATIONS", indexes);
083
084        indexes = new ArrayList<String>();
085        indexes.add("CREATE_INDEX_CMS_ONLINE_RELATIONS_01");
086        indexes.add("CREATE_INDEX_CMS_ONLINE_RELATIONS_02");
087        indexes.add("CREATE_INDEX_CMS_ONLINE_RELATIONS_03");
088        indexes.add("CREATE_INDEX_CMS_ONLINE_RELATIONS_04");
089        indexes.add("CREATE_INDEX_CMS_ONLINE_RELATIONS_05");
090        elements.put("CMS_ONLINE_RESOURCE_RELATIONS", indexes);
091
092        elements.put("CMS_PUBLISH_JOBS", new ArrayList<String>());
093        elements.put("CMS_RESOURCE_LOCKS", new ArrayList<String>());
094
095        indexes = new ArrayList<String>();
096        indexes.add("CREATE_INDEX_CMS_CONTENTS_01");
097        indexes.add("CREATE_INDEX_CMS_CONTENTS_02");
098        indexes.add("CREATE_INDEX_CMS_CONTENTS_03");
099        indexes.add("CREATE_INDEX_CMS_CONTENTS_04");
100        indexes.add("CREATE_INDEX_CMS_CONTENTS_05");
101        elements.put("CMS_CONTENTS", indexes);
102
103        elements.put("CMS_HISTORY_PROJECTRESOURCES", new ArrayList<String>());
104        elements.put("CMS_HISTORY_PROPERTYDEF", new ArrayList<String>());
105
106        indexes = new ArrayList<String>();
107        indexes.add("CREATE_INDEX_CMS_HISTORY_PROPERTIES_01");
108        indexes.add("CREATE_INDEX_CMS_HISTORY_PROPERTIES_02");
109        indexes.add("CREATE_INDEX_CMS_HISTORY_PROPERTIES_03");
110        indexes.add("CREATE_INDEX_CMS_HISTORY_PROPERTIES_04");
111        indexes.add("CREATE_INDEX_CMS_HISTORY_PROPERTIES_05");
112        elements.put("CMS_HISTORY_PROPERTIES", indexes);
113
114        indexes = new ArrayList<String>();
115        indexes.add("CREATE_INDEX_CMS_HISTORY_RESOURCES_01");
116        indexes.add("CREATE_INDEX_CMS_HISTORY_RESOURCES_02");
117        indexes.add("CREATE_INDEX_CMS_HISTORY_RESOURCES_03");
118        indexes.add("CREATE_INDEX_CMS_HISTORY_RESOURCES_04");
119        indexes.add("CREATE_INDEX_CMS_HISTORY_RESOURCES_05");
120        indexes.add("CREATE_INDEX_CMS_HISTORY_RESOURCES_06");
121        elements.put("CMS_HISTORY_RESOURCES", indexes);
122
123        indexes = new ArrayList<String>();
124        indexes.add("CREATE_INDEX_CMS_HISTORY_STRUCTURE_01");
125        indexes.add("CREATE_INDEX_CMS_HISTORY_STRUCTURE_02");
126        indexes.add("CREATE_INDEX_CMS_HISTORY_STRUCTURE_03");
127        indexes.add("CREATE_INDEX_CMS_HISTORY_STRUCTURE_04");
128        indexes.add("CREATE_INDEX_CMS_HISTORY_STRUCTURE_05");
129        indexes.add("CREATE_INDEX_CMS_HISTORY_STRUCTURE_06");
130        indexes.add("CREATE_INDEX_CMS_HISTORY_STRUCTURE_07");
131        indexes.add("CREATE_INDEX_CMS_HISTORY_STRUCTURE_08");
132        elements.put("CMS_HISTORY_STRUCTURE", indexes);
133
134        Map<String, String> replacer = new HashMap<String, String>();
135        replacer.put(REPLACEMENT_TABLEINDEX_SPACE, indexTablespace);
136
137        for (Map.Entry<String, List<String>> entry : elements.entrySet()) {
138            String table = entry.getKey();
139            if (!dbCon.hasTableOrColumn(table, null)) {
140                String query = readQuery(table);
141                dbCon.updateSqlStatement(query, replacer, null);
142
143                for (String index : entry.getValue()) {
144                    query = readQuery(index);
145                    dbCon.updateSqlStatement(query, replacer, null);
146                }
147            } else {
148                System.out.println("table " + table + " already exists");
149            }
150        }
151    }
152}