summaryrefslogtreecommitdiffstats
path: root/tags/java-stable-20060304/das/rdb/src/main/java/org/apache/tuscany/das/rdb/Command.java
blob: 0f5534f7054ff1716453471f866f5e93b95c6cca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/**
 *
 *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.apache.tuscany.das.rdb;

import java.sql.Connection;

import org.apache.tuscany.das.rdb.impl.CommandFactoryImpl;

import commonj.sdo.DataObject;
import commonj.sdo.Type;

/**
 * A Command is used to execute a read or write to a database
 * 
 * 
 */
public interface Command {

	public static CommandFactory FACTORY = new CommandFactoryImpl();

	/**
	 * Performs the function defined by the command
	 */
	public void execute();

	/**
	 * Performs the function defined by the command and return the results in
	 * the root DataObject
	 * 
	 * @return the root DataObject
	 */
	public DataObject executeQuery();

	/**
	 * Returns the parameter associated with "name"
	 * 
	 * @param name
	 *            the name of the parameter
	 * @return the associated parameter
	 */
	public Parameter getParameter(String name);

	/**
	 * Returns the Parameter at index
	 * 
	 * @param index
	 *            the index of the Parameter
	 * @return the associated Parameter
	 */
	public Parameter getParameter(int index);

	/**
	 * Sets the value of the named Parameter
	 * 
	 * @param name
	 *            the name of this Parameter
	 * @param value
	 *            the value for the Parameter
	 */
	public void setParameterValue(String name, Object value);

	/**
	 * Sets the value of the associated Parameter
	 * 
	 * @param index
	 *            the index of the Parameter
	 * @param value
	 *            the value for the Parameter
	 */
	public void setParameterValue(int index, Object value);

    /**
     * Sets the "type" of the associated Parameter
     * 
     * @param name
     *            the name of this Parameter
     * @param type
     *            the SDODataTypes-defined "type" for the Parameter.
     */
    public void setParameterType(String string, Type dataType);
     
     /**
     * Sets the "type" of the associated Parameter
     * 
     * @param index
     *            the index of the Parameter
     * @param type
     *            the SDODataTypes-defined "type" for the Parameter.
     */
    public void setParameterType(int index, Type dataType);
    
    /**
	 * Returns the value of the associated Parameter
	 * 
	 * @param name
	 *            the name of the Parameter
	 * @return the value of the Parameter
	 */
	public Object getParameterValue(String name);

	/**
	 * Returns the value of the associated Parameter
	 * 
	 * @param index
	 *            the index of the Parameter
	 * @return the value of the Parameter
	 */
	public Object getParameterValue(int index);

	/**
	 * Adds a Parameter to the command
	 * 
	 * @param index
	 *            the index of the parameter
	 * @param sdoType
	 *            the commonj.sdo.Type of the Parameter
	 */
	public void addParameter(int index, Type sdoType);

	/**
	 * Adds a Parameter to the command
	 * 
	 * @param name
	 *            the index of the parameter
	 * @param sdoType
	 *            the commonj.sdo.Type of the Parameter
	 */
	public void addParameter(String name, Type sdoType);

	/**
	 * Adds a Parameter to the command
	 * 
	 * @param index
	 *            the index of the parameter
	 * @param direction
	 *            the direction of the Parameter. Either Parameter.IN,
	 *            Parameter.OUT or Parameter.INOUT
	 * @param sdoType
	 *            specifies the type as a commonj.sdo.Type from
	 *            {@link SDODataTypes}
	 */
	public void addParameter(int index, int direction, Type sdoType);

	/**
	 * Adds a Parameter to the command
	 * 
	 * @param name
	 *            the name associated with the Parameter
	 * @param direction
	 *            the direction of the Parameter. Either Parameter.IN,
	 *            Parameter.OUT or Parameter.INOUT
	 * @param sdoType
	 *            specifies the type as a commonj.sdo.Type from
	 *            {@link SDODataTypes}
	 */
	public void addParameter(String name, int direction, Type sdoType);

	/**
	 * Specifies an object model for a graph of DataObjects returned by
	 * #executeQuery()
	 * 
	 * @param schema
	 *            the model as a commonj.sdo.Type
	 */
	public void setDataObjectModel(Type schema);

	/**
	 * Defines the structure of the ResultSet returned by the JDBC Driver when
	 * this command is executed. If the shape is not specified then the shape is
	 * taken from the ResultSetMetatadta instance provided by the JDBC Driver.
	 * <p>
	 * This method is prvided primarily to support platforms (such as Oracle)
	 * that do not provide complete support for ResultSetMetadata
	 * 
	 * @param shape
	 *            the specified result set shape
	 * @see ResultSetShape
	 */
	public void setResultSetShape(ResultSetShape shape);

	/**
	 * Provides the java.sql.Connection to be used for this executing this
	 * command.
	 * 
	 * @param connection
	 *            the java.sql.Connection
	 */
	public void setConnection(Connection connection);

	/**
	 * Provides the java.sql.Connection to be used for this executing this
	 * command.
	 * 
	 * @param connection
	 *            the java.sql.Connection
	 * @param manageTransactions
	 *            <code>true</code> if the DAS should perform tx
	 *            commit/rollback
	 */
	public void setConnection(Connection connection, boolean manageTransactions);

	/**
	 * Add relationship metadata necessary for processing query results. This is
	 * an alternative to providing the same information in a config file.
	 * 
	 * @param parent
	 *            a name identifying the relationship parent key (example:
	 *            "CUSTOMER.ID")
	 * @param child
	 *            a name identifying the relationship child key
	 *            ("ORDER.CUSTOMER_ID")
	 */
	public void addRelationship(String parent, String child);

	/**
	 * Add relationship metadata necessary for processing query results. This is
	 * an alternative to providing the same information in a config file.
	 * 
	 * @param parentKey
	 *            the parent key for the relationship
	 * @param childKey
	 *            the child key in the relationship
	 * @see Key
	 */
	public void addRelationship(Key parentKey, Key childKey);

	/**
	 * Add primary key metadata. This is an alternative to providing the same
	 * information in a config file.
	 * 
	 * @param pk
	 *            the string identifying a prmary key. (Example: "CUSTOMER.ID")
	 */
	public void addPrimaryKey(String pk);

	/**
	 * Add primary key metadata. This is an alternative to providing the same
	 * information in a config file.
	 * 
	 * @param key
	 *            the primary key
	 * @see Key
	 */
	public void addPrimaryKey(Key key);

	/**
	 * Associate a {@link Converter} with a column to be used by this command.
	 * This is an alternative to providing the same information in a config
	 * file.
	 * 
	 * @param name
	 *            the name of the column being assigned a converter (example:
	 *            "CUSTOMER.LASTNAME")
	 * @param converterName
	 *            the name of the converter instance being assigned (example:
	 *            org.company.project.StringConverter)
	 * @see Converter
	 */
	public void addConverter(String name, String converterName);

	/**
	 * Cleans up and realeases all resources associated with this command. This
	 * should be called when the application is done with this command.
	 */
	public void close();



}