Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SqlProcedureStatement |
|
| 2.5;2.5 |
1 | package org.apache.ojb.broker.accesslayer.sql; | |
2 | ||
3 | /* Copyright 2003-2005 The Apache Software Foundation | |
4 | * | |
5 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | * you may not use this file except in compliance with the License. | |
7 | * You may obtain a copy of the License at | |
8 | * | |
9 | * 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.1 2007-08-24 22:17:39 ewestfal Exp $ | |
28 | */ | |
29 | ||
30 | public class SqlProcedureStatement implements SqlStatement | |
31 | { | |
32 | ||
33 | /** | |
34 | * The descriptor that defines the procedure to invoke. | |
35 | */ | |
36 | private ProcedureDescriptor procedureDescriptor; | |
37 | ||
38 | /** | |
39 | * The logger to utilize | |
40 | */ | |
41 | private Logger logger; | |
42 | ||
43 | /** | |
44 | * Create an instance of this object. | |
45 | * | |
46 | * @param procedureDescriptor the descriptor that defines the procedure to invoke. | |
47 | * @param logger the logger to utilize | |
48 | */ | |
49 | public SqlProcedureStatement(ProcedureDescriptor procedureDescriptor, Logger logger) | |
50 | { | |
51 | // Save the values. | |
52 | this.procedureDescriptor = procedureDescriptor; | |
53 | this.logger = logger; | |
54 | } | |
55 | ||
56 | /** | |
57 | * Get the syntax that is required to invoke the procedure that is defined | |
58 | * by the <code>ProcedureDescriptor</code> that was passed to the | |
59 | * constructor of this class. | |
60 | * | |
61 | * @see SqlStatement#getStatement() | |
62 | */ | |
63 | public String getStatement() | |
64 | { | |
65 | StringBuffer sb = new StringBuffer(512); | |
66 | int argumentCount = this.procedureDescriptor.getArgumentCount(); | |
67 | if (this.procedureDescriptor.hasReturnValue()) | |
68 | { | |
69 | sb.append("{ ?= call "); | |
70 | } | |
71 | else | |
72 | { | |
73 | sb.append("{ call "); | |
74 | } | |
75 | sb.append(this.procedureDescriptor.getName()); | |
76 | sb.append("("); | |
77 | for (int i = 0; i < argumentCount; i++) | |
78 | { | |
79 | if (i == 0) | |
80 | { | |
81 | sb.append("?"); | |
82 | } | |
83 | else | |
84 | { | |
85 | sb.append(",?"); | |
86 | } | |
87 | } | |
88 | sb.append(") }"); | |
89 | return sb.toString(); | |
90 | } | |
91 | } |