use of com.jolbox.bonecp.BoneCP in project platformlayer by platformlayer.
the class BoneCpMetricsReporter method addMetrics.
@Override
public void addMetrics(MetricTreeObject tree) {
BoneCP pool = getPool();
if (pool == null) {
// TODO: Should we handle this properly??
return;
}
Statistics stats = pool.getStatistics();
MetricTreeObject subtree = tree.getSubtree(key);
subtree.addInt("hitCount", stats.getCacheHits());
subtree.addInt("missCount", stats.getCacheMiss());
subtree.addInt("connectionsRequested", stats.getConnectionsRequested());
subtree.addInt("statementsCached", stats.getStatementsCached());
subtree.addInt("statementsExecuted", stats.getStatementsExecuted());
subtree.addInt("statementsPrepared", stats.getStatementsPrepared());
subtree.addInt("cumulativeConnectionWaitTime", stats.getCumulativeConnectionWaitTime());
subtree.addInt("cumulativeStatementExecutionTime", stats.getCumulativeStatementExecutionTime());
subtree.addInt("cumulativeStatementPrepareTime", stats.getCumulativeStatementPrepareTime());
}
use of com.jolbox.bonecp.BoneCP in project platformlayer by platformlayer.
the class BoneCpMetricsReporter method getPool.
private static BoneCP getPool(BoneCPDataSource dataSource) {
// TODO: This is fixed in 0.8
try {
Field field = BoneCPDataSource.class.getDeclaredField("pool");
field.setAccessible(true);
return (BoneCP) field.get(dataSource);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Error getting pool", e);
} catch (SecurityException e) {
throw new IllegalArgumentException("Error getting pool", e);
} catch (NoSuchFieldException e) {
throw new IllegalArgumentException("Error getting pool", e);
}
}
use of com.jolbox.bonecp.BoneCP in project disgear by yangbutao.
the class TestClient method loadIntoRedis.
public static void loadIntoRedis() {
BoneCP connectionPool = null;
Connection connection = null;
try {
// load the database driver (make sure this is in your classpath!)
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (Exception e) {
e.printStackTrace();
return;
}
try {
// setup the connection pool
BoneCPConfig config = null;
try {
config = new BoneCPConfig("bonecp-config.xml");
} catch (Exception e) {
e.printStackTrace();
}
// setup the connection pool
connectionPool = new BoneCP(config);
long startTime = System.currentTimeMillis();
// fetch a
connection = connectionPool.getConnection();
// connection
if (connection != null) {
System.out.println("Connection successful!");
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select * from lsmp_lottery_user");
while (rs.next()) {
String key = rs.getString("LUSER_NUM");
String userName = rs.getString("LUSER_NAME");
String userId = rs.getString("ID");
String userProvinceNum = rs.getString("LUSER_PROVINCE_NUM");
String userLevel = rs.getString("LUSER_LEVEL");
String telephone = rs.getString("LUSER_TELEPHONE");
String email = "yangbutao@newcosoft.com";
int errorLoginCnt = 10;
long lastLoginTime = 1988922384994L;
String cityNum = rs.getString("LUSER_CITY_NUM");
String group = "1";
String realName = rs.getString("LUSER_REAL_NAME");
String area = "xxxxxxxxxxxxxxxxxx";
String lastLoginIp = "109.222.44.32";
Map<String, String> hash = new HashMap<String, String>();
hash.put("userNum", key);
hash.put("userId", userId);
hash.put("userName", userName);
hash.put("userProvinceNum", userProvinceNum);
hash.put("userLevel", userLevel);
hash.put("telephone", telephone);
hash.put("email", email);
hash.put("errorLoginCnt", new Integer(errorLoginCnt).toString());
hash.put("lastLoginTime", new Long(lastLoginTime).toString());
hash.put("cityNum", cityNum);
hash.put("group", group);
hash.put("realName", realName);
hash.put("area", area);
hash.put("lastLoginIp", lastLoginIp);
String writeUrl = getWriteUrl("col1", key);
String[] urls = writeUrl.split(":");
CacheClient.INSTANCE.insert(urls[0], new Integer(urls[1]), key, hash);
}
}
// shutdown connection pool.
connectionPool.shutdown();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
use of com.jolbox.bonecp.BoneCP in project disgear by yangbutao.
the class CacheClient method loadIntoRedis.
public static void loadIntoRedis() {
BoneCP connectionPool = null;
Connection connection = null;
try {
// load the database driver (make sure this is in your classpath!)
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (Exception e) {
e.printStackTrace();
return;
}
try {
// setup the connection pool
BoneCPConfig config = null;
try {
config = new BoneCPConfig("bonecp-config.xml");
} catch (Exception e) {
e.printStackTrace();
}
// setup the connection pool
connectionPool = new BoneCP(config);
long startTime = System.currentTimeMillis();
// fetch a
connection = connectionPool.getConnection();
// connection
if (connection != null) {
System.out.println("Connection successful!");
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select * from lsmp_lottery_user");
while (rs.next()) {
String key = rs.getString("LUSER_NUM");
String userName = rs.getString("LUSER_NAME");
String userId = rs.getString("ID");
String userProvinceNum = rs.getString("LUSER_PROVINCE_NUM");
String userLevel = rs.getString("LUSER_LEVEL");
String telephone = rs.getString("LUSER_TELEPHONE");
String email = "yangbutao@newcosoft.com";
int errorLoginCnt = 10;
long lastLoginTime = 1988922384994L;
String cityNum = rs.getString("LUSER_CITY_NUM");
String group = "1";
String realName = rs.getString("LUSER_REAL_NAME");
String area = "xxxxxxxxxxxxxxxxxx";
String lastLoginIp = "109.222.44.32";
Map<String, String> hash = new HashMap<String, String>();
hash.put("userNum", key);
hash.put("userId", userId);
hash.put("userName", userName);
hash.put("userProvinceNum", userProvinceNum);
hash.put("userLevel", userLevel);
hash.put("telephone", telephone);
hash.put("email", email);
hash.put("errorLoginCnt", new Integer(errorLoginCnt).toString());
hash.put("lastLoginTime", new Long(lastLoginTime).toString());
hash.put("cityNum", cityNum);
hash.put("group", group);
hash.put("realName", realName);
hash.put("area", area);
hash.put("lastLoginIp", lastLoginIp);
String writeUrl = getWriteUrl("col1", key);
String[] urls = writeUrl.split(":");
CacheOperation.INSTANCE.insert(urls[0], new Integer(urls[1]), key, hash);
}
}
// shutdown connection pool.
connectionPool.shutdown();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
Aggregations