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