KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > databaseaccess > OutputParameterForCallableStatement


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.databaseaccess;
23
24 import java.sql.*;
25 import oracle.toplink.essentials.internal.helper.*;
26 import oracle.toplink.essentials.internal.sessions.AbstractSession;
27
28 public class OutputParameterForCallableStatement extends BindCallCustomParameter {
29     // this attribute is provided by the caller
30
protected boolean isCursor;
31
32     // these attributes are generated by prepare method
33
protected int jdbcType;
34     protected String JavaDoc typeName;
35     protected boolean isTypeNameRequired;
36
37     public OutputParameterForCallableStatement(DatabaseField field) {
38         super(field);
39     }
40
41     public OutputParameterForCallableStatement(DatabaseField field, DatabasePlatform platform) {
42         this(field, platform, false);
43     }
44
45     public OutputParameterForCallableStatement(DatabaseField field, DatabasePlatform platform, boolean isCursor) {
46         this(field);
47         this.isCursor = isCursor;
48         prepare(platform);
49     }
50
51     public OutputParameterForCallableStatement(OutputParameterForCallableStatement outParameter) {
52         super(outParameter.obj);
53         this.isCursor = outParameter.isCursor;
54         this.jdbcType = outParameter.jdbcType;
55         this.typeName = outParameter.typeName;
56         this.isTypeNameRequired = outParameter.isTypeNameRequired;
57     }
58
59     protected OutputParameterForCallableStatement() {
60     }
61
62     public void setIsCursor(boolean isCursor) {
63         this.isCursor = isCursor;
64     }
65
66     // make sure to call prepare() method after this
67
public boolean isCursor() {
68         return isCursor;
69     }
70
71     public boolean isTypeNameRequired() {
72         return isTypeNameRequired;
73     }
74
75     public int getJdbcType() {
76         return jdbcType;
77     }
78
79     public String JavaDoc getTypeName() {
80         return typeName;
81     }
82
83     public DatabaseField getOutputField() {
84         return (DatabaseField)obj;
85     }
86
87     public void prepare(DatabasePlatform platform) {
88         if (isCursor()) {
89             jdbcType = platform.getCursorCode();// Oracle code for cursors
90
} else {
91             jdbcType = platform.getJDBCType(getOutputField());
92             isTypeNameRequired = platform.requiresTypeNameToRegisterOutputParameter();
93             if (isTypeNameRequired) {
94                 typeName = platform.getJdbcTypeName(jdbcType);
95             }
96         }
97     }
98
99     public void set(DatabasePlatform platform, PreparedStatement statement, int index, AbstractSession session) throws SQLException {
100         if (isTypeNameRequired) {
101             ((CallableStatement)statement).registerOutParameter(index, jdbcType, typeName);
102         } else {
103             ((CallableStatement)statement).registerOutParameter(index, jdbcType);
104         }
105     }
106
107     public String JavaDoc toString() {
108         return "=> " + getOutputField().getName();
109     }
110 }
111
Popular Tags