1 21 22 package org.apache.derby.client.am; 23 24 import org.apache.derby.shared.common.reference.JDBC30Translation; 25 26 import org.apache.derby.shared.common.reference.SQLState; 27 28 29 public class SectionManager { 30 String collection_; 31 Agent agent_; 32 33 final static int HOLD = 0; 39 final static int NO_HOLD = 1; 40 41 java.util.Stack freeSectionsNonHold_ = null; 47 java.util.Stack freeSectionsHold_ = null; 48 49 int nextAvailableSectionNumber_ = 1; 50 51 public static byte[] holdPKGNAMCBytes = null; 56 public static byte[] noHoldPKGNAMCBytes = null; 57 58 59 final static String packageNameWithHold__ = "SYSLH000"; 60 final static String packageNameWithNoHold__ = "SYSLN000"; 61 62 final static String cursorNamePrefixWithHold__ = "SQL_CURLH000C"; 63 final static String cursorNamePrefixWithNoHold__ = "SQL_CURLN000C"; 64 65 private java.util.Hashtable positionedUpdateCursorNameToQuerySection_ = new java.util.Hashtable (); 77 78 private java.util.Hashtable positionedUpdateCursorNameToResultSet_ = new java.util.Hashtable (); 81 82 String databaseName; 83 84 int maxNumSections_ = 32768; 85 86 public SectionManager(String collection, Agent agent, String databaseName) { 87 collection_ = collection; 88 agent_ = agent; 89 this.databaseName = databaseName; 90 freeSectionsNonHold_ = new java.util.Stack (); 91 freeSectionsHold_ = new java.util.Stack (); 92 } 93 94 103 public void setPKGNAMCBytes(byte[] b, int resultSetHoldability) { 104 if (resultSetHoldability == JDBC30Translation.HOLD_CURSORS_OVER_COMMIT) { 105 agent_.sectionManager_.holdPKGNAMCBytes = b; 106 } else if (resultSetHoldability == JDBC30Translation.CLOSE_CURSORS_AT_COMMIT) { 107 agent_.sectionManager_.noHoldPKGNAMCBytes = b; 108 } 109 } 110 111 112 114 public Section getDynamicSection(int resultSetHoldability) throws SqlException { 116 int cursorHoldIndex; 117 if (resultSetHoldability == JDBC30Translation.HOLD_CURSORS_OVER_COMMIT) { 118 return getSection(freeSectionsHold_, packageNameWithHold__, cursorNamePrefixWithHold__, resultSetHoldability); 119 } else if (resultSetHoldability == JDBC30Translation.CLOSE_CURSORS_AT_COMMIT) { 120 return getSection(freeSectionsNonHold_, packageNameWithNoHold__, cursorNamePrefixWithNoHold__, resultSetHoldability); 121 } else { 122 throw new SqlException(agent_.logWriter_, 123 new ClientMessageId(SQLState.UNSUPPORTED_HOLDABILITY_PROPERTY), 124 new Integer (resultSetHoldability)); 125 } 126 } 127 128 protected Section getSection(java.util.Stack freeSections, String packageName, String cursorNamePrefix, int resultSetHoldability) throws SqlException { 129 if (!freeSections.empty()) { 130 return (Section) freeSections.pop(); 131 } else if (nextAvailableSectionNumber_ < (maxNumSections_ - 1)) { 132 String cursorName = cursorNamePrefix + nextAvailableSectionNumber_; 133 Section section = new Section(agent_, packageName, nextAvailableSectionNumber_, cursorName, resultSetHoldability); 134 nextAvailableSectionNumber_++; 135 return section; 136 } else 137 { 139 throw new SqlException(agent_.logWriter_, 140 new ClientMessageId(SQLState.EXCEEDED_MAX_SECTIONS), 141 "32k"); 142 } 143 } 144 145 public void freeSection(Section section, int resultSetHoldability) { 146 if (resultSetHoldability == JDBC30Translation.HOLD_CURSORS_OVER_COMMIT) { 147 this.freeSectionsHold_.push(section); 148 } else if (resultSetHoldability == JDBC30Translation.CLOSE_CURSORS_AT_COMMIT) { 149 this.freeSectionsNonHold_.push(section); 150 } 151 } 152 153 Section getPositionedUpdateSection(Section querySection) throws SqlException { 156 Connection connection = agent_.connection_; 157 return getDynamicSection(connection.holdability()); 158 } 159 160 Section getPositionedUpdateSection(String cursorName, boolean useExecuteImmediateSection) throws SqlException { 163 Section querySection = (Section) positionedUpdateCursorNameToQuerySection_.get(cursorName); 164 165 if (querySection != null) { 169 Section section = getPositionedUpdateSection(querySection); 170 section.setClientCursorName(querySection.getClientCursorName()); 175 section.serverCursorNameForPositionedUpdate_ = querySection.getServerCursorName(); 176 return section; 177 } else { 178 return null; 179 } 180 } 181 182 void mapCursorNameToQuerySection(String cursorName, Section section) { 183 positionedUpdateCursorNameToQuerySection_.put(cursorName, section); 184 } 185 186 void mapCursorNameToResultSet(String cursorName, ResultSet resultSet) { 187 positionedUpdateCursorNameToResultSet_.put(cursorName, resultSet); 188 } 189 190 ResultSet getPositionedUpdateResultSet(String cursorName) throws SqlException { 191 ResultSet rs = (ResultSet) positionedUpdateCursorNameToResultSet_.get(cursorName); 192 if (rs == null) { 193 throw new SqlException(agent_.logWriter_, 194 new ClientMessageId(SQLState.CLIENT_RESULT_SET_NOT_OPEN)); 195 } 196 return (rs.resultSetType_ == java.sql.ResultSet.TYPE_FORWARD_ONLY) ? null : rs; 197 } 198 199 void removeCursorNameToResultSetMapping(String clientCursorName, 200 String serverCursorName) { 201 if (clientCursorName != null) { 202 positionedUpdateCursorNameToResultSet_.remove(clientCursorName); 203 } 204 if (serverCursorName != null) { 205 positionedUpdateCursorNameToResultSet_.remove(serverCursorName); 206 } 207 } 208 209 void removeCursorNameToQuerySectionMapping(String clientCursorName, 210 String serverCursorName) { 211 if (clientCursorName != null) { 212 positionedUpdateCursorNameToQuerySection_.remove(clientCursorName); 213 } 214 if (serverCursorName != null) { 215 positionedUpdateCursorNameToQuerySection_.remove(serverCursorName); 216 } 217 } 218 219 } 220 221 | Popular Tags |