/* JFox, the OpenSource J2EE Application Server
 *
 * Copyright (C) 2002 huihoo.com
 * Distributable under GNU LGPL license
 * See the GNU Lesser General Public License for more details.
 */

package org.jfox.jdbc.datasource;

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

/**
 * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
 */

public class ConnectionPoolTest {
  public static void main(String[] args) throws Exception {
    org.jfox.jdbc.datasource.ConnectionPool pool = new org.jfox.jdbc.datasource.ConnectionPool("org.gjt.mm.mysql.Driver",
        "jdbc:mysql://localhost/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));
    }
  }

}