package org.huihoo.jfox.pool.connection;

//import org.huihoo.jfox.pool.PoolManager;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * Created by IntelliJ IDEA.
 * User: kelvin.wu
 * Date: 2003-3-28
 * Time: 16:29:06
 * To change this template use Options | File Templates.
 */
public class Test {
  public static void main(String[] args) throws Exception {
    SimpleConnectionPool pool = new SimpleConnectionPool("org.gjt.mm.mysql.Driver",
        "jdbc:mysql://192.168.0.1/mysql", "root", "");
    pool.init();

    System.out.println("Working: " + pool.getWorking());
    System.out.println("Rest: " + pool.getRest());

    Connection conn = pool.getConnection();
    System.out.println(conn);

    executeSQL(conn);
    conn.close();

//    executeSQL(conn);
//    Connection conn2 = pool.getConnection();
//    System.out.println(conn2);
//    Connection conn3 = pool.getConnection();
//    System.out.println(conn3);
//    Connection conn4 = pool.getConnection();
//    System.out.println(conn4);
//    Connection conn5 = pool.getConnection();
//    System.out.println(conn5);
//    Connection conn6 = pool.getConnection();
//    System.out.println(conn6);
//    Connection conn7 = pool.getConnection();
//    System.out.println(conn7);
//    Thread.sleep(9000);

//    ObjectPool op = PoolManager.obtainPool(new ConnectionFactory(SimplePoolableConnection.class));
    System.out.println("Working: " + pool.getWorking());
    System.out.println("Rest: " + pool.getRest());

//    conn7.close();
//    System.out.println("Working: " + op.getWorking());
//    System.out.println("Rest: " + op.getRest());
//    conn6.close();
//    System.out.println("Working: " + op.getWorking());
//    System.out.println("Rest: " + op.getRest());
//    conn5.close();
//    System.out.println("Working: " + op.getWorking());
//    System.out.println("Rest: " + op.getRest());
//    conn4.close();
//    System.out.println("Working: " + op.getWorking());
//    System.out.println("Rest: " + op.getRest());
////        Statement smt = conn7.createStatement();
//    executeSQL(conn);
//        op.destory();
    System.out.println(pool.getObjectFactory());
    System.out.println(pool.getObjectClass());
    pool.clear();
//    System.out.println(PoolManager.existsPool(ConnectionFactory.class));
  }

  public static void executeSQL(Connection conn) throws Exception {
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("select * from user");
    while (rs.next()) {
      System.out.println(rs.getString(2));
    }
  }
}
