datahub/wherehows-api/app/dao/MySQLDataSource.java

62 lines
2.7 KiB
Java
Raw Normal View History

2015-11-19 14:39:21 -08:00
/**
* Copyright 2015 LinkedIn Corp. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
package dao;
import org.apache.commons.lang3.StringUtils;
import play.Play;
public class MySQLDataSource extends DataSource
{
public static String DatabaseType = "mysql";
public static String MYSQL_DRIVER_CLASS = "com.mysql.jdbc.Driver";
public static String DATABASE_WHEREHOWS_OPENSOURCE = "wherehows_opensource_mysql";
public static String DATABASE_WHEREHOWS_OPENSOURCE_USER_NAME_KEY = "database.opensource.username";
public static String DATABASE_WHEREHOWS_OPENSOURCE_USER_PASSWORD_KEY = "database.opensource.password";
public static String DATABASE_WHEREHOWS_OPENSOURCE_URL_KEY = "database.opensource.url";
2016-02-10 19:17:47 -08:00
public static String DATABASE_WHEREHOWS_DB = "wherehows_mysql";
public static String DATABASE_WHEREHOWS_DB_USER_NAME_KEY = "database.wherehows.username";
public static String DATABASE_WHEREHOWS_DB_USER_PASSWORD_KEY = "database.wherehows.password";
public static String DATABASE_WHEREHOWS_DB_URL_KEY = "database.wherehows.url";
2015-11-19 14:39:21 -08:00
@Override
public String getType()
{
return DatabaseType;
}
public MySQLDataSource(String identifier)
{
setDriverClass(MYSQL_DRIVER_CLASS);
if (StringUtils.isNotBlank(identifier) && identifier.equalsIgnoreCase(DATABASE_WHEREHOWS_OPENSOURCE))
{
setUsername(Play.application().configuration().getString(DATABASE_WHEREHOWS_OPENSOURCE_USER_NAME_KEY));
setPassword(Play.application().configuration().getString(DATABASE_WHEREHOWS_OPENSOURCE_USER_PASSWORD_KEY));
setJdbcUrl(Play.application().configuration().getString(DATABASE_WHEREHOWS_OPENSOURCE_URL_KEY));
}
2016-02-10 19:17:47 -08:00
else if (StringUtils.isNotBlank(identifier) && identifier.equalsIgnoreCase(DATABASE_WHEREHOWS_DB))
{
setUsername(Play.application().configuration().getString(DATABASE_WHEREHOWS_DB_USER_NAME_KEY));
setPassword(Play.application().configuration().getString(DATABASE_WHEREHOWS_DB_USER_PASSWORD_KEY));
setJdbcUrl(Play.application().configuration().getString(DATABASE_WHEREHOWS_DB_URL_KEY));
}
2015-11-19 14:39:21 -08:00
setIdleConnectionTestPeriodInMinutes(1);
setIdleMaxAgeInMinutes(1);
setMaxConnectionsPerPartition(10);
setMinConnectionsPerPartition(5);
setPartitionCount(3);
setAcquireIncrement(5);
setStatementsCacheSize(100);
}
}