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: import java.sql.CallableStatement;
17:
18: /**
19: * @see CacheResourceFactory
20: *
21: * @author Gennady Krizhevsky
22: */
23: public class SimpleCallResourceFactory implements CacheResourceFactory {
24:
25: /**
26: * @see CacheResourceFactory#createResource(Object, Object)
27: */
28: final public Object createResource(Object context, Object key) {
29: try {
30: Connection connection = (Connection) context;
31: return connection.prepareCall((String) key);
32: } catch (SQLException e) {
33: throw new RuntimeException(e);
34: }
35: }
36:
37: /**
38: * @see CacheResourceFactory#destroyResource(Object, Object)
39: */
40: final public void destroyResource(Object context, Object resource) {
41: try {
42: ((CallableStatement) resource).close();
43: } catch (SQLException e) {
44: throw new RuntimeException(e);
45: }
46: }
47: }
|