Package de.innovationgate.webgate.api.mysql

Source Code of de.innovationgate.webgate.api.mysql.WGDatabaseImpl

/*******************************************************************************
* Copyright 2009, 2010 Innovation Gate GmbH. All Rights Reserved.
*
* This file is part of the OpenWGA server platform.
*
* OpenWGA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition, a special exception is granted by the copyright holders
* of OpenWGA called "OpenWGA plugin exception". You should have received
* a copy of this exception along with OpenWGA in file COPYING.
* If not, see <http://www.openwga.com/gpl-plugin-exception>.
*
* OpenWGA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenWGA in file COPYING.
* If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

package de.innovationgate.webgate.api.mysql;


import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

import org.hibernate.dialect.MySQLDialect;

import de.innovationgate.utils.WGUtils;
import de.innovationgate.webgate.api.WGDatabase;
import de.innovationgate.webgate.api.WGInvalidDatabaseException;
import de.innovationgate.webgate.api.WGUserAccess;

public class WGDatabaseImpl extends de.innovationgate.webgate.api.jdbc.WGDatabaseImpl {

    public static final String DRIVER = "com.mysql.jdbc.Driver";

    public WGUserAccess open(WGDatabase db, String path, String user, String pwd, boolean prepareOnly) throws WGInvalidDatabaseException {
       
        // Register drivers with driver manager
        try {
            Class.forName(DRIVER);
        }
        catch (ClassNotFoundException e) {
            throw new WGInvalidDatabaseException("Necessary JDBC driver not found: " + e.getMessage());
        }
       
        // Build creations options
        Map creationOptions = db.getCreationOptions();
       
        // Hibernate configuration
        WGDatabase.putDefaultOption(creationOptions, "hibernate.dialect", MySQLDialect.class.getName());
        WGDatabase.putDefaultOption(creationOptions, "hibernate.connection.driver_class", DRIVER);
        WGDatabase.putDefaultOption(creationOptions, "hibernate.dbcp.validationQuery", "select 1");
        WGDatabase.putDefaultOption(creationOptions, "hibernate.dbcp.testOnBorrow", "true");
        WGDatabase.putDefaultOption(creationOptions, "hibernate.dbcp.maxWait", "30000");
        WGDatabase.putDefaultOption(creationOptions, "hibernate.connection.connectTimeout", "60000");
        WGDatabase.putDefaultOption(creationOptions, "hibernate.connection.socketTimeout", "120000");

        // enable query paging for mysql
        WGDatabase.putDefaultOption(creationOptions, COPTION_OPTIMIZED_FILE_HANDLING_DISABLEQUERYPAGING, "false");
                       
       
        return super.open(db, path, user, pwd, prepareOnly);
    }
   
    /* (Kein Javadoc)
     * @see de.innovationgate.webgate.api.WGDatabaseCore#getTypeName()
     */
    public String getTypeName() {
        return "jdbc/wgacontentstore/mysql";
    }

    /* (non-Javadoc)
     * @see de.innovationgate.webgate.api.jdbc.WGDatabaseImpl#hasFeature(java.lang.String)
     */
    public boolean hasFeature(String feature) {

        if (feature.equals(WGDatabase.FEATURE_CREATEABLE)) {
            return true;
        }
       
        return super.hasFeature(feature);
    }
   
}
TOP

Related Classes of de.innovationgate.webgate.api.mysql.WGDatabaseImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.