001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.platforms.stores.base;
009:
010: //base classes
011: import java.math.BigDecimal;
012: import java.sql.PreparedStatement;
013: import java.sql.ResultSet;
014: import java.sql.SQLException;
015: import java.util.ArrayList;
016:
017: //project specific classes
018: import org.jfolder.common.UnexpectedSystemException;
019:
020: //other classes
021:
022: public class SystemResultSet {
023:
024: private int columns = 0;
025: private ArrayList typeRows = null;
026: private ArrayList valueRows = null;
027:
028: protected SystemResultSet(int inColumns) {
029: this .columns = inColumns;
030: this .typeRows = new ArrayList();
031: this .valueRows = new ArrayList();
032: }
033:
034: public int getColumnCount() {
035: return this .columns;
036: }
037:
038: public int getRowCount() {
039: return this .typeRows.size();
040: }
041:
042: public void addRow(ArrayList inTypes, ArrayList inValues) {
043: this .typeRows.add(inTypes);
044: this .valueRows.add(inValues);
045: }
046:
047: //
048: public BigDecimal getDecimal(int inRow, int inColumn) {
049: return (BigDecimal) getValue(inRow, inColumn,
050: SystemStatement.DECIMAL);
051: }
052:
053: public String getSString(int inRow, int inColumn) {
054: return (String) getValue(inRow, inColumn,
055: SystemStatement.SHORT_STRING);
056: }
057:
058: public String getLString(int inRow, int inColumn) {
059: return (String) getValue(inRow, inColumn,
060: SystemStatement.LONG_STRING);
061: }
062:
063: public Boolean getBoolean(int inRow, int inColumn) {
064: return (Boolean) getValue(inRow, inColumn,
065: SystemStatement.BOOLEAN);
066: }
067:
068: public byte[] getBObject(int inRow, int inColumn) {
069: return (byte[]) getValue(inRow, inColumn,
070: SystemStatement.BINARY_OBJECT);
071: }
072:
073: //
074: private Object getValue(int inRow, int inColumn, Integer inType) {
075:
076: Object outValue = null;
077:
078: Integer type = (Integer) getItem(this .typeRows, inRow, inColumn);
079: //MiscHelper.println("ExpectedType = " + inType);
080: //MiscHelper.println("ActualType = " + type);
081: //MiscHelper.println("Value = "
082: // + getItem(this.valueRows, inRow, inColumn).toString().substring(
083: // 0, 50));
084: if (type.equals(inType)) {
085: outValue = getItem(this .valueRows, inRow, inColumn);
086: } else {
087: throw new UnexpectedSystemException("Type Mismatch");
088: }
089:
090: return outValue;
091: }
092:
093: private Object getItem(ArrayList inList, int inRow, int inColumn) {
094:
095: Object outValue = null;
096:
097: ArrayList columns = (ArrayList) inList.get(inRow);
098: outValue = columns.get(inColumn);
099:
100: return outValue;
101: }
102:
103: public String toString() {
104:
105: StringBuffer outValue = new StringBuffer();
106:
107: outValue.append(" SYSTEM_RESULT_SET\n");
108: outValue.append(" TYPES = " + this .typeRows + "\n");
109: outValue.append(" VALUES = " + this .valueRows + "\n");
110: //for (int i = 0; i < getRowCount(); i++) {
111: // for (int j = 0; j < getColumnCount(); j++) {
112: // Object o = getItem(this.valueRows, i, j);
113: // outValue.append("(" + i + ", " + j + ") = " + o);
114: // }
115: //}
116:
117: return outValue.toString();
118: }
119: }
|