KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > client > am > Section


1 /*
2  *
3  * Derby - Class org.apache.derby.client.am.Section
4  *
5  * Licensed to the Apache Software Foundation (ASF) under one or more
6  * contributor license agreements. See the NOTICE file distributed with
7  * this work for additional information regarding copyright ownership.
8  * The ASF licenses this file to You under the Apache License, Version 2.0
9  * (the "License"); you may not use this file except in compliance with
10  * the License. You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
15  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations under the License.
17  *
18  */

19
20 package org.apache.derby.client.am;
21
22 public class Section {
23
24     protected int sectionNumber;
25     protected String JavaDoc packageName;
26     protected String JavaDoc serverCursorName; // As given by dnc package set
27
int resultSetHoldability_;
28
29     // Stores the package name and consistency token
30
byte[] PKGNAMCBytes;
31     boolean isGenerated; // flag to identify server generated sections
32

33     public Section(Agent agent, String JavaDoc name, int sectionNumber, String JavaDoc cursorName, int resultSetHoldability) {
34         // default for all sections except for generated section , isGenerated is set to false
35
init(agent, name, sectionNumber, cursorName, resultSetHoldability, false);
36     }
37
38     public Section(Agent agent, String JavaDoc name, int sectionNumber, String JavaDoc cursorName, int resultSetHoldability, boolean isGenerated) {
39         init(agent, name, sectionNumber, cursorName, resultSetHoldability, isGenerated);
40     }
41
42     private void init(Agent agent, String JavaDoc name, int sectionNumber, String JavaDoc cursorName, int resultSetHoldability, boolean isGenerated) {
43         this.packageName = name;
44         this.sectionNumber = sectionNumber;
45         this.serverCursorName = cursorName;
46         resultSetHoldability_ = resultSetHoldability;
47         agent_ = agent;
48         this.isGenerated = isGenerated;
49
50         // Store the packagename and consistency token bytes depending on the holdability
51
// PKGNAMCBytes will point to the appropriate byte array in SectionManager
52
// that stores the PKGNAMCBytes for reuse
53
// There are 2 byte arrays in SectionManager
54
// 1. holdPKGNAMCBytes which stores the PKGNAMCBytes when holdability is set
55
// 2. noHoldPKGNAMCBytes which stores the PKGNAMCBytes when holdability is non hold
56
// Note for generated sections, PKGNAMCBytes is generated by the server.
57
if (!isGenerated) {
58             if (resultSetHoldability_ == ResultSet.HOLD_CURSORS_OVER_COMMIT) {
59                 PKGNAMCBytes = agent_.sectionManager_.holdPKGNAMCBytes;
60             } else if (resultSetHoldability_ == ResultSet.CLOSE_CURSORS_AT_COMMIT) {
61                 PKGNAMCBytes = agent_.sectionManager_.noHoldPKGNAMCBytes;
62             }
63         }
64     }
65
66     /**
67      * Store the Packagename and consistency token information for reuse. Case 1: if it is generated section, just store
68      * the byte array in PKGNAMCBytes Case 2: for not a generated section, information is stored in the correct byte
69      * array depending on the holdability in SectionManager
70      */

71     public void setPKGNAMCBytes(byte[] b) {
72         if (isGenerated) {
73             PKGNAMCBytes = b;
74         } else {
75             agent_.sectionManager_.setPKGNAMCBytes(b, resultSetHoldability_);
76         }
77     }
78
79     /**
80      * retrieve the package name and consistency token information
81      */

82     public byte[] getPKGNAMCBytes() {
83         return PKGNAMCBytes;
84     }
85
86     public String JavaDoc getPackageName() {
87         return this.packageName;
88     }
89
90
91     // Add a finalizer to free() the section, useful for Statement.executes that result in exceptions
92

93     public int getSectionNumber() {
94         return this.sectionNumber;
95     }
96
97     public String JavaDoc getPackage() {
98         return this.packageName;
99     }
100
101     public String JavaDoc getServerCursorName() {
102         return this.serverCursorName;
103     }
104
105     // ------------------------ transient members --------------------------------
106

107     public String JavaDoc serverCursorNameForPositionedUpdate_ = null; // member for positioned update sections only
108
transient protected String JavaDoc clientCursorName_; // As given by jdbc setCursorName(), this can change
109

110     public String JavaDoc getServerCursorNameForPositionedUpdate() {
111         return serverCursorNameForPositionedUpdate_;
112     }
113
114     public String JavaDoc getClientCursorName() {
115         return clientCursorName_;
116     }
117
118     public void setClientCursorName(String JavaDoc clientCursorName) { //
119
//System.out.println("clientCursorName is set"+ clientCursorName);
120
this.clientCursorName_ = clientCursorName;
121     }
122
123     protected Agent agent_;
124
125
126     public void free() {
127         if (resultSetHoldability_ != -1) {
128             this.agent_.sectionManager_.freeSection(this, resultSetHoldability_);
129         }
130     }
131
132     public boolean isReservedPositionedUpdate() {
133         return false;
134     }
135
136     public int getStaticStatementType() {
137         return 0;
138     }
139
140     public Section getPositionedUpdateSection() throws SqlException {
141         return agent_.sectionManager_.getPositionedUpdateSection(this);
142     }
143
144     public void setCursorName(String JavaDoc name) {
145         serverCursorName = name;
146     }
147
148 }
149
150
Popular Tags