Project

General

Profile

« Previous | Next » 

Revision 1128

Added by Jing Tao over 22 years ago

Using getDBConnection rather than pass connection as a parameter.

View differences:

src/edu/ucsb/nceas/dbadapter/PostgresqlAdapter.java
28 28
package edu.ucsb.nceas.dbadapter;
29 29

  
30 30
import java.sql.*;
31
import edu.ucsb.nceas.metacat.*;
31 32

  
32 33
/**
33 34
 * The PostgreSQL db adapter implementation.
......
49 50
   *            during the db operation
50 51
   * @return return the generated unique id as a long type
51 52
   */
52
  public long getUniqueID(Connection conn, String tableName) 
53
  public long getUniqueID(String tableName) 
53 54
                                         throws SQLException {
54 55
    long uniqueid = 0;
55
    Statement stmt = conn.createStatement();
56
    stmt.execute("SELECT currval('" + tableName + "_id_seq')");
57
    ResultSet rs = stmt.getResultSet();
58
    if ( rs.next() ) 
59
		{
60
      uniqueid = rs.getLong(1);
61
    }
62
    stmt.close();
63
    //System.out.println("Unique ID: " + uniqueid);    
56
    DBConnection conn = null;
57
    int serialNumber = -1;
58
    Statement stmt = null;
59
    try
60
    {
61
      //check out DBConnection
62
      conn=DBConnectionPool.getDBConnection("PostgresqlAdapter.getUniqueID");
63
      serialNumber=conn.getCheckOutSerialNumber();
64
      stmt = conn.createStatement();
65
      stmt.execute("SELECT currval('" + tableName + "_id_seq')");
66
      ResultSet rs = stmt.getResultSet();
67
      if ( rs.next() ) 
68
		  {
69
        uniqueid = rs.getLong(1);
70
      }
71
      stmt.close();
72
    }//try
73
    finally
74
    {
75
      DBConnectionPool.returnDBConnection(conn, serialNumber);
76
    }//finally
77
      //System.out.println("Unique ID: " + uniqueid);    
64 78
    return uniqueid;
65 79
  }
66 80

  

Also available in: Unified diff