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.Collections;
035import java.util.HashMap;
036import java.util.Map;
037
038/**
039 * PostgreSQL implementation of the generic update of the contents tables.<p>
040 *
041 * @since 7.0.2
042 */
043public class CmsUpdateDBContentTables extends org.opencms.setup.db.update6to7.CmsUpdateDBContentTables {
044
045    /** Constant for the sql query to transfer the online contents.<p> */
046    protected static final String QUERY_UPDATE_ONLINE_CONTENTS_PUBLISH_TAG_FROM = "Q_UPDATE_ONLINE_CONTENTS_PUBLISH_TAG_FROM";
047
048    /** Constant for the sql query to transfer the online contents.<p> */
049    protected static final String QUERY_UPDATE_ONLINE_CONTENTS_PUBLISH_TAG_TO = "Q_UPDATE_ONLINE_CONTENTS_PUBLISH_TAG_TO";
050
051    /** Constant for the SQL query properties.<p> */
052    private static final String QUERY_PROPERTY_FILE = "postgresql/cms_content_table_queries.properties";
053
054    /** Constant for the replacement in the sql query. */
055    private static final String REPLACEMENT_TABLEDATA_SPACE = "${dataTablespace}";
056
057    /**
058     * Constructor.<p>
059     *
060     * @throws IOException if the sql queries properties file could not be read
061     */
062    public CmsUpdateDBContentTables()
063    throws IOException {
064
065        super();
066        loadQueryProperties(getPropertyFileLocation() + QUERY_PROPERTY_FILE);
067    }
068
069    /**
070     * @see org.opencms.setup.db.update6to7.CmsUpdateDBContentTables#createContentsTable(org.opencms.setup.CmsSetupDb)
071     */
072    @Override
073    protected void createContentsTable(CmsSetupDb dbCon) throws SQLException {
074
075        String dataTablespace = m_poolData.get("dataTablespace");
076
077        System.out.println(new Exception().getStackTrace()[0].toString());
078        if (!dbCon.hasTableOrColumn(TABLE_CMS_CONTENTS, null)) {
079            String query = readQuery(QUERY_CREATE_CMS_CONTENTS_TABLE);
080
081            Map<String, String> replacer = new HashMap<String, String>();
082            replacer.put(REPLACEMENT_TABLEDATA_SPACE, dataTablespace);
083
084            dbCon.updateSqlStatement(query, null, null);
085        } else {
086            System.out.println("table " + TABLE_CMS_CONTENTS + " already exists");
087        }
088    }
089
090    /**
091     * @see org.opencms.setup.db.update6to7.CmsUpdateDBContentTables#transferOnlineContents(org.opencms.setup.CmsSetupDb, int)
092     */
093    @Override
094    protected void transferOnlineContents(CmsSetupDb dbCon, int pubTag) throws SQLException {
095
096        String query = readQuery(QUERY_TRANSFER_ONLINE_CONTENTS);
097        Map<String, String> replacer = Collections.singletonMap("${pubTag}", "" + pubTag);
098        dbCon.updateSqlStatement(query, replacer, null);
099
100        query = readQuery(QUERY_UPDATE_ONLINE_CONTENTS_PUBLISH_TAG_FROM);
101        dbCon.updateSqlStatement(query, null, null);
102
103        query = readQuery(QUERY_UPDATE_ONLINE_CONTENTS_PUBLISH_TAG_TO);
104        dbCon.updateSqlStatement(query, null, null);
105    }
106
107}