Methods Summary |
---|
public void | clearWarnings()
setWarning(null);
|
public void | close()
try {
if (rafSDF != null) {
rafSDF.close();
}
if (rafSBF != null) {
rafSBF.close();
}
}
catch (Exception ex) {
}
|
protected boolean | filterRow(java.util.Hashtable values, jdbc.SimpleText.SimpleTextFilter filter)
if (filter == null) {
return true;
}
boolean valid = false;
// Get the column number
int column = filter.column.colNo;
// Get the data for the column
CommonValue value = (CommonValue) values.get(new Integer(column));
// If we didn't find the column, invalidate the column
if (value == null) {
return false;
}
switch(filter.column.type) {
// Perform integer comparisions
case Types.INTEGER:
{
int icol = value.getInt();
int ifilter = filter.value.getInt();
switch (filter.operator) {
case SimpleTextFilter.OP_EQ:
valid = (icol == ifilter);
break;
case SimpleTextFilter.OP_GT:
valid = (icol > ifilter);
break;
case SimpleTextFilter.OP_LT:
valid = (icol < ifilter);
break;
case SimpleTextFilter.OP_NE:
valid = (icol != ifilter);
break;
}
}
break;
// By default, compare as a string
default:
{
String scol = value.getString();
String sfilter = filter.value.getString();
switch (filter.operator) {
case SimpleTextFilter.OP_EQ:
valid = (scol.equals(sfilter));
break;
case SimpleTextFilter.OP_GT:
valid = (scol.compareTo(sfilter) > 0);
break;
case SimpleTextFilter.OP_LT:
valid = (scol.compareTo(sfilter) < 0);
break;
case SimpleTextFilter.OP_NE:
valid = (!scol.equals(sfilter));
break;
}
}
break;
}
return valid;
|
public int | findColumn(java.lang.String columnName)
// Make a mapping cache if we don't already have one.
if (md == null) {
md = getMetaData();
s2c = new Hashtable();
}
// Look for the mapping in our cache
Integer x = (Integer) s2c.get(columnName);
if (x != null) {
return (x.intValue());
}
// OK, we'll have to use metadata
for (int i = 1; i <= md.getColumnCount(); i++) {
if (md.getColumnName(i).equalsIgnoreCase(columnName)) {
// Success! Add an entry to the cache
s2c.put(columnName, new Integer(i));
return (i);
}
}
throw new SQLException("Column name not found: " + columnName,
"S0022");
|
public java.io.InputStream | getAsciiStream(int columnIndex)
// Binary InputStreams are the only InputStream types supported
throw DataTypeNotSupported();
|
public java.io.InputStream | getAsciiStream(java.lang.String columnName)
return getAsciiStream(findColumn(columnName));
|
public java.math.BigDecimal | getBigDecimal(int columnIndex, int scale)
String s = getString(columnIndex);
java.math.BigDecimal d = null;
if (s != null) {
java.math.BigInteger i = new java.math.BigInteger(s);
d = new java.math.BigDecimal (i, scale);
}
return d;
|
public java.math.BigDecimal | getBigDecimal(java.lang.String columnName, int scale)
return getBigDecimal(findColumn(columnName), scale);
|
public java.io.InputStream | getBinaryStream(int columnIndex)
// Verify the column
verify(columnIndex);
CommonValue value = null;
if (inMemoryRows != null) {
value = getColumn(rowNum, columnIndex);
}
else {
value = getValue(columnIndex);
}
int length = -1;
// Get the length, if possible
if (value != null) {
byte b[] = value.getBytes();
if (b != null) {
length = b.length;
}
}
SimpleTextInputStream inputStream = new SimpleTextInputStream(
value, SimpleTextInputStream.STREAM_TYPE_BINARY,
length);
return inputStream;
|
public java.io.InputStream | getBinaryStream(java.lang.String columnName)
return getBinaryStream(findColumn(columnName));
|
public boolean | getBoolean(java.lang.String columnName)
return getBoolean(findColumn(columnName));
|
public boolean | getBoolean(int columnIndex)
// We could coerce the data, but for now an exception is thrown
throw DataTypeNotSupported();
|
public byte | getByte(java.lang.String columnName)
return getByte(findColumn(columnName));
|
public byte | getByte(int columnIndex)
// We could coerce the data, but for now an exception is thrown
throw DataTypeNotSupported();
|
public byte[] | getBytes(int columnIndex)
// Verify the column
verify(columnIndex);
byte b[] = null;
if (inMemoryRows != null) {
b = (getColumn(rowNum, columnIndex)).getBytes();
}
else {
CommonValue value = getValue(columnIndex);
if (value != null) {
b = value.getBytes();
}
}
if (b == null) {
lastNull = true;
}
return b;
|
public byte[] | getBytes(java.lang.String columnName)
return getBytes(findColumn(columnName));
|
protected CommonValue | getColumn(int rowNum, int column)
// First, get the row
Hashtable row = (Hashtable) inMemoryRows.get(new Integer(rowNum));
if (row == null) {
throw new SQLException("Invalid row number: " + rowNum);
}
// Get the value
CommonValue value = (CommonValue) row.get(new Integer(column));
if (value == null) {
// Column wasn't found. Return a null value
value = new CommonValue();
}
return value;
|
protected SimpleTextColumn | getColumn(int col)
SimpleTextColumn column = (SimpleTextColumn)
inMemoryColumns.get(new Integer(col));
if (column == null) {
throw new SQLException("Invalid column number: " + col);
}
return column;
|
public java.lang.String | getCursorName()
// The SimpleText driver does not support positioned updates
throw DriverNotCapable();
|
public java.sql.Date | getDate(int columnIndex)
// We could coerce the data, but for now an exception is thrown
throw DataTypeNotSupported();
|
public java.sql.Date | getDate(java.lang.String columnName)
return getDate(findColumn(columnName));
|
public double | getDouble(int columnIndex)
// We could coerce the data, but for now an exception is thrown
throw DataTypeNotSupported();
|
public double | getDouble(java.lang.String columnName)
return getDouble(findColumn(columnName));
|
public float | getFloat(int columnIndex)
// We could coerce the data, but for now an exception is thrown
throw DataTypeNotSupported();
|
public float | getFloat(java.lang.String columnName)
return getFloat(findColumn(columnName));
|
public int | getInt(int columnIndex)
// Verify the column
verify(columnIndex);
CommonValue value;
if (inMemoryRows != null) {
value = getColumn(rowNum, columnIndex);
}
else {
value = getValue(columnIndex);
}
// Check for a null value
if (value == null) {
lastNull = true;
return 0;
}
if (value.isNull()) {
lastNull = true;
return 0;
}
return value.getInt();
|
public int | getInt(java.lang.String columnName)
return getInt(findColumn(columnName));
|
public long | getLong(int columnIndex)
// We could coerce the data, but for now an exception is thrown
throw DataTypeNotSupported();
|
public long | getLong(java.lang.String columnName)
return getLong(findColumn(columnName));
|
public java.sql.ResultSetMetaData | getMetaData()
SimpleTextResultSetMetaData md = new SimpleTextResultSetMetaData();
md.initialize(inMemoryColumns, ownerConnection.isReadOnly());
return md;
|
public java.lang.Object | getObject(int columnIndex)
// Verify the column
verify(columnIndex);
// Get the data type of the column
int type = (getColumn(columnIndex)).type;
// The CommonValue for the column
CommonValue value;
if (inMemoryRows != null) {
value = getColumn(rowNum, columnIndex);
}
else {
value = getValue(columnIndex);
}
// Check for a null value
if (value == null) {
lastNull = true;
return null;
}
if (value.isNull()) {
lastNull = true;
return null;
}
Object o = null;
// Return the appropriate object for the given type
switch(type) {
case Types.VARCHAR:
o = value.getString();
break;
case Types.INTEGER:
o = new Integer(value.getInt());
break;
case Types.VARBINARY:
o = value.getBytes();
break;
default:
throw DataTypeNotSupported();
}
return o;
|
public java.lang.Object | getObject(java.lang.String columnName)
return getObject(findColumn(columnName));
|
public short | getShort(java.lang.String columnName)
return getShort(findColumn(columnName));
|
public short | getShort(int columnIndex)
// We could coerce the data, but for now an exception is thrown
throw DataTypeNotSupported();
|
public java.lang.String | getString(java.lang.String columnName)
return getString(findColumn(columnName));
|
public java.lang.String | getString(int columnIndex)
// Verify the column
verify(columnIndex);
String s = null;
if (inMemoryRows != null) {
s = (getColumn(rowNum, columnIndex)).getString();
}
else {
CommonValue value = getValue(columnIndex);
if (value != null) {
s = value.getString();
}
}
if (s == null) {
lastNull = true;
}
return s;
|
public java.sql.Time | getTime(int columnIndex)
// We could coerce the data, but for now an exception is thrown
throw DataTypeNotSupported();
|
public java.sql.Time | getTime(java.lang.String columnName)
return getTime(findColumn(columnName));
|
public java.sql.Timestamp | getTimestamp(int columnIndex)
// We could coerce the data, but for now an exception is thrown
throw DataTypeNotSupported();
|
public java.sql.Timestamp | getTimestamp(java.lang.String columnName)
return getTimestamp(findColumn(columnName));
|
public java.io.InputStream | getUnicodeStream(int columnIndex)
// Binary InputStreams are the only InputStream types supported
throw DataTypeNotSupported();
|
public java.io.InputStream | getUnicodeStream(java.lang.String columnName)
return getUnicodeStream(findColumn(columnName));
|
protected CommonValue | getValue(int column)
CommonValue value;
// Get the column definition (we already know it's there)
SimpleTextColumn col = (SimpleTextColumn) inMemoryColumns.get(
new Integer(column));
// value = (CommonValue) columnValues.get(new Integer(column));
value = (CommonValue) columnValues.get(new Integer(col.colNo));
if (value == null) {
return null;
}
switch(col.type) {
// For binary types, read the binary file
case Types.VARBINARY:
{
byte b[] = readSBF(value.getInt());
value = new CommonValue(b);
}
break;
}
return value;
|
public java.sql.SQLWarning | getWarnings()
return lastWarning;
|
public void | initialize(SimpleTextIStatement statement, java.lang.String catalog, java.lang.String table, java.util.Hashtable columns, jdbc.SimpleText.SimpleTextFilter filter)
// Save the owning statement object
ownerStatement = statement;
ownerConnection = ownerStatement.getConnection();
// Save the in-memory column definitions
inMemoryColumns = columns;
// Save the select WHERE filter
selectFilter = filter;
// If a table was given, open it now
if (table != null) {
openSDF(catalog, table);
}
|
public void | initialize(SimpleTextIStatement statement, java.util.Hashtable columns, java.util.Hashtable rows)
// Save the in-memory rows (used for catalog functions)
inMemoryRows = rows;
rowNum = 0;
initialize(statement, null, null, columns, null);
|
public boolean | next()
boolean rc = true;
boolean validRow = false;
// In memory result set, get the next row
if (inMemoryRows != null) {
rowNum++;
// No more rows, return end-of-file
if (rowNum > inMemoryRows.size()) {
rc = false;
}
}
else {
// Not in-memory, read the next line from the file until a
// valid row has been found
while (!validRow) {
currentLine = readLine(rafSDF);
if (currentLine == null) {
rc = false;
break;
}
// We'll cheat a little bit here. We'll use the SQL
// parser to break the line up, then treat it as a
// comma separated list (much like a select list)
String data[] = ownerConnection.parseSQL(currentLine);
Hashtable dataList = new Hashtable();
ownerStatement.buildList(data, 0, "", dataList);
// Now go through each data element and create a
// CommonValue object. Then, put the CommonValue object
// on our columnValues list
SimpleTextColumn column;
columnValues = new Hashtable();
String s;
CommonValue value;
for (int i = 1; i <= dataList.size(); i++) {
column = (SimpleTextColumn) dataList.get(new Integer(i));
// Get the data item
s = column.name;
// Remove any quotes
if (s.startsWith("'") &&
s.endsWith("'")) {
s = s.substring(1, s.length() - 1);
}
// Create a CommonValue object using the string
value = new CommonValue(s);
// Create a CommonValue object
columnValues.put(new Integer(i), value);
}
// Filter the row, if necessary
validRow = filterRow(columnValues, selectFilter);
}
}
return rc;
|
protected void | openSDF(java.lang.String catalog, java.lang.String table)
String fullName = catalog + "/" + table +
SimpleTextDefine.DATA_FILE_EXT;
String sbfName = catalog + "/" + table +
SimpleTextDefine.BINARY_FILE_EXT;
// Make sure the file exists
SDF = new File(fullName);
SBF = new File(sbfName);
if (!SDF.exists()) {
throw new SQLException("Text file does not exist: " + fullName);
}
try {
// Create our random access object (read only)
rafSDF = new RandomAccessFile(SDF, "r");
}
catch (Exception ex) {
throw new SQLException("Unable to access file: " +ex.getMessage());
}
// Read past the first line (the column definitions). Before
// we got to this point, the Statement object verified that
// it is a valid file
readLine(rafSDF);
|
protected java.lang.String | readLine(java.io.RandomAccessFile f)
String s = null;
try {
if (f.getFilePointer() >= f.length()) {
return null;
}
s = f.readLine();
}
catch (Exception ex) {
throw new SQLException("Error reading file: " + ex.getMessage());
}
return s;
|
protected byte[] | readSBF(int offset)
// Invalid offset, return null
if (offset < 0) {
return null;
}
byte b[] = null;
// First time, check to make sure it exists
if (rafSBF == null) {
if (!SBF.exists()) {
throw new SQLException("Binary file does not exist");
}
}
try {
// First time, create random access file object
if (rafSBF == null) {
rafSBF = new RandomAccessFile(SBF, "r");
}
// Position to the given offset
rafSBF.seek(offset);
// Make sure there is enough file to read an int
if ((rafSBF.getFilePointer() + 4) > rafSBF.length()) {
throw new SQLException("Attempt to read beyond end-of-file");
}
// Read the length of the data
int len = rafSBF.readInt();
// Make sure there's enough data to read
if ((rafSBF.getFilePointer() + len) > rafSBF.length()) {
throw new SQLException("Attempt to read beyond end-of-file");
}
b = new byte[len];
rafSBF.read(b);
}
catch (Exception ex) {
throw new SQLException("Unable to access SBF: " + ex.getMessage());
}
return b;
|
protected void | setWarning(java.sql.SQLWarning warning)
if (warning == null) {
lastWarning = null;
}
else {
SQLWarning chain = lastWarning;
// Find the end of the chain
while (chain.getNextWarning() != null) {
chain = chain.getNextWarning();
}
// We're at the end of the chain. Add the new warning
chain.setNextWarning(warning);
}
|
protected int | verify(int column)
clearWarnings();
lastNull = false;
SimpleTextColumn col = (SimpleTextColumn) inMemoryColumns.get(
new Integer(column));
if (col == null) {
throw new SQLException("Invalid column number: " + column);
}
return col.colNo;
|
public boolean | wasNull()
return lastNull;
|