com.manydesigns.portofino.database.platforms.GoogleCloudSQLDatabasePlatform.java Source code

Java tutorial

Introduction

Here is the source code for com.manydesigns.portofino.database.platforms.GoogleCloudSQLDatabasePlatform.java

Source

/*
 * Copyright (C) 2005-2015 ManyDesigns srl.  All rights reserved.
 * http://www.manydesigns.com/
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This software 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package com.manydesigns.portofino.database.platforms;

import com.manydesigns.portofino.model.database.ConnectionProvider;
import org.apache.commons.dbutils.DbUtils;
import org.hibernate.dialect.MySQLDialect;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

/*
* @author Paolo Predonzani     - paolo.predonzani@manydesigns.com
* @author Angelo Lupo          - angelo.lupo@manydesigns.com
* @author Giampiero Granatella - giampiero.granatella@manydesigns.com
* @author Alessio Stalla       - alessio.stalla@manydesigns.com
*/
public class GoogleCloudSQLDatabasePlatform extends AbstractDatabasePlatform {
    public static final String copyright = "Copyright (c) 2005-2015, ManyDesigns srl";

    public final static String DESCRIPTION = "Google Cloud SQL";
    public final static String STANDARD_DRIVER_CLASS_NAME = "com.google.appengine.api.rdbms.AppEngineDriver";

    //**************************************************************************
    // Constructors
    //**************************************************************************

    public GoogleCloudSQLDatabasePlatform() {
        super(new MySQLDialect(), "jdbc:google:rdbms://<instance-name>/<database>");
        try {
            DriverManager.registerDriver((Driver) Class.forName("com.google.cloud.sql.Driver").newInstance());
        } catch (Exception e) {
            logger.debug("The driver to connect to Google Cloud SQL from a non-GAE application was not found", e);
        }
    }

    //**************************************************************************
    // Implementation of DatabaseAbstraction
    //**************************************************************************

    public String getDescription() {
        return DESCRIPTION;
    }

    public String getStandardDriverClassName() {
        return STANDARD_DRIVER_CLASS_NAME;
    }

    public boolean isApplicable(ConnectionProvider connectionProvider) {
        return connectionProvider.getDatabaseProductName().contains("Google");
    }

    public List<String> getSchemaNames(DatabaseMetaData databaseMetaData) throws SQLException {
        ResultSet rs = databaseMetaData.getCatalogs();
        List<String> schemaNames = new ArrayList<String>();
        try {
            while (rs.next()) {
                String schemaName = rs.getString(TABLE_CAT);
                schemaNames.add(schemaName);
            }
        } finally {
            DbUtils.closeQuietly(rs);
        }
        return schemaNames;
    }

    @Override
    public boolean isDialectAutodetected() {
        return false;
    }
}