KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > CursorInfo


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.CursorInfo
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
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql;
23
24 import org.apache.derby.iapi.sql.ResultColumnDescriptor;
25 import org.apache.derby.iapi.sql.execute.ExecCursorTableReference;
26 import org.apache.derby.iapi.services.sanity.SanityManager;
27
28 import org.apache.derby.iapi.services.io.ArrayUtil;
29 import org.apache.derby.iapi.services.io.StoredFormatIds;
30 import org.apache.derby.iapi.services.io.FormatIdUtil;
31 import org.apache.derby.iapi.services.io.Formatable;
32
33 import java.io.ObjectOutput JavaDoc;
34 import java.io.ObjectInput JavaDoc;
35 import java.io.IOException JavaDoc;
36 /**
37  * A basic holder for information about cursors
38  * for execution.
39  *
40  * @author jamie
41  */

42 public class CursorInfo
43     implements Formatable
44 {
45
46     /********************************************************
47     **
48     ** This class implements Formatable. That means that it
49     ** can write itself to and from a formatted stream. If
50     ** you add more fields to this class, make sure that you
51     ** also write/read them with the writeExternal()/readExternal()
52     ** methods.
53     **
54     ** If, inbetween releases, you add more fields to this class,
55     ** then you should bump the version number emitted by the getTypeFormatId()
56     ** method.
57     **
58     ********************************************************/

59
60     ExecCursorTableReference targetTable;
61     ResultColumnDescriptor[] targetColumns;
62     String JavaDoc[] updateColumns;
63     int updateMode;
64
65     /**
66      * Niladic constructor for Formatable
67      */

68     public CursorInfo()
69     {
70     }
71
72     /**
73      *
74      */

75     public CursorInfo
76     (
77         int updateMode,
78         ExecCursorTableReference targetTable,
79         ResultColumnDescriptor[] targetColumns,
80         String JavaDoc[] updateColumns
81     )
82     {
83         this.updateMode = updateMode;
84         this.targetTable = targetTable;
85         this.targetColumns = targetColumns;
86         this.updateColumns = updateColumns;
87     }
88
89     //////////////////////////////////////////////
90
//
91
// FORMATABLE
92
//
93
//////////////////////////////////////////////
94
/**
95      * Write this object out
96      *
97      * @param out write bytes here
98      *
99      * @exception IOException thrown on error
100      */

101     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
102     {
103         out.writeInt(updateMode);
104         out.writeObject(targetTable);
105         ArrayUtil.writeArray(out, targetColumns);
106         ArrayUtil.writeArray(out, updateColumns);
107     }
108
109     /**
110      * Read this object from a stream of stored objects.
111      *
112      * @param in read this.
113      *
114      * @exception IOException thrown on error
115      * @exception ClassNotFoundException thrown on error
116      */

117     public void readExternal(ObjectInput JavaDoc in)
118         throws IOException JavaDoc, ClassNotFoundException JavaDoc
119     {
120         updateMode = in.readInt();
121         targetTable = (ExecCursorTableReference)in.readObject();
122         int len = ArrayUtil.readArrayLength(in);
123         if (len != 0)
124         {
125             targetColumns = new ResultColumnDescriptor[len];
126             ArrayUtil.readArrayItems(in, targetColumns);
127         }
128         len = ArrayUtil.readArrayLength(in);
129         if (len != 0)
130         {
131             updateColumns = new String JavaDoc[len];
132             ArrayUtil.readArrayItems(in, updateColumns);
133         }
134     }
135     
136     /**
137      * Get the formatID which corresponds to this class.
138      *
139      * @return the formatID of this class
140      */

141     public int getTypeFormatId() { return StoredFormatIds.CURSOR_INFO_V01_ID; }
142
143     public String JavaDoc toString()
144     {
145         if (SanityManager.DEBUG)
146         {
147             StringBuffer JavaDoc strbuf = new StringBuffer JavaDoc();
148         
149             strbuf.append("CursorInfo"+
150                 "\n\tupdateMode: "+updateMode+
151                 "\n\ttargetTable: "+targetTable+
152                 "\n\tupdateColumns: ");
153
154             if (updateColumns == null)
155             {
156                 strbuf.append("NULL\n");
157             }
158             else
159             {
160                 strbuf.append("{");
161                 for (int i = 0; i < updateColumns.length; i++)
162                 {
163                     if (i > 0)
164                         strbuf.append(",");
165                     strbuf.append(updateColumns[i]);
166                 }
167                 strbuf.append(")\n");
168             }
169
170             strbuf.append("\tTargetColumnDescriptors: \n");
171             if (targetColumns == null)
172             {
173                 strbuf.append("NULL");
174             }
175             else
176             {
177                 for (int i = 0; i < targetColumns.length; i++)
178                 {
179                     strbuf.append(targetColumns[i]);
180                 }
181                 strbuf.append("\n");
182             }
183             return strbuf.toString();
184         }
185         else
186         {
187             return "";
188         }
189     }
190 }
191
Popular Tags