KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > core > persist > db > DatabaseOperation


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: DatabaseOperation.java,v 1.5 2007/01/07 06:14:18 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.core.persist.db;
23
24 /**
25  * Base class for adapter to simplify writing of database operations, which
26  * should take care of requesting and returning connections, transaction
27  * management and exception handling.
28  *
29  * @version $Id: DatabaseOperation.java,v 1.5 2007/01/07 06:14:18 bastafidli Exp $
30  * @author Miro Halas
31  * @code.reviewer Miro Halas
32  * @code.reviewed 1.1 2005/08/24 06:55:27 bastafidli
33  */

34 public abstract class DatabaseOperation
35 {
36    // Attributes ///////////////////////////////////////////////////////////////
37

38    /**
39     * Factory which is executing this operation.
40     */

41    protected DatabaseFactoryImpl m_factory;
42    
43    /**
44     * Attribute to store data to return from executeUpdate.
45     */

46    protected Object JavaDoc m_returnData;
47    
48    /**
49     * Query specified by the caller to prepare if any.
50     */

51    protected String JavaDoc m_strQuery;
52
53    /**
54     * Schema which is executing this operation.
55     */

56    protected DatabaseSchema m_dbschema;
57
58    /**
59     * Data type the operation is used for.
60     */

61    protected int m_iDataType;
62
63    /**
64     * Data used for this operation.
65     */

66    protected Object JavaDoc m_data;
67
68    // Constructors /////////////////////////////////////////////////////////////
69

70    /**
71     * Constructor to use when the database operation doesn't require any
72     * prepared statement.
73     *
74     * @param factory - factory which is executing this operation
75     */

76    public DatabaseOperation(
77       DatabaseFactoryImpl factory
78    )
79    {
80       this(factory, null);
81    }
82
83    /**
84     * Constructor to use when database operation doesn't require any prepared
85     * statement.
86     *
87     * @param factory - factory which is executing this operation
88     * @param strQueryToPrepare - query which should be used to construct prepared
89     * statement which will be passed in to executeUpdate
90     */

91    public DatabaseOperation(
92       DatabaseFactoryImpl factory,
93       String JavaDoc strQueryToPrepare
94    )
95    {
96       super();
97       
98       m_factory = factory;
99       m_strQuery = strQueryToPrepare;
100    }
101
102    /**
103     * Full constructor to use when database operation doesn't require any prepared
104     * statement.
105     *
106     * @param factory - factory which is executing this operation
107     * @param strQueryToPrepare - query which should be used to construct prepared
108     * statement which will be passed in to executeUpdate
109     * @param schema - database schema used with this operation
110     * @param data - data used for operation
111     * @param dataType - data type used with operation
112     */

113    public DatabaseOperation(
114       DatabaseFactoryImpl factory,
115       String JavaDoc strQueryToPrepare,
116       DatabaseSchema schema,
117       Object JavaDoc data,
118       int dataType
119    )
120    {
121       super();
122       
123       m_factory = factory;
124       m_strQuery = strQueryToPrepare;
125       m_dbschema = schema;
126       m_data = data;
127       m_iDataType = dataType;
128    }
129
130    // Public methods ///////////////////////////////////////////////////////////
131

132    /**
133     * Get data which should be returned from method which actuall implements
134     * database operation
135     *
136     * @return Object - data set by executeUpdate using set method
137     */

138    public Object JavaDoc getReturnData(
139    )
140    {
141       return m_returnData;
142    }
143
144    /**
145     * Set data which should be returned from method which actuall implements
146     * database operation
147     *
148     * @param returnData - data set by executeUpdate using set method
149     */

150    public void setReturnData(
151       Object JavaDoc returnData
152    )
153    {
154       m_returnData = returnData;
155    }
156 }
157
Free Books   Free Magazines  
Popular Tags