Project

General

Profile

« Previous | Next » 

Revision 5108

Added by daigle over 14 years ago

move dbconnection object out of base class and create it for each db access so it can be released

View differences:

BaseAccess.java
27 27

  
28 28
package edu.ucsb.nceas.metacat.shared;
29 29

  
30
import java.sql.PreparedStatement;
30 31
import java.sql.ResultSet;
31 32
import java.sql.SQLException;
32 33

  
34
import org.apache.log4j.Logger;
35

  
33 36
import edu.ucsb.nceas.metacat.database.DBConnection;
34 37
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
35 38

  
36 39
public abstract class BaseAccess {
37 40
	
38
	protected DBConnection conn = null;
39
    protected int serialNumber = -1;
40
    protected ResultSet rs = null;
41
	
42
    protected BaseAccess(String methodName) throws AccessException {
43
        //check out DBConnection
44
    	try {
45
    		conn = DBConnectionPool.
46
                	getDBConnection(methodName);
47
    		serialNumber = conn.getCheckOutSerialNumber();
48
    	} catch (SQLException sqle) {
49
    		throw new AccessException("Could not get connection from DB connection pool: " 
50
    				+ sqle.getMessage());
51
    	}
52
    }
53 41
    
54 42
    protected abstract BaseDAO populateDAO(ResultSet resultSet) throws SQLException ;
43
    
44
    protected void closeDBObjects(PreparedStatement pstmt, DBConnection conn,  
45
    		int serialNumber, Logger logMetacat) {
46
		try {
47
			if (pstmt != null) {
48
				pstmt.close();
49
			}
50
		} catch (SQLException sqle) {
51
			logMetacat.error("BaseAccess.closeDBObjects - An error occurred "
52
					+ "closing prepared statement: " + sqle.getMessage());
53
		} finally {
54
			DBConnectionPool.returnDBConnection(conn, serialNumber);
55
		}
56
	}
55 57
}

Also available in: Unified diff