01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: DbPreparedStatementHandler.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.database;
09:
10: /**
11: * By extending this class it's possible to easily customize the behaviour of
12: * a large number of methods in the {@link DbQueryManager} class.
13: * <p>You're able to set the parameters of a {@link DbPreparedStatement}
14: * before the actual execution of any logic by overriding the {@link
15: * #setParameters(DbPreparedStatement) setParameters} method.
16: * <p>If you need to customize the entire query execution, you can override
17: * the {@link #performUpdate(DbPreparedStatement) performUpdate} and {@link
18: * #performQuery(DbPreparedStatement) performQuery} methods. Note that these
19: * methods are actually responsible for calling the {@link
20: * #setParameters(DbPreparedStatement) setParameters} method, so if you
21: * override them you either have to call this method yourself or include the
22: * code in the overridden method.
23: * <p>This class has both a default constructor and one that can take a data
24: * object. This can be handy when using it as an extending anonymous inner
25: * class when you need to use variables inside the inner class that are
26: * cumbersome to change to <code>final</code> in the enclosing class.
27: *
28: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
29: * @version $Revision: 3634 $
30: * @see DbPreparedStatement
31: * @see DbQueryManager
32: * @since 1.0
33: */
34: public abstract class DbPreparedStatementHandler<DataType> extends
35: DbResultSetHandler {
36: protected DataType mData = null;
37:
38: public DbPreparedStatementHandler() {
39: }
40:
41: public DbPreparedStatementHandler(DataType data) {
42: mData = data;
43: }
44:
45: public DataType getData() {
46: return mData;
47: }
48:
49: public void setParameters(DbPreparedStatement statement) {
50: }
51:
52: public int performUpdate(DbPreparedStatement statement) {
53: setParameters(statement);
54: return statement.executeUpdate();
55: }
56:
57: public void performQuery(DbPreparedStatement statement) {
58: setParameters(statement);
59: statement.executeQuery();
60: }
61: }
|