1 package com.daffodilwoods.daffodildb.odbc; 2 3 import java.sql.*; 4 5 import com.daffodilwoods.daffodildb.client.*; 6 import com.daffodilwoods.database.resource.*; 7 import in.co.daffodil.db.jdbc.*; 8 9 public class OdbcResultSet extends OdbcResultSetMetaData{ 10 11 public OdbcResultSet(){} 12 13 public OdbcResultSet(String path){ 14 } 15 16 public Object getObjectAtFetch(Object resultObject, int index, 17 int requiredType) throws Exception { 18 _RecordSetBufferIterator rsbi = (_RecordSetBufferIterator) resultObject; 19 Object value = rsbi.getColumnValue(index); 20 if (value != null){ 21 if(value instanceof byte[] && requiredType == Types.CHAR) 22 value = new String ((byte[]) value); 23 else 24 value = Utilities.convertObject(value, requiredType); 25 } 26 return value; 27 } 28 29 30 public short getShort(Object retObj, int columnIndex) throws Exception { 31 Number shortVal = (Number ) getObjectAtFetch(retObj, columnIndex, 32 Types.SMALLINT); 33 return shortVal == null ? (short) 0 : shortVal.shortValue(); 34 } 35 36 public int getInt(Object retObj, int columnIndex) throws Exception { 37 Number intVal = (Number ) getObjectAtFetch(retObj, columnIndex, 38 Types.INTEGER); 39 return intVal == null ? (int) 0 : intVal.intValue(); 40 } 41 42 public double getDouble(Object retObj, int columnIndex) throws Exception { 43 Number doubleVal = (Number ) getObjectAtFetch(retObj, columnIndex, 44 Types.DOUBLE); 45 return doubleVal == null ? (double) 0 : doubleVal.doubleValue(); 46 } 47 48 public float getFloat(Object retObj, int columnIndex) throws Exception { 49 Number floatVal = (Number ) getObjectAtFetch(retObj, columnIndex, Types.REAL); 50 return floatVal == null ? (float) 0 : floatVal.floatValue(); 51 } 52 53 public boolean getBoolean(Object retObj, int columnIndex) throws Exception { 54 Boolean boolVal = (Boolean ) getObjectAtFetch(retObj, columnIndex, Types.BIT); 55 return boolVal.booleanValue(); 56 } 57 58 public byte getTinyInt(Object retObj, int columnIndex) throws Exception { 59 Number byteVal = (Number ) getObjectAtFetch(retObj, columnIndex, 60 Types.TINYINT); 61 return byteVal == null ? (byte) 0 : byteVal.byteValue(); 62 } 63 64 public long getBigInt(Object retObj, int columnIndex) throws Exception { 65 Number bigIntVal = (Number ) getObjectAtFetch(retObj, columnIndex, 66 Types.BIGINT); 67 return bigIntVal == null ? (long) 0 : bigIntVal.longValue(); 68 } 69 70 public Object getColumnCharacteristics(Object obj) throws 71 DException { 72 if (obj == null || ! (obj instanceof _RecordSetBufferIterator)) 73 return null; 74 return ( (_RecordSetBufferIterator) obj).getRecordSetBuffer(). 75 getColumnCharacteristics(); 76 } 77 78 public boolean next(Object returnObj) throws Exception { 79 _RecordSetBufferIterator rsbi = (_RecordSetBufferIterator)returnObj; 80 return rsbi.next(); 81 } 82 83 public boolean top(Object returnObj) throws Exception { 84 _RecordSetBufferIterator rsbi = (_RecordSetBufferIterator)returnObj; 85 return rsbi.top(); 86 } 87 88 public boolean previous(Object returnObj)throws Exception { 89 _RecordSetBufferIterator rsbi = (_RecordSetBufferIterator)returnObj; 90 return rsbi.previous(); 91 } 92 93 public boolean bottom(Object returnObj)throws Exception { 94 _RecordSetBufferIterator rsbi = (_RecordSetBufferIterator)returnObj; 95 return rsbi.bottom(); 96 } 97 98 public boolean absolute(Object returnObj,int rows,int rowCount) throws Exception { 99 _RecordSetBufferIterator rsbi = (_RecordSetBufferIterator)returnObj; 100 boolean found = rows > 0 ? rsbi.top() : rsbi.bottom(); 101 if(!found) 102 return false; 103 if( rows == -1 || rows == 1) 104 return found; 105 int absRows = Math.abs(rows); 106 if(absRows >= rowCount){ 107 if(rows > 0 ) 108 rsbi.bottom(); 109 else 110 rsbi.top(); 111 return absRows == rowCount; 112 } 113 if(rows > 0){ 114 for (int i = 1; i < rows; i++) { 115 rsbi.next(); 116 } 117 }else{ 118 for (int i = 1; i < absRows; i++) { 119 rsbi.previous(); 120 } 121 } 122 return true; 123 } 124 125 public boolean relative(Object returnObj,int rows,int rowCount,int currentRow) throws Exception { 126 _RecordSetBufferIterator rsbi = (_RecordSetBufferIterator) returnObj; 127 int endBecomes = currentRow + rows; 128 if (endBecomes <= 0) { 129 rsbi.top(); 130 return false; 131 } 132 if (endBecomes > rowCount) { 133 rsbi.bottom(); 134 return false; 135 } 136 int actualMove = rows; 137 if (currentRow == 0) { 138 actualMove = rows - 1; 139 rsbi.top(); 140 } 141 else if (currentRow > rowCount) { 142 actualMove = rows + 1; 143 } 144 if (actualMove > 0) { 145 for (int i = 1; i < rows; i++) { 146 rsbi.next(); 147 } 148 } 149 else { 150 for (int i = actualMove; i > 1; i--) { 151 rsbi.previous(); 152 } 153 } 154 return true; 155 } 156 157 158 } 159 | Popular Tags |