01: /**
02: * Objective Database Abstraction Layer (ODAL)
03: * Copyright (c) 2004, The ODAL Development Group
04: * All rights reserved.
05: * For definition of the ODAL Development Group please refer to LICENCE.txt file
06: *
07: * Distributable under LGPL license.
08: * See terms of license at gnu.org.
09: */package com.completex.objective.components.cache.impl;
10:
11: import com.completex.objective.components.cache.CacheResourceFactory;
12:
13: import java.sql.Connection;
14: import java.sql.SQLException;
15: import java.sql.PreparedStatement;
16:
17: /**
18: * @see CacheResourceFactory
19: *
20: * @author Gennady Krizhevsky
21: */
22: public class SimplePstmtResourceFactory implements CacheResourceFactory {
23:
24: /**
25: * @see CacheResourceFactory#createResource(Object, Object)
26: */
27: final public Object createResource(Object context, Object key) {
28: try {
29: Connection connection = (Connection) context;
30: return connection.prepareStatement((String) key);
31: } catch (SQLException e) {
32: throw new RuntimeException(e);
33: }
34: }
35:
36: /**
37: * @see CacheResourceFactory#destroyResource(Object, Object)
38: */
39: final public void destroyResource(Object context, Object resource) {
40: try {
41: ((PreparedStatement) resource).close();
42: } catch (SQLException e) {
43: throw new RuntimeException(e);
44: }
45: }
46: }
|