01: /*
02: * HA-JDBC: High-Availability JDBC
03: * Copyright (c) 2004-2007 Paul Ferraro
04: *
05: * This library is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU Lesser General Public License as published by the
07: * Free Software Foundation; either version 2.1 of the License, or (at your
08: * option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful, but WITHOUT
11: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13: * for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public License
16: * along with this library; if not, write to the Free Software Foundation,
17: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: *
19: * Contact: ferraro@users.sourceforge.net
20: */
21: package net.sf.hajdbc.sql;
22:
23: import java.lang.reflect.Method;
24: import java.util.Map;
25: import java.util.Set;
26:
27: import net.sf.hajdbc.Database;
28:
29: /**
30: * @author Paul Ferraro
31: * @param <D>
32: * @param <P>
33: * @param <E>
34: */
35: public abstract class AbstractLobInvocationHandler<D, P, E> extends
36: AbstractChildInvocationHandler<D, P, E> {
37: /**
38: * @param object
39: * @param proxy
40: * @param invoker
41: * @param proxyClass
42: * @param objectMap
43: * @throws Exception
44: */
45: protected AbstractLobInvocationHandler(P object,
46: SQLProxy<D, P> proxy, Invoker<D, P, E> invoker,
47: Class<E> proxyClass, Map<Database<D>, E> objectMap)
48: throws Exception {
49: super (object, proxy, invoker, proxyClass, objectMap);
50: }
51:
52: /**
53: * @see net.sf.hajdbc.sql.AbstractChildInvocationHandler#getInvocationStrategy(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
54: */
55: @Override
56: protected InvocationStrategy<D, E, ?> getInvocationStrategy(
57: E object, Method method, Object[] parameters)
58: throws Exception {
59: String methodName = method.getName();
60:
61: if (this .getDatabaseReadMethodSet().contains(methodName)) {
62: return new DatabaseReadInvocationStrategy<D, E, Object>();
63: }
64:
65: return super .getInvocationStrategy(object, method, parameters);
66: }
67:
68: protected abstract Set<String> getDatabaseReadMethodSet();
69:
70: /**
71: * @see net.sf.hajdbc.sql.AbstractChildInvocationHandler#postInvoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
72: */
73: @SuppressWarnings("nls")
74: @Override
75: protected void postInvoke(E object, Method method,
76: Object[] parameters) {
77: if (method.getName().equals("free")) {
78: this .getParentProxy().removeChild(this );
79: }
80: }
81:
82: /**
83: * @see net.sf.hajdbc.sql.AbstractChildInvocationHandler#close(java.lang.Object, java.lang.Object)
84: */
85: @SuppressWarnings("nls")
86: @Override
87: protected void close(P parent, E lob) {
88: try {
89: lob.getClass().getMethod("free").invoke(lob);
90: } catch (Exception e) {
91: // Ignore
92: }
93: }
94: }
|