Package com.mchange.v2.c3p0.impl

Examples of com.mchange.v2.c3p0.impl.C3P0ImplUtils


  /** 内部保存的连接池引用, 用于释放资源 */
  private ComboPooledDataSource ds;

  @Override
  protected DataSource getDataSource() throws Exception {
    ds = new ComboPooledDataSource();
    // 当连接池中的连接耗尽的时候c3p0一次同时获取的连接数
    ds.setAcquireIncrement(5);
    // 如果连接失败重试连接的间隔时间
    ds.setAcquireRetryDelay(60);
    // 初始化时获取的连接数
View Full Code Here


        usage();
   
    if (! jdbc_url.startsWith("jdbc:") )
        usage();
           
    ComboPooledDataSource cpds = new ComboPooledDataSource();
    cpds.setJdbcUrl( jdbc_url );
    cpds.setUser( username );
    cpds.setPassword( password );
      cpds.setMaxPoolSize( 10 );
//      cpds.setUsesTraditionalReflectiveProxies( true );
       
    C3P0ProxyConnection conn = (C3P0ProxyConnection) cpds.getConnection();
    Method toStringMethod = Object.class.getMethod("toString", new Class[]{});
    Method identityHashCodeMethod = System.class.getMethod("identityHashCode", new Class[] {Object.class});
    System.out.println("rawConnection.toString() -> " +
           conn.rawConnectionOperation(toStringMethod, C3P0ProxyConnection.RAW_CONNECTION, new Object[]{}));
    Integer ihc = (Integer) conn.rawConnectionOperation(identityHashCodeMethod, null, new Object[]{C3P0ProxyConnection.RAW_CONNECTION});
    System.out.println("System.identityHashCode( rawConnection ) -> " + Integer.toHexString( ihc.intValue() ));

    C3P0ProxyStatement stmt = (C3P0ProxyStatement) conn.createStatement();
    System.out.println("rawStatement.toString() -> " +
           stmt.rawStatementOperation(toStringMethod, C3P0ProxyStatement.RAW_STATEMENT, new Object[]{}));
    Integer ihc2 = (Integer) stmt.rawStatementOperation(identityHashCodeMethod, null, new Object[]{C3P0ProxyStatement.RAW_STATEMENT});
    System.out.println("System.identityHashCode( rawStatement ) -> " + Integer.toHexString( ihc2.intValue() ));

    conn.close()

      for (int i = 0; i < 10; ++i)
          {
        C3P0ProxyConnection check = null;
        try
            {
          check = (C3P0ProxyConnection) cpds.getConnection();
          //System.err.println( TestUtils.samePhysicalConnection( conn, check ) );
          System.err.println( TestUtils.physicalConnectionIdentityHashCode( check ) == ihc.intValue() );
            }
        finally
            { /* if (check != null) check.close(); */ }
View Full Code Here

    }

    public static synchronized DataSource getInstance() {
        if (instance == null) {
            boolean debug = ApplicationContext.getInstance().isDebug();
            ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();

            comboPooledDataSource.setJdbcUrl(properties.getProperty("database.url"));
            comboPooledDataSource.setUser(properties.getProperty("database.user"));
            comboPooledDataSource.setPassword(properties.getProperty("database.password"));
            comboPooledDataSource.setCheckoutTimeout(60000);
            comboPooledDataSource.setIdleConnectionTestPeriod(60);
            comboPooledDataSource.setMaxStatementsPerConnection(128);

            if (debug) {
                comboPooledDataSource.setInitialPoolSize(1);
            } else {
                comboPooledDataSource.setInitialPoolSize(4);
            }

            comboPooledDataSource.setMaxPoolSize(4);
            comboPooledDataSource.setPreferredTestQuery("SET time_zone='" + Configuration.getTimeZone() + "'");

            instance = comboPooledDataSource;
        }

        return instance;
View Full Code Here

    public void testSerializationRoundTrip()
    {
  try
      {
    byte[] pickled = SerializableUtils.toByteArray(cpds);
    ComboPooledDataSource unpickled = (ComboPooledDataSource) SerializableUtils.fromByteArray( pickled );
    assertTrue( "Marshalled and unmarshalled DataSources should have the same properties!",
          BeansUtils.equalsByAccessibleProperties( cpds, unpickled, EXCLUDE_PROPS ) );
      }
  catch (Exception e)
      {
View Full Code Here

    public void testRefDerefRoundTrip()
    {
  try
      {
    Reference ref = cpds.getReference();
    ComboPooledDataSource unpickled = (ComboPooledDataSource) ReferenceableUtils.referenceToObject( ref, null, null, null );
    assertTrue( "Marshalled and unmarshalled DataSources should have the same properties!",
          BeansUtils.equalsByAccessibleProperties( cpds, unpickled, EXCLUDE_PROPS ) );
      }
  catch (Exception e)
      {
View Full Code Here

            {
                Config.DATABASE_MAX_CONNECTIONS = 2;
                _log.warning("at least " + Config.DATABASE_MAX_CONNECTIONS + " db connections are required.");
            }

      _source = new ComboPooledDataSource();
      _source.setAutoCommitOnClose(true);

      _source.setInitialPoolSize(10);
      _source.setMinPoolSize(10);
      _source.setMaxPoolSize(Config.DATABASE_MAX_CONNECTIONS);
View Full Code Here

     * @return Retorna un valor verdadero en caso de que
     * se inicialice correctamente la piscina de conexiones.
     */
    protected static boolean initialize(){
        try {
            cpds = new ComboPooledDataSource();
            cpds.setCheckoutTimeout(Constants.dbTimeout);
            cpds.setDriverClass("com.mysql.jdbc.Driver");
            String sT;
            if ( Shared.storeIp != null ){
                sT = "jdbc:mysql://" + Shared.storeIp + "/" +
View Full Code Here

       
    }
    protected static boolean initializeProfit(){
        try {
            cpdsProfit = new ComboPooledDataSource();
            cpdsProfit.setCheckoutTimeout(Constants.dbTimeout);
            cpdsProfit.setDriverClass("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            String url = "jdbc:sqlserver://" + Shared.getConfig("serverSQLServerProfitAdd") + ":" + Shared.getConfig("portSqlServer") + ";DatabaseName=" + Shared.getConfig("profitDatabase");
            cpdsProfit.setJdbcUrl(url);
            cpdsProfit.setUser(Shared.getFileConfig("dbSqlServerUser"));
View Full Code Here

        return cpdsProfit != null;
    }

    protected static boolean reinitializeOffline(){
        try {
            cpds = new ComboPooledDataSource();
            cpds.setDriverClass("com.mysql.jdbc.Driver");
            String sT = "jdbc:mysql://" + Shared.getFileConfig("ServerMirror") + "/" +
                            Shared.getFileConfig("mirrorDbName");
            cpds.setJdbcUrl(sT);
            cpds.setUser(Shared.getFileConfig("mirrordbUser"));
View Full Code Here

        }

        System.out.println("[" + Shared.now() + "] Driver de conexiones " + Shared.lineNumber() " Replica normal de tabla");

        if ( !mirrorConnected ){ // just once =D
            cpdsMirror = new ComboPooledDataSource();
            cpdsMirror.setDriverClass("com.mysql.jdbc.Driver");
            String sT = "jdbc:mysql://" + Shared.getFileConfig("ServerMirror") + "/" + Shared.getFileConfig("mirrorDbName");
            cpdsMirror.setJdbcUrl(sT);
            cpdsMirror.setUser(Shared.getFileConfig("mirrordbUser"));
            cpdsMirror.setPassword(Shared.getFileConfig("mirrordbPassword"));
View Full Code Here

TOP

Related Classes of com.mchange.v2.c3p0.impl.C3P0ImplUtils

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.