Index: src/edu/ucsb/nceas/metacat/AccessionNumber.java
===================================================================
--- src/edu/ucsb/nceas/metacat/AccessionNumber.java	(revision 1214)
+++ src/edu/ucsb/nceas/metacat/AccessionNumber.java	(revision 1215)
@@ -45,7 +45,7 @@
   
   private static final AbstractDatabase dbAdapter = MetaCatUtil.dbAdapter;
 
-  private Connection conn = null;
+  //private Connection conn = null;
   private String sitecode = null;
   private String sep = null;
   private String docid = null;
@@ -54,12 +54,12 @@
   /** 
    * Construct an AccessionNumber 
    */
-  public AccessionNumber () 
-         throws SQLException, ClassNotFoundException  
-  {
+  //public AccessionNumber () 
+         //throws SQLException, ClassNotFoundException  
+  //{
     // Open a connection to the database from here
-    this((new MetaCatUtil()).openDBConnection());
-  }  
+    //this((new MetaCatUtil()).openDBConnection());
+  //}  
 
   /** 
    * Construct an AccessionNumber
@@ -66,11 +66,11 @@
    *
    * @param conn the db connection to read from and write Accession# to
    */
-  public AccessionNumber (Connection conn) 
+  public AccessionNumber () 
   {
     this.sitecode = MetaCatUtil.getOption("sitecode");
     this.sep = MetaCatUtil.getOption("accNumSeparator");
-    this.conn = conn;
+    //this.conn = conn;
   }
 
   /** NEW - WHEN CLIENT ALWAYS PROVIDE ACCESSION NUMBER INCLUDING REV IN IT
@@ -79,10 +79,10 @@
    * @param conn the db connection to read Accession number from
    * @param accnum the accession number to be checked for validness
    */
-  public AccessionNumber (Connection conn, String accnum, String action) 
+  public AccessionNumber (String accnum, String action) 
            throws AccessionNumberException, SQLException, NumberFormatException
  {
-    this(conn);
+    this();
 
     this.rev = null;
     this.docid = accnum;
@@ -244,9 +244,14 @@
   {
     String uniqueid;
     String sysdate = dbAdapter.getDateTimeFunction();
-    
+    DBConnection conn = null;
+    int serialNumber = -1;
     try {
-      PreparedStatement pstmt;
+      PreparedStatement pstmt = null;
+      
+      //check out DBConnection
+      conn=DBConnectionPool.getDBConnection("AccessionNumber.getUniqueID");
+      serialNumber=conn.getCheckOutSerialNumber();
       pstmt = conn.prepareStatement
               ("INSERT INTO accession_number (site_code, date_created) " +
                "VALUES (?, " + sysdate + ")");
@@ -254,13 +259,20 @@
       pstmt.execute();
       pstmt.close();
       
-      uniqueid = "" + dbAdapter.getUniqueID(conn, "accession_number");
+      uniqueid = "" + dbAdapter.getUniqueID(conn.getConnections(),
+                                                          "accession_number");
+      //because we only count the connection usage one when it check in
+      //but it use twice. So we need to increase one
+      conn.increaseUsageCount(1);
 
     } catch (SQLException e) {
       throw new 
       SQLException("Error on AccessionNumber.getUniqueID(): "+e.getMessage());
     }
-
+    finally
+    {
+      DBConnectionPool.returnDBConnection(conn, serialNumber);
+    }
     return uniqueid;
   }
 
@@ -269,9 +281,14 @@
                   throws SQLException {
         
     boolean hasAccNumber = false;
+    DBConnection conn = null;
+    int serialNumber = -1;
         
     try {
-      PreparedStatement pstmt;
+      PreparedStatement pstmt = null;
+      //check out DBConnection
+      conn=DBConnectionPool.getDBConnection("AccessionNumber.accNumberUsed");
+      serialNumber=conn.getCheckOutSerialNumber();
       pstmt = conn.prepareStatement(
                 "SELECT 'x' FROM xml_documents " + 
                 "WHERE docid = ? " +
@@ -288,7 +305,11 @@
     } catch (SQLException e) {
       throw new SQLException
       ("Error on AccessionNumber.accNumberUsed(accNumber): " + e.getMessage());
-    }    
+    }
+    finally
+    {
+      DBConnectionPool.returnDBConnection(conn, serialNumber);
+    }
         
     return hasAccNumber;
   }    
@@ -297,9 +318,14 @@
   private boolean accNumberIsCurrent(String accNumber) throws SQLException {
         
     boolean hasCurrentAccNumber = false;
+    DBConnection conn = null;
+    int serialNumber = -1;
         
     try {
-      PreparedStatement pstmt;
+      PreparedStatement pstmt = null;
+      //check out DBConnection
+      conn=DBConnectionPool.getDBConnection("AccessionNumber.accNumberIsCurre");
+      serialNumber=conn.getCheckOutSerialNumber();
       pstmt = conn.prepareStatement(
                 "SELECT 'x' FROM xml_documents " + 
                 "WHERE docid = ?");
@@ -313,7 +339,11 @@
       throw new SQLException(
           "Error on AccessionNumber.accNumberIsCurrent(String accNumber): " +
           e.getMessage());
-    }    
+    }
+    finally
+    {
+      DBConnectionPool.returnDBConnection(conn, serialNumber);
+    }
   
     return hasCurrentAccNumber;
   }    
@@ -322,9 +352,14 @@
   private String getLastRevision(String docid) throws SQLException
   {
     String rev = "";
+    DBConnection conn = null;
+    int serialNumber = -1;
     
     try {
-      PreparedStatement pstmt;
+      PreparedStatement pstmt = null;
+      //check out DBConnection
+      conn=DBConnectionPool.getDBConnection("AccessionNumber.getLastRevision");
+      serialNumber=conn.getCheckOutSerialNumber();
       pstmt = conn.prepareStatement
               ("SELECT rev FROM xml_documents WHERE docid='" + docid + "'");
       pstmt.execute();
@@ -338,6 +373,10 @@
       throw new SQLException(
       "Error on AccessionNumber.getLastRevision(): " + e.getMessage());
     }
+    finally
+    {
+      DBConnectionPool.returnDBConnection(conn,serialNumber);
+    }
 
     return rev;
   }
@@ -350,9 +389,15 @@
   private int getLastRevisionNumber(String docId) throws SQLException
   {
     int rev = 1;
+    DBConnection conn =null;
+    int serialNumber = -1;
     
     try {
-      PreparedStatement pStmt;
+      PreparedStatement pStmt = null;
+      //check out DBConnection
+      conn=DBConnectionPool.getDBConnection("AccessionNumber.getLastRevisionN");
+      serialNumber=conn.getCheckOutSerialNumber();
+      
       pStmt = conn.prepareStatement
               ("SELECT rev FROM xml_documents WHERE docid='" + docId + "'");
       pStmt.execute();
@@ -366,7 +411,10 @@
       throw new SQLException(
       "Error on AccessionNumber.getLastRevision(): " + e.getMessage());
     }
-
+    finally
+    {
+      DBConnectionPool.returnDBConnection(conn,serialNumber);
+    }
     return rev;
   }
   
@@ -374,9 +422,13 @@
   private String getNextRevision(String docid) throws SQLException
   {
     String rev = "";
-    
+    DBConnection conn = null;
+    int serialNumber = -1;
     try {
-      PreparedStatement pstmt;
+      PreparedStatement pstmt = null;
+      //check out DBConnection
+      conn=DBConnectionPool.getDBConnection("AccessionNumber.getNextRevision");
+      serialNumber=conn.getCheckOutSerialNumber();
       pstmt = conn.prepareStatement
               ("SELECT rev+1 FROM xml_documents WHERE docid='" + docid + "'");
       pstmt.execute();
@@ -390,6 +442,10 @@
       throw new SQLException(
       "Error on AccessionNumber.getNextRevision(): " + e.getMessage());
     }
+    finally
+    {
+      DBConnectionPool.returnDBConnection(conn, serialNumber);
+    }
 
     return rev;
   }
