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