KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > unitTests > store > T_AccessRow


1 /*
2
3    Derby - Class org.apache.derbyTesting.unitTests.store.T_AccessRow
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.derbyTesting.unitTests.store;
23
24 import org.apache.derby.iapi.store.access.*;
25
26 import org.apache.derby.iapi.services.io.Storable;
27
28 import org.apache.derby.iapi.types.DataValueDescriptor;
29
30 import org.apache.derby.iapi.types.CloneableObject;
31
32 import org.apache.derby.iapi.types.SQLInteger;
33
34 import org.apache.derby.iapi.error.StandardException;
35
36 public class T_AccessRow
37 {
38
39     protected DataValueDescriptor column[];
40
41     /**
42     Construct a new row which can hold the provided number of columns.
43     **/

44     public T_AccessRow(int ncols)
45     {
46          column = new DataValueDescriptor[ncols];
47          for (int i = 0; i < ncols; i++)
48              column[i] = new SQLInteger(0);
49     }
50
51     /**
52     Construct a new row with three integer columns which
53     have the column values provided.
54     **/

55     public T_AccessRow(int col0value, int col1value, int col2value)
56     {
57         column = new DataValueDescriptor[3];
58         column[0] = new SQLInteger(col0value);
59         column[1] = new SQLInteger(col1value);
60         column[2] = new SQLInteger(col2value);
61     }
62
63     public DataValueDescriptor getCol(int colid)
64     {
65         if (colid >= column.length)
66             return null;
67         else
68             return column[colid];
69     }
70
71     public void setCol(int colid, DataValueDescriptor val)
72     {
73         if (colid >= column.length)
74             realloc(colid + 1);
75         column[colid] = val;
76     }
77
78     public boolean equals(T_AccessRow other) throws StandardException
79     {
80         if (other == null)
81             return false;
82         if (other.column.length != this.column.length)
83             return false;
84         for (int i = 0; i < this.column.length; i++)
85             if (this.column[i].compare(other.column[i]) != 0)
86                 return false;
87         return true;
88     }
89
90     public String JavaDoc toString()
91     {
92         String JavaDoc s = "{ ";
93         for (int i = 0; i < column.length; i++)
94         {
95             s += column[i].toString();
96             if (i < (column.length - 1))
97                 s += ", ";
98         }
99         s += " }";
100         return s;
101     }
102
103     // Set the number of columns in the row to ncols, preserving
104
// the existing contents.
105
protected void realloc(int ncols)
106     {
107         DataValueDescriptor newcol[] = new DataValueDescriptor[ncols];
108         for (int i = 0; i < column.length; i++)
109             newcol[i] = column[i];
110         column = newcol;
111     }
112
113     public Storable getStorableColumn(int colid)
114     {
115         return column[colid];
116     }
117
118     public void setStorableColumn(int colid, Storable value) {
119         column[colid] = (DataValueDescriptor) value;
120     }
121
122     public int nColumns()
123     {
124         return column.length;
125     }
126
127     public DataValueDescriptor[] getRowArray() {
128         return column;
129     }
130
131     public DataValueDescriptor[] getRowArrayClone() {
132         DataValueDescriptor[] retval = new DataValueDescriptor[column.length];
133         for (int index = 0; index < column.length; index++)
134             retval[index] = column[index].getClone();
135         return retval;
136     }
137 }
138
139
140
141
142
Popular Tags