com.mysql.fabric.jdbc.FabricMySQLDataSource Maven / Gradle / Ivy
/*
Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
The MySQL Connector/J is licensed under the terms of the GPLv2
, like most MySQL Connectors.
There are special exceptions to the terms and conditions of the GPLv2 as it is applied to
this software, see the FLOSS License Exception
.
This program 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; version 2
of the License.
This program 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 this
program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth
Floor, Boston, MA 02110-1301 USA
*/
package com.mysql.fabric.jdbc;
import java.sql.Driver;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Properties;
import com.mysql.jdbc.NonRegisteringDriver;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
/**
* DataSource used to create connections to a MySQL fabric.
*/
public class FabricMySQLDataSource extends MysqlDataSource implements FabricMySQLConnectionProperties {
private static final long serialVersionUID = 1L;
/** Driver used to create connections. */
private final static Driver driver;
static {
try {
driver = new FabricMySQLDriver();
} catch (Exception ex) {
throw new RuntimeException("Can create driver", ex);
}
}
/**
* Creates a connection using the specified properties.
* copied directly from MysqlDataSource.getConnection().
* No easy way to override the static `mysqlDriver' without
* globally affecting the driver.
*
* @param props
* the properties to connect with
*
* @return a connection to the database
*
* @throws SQLException
* if an error occurs
*/
@Override
protected java.sql.Connection getConnection(Properties props) throws SQLException {
String jdbcUrlToUse = null;
if (!this.explicitUrl) {
StringBuffer jdbcUrl = new StringBuffer("jdbc:mysql:fabric://");
if (this.hostName != null) {
jdbcUrl.append(this.hostName);
}
jdbcUrl.append(":");
jdbcUrl.append(this.port);
jdbcUrl.append("/");
if (this.databaseName != null) {
jdbcUrl.append(this.databaseName);
}
jdbcUrlToUse = jdbcUrl.toString();
} else {
jdbcUrlToUse = this.url;
}
//
// URL should take precedence over properties
//
Properties urlProps = ((FabricMySQLDriver) driver).parseFabricURL(jdbcUrlToUse, null);
urlProps.remove(NonRegisteringDriver.DBNAME_PROPERTY_KEY);
urlProps.remove(NonRegisteringDriver.HOST_PROPERTY_KEY);
urlProps.remove(NonRegisteringDriver.PORT_PROPERTY_KEY);
Iterator
© 2015 - 2025 Weber Informatics LLC | Privacy Policy