Search in sources :

Example 1 with BoneCP

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());
}
Also used : Statistics(com.jolbox.bonecp.Statistics) BoneCP(com.jolbox.bonecp.BoneCP)

Example 2 with BoneCP

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);
    }
}
Also used : Field(java.lang.reflect.Field) BoneCP(com.jolbox.bonecp.BoneCP)

Example 3 with BoneCP

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();
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) SQLException(java.sql.SQLException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResultSet(java.sql.ResultSet) BoneCPConfig(com.jolbox.bonecp.BoneCPConfig) BoneCP(com.jolbox.bonecp.BoneCP)

Example 4 with BoneCP

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();
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) SQLException(java.sql.SQLException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResultSet(java.sql.ResultSet) BoneCPConfig(com.jolbox.bonecp.BoneCPConfig) BoneCP(com.jolbox.bonecp.BoneCP)

Aggregations

BoneCP (com.jolbox.bonecp.BoneCP)4 BoneCPConfig (com.jolbox.bonecp.BoneCPConfig)2 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Statistics (com.jolbox.bonecp.Statistics)1 Field (java.lang.reflect.Field)1