1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.sql.CursorInfo |
4 | |
5 | Copyright 1999, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.impl.sql; |
22 | |
23 | import org.apache.derby.iapi.sql.ResultColumnDescriptor; |
24 | import org.apache.derby.iapi.sql.execute.ExecCursorTableReference; |
25 | import org.apache.derby.iapi.services.sanity.SanityManager; |
26 | |
27 | import org.apache.derby.iapi.services.io.ArrayUtil; |
28 | import org.apache.derby.iapi.services.io.StoredFormatIds; |
29 | import org.apache.derby.iapi.services.io.FormatIdUtil; |
30 | import org.apache.derby.iapi.services.io.Formatable; |
31 | |
32 | import java.io.ObjectOutput; |
33 | import java.io.ObjectInput; |
34 | import java.io.IOException; |
35 | /** |
36 | * A basic holder for information about cursors |
37 | * for execution. |
38 | * |
39 | * @author jamie |
40 | */ |
41 | public class CursorInfo |
42 | implements Formatable |
43 | { |
44 | |
45 | /******************************************************** |
46 | ** |
47 | ** This class implements Formatable. That means that it |
48 | ** can write itself to and from a formatted stream. If |
49 | ** you add more fields to this class, make sure that you |
50 | ** also write/read them with the writeExternal()/readExternal() |
51 | ** methods. |
52 | ** |
53 | ** If, inbetween releases, you add more fields to this class, |
54 | ** then you should bump the version number emitted by the getTypeFormatId() |
55 | ** method. |
56 | ** |
57 | ********************************************************/ |
58 | |
59 | ExecCursorTableReference targetTable; |
60 | ResultColumnDescriptor[] targetColumns; |
61 | String[] updateColumns; |
62 | int updateMode; |
63 | |
64 | /** |
65 | * Niladic constructor for Formatable |
66 | */ |
67 | public CursorInfo() |
68 | { |
69 | } |
70 | |
71 | /** |
72 | * |
73 | */ |
74 | public CursorInfo |
75 | ( |
76 | int updateMode, |
77 | ExecCursorTableReference targetTable, |
78 | ResultColumnDescriptor[] targetColumns, |
79 | String[] updateColumns |
80 | ) |
81 | { |
82 | this.updateMode = updateMode; |
83 | this.targetTable = targetTable; |
84 | this.targetColumns = targetColumns; |
85 | this.updateColumns = updateColumns; |
86 | } |
87 | |
88 | ////////////////////////////////////////////// |
89 | // |
90 | // FORMATABLE |
91 | // |
92 | ////////////////////////////////////////////// |
93 | /** |
94 | * Write this object out |
95 | * |
96 | * @param out write bytes here |
97 | * |
98 | * @exception IOException thrown on error |
99 | */ |
100 | public void writeExternal(ObjectOutput out) throws IOException |
101 | { |
102 | out.writeInt(updateMode); |
103 | out.writeObject(targetTable); |
104 | ArrayUtil.writeArray(out, targetColumns); |
105 | ArrayUtil.writeArray(out, updateColumns); |
106 | } |
107 | |
108 | /** |
109 | * Read this object from a stream of stored objects. |
110 | * |
111 | * @param in read this. |
112 | * |
113 | * @exception IOException thrown on error |
114 | * @exception ClassNotFoundException thrown on error |
115 | */ |
116 | public void readExternal(ObjectInput in) |
117 | throws IOException, ClassNotFoundException |
118 | { |
119 | updateMode = in.readInt(); |
120 | targetTable = (ExecCursorTableReference)in.readObject(); |
121 | int len = ArrayUtil.readArrayLength(in); |
122 | if (len != 0) |
123 | { |
124 | targetColumns = new ResultColumnDescriptor[len]; |
125 | ArrayUtil.readArrayItems(in, targetColumns); |
126 | } |
127 | len = ArrayUtil.readArrayLength(in); |
128 | if (len != 0) |
129 | { |
130 | updateColumns = new String[len]; |
131 | ArrayUtil.readArrayItems(in, updateColumns); |
132 | } |
133 | } |
134 | |
135 | /** |
136 | * Get the formatID which corresponds to this class. |
137 | * |
138 | * @return the formatID of this class |
139 | */ |
140 | public int getTypeFormatId() { return StoredFormatIds.CURSOR_INFO_V01_ID; } |
141 | |
142 | public String toString() |
143 | { |
144 | if (SanityManager.DEBUG) |
145 | { |
146 | StringBuffer strbuf = new StringBuffer(); |
147 | |
148 | strbuf.append("CursorInfo"+ |
149 | "\n\tupdateMode: "+updateMode+ |
150 | "\n\ttargetTable: "+targetTable+ |
151 | "\n\tupdateColumns: "); |
152 | |
153 | if (updateColumns == null) |
154 | { |
155 | strbuf.append("NULL\n"); |
156 | } |
157 | else |
158 | { |
159 | strbuf.append("{"); |
160 | for (int i = 0; i < updateColumns.length; i++) |
161 | { |
162 | if (i > 0) |
163 | strbuf.append(","); |
164 | strbuf.append(updateColumns[i]); |
165 | } |
166 | strbuf.append(")\n"); |
167 | } |
168 | |
169 | strbuf.append("\tTargetColumnDescriptors: \n"); |
170 | if (targetColumns == null) |
171 | { |
172 | strbuf.append("NULL"); |
173 | } |
174 | else |
175 | { |
176 | for (int i = 0; i < targetColumns.length; i++) |
177 | { |
178 | strbuf.append(targetColumns[i]); |
179 | } |
180 | strbuf.append("\n"); |
181 | } |
182 | return strbuf.toString(); |
183 | } |
184 | else |
185 | { |
186 | return ""; |
187 | } |
188 | } |
189 | } |