01: /*
02: * Licensed under the X license (see http://www.x.org/terms.htm)
03: */
04: package org.ofbiz.minerva.pool.jdbc;
05:
06: import java.sql.Connection;
07: import java.sql.PreparedStatement;
08: import java.sql.SQLException;
09:
10: import org.apache.log4j.Logger;
11: import org.ofbiz.minerva.pool.cache.CachedObjectFactory;
12:
13: /**
14: * Creates PreparedStatements for a PS cache. Doesn't yet handle
15: * different isolation levels, etc.
16: *
17: * @author Aaron Mulder ammulder@alumni.princeton.edu
18: */
19: public class PreparedStatementFactory extends CachedObjectFactory {
20:
21: private Connection con;
22: private Logger logger = Logger
23: .getLogger(PreparedStatementFactory.class);
24:
25: public PreparedStatementFactory(Connection con) {
26: this .con = con;
27: }
28:
29: /**
30: * Creates a PreparedStatement from a Connection & SQL String.
31: */
32: public Object createObject(Object sqlString) {
33: String sql = (String) sqlString;
34: try {
35: return con.prepareStatement(sql);
36: } catch (SQLException e) {
37: logger.warn("Error creating prepared statement.", e);
38: return null;
39: }
40: }
41:
42: /**
43: * Closes a PreparedStatement.
44: */
45: public void deleteObject(Object pooledObject) {
46: try {
47: ((PreparedStatement) pooledObject).close();
48: } catch (SQLException e) {
49: }
50: }
51: }
|