001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.CursorInfo
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
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.sql;
023:
024: import org.apache.derby.iapi.sql.ResultColumnDescriptor;
025: import org.apache.derby.iapi.sql.execute.ExecCursorTableReference;
026: import org.apache.derby.iapi.services.sanity.SanityManager;
027:
028: import org.apache.derby.iapi.services.io.ArrayUtil;
029: import org.apache.derby.iapi.services.io.StoredFormatIds;
030: import org.apache.derby.iapi.services.io.FormatIdUtil;
031: import org.apache.derby.iapi.services.io.Formatable;
032:
033: import java.io.ObjectOutput;
034: import java.io.ObjectInput;
035: import java.io.IOException;
036:
037: /**
038: * A basic holder for information about cursors
039: * for execution.
040: *
041: * @author jamie
042: */
043: public class CursorInfo implements Formatable {
044:
045: /********************************************************
046: **
047: ** This class implements Formatable. That means that it
048: ** can write itself to and from a formatted stream. If
049: ** you add more fields to this class, make sure that you
050: ** also write/read them with the writeExternal()/readExternal()
051: ** methods.
052: **
053: ** If, inbetween releases, you add more fields to this class,
054: ** then you should bump the version number emitted by the getTypeFormatId()
055: ** method.
056: **
057: ********************************************************/
058:
059: ExecCursorTableReference targetTable;
060: ResultColumnDescriptor[] targetColumns;
061: String[] updateColumns;
062: int updateMode;
063:
064: /**
065: * Niladic constructor for Formatable
066: */
067: public CursorInfo() {
068: }
069:
070: /**
071: *
072: */
073: public CursorInfo(int updateMode,
074: ExecCursorTableReference targetTable,
075: ResultColumnDescriptor[] targetColumns,
076: String[] updateColumns) {
077: this .updateMode = updateMode;
078: this .targetTable = targetTable;
079: this .targetColumns = targetColumns;
080: this .updateColumns = updateColumns;
081: }
082:
083: //////////////////////////////////////////////
084: //
085: // FORMATABLE
086: //
087: //////////////////////////////////////////////
088: /**
089: * Write this object out
090: *
091: * @param out write bytes here
092: *
093: * @exception IOException thrown on error
094: */
095: public void writeExternal(ObjectOutput out) throws IOException {
096: out.writeInt(updateMode);
097: out.writeObject(targetTable);
098: ArrayUtil.writeArray(out, targetColumns);
099: ArrayUtil.writeArray(out, updateColumns);
100: }
101:
102: /**
103: * Read this object from a stream of stored objects.
104: *
105: * @param in read this.
106: *
107: * @exception IOException thrown on error
108: * @exception ClassNotFoundException thrown on error
109: */
110: public void readExternal(ObjectInput in) throws IOException,
111: ClassNotFoundException {
112: updateMode = in.readInt();
113: targetTable = (ExecCursorTableReference) in.readObject();
114: int len = ArrayUtil.readArrayLength(in);
115: if (len != 0) {
116: targetColumns = new ResultColumnDescriptor[len];
117: ArrayUtil.readArrayItems(in, targetColumns);
118: }
119: len = ArrayUtil.readArrayLength(in);
120: if (len != 0) {
121: updateColumns = new String[len];
122: ArrayUtil.readArrayItems(in, updateColumns);
123: }
124: }
125:
126: /**
127: * Get the formatID which corresponds to this class.
128: *
129: * @return the formatID of this class
130: */
131: public int getTypeFormatId() {
132: return StoredFormatIds.CURSOR_INFO_V01_ID;
133: }
134:
135: public String toString() {
136: if (SanityManager.DEBUG) {
137: StringBuffer strbuf = new StringBuffer();
138:
139: strbuf.append("CursorInfo" + "\n\tupdateMode: "
140: + updateMode + "\n\ttargetTable: " + targetTable
141: + "\n\tupdateColumns: ");
142:
143: if (updateColumns == null) {
144: strbuf.append("NULL\n");
145: } else {
146: strbuf.append("{");
147: for (int i = 0; i < updateColumns.length; i++) {
148: if (i > 0)
149: strbuf.append(",");
150: strbuf.append(updateColumns[i]);
151: }
152: strbuf.append(")\n");
153: }
154:
155: strbuf.append("\tTargetColumnDescriptors: \n");
156: if (targetColumns == null) {
157: strbuf.append("NULL");
158: } else {
159: for (int i = 0; i < targetColumns.length; i++) {
160: strbuf.append(targetColumns[i]);
161: }
162: strbuf.append("\n");
163: }
164: return strbuf.toString();
165: } else {
166: return "";
167: }
168: }
169: }
|