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.mysql;
029
030import org.opencms.setup.CmsSetupDb;
031
032import java.io.IOException;
033import java.sql.SQLException;
034import java.util.Collections;
035import java.util.Map;
036
037/**
038 * This class inserts formerly deleted users/groups in the CMS_HISTORY_PRINCIPALS table.<p>
039 *
040 * These users/groups are read out of the following tables:
041 * <ul>
042 * <li>CMS_BACKUP_RESOURCES</li>
043 * <li>CMS_BACKUP_PROJECTS</li>
044 * </ul>
045 */
046public class CmsUpdateDBHistoryPrincipals extends org.opencms.setup.db.update6to7.CmsUpdateDBHistoryPrincipals {
047
048    /** Constant for sql query to create the history principals table.<p> */
049    private static final String QUERY_HISTORY_PRINCIPALS_CREATE_TABLE_MYSQL = "Q_HISTORY_PRINCIPALS_CREATE_TABLE_MYSQL";
050
051    /** Constant for the SQL query properties.<p> */
052    private static final String QUERY_PROPERTY_FILE = "cms_history_principals_queries.properties";
053
054    /**
055     * Constructor.<p>
056     *
057     * @throws IOException if the sql queries properties file could not be read
058     */
059    public CmsUpdateDBHistoryPrincipals()
060    throws IOException {
061
062        super();
063        loadQueryProperties(getPropertyFileLocation() + QUERY_PROPERTY_FILE);
064    }
065
066    /**
067     * Creates the CMS_HISTORY_PRINCIPALS table if it does not exist yet.<p>
068     *
069     * @param dbCon the db connection interface
070     *
071     * @throws SQLException if something goes wrong
072     */
073    @Override
074    protected void createHistPrincipalsTable(CmsSetupDb dbCon) throws SQLException {
075
076        System.out.println(new Exception().getStackTrace()[0].toString());
077        if (!dbCon.hasTableOrColumn(TABLE_CMS_HISTORY_PRINCIPALS, null)) {
078            String createStatement = readQuery(QUERY_HISTORY_PRINCIPALS_CREATE_TABLE_MYSQL);
079            Map<String, String> replacer = Collections.singletonMap("${tableEngine}", m_poolData.get("engine"));
080            dbCon.updateSqlStatement(createStatement, replacer, null);
081        } else {
082            System.out.println("table " + TABLE_CMS_HISTORY_PRINCIPALS + " already exists");
083        }
084    }
085}