001: /*
002:
003: Derby - Class org.apache.derbyTesting.unitTests.store.T_AccessRow
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.derbyTesting.unitTests.store;
023:
024: import org.apache.derby.iapi.store.access.*;
025:
026: import org.apache.derby.iapi.services.io.Storable;
027:
028: import org.apache.derby.iapi.types.DataValueDescriptor;
029:
030: import org.apache.derby.iapi.types.CloneableObject;
031:
032: import org.apache.derby.iapi.types.SQLInteger;
033:
034: import org.apache.derby.iapi.error.StandardException;
035:
036: public class T_AccessRow {
037:
038: protected DataValueDescriptor column[];
039:
040: /**
041: Construct a new row which can hold the provided number of columns.
042: **/
043: public T_AccessRow(int ncols) {
044: column = new DataValueDescriptor[ncols];
045: for (int i = 0; i < ncols; i++)
046: column[i] = new SQLInteger(0);
047: }
048:
049: /**
050: Construct a new row with three integer columns which
051: have the column values provided.
052: **/
053: public T_AccessRow(int col0value, int col1value, int col2value) {
054: column = new DataValueDescriptor[3];
055: column[0] = new SQLInteger(col0value);
056: column[1] = new SQLInteger(col1value);
057: column[2] = new SQLInteger(col2value);
058: }
059:
060: public DataValueDescriptor getCol(int colid) {
061: if (colid >= column.length)
062: return null;
063: else
064: return column[colid];
065: }
066:
067: public void setCol(int colid, DataValueDescriptor val) {
068: if (colid >= column.length)
069: realloc(colid + 1);
070: column[colid] = val;
071: }
072:
073: public boolean equals(T_AccessRow other) throws StandardException {
074: if (other == null)
075: return false;
076: if (other.column.length != this .column.length)
077: return false;
078: for (int i = 0; i < this .column.length; i++)
079: if (this .column[i].compare(other.column[i]) != 0)
080: return false;
081: return true;
082: }
083:
084: public String toString() {
085: String s = "{ ";
086: for (int i = 0; i < column.length; i++) {
087: s += column[i].toString();
088: if (i < (column.length - 1))
089: s += ", ";
090: }
091: s += " }";
092: return s;
093: }
094:
095: // Set the number of columns in the row to ncols, preserving
096: // the existing contents.
097: protected void realloc(int ncols) {
098: DataValueDescriptor newcol[] = new DataValueDescriptor[ncols];
099: for (int i = 0; i < column.length; i++)
100: newcol[i] = column[i];
101: column = newcol;
102: }
103:
104: public Storable getStorableColumn(int colid) {
105: return column[colid];
106: }
107:
108: public void setStorableColumn(int colid, Storable value) {
109: column[colid] = (DataValueDescriptor) value;
110: }
111:
112: public int nColumns() {
113: return column.length;
114: }
115:
116: public DataValueDescriptor[] getRowArray() {
117: return column;
118: }
119:
120: public DataValueDescriptor[] getRowArrayClone() {
121: DataValueDescriptor[] retval = new DataValueDescriptor[column.length];
122: for (int index = 0; index < column.length; index++)
123: retval[index] = column[index].getClone();
124: return retval;
125: }
126: }
|