001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.harmony.sql.internal.rowset;
018:
019: import java.sql.SQLException;
020: import java.util.BitSet;
021:
022: public class CachedRow implements Cloneable {
023: private Object[] columnData;
024:
025: private Object[] originalColumnData;
026:
027: private BitSet mask;
028:
029: private boolean isDelete;
030:
031: private boolean isInsert;
032:
033: private boolean isUpdate;
034:
035: private boolean nonUpdateable = false;
036:
037: public CachedRow(Object[] columnData) {
038: this .columnData = columnData.clone();
039: originalColumnData = columnData.clone();
040: mask = new BitSet(columnData.length);
041: }
042:
043: public boolean getUpdateMask(int i) {
044: return mask.get(i);
045: }
046:
047: public void setUpdateMask(int i) {
048: mask.set(i);
049: }
050:
051: public void setUnavailable() {
052: // FIXME: What is this method used for?
053: setDelete();
054: setInsert();
055: mask.clear();
056: mask.flip(0, columnData.length);
057: }
058:
059: public void setNonUpdateable() {
060: // setDelete();
061: // setInsert();
062: // mask.clear();
063: // mask.flip(0,columnData.length);
064: nonUpdateable = true;
065: }
066:
067: public boolean getNonUpdateable() {
068: return nonUpdateable;
069: }
070:
071: public void setDelete() {
072: isDelete = true;
073: isUpdate = false;
074: isInsert = false;
075: }
076:
077: public void undoDelete() {
078: isDelete = false;
079: }
080:
081: public boolean isDelete() {
082: return isDelete;
083: }
084:
085: public void setInsert() {
086: isInsert = true;
087: isUpdate = false;
088: isDelete = false;
089: }
090:
091: public boolean isInsert() {
092: return isInsert;
093: }
094:
095: public void setUpdate() {
096: isUpdate = true;
097: isInsert = false;
098: isDelete = false;
099: }
100:
101: public void undoUpdate() {
102: isUpdate = false;
103: mask.flip(0, columnData.length);
104: columnData = originalColumnData.clone();
105: }
106:
107: public boolean isUpdate() {
108: return isUpdate;
109: }
110:
111: public void updateObject(int columnIndex, Object x)
112: throws SQLException {
113: if (nonUpdateable) {
114: // TODO load message from resource file
115: throw new SQLException("Not Updateable of the CurrentRow");
116: }
117:
118: columnData[columnIndex - 1] = x;
119: setUpdateMask(columnIndex - 1);
120: }
121:
122: public CachedRow getOriginal() {
123: return new CachedRow(originalColumnData);
124: }
125:
126: public Object getObject(int columnIndex) {
127: return columnData[columnIndex - 1];
128: }
129:
130: // deep clone
131: public CachedRow createClone() throws CloneNotSupportedException {
132: CachedRow cr = (CachedRow) super .clone();
133:
134: Object[] cd = new Object[columnData.length];
135: for (int i = 0; i < columnData.length; i++) {
136: cd[i] = columnData[i];
137: }
138: cr.columnData = cd;
139: cr.isInsert = isInsert;
140: cr.isDelete = isDelete;
141: cr.isUpdate = isUpdate;
142: cr.mask = (BitSet) mask.clone();
143: cr.nonUpdateable = nonUpdateable;
144: // cr.originalColumnData
145: return cr;
146: }
147: }
|