Subversion Repositories DevTools

Rev

Rev 918 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 918 Rev 920
Line 86... Line 86...
86
  private static final Logger mLogger = Logger.getLogger(ReleaseManager.class);
86
  private static final Logger mLogger = Logger.getLogger(ReleaseManager.class);
87
 
87
 
88
  /**database session handle
88
  /**database session handle
89
   * @attribute
89
   * @attribute
90
   */
90
   */
91
  private static Connection mConnection = null;
91
  private static Connection mNonPlanningConnection = null;
92
 
92
 
93
  /**database session handle
93
  /**database session handle
94
   * @attribute
94
   * @attribute
95
   */
95
   */
96
  private static Connection mPlanningConnection = null;
96
  private static Connection mPlanningConnection = null;
97
  
97
  
-
 
98
  /**database session handle
-
 
99
   * note this handle is only ever set to mNonPlanningConnection or mPlanningConnection
-
 
100
   * @attribute
-
 
101
   */
-
 
102
  private Connection mConnection = null;
-
 
103
 
98
  /**thread synchronisation governing non planning database connection usage
104
  /**thread synchronisation governing non planning database connection usage
99
   * this lock is used by all build threads
105
   * this lock is used by all build threads
100
   * @attribute
106
   * @attribute
101
   */
107
   */
102
  private static final ReentrantLock mSession = new ReentrantLock();
108
  private static final ReentrantLock mSession = new ReentrantLock();
Line 4385... Line 4391...
4385
  /**connect to oracle
4391
  /**connect to oracle
4386
   */
4392
   */
4387
  public void connect() throws SQLException, Exception
4393
  public void connect() throws SQLException, Exception
4388
  {
4394
  {
4389
    mLogger.debug("connect");
4395
    mLogger.debug("connect");
4390
    
-
 
4391
    connect( mSession, mConnection );    
4396
    mNonPlanningConnection = connect( mSession, mNonPlanningConnection );
4392
  }
4397
  }
4393
 
4398
 
4394
  /**connect to oracle
4399
  /**connect to oracle
4395
   */
4400
   */
4396
  public void connectForPlanning( boolean priority ) throws SQLException, Exception
4401
  public void connectForPlanning( boolean priority ) throws SQLException, Exception
Line 4413... Line 4418...
4413
        mLogger.warn("connectForPlanning called lock");
4418
        mLogger.warn("connectForPlanning called lock");
4414
      }
4419
      }
4415
    }
4420
    }
4416
    
4421
    
4417
    // threads with a high priority build requirement are not subject to the mLowPriorityQueue
4422
    // threads with a high priority build requirement are not subject to the mLowPriorityQueue
4418
    connect( mPlanningSession, mPlanningConnection );    
4423
    mPlanningConnection = connect( mPlanningSession, mPlanningConnection );    
4419
  }
4424
  }
4420
 
4425
 
4421
  /**connect to oracle
4426
  /**connect to oracle
4422
   */
4427
   */
4423
  private void connect( ReentrantLock session, Connection connection ) throws SQLException, Exception
4428
  private Connection connect( ReentrantLock session, Connection connection ) throws SQLException, Exception
4424
  {
4429
  {
4425
    mLogger.debug("connect");
4430
    mLogger.debug("connect");
4426
    
4431
 
4427
    if ( session.isHeldByCurrentThread() )
-
 
4428
    {
4432
    try
4429
      // by design a thread must NOT connect multiple times
-
 
4430
      // this is to ensure the lock is claimed only once
-
 
4431
      mLogger.error("connect thread already has the lock");
-
 
4432
    }
-
 
4433
    else
-
 
4434
    {
-
 
4435
      mLogger.warn("connect calling lock");
-
 
4436
      session.lock();
-
 
4437
      mLogger.warn("connect called lock");
-
 
4438
    }
-
 
4439
    
-
 
4440
    if ( !mUseDatabase )
-
 
4441
    {
-
 
4442
      mLogger.info("connect !mUseDatabase");
-
 
4443
    }
-
 
4444
    else
-
 
4445
    {
4433
    {
-
 
4434
      if ( session.isHeldByCurrentThread() )
4446
      // DEVI 46868
4435
      {
4447
      // loop indefinitely until a connection attempt succeeds
4436
        // by design a thread must NOT connect multiple times
4448
      // unless the failure is on the first attempt
4437
        // this is to ensure the lock is claimed only once
-
 
4438
        mLogger.error("connect thread already has the lock");
-
 
4439
      }
-
 
4440
      else
-
 
4441
      {
4449
      boolean problemConnecting;
4442
        mLogger.warn("connect calling lock");
-
 
4443
        session.lock();
-
 
4444
        mLogger.warn("connect called lock");
-
 
4445
      }
4450
      
4446
      
4451
      do
4447
      if ( !mUseDatabase )
4452
      {
4448
      {
4453
        mLogger.warn("connect check connection");
4449
        mLogger.info("connect !mUseDatabase");
-
 
4450
      }
-
 
4451
      else
-
 
4452
      {
-
 
4453
        // DEVI 46868
-
 
4454
        // loop indefinitely until a connection attempt succeeds
-
 
4455
        // unless the failure is on the first attempt
4454
        problemConnecting = false;
4456
        boolean problemConnecting;
4455
        
4457
        
4456
        try
-
 
4457
        {
4458
        do
4458
          if ( connection == null || ( connection != null && !connection.isValid(10) ) )
-
 
4459
          {
-
 
4460
            mLogger.warn("connect calling getConnection");
-
 
4461
            connection = DriverManager.getConnection(mConnectionString, mUsername, mPassword);
-
 
4462
            // when connection to the database is established, the connection, by default, is in auto-commit mode
-
 
4463
            // to adhere to the design in the use of select for update, it is crucial to turn auto-commit off
-
 
4464
            // this also improves performance
-
 
4465
            connection.setAutoCommit(false);
-
 
4466
          }
-
 
4467
        }
-
 
4468
        catch(SQLException e)
-
 
4469
        {
4459
        {
4470
          mLogger.warn("connect determined problem connecting");
4460
          mLogger.warn("connect check connection");
4471
          problemConnecting = true;
4461
          problemConnecting = false;
-
 
4462
          
4472
          try
4463
          try
4473
          {
4464
          {
-
 
4465
            if ( connection == null || ( connection != null && !connection.isValid(10) ) )
4474
            // sleep 30 secs
4466
            {
4475
            mLogger.warn("connect getConnection failed. sleep 30secs");
4467
              mLogger.warn("connect calling getConnection");
4476
            Thread.sleep(30000);
4468
              connection = DriverManager.getConnection(mConnectionString, mUsername, mPassword);
-
 
4469
              // when connection to the database is established, the connection, by default, is in auto-commit mode
-
 
4470
              // to adhere to the design in the use of select for update, it is crucial to turn auto-commit off
4477
          }
4471
              // this also improves performance
4478
          catch (InterruptedException f)
4472
              connection.setAutoCommit(false);
4479
          {
4473
            }
4480
            mLogger.warn("connect caught InterruptedException");
-
 
4481
          }
4474
          }
4482
 
-
 
4483
          if ( connection == null )
4475
          catch(SQLException e)
4484
          {
4476
          {
-
 
4477
            mLogger.warn("connect determined problem connecting");
-
 
4478
            problemConnecting = true;
-
 
4479
            try
-
 
4480
            {
-
 
4481
              // sleep 30 secs
-
 
4482
              mLogger.warn("connect getConnection failed. sleep 30secs");
-
 
4483
              Thread.sleep(30000);
-
 
4484
            }
-
 
4485
            catch (InterruptedException f)
-
 
4486
            {
-
 
4487
              mLogger.warn("connect caught InterruptedException");
-
 
4488
            }
-
 
4489
  
-
 
4490
            if ( connection == null )
-
 
4491
            {
4485
            // failed on first connection attempt - unlikely due to database loading - likely bad connection parameters
4492
              // failed on first connection attempt - unlikely due to database loading - likely bad connection parameters
4486
            throw new SQLException();
4493
              throw new SQLException();
-
 
4494
            }
4487
          }
4495
          }
-
 
4496
        } while ( problemConnecting );
4488
        }
4497
      }
-
 
4498
    }
-
 
4499
    finally
-
 
4500
    {
4489
      } while ( problemConnecting );
4501
      mConnection = connection;
4490
    }
4502
    }
-
 
4503
    return connection;
4491
 
4504
 
4492
  }
4505
  }
4493
 
4506
 
4494
  /**disconnect from oracle
4507
  /**disconnect from oracle
4495
   */
4508
   */