01: package org.apache.ojb.broker.accesslayer.sql;
02:
03: /* Copyright 2003-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: import org.apache.ojb.broker.metadata.ProcedureDescriptor;
19: import org.apache.ojb.broker.util.logging.Logger;
20:
21: /**
22: * Model a call to a stored procedure based on ProcedureDescriptors
23: *
24: * @see org.apache.ojb.broker.metadata.ProcedureDescriptor
25: * @author <a href="mailto:rburt3@mchsi.com">Randall Burt</a>
26: * @author <a href="mailto:rgallagh@bellsouth.net">Ron Gallagher</a>
27: * @version $Id: SqlProcedureStatement.java,v 1.5.2.1 2005/12/21 22:23:44 tomdz Exp $
28: */
29:
30: public class SqlProcedureStatement implements SqlStatement {
31:
32: /**
33: * The descriptor that defines the procedure to invoke.
34: */
35: private ProcedureDescriptor procedureDescriptor;
36:
37: /**
38: * The logger to utilize
39: */
40: private Logger logger;
41:
42: /**
43: * Create an instance of this object.
44: *
45: * @param procedureDescriptor the descriptor that defines the procedure to invoke.
46: * @param logger the logger to utilize
47: */
48: public SqlProcedureStatement(
49: ProcedureDescriptor procedureDescriptor, Logger logger) {
50: // Save the values.
51: this .procedureDescriptor = procedureDescriptor;
52: this .logger = logger;
53: }
54:
55: /**
56: * Get the syntax that is required to invoke the procedure that is defined
57: * by the <code>ProcedureDescriptor</code> that was passed to the
58: * constructor of this class.
59: *
60: * @see SqlStatement#getStatement()
61: */
62: public String getStatement() {
63: StringBuffer sb = new StringBuffer(512);
64: int argumentCount = this .procedureDescriptor.getArgumentCount();
65: if (this .procedureDescriptor.hasReturnValue()) {
66: sb.append("{ ?= call ");
67: } else {
68: sb.append("{ call ");
69: }
70: sb.append(this .procedureDescriptor.getName());
71: sb.append("(");
72: for (int i = 0; i < argumentCount; i++) {
73: if (i == 0) {
74: sb.append("?");
75: } else {
76: sb.append(",?");
77: }
78: }
79: sb.append(") }");
80: return sb.toString();
81: }
82: }
|