001: /*
002: *
003: * Derby - Class org.apache.derby.client.am.Section
004: *
005: * Licensed to the Apache Software Foundation (ASF) under one or more
006: * contributor license agreements. See the NOTICE file distributed with
007: * this work for additional information regarding copyright ownership.
008: * The ASF licenses this file to You under the Apache License, Version 2.0
009: * (the "License"); you may not use this file except in compliance with
010: * the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
015: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations under the License.
017: *
018: */
019:
020: package org.apache.derby.client.am;
021:
022: public class Section {
023:
024: protected int sectionNumber;
025: protected String packageName;
026: protected String serverCursorName; // As given by dnc package set
027: int resultSetHoldability_;
028:
029: // Stores the package name and consistency token
030: byte[] PKGNAMCBytes;
031: boolean isGenerated; // flag to identify server generated sections
032:
033: public Section(Agent agent, String name, int sectionNumber,
034: String cursorName, int resultSetHoldability) {
035: // default for all sections except for generated section , isGenerated is set to false
036: init(agent, name, sectionNumber, cursorName,
037: resultSetHoldability, false);
038: }
039:
040: public Section(Agent agent, String name, int sectionNumber,
041: String cursorName, int resultSetHoldability,
042: boolean isGenerated) {
043: init(agent, name, sectionNumber, cursorName,
044: resultSetHoldability, isGenerated);
045: }
046:
047: private void init(Agent agent, String name, int sectionNumber,
048: String cursorName, int resultSetHoldability,
049: boolean isGenerated) {
050: this .packageName = name;
051: this .sectionNumber = sectionNumber;
052: this .serverCursorName = cursorName;
053: resultSetHoldability_ = resultSetHoldability;
054: agent_ = agent;
055: this .isGenerated = isGenerated;
056:
057: // Store the packagename and consistency token bytes depending on the holdability
058: // PKGNAMCBytes will point to the appropriate byte array in SectionManager
059: // that stores the PKGNAMCBytes for reuse
060: // There are 2 byte arrays in SectionManager
061: // 1. holdPKGNAMCBytes which stores the PKGNAMCBytes when holdability is set
062: // 2. noHoldPKGNAMCBytes which stores the PKGNAMCBytes when holdability is non hold
063: // Note for generated sections, PKGNAMCBytes is generated by the server.
064: if (!isGenerated) {
065: if (resultSetHoldability_ == ResultSet.HOLD_CURSORS_OVER_COMMIT) {
066: PKGNAMCBytes = agent_.sectionManager_.holdPKGNAMCBytes;
067: } else if (resultSetHoldability_ == ResultSet.CLOSE_CURSORS_AT_COMMIT) {
068: PKGNAMCBytes = agent_.sectionManager_.noHoldPKGNAMCBytes;
069: }
070: }
071: }
072:
073: /**
074: * Store the Packagename and consistency token information for reuse. Case 1: if it is generated section, just store
075: * the byte array in PKGNAMCBytes Case 2: for not a generated section, information is stored in the correct byte
076: * array depending on the holdability in SectionManager
077: */
078: public void setPKGNAMCBytes(byte[] b) {
079: if (isGenerated) {
080: PKGNAMCBytes = b;
081: } else {
082: agent_.sectionManager_.setPKGNAMCBytes(b,
083: resultSetHoldability_);
084: }
085: }
086:
087: /**
088: * retrieve the package name and consistency token information
089: */
090: public byte[] getPKGNAMCBytes() {
091: return PKGNAMCBytes;
092: }
093:
094: public String getPackageName() {
095: return this .packageName;
096: }
097:
098: // Add a finalizer to free() the section, useful for Statement.executes that result in exceptions
099:
100: public int getSectionNumber() {
101: return this .sectionNumber;
102: }
103:
104: public String getPackage() {
105: return this .packageName;
106: }
107:
108: public String getServerCursorName() {
109: return this .serverCursorName;
110: }
111:
112: // ------------------------ transient members --------------------------------
113:
114: public String serverCursorNameForPositionedUpdate_ = null; // member for positioned update sections only
115: transient protected String clientCursorName_; // As given by jdbc setCursorName(), this can change
116:
117: public String getServerCursorNameForPositionedUpdate() {
118: return serverCursorNameForPositionedUpdate_;
119: }
120:
121: public String getClientCursorName() {
122: return clientCursorName_;
123: }
124:
125: public void setClientCursorName(String clientCursorName) { //
126: //System.out.println("clientCursorName is set"+ clientCursorName);
127: this .clientCursorName_ = clientCursorName;
128: }
129:
130: protected Agent agent_;
131:
132: public void free() {
133: if (resultSetHoldability_ != -1) {
134: this .agent_.sectionManager_.freeSection(this ,
135: resultSetHoldability_);
136: }
137: }
138:
139: public boolean isReservedPositionedUpdate() {
140: return false;
141: }
142:
143: public int getStaticStatementType() {
144: return 0;
145: }
146:
147: public Section getPositionedUpdateSection() throws SqlException {
148: return agent_.sectionManager_.getPositionedUpdateSection(this );
149: }
150:
151: public void setCursorName(String name) {
152: serverCursorName = name;
153: }
154:
155: }
|