|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--AsciiDatabase.AsciiTable
A DatabaseTable that can represent any flat ascii file as a table for ModSQL to query. A table definition file describes the format of the ascii file.
| Field Summary | |
private static int |
binfileVersion
Version number of compiled table definition file. |
private ColumnProperties[] |
columns
Properties of the table's columns. |
private static String |
compiledExtension
Filename extension applied to compiled table definition files. |
private int |
dataoffset
Offset of start of data within data files. |
private AsciiReader[] |
datastream
List of data file to read data from. |
private String |
delimiter
Delimiter for delimited files. |
private int |
filenum
File where current pointer is located. |
private int |
maxdelimiter
Max number of delimited fields. |
private String |
name
Name of this table. |
private int |
ncolumns
Number of columns. |
private int |
nfiles
Total number of data files. |
private int |
nsourcerows
Number of rows per data block. |
private RowOption[][] |
options
Each row within a block can have multiple options applied to it before column data is extracted from it. |
private byte[] |
record
Buffer for holding blocks of data. |
private int |
recordsize
Size of fixed length records or -1 for variable length records. |
private int |
recordvalid
Length of valid data within record. |
private long |
rowoffset
Offset of current record within current file. |
private int |
sourceid
Current row within the current record. |
private SourceProperties[][] |
sources
Properties of the table's source rows. |
private static int |
startrecordsize
Initial record size for variable length record files. |
private long |
tablesignature
This table's signature. |
| Constructor Summary | |
AsciiTable(String tablename,
String deffilename)
Open existing table. |
|
AsciiTable(String tablename,
String deffilename,
String datafilename)
Opens existing table. |
|
| Method Summary | |
boolean |
absolute(Object id)
Seek to an absolute row id. |
private static Number |
Add(Number n,
double d)
Add a double to a Number. |
void |
addColumn(String name,
int type,
int maxlen)
Add a column to the database. |
void |
AddDataFile(String datafilename)
Add a new data file to the table. |
void |
addRow()
Add a new row. |
void |
afterLast()
Position pointer after last row. |
void |
beforeFirst()
Position pointer before first row. |
protected long |
calculateTableSignature()
Calculate a unique signature for this table. |
void |
close()
Close the table. |
void |
commitUpdates()
ModSQL will always call this method after performing a series of updateObject() calls on a particular row. |
void |
deleteRow()
Delete the current row. |
private void |
delimitFields()
Delimit fields. |
private static Number |
Divide(Number n,
double d)
Divide a Number by a double. |
private static String |
FilterForNumber(String s)
Filter string of a number. |
protected void |
finalize()
Close files. |
int |
findColumn(String name)
Find a column by name. |
boolean |
findNext(int columnIndex,
Object data)
Find next row containing the specified data. |
int |
getColumnCount()
Get count of columns. |
int |
getColumnDisplaySize(int column)
Get ideal display width for column. |
String |
getColumnLabel(int column)
Get an appropriate lable for the column. |
String |
getColumnName(int column)
Get name of column. |
int |
getColumnType(int column)
Get SQL type of column. |
Object |
getObject(int column)
Read column data. |
long |
getRowCount()
This method is expected to return the total number of rows in the database. |
Object |
getRowId()
Get the id of the current row. |
String |
getTableName()
Get table name. |
long |
getTableSignature()
Get signature for table. |
long |
getTableSize()
Get size of table. |
boolean |
isAfterLast()
Is after last row? |
boolean |
isBeforeFirst()
Is before first row? |
boolean |
isIndexAvailable(int column)
Is a particular column indexed? No. |
boolean |
isReadOnly()
Is the table read only? Yes. |
private static Number |
Multiply(Number n,
double d)
Multiply a double to a Number. |
boolean |
next()
Advance to next row. |
DatabaseIndex |
openIndex(int column)
Open index of specified column. |
private void |
ParseColumnDef(ColumnProperties column,
SourceProperties source,
String columndef,
int offset)
Parse an entire column definition. |
private ColumnOption[] |
ParseColumnOptions(String optionstring)
Parse column options. |
private RowOption |
ParseRowOption(String optionstring)
Parse a row option. |
private int |
ParseType(String type)
Parse column type string. |
private boolean |
ReadCompiledFile(File filename)
Read the compiled (binary) version of the table definition file. |
private void |
ReadRawTableDefinition(File filename)
Read a raw (uncompressed) table definition file. |
protected void |
ReadTableDefinition(String filename)
Read the table definition file. |
private void |
ResetTable(int file)
Reset the table to before the beginning of the specified data file. |
void |
updateObject(int columnIndex,
Object x)
Change column data. |
private void |
WriteCompiledFile(File filename)
Attemp to write the compiled (binary) version of the table definition file. |
private static Number |
Y2K(Number n,
double d)
Convert 2-digit year to 4-digit year. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
private static final int binfileVersion
private static final String compiledExtension
private static final int startrecordsize
private transient AsciiReader[] datastream
private transient int nfiles
private transient int filenum
private int recordsize
private String delimiter
private transient int maxdelimiter
private int dataoffset
private ColumnProperties[] columns
private int ncolumns
private SourceProperties[][] sources
private int nsourcerows
private RowOption[][] options
private transient byte[] record
private transient int recordvalid
private transient long rowoffset
private transient int sourceid
private transient String name
private transient long tablesignature
| Constructor Detail |
public AsciiTable(String tablename,
String deffilename)
throws IOException,
DatabaseException
tablename - name of tabledeffilename - path to table definition fileIOException - if error occurs reading table definitionDatabaseException - if other error occurs
public AsciiTable(String tablename,
String deffilename,
String datafilename)
throws IOException,
DatabaseException
tablename - name of tabledeffilename - path to table definition filedatafilename - path to first data fileIOException - if error reading filesDatabaseException - if other error occurs| Method Detail |
protected void finalize()
finalize in class Object
public void AddDataFile(String datafilename)
throws IOException,
DatabaseException
datafilename - path to data fileIOException - if error reading data fileDatabaseException - if other error occurs
protected void ReadTableDefinition(String filename)
throws DatabaseException,
IOException
filename - path to raw (uncompiled) table definition fileIOException - if error reading file occursDatabaseException - if other error occursprivate boolean ReadCompiledFile(File filename)
filename - File object pointing to binary fileprivate void WriteCompiledFile(File filename)
filename - File object point to binary fileprivate int ParseType(String type)
type - string to parse
private RowOption ParseRowOption(String optionstring)
throws DatabaseException
optionstring - String to parseDatabaseException - if an error occurs
private ColumnOption[] ParseColumnOptions(String optionstring)
throws DatabaseException
optionstring - String to parseDatabaseException - if error occurs
private void ParseColumnDef(ColumnProperties column,
SourceProperties source,
String columndef,
int offset)
throws IOException,
DatabaseException
source_type source_length source_offset column_type column_name options
Obviously, options are optional. Any whitespace can seperate the columns.
column - ColumnProperties object to setsource - SourceProperties object to setcolumndef - ascii line to parseoffset - to be added to source_offset before storing in SourcePropertiesIOException - if an error occursDatabaseException - if an error occurs
private void ReadRawTableDefinition(File filename)
throws DatabaseException
filename - File object pointing to raw fileDatabaseException - if an error occurspublic DatabaseIndex openIndex(int column)
openIndex in interface DatabaseTablecolumn - index of column to find index forpublic void close()
close in interface DatabaseTableBaseModSQL.DatabaseTableBaseDatabaseException - if a database-access error occurspublic boolean isIndexAvailable(int column)
isIndexAvailable in interface DatabaseTablecolumn - index of column that should be indexedpublic boolean isReadOnly()
isReadOnly in interface DatabaseTablepublic String getTableName()
getTableName in interface DatabaseTablepublic int getColumnCount()
getColumnCount in interface DatabaseTablepublic long getTableSize()
getTableSize in interface DatabaseTableprotected long calculateTableSignature()
Any change in the table that would invalidate an index should result in a change of this signature.
public long getTableSignature()
getTableSignature in interface DatabaseTablepublic long getRowCount()
DatabaseTableBasegetRowCount in interface DatabaseTableBaseModSQL.DatabaseTableBaseDatabaseException - if a database-access error occurspublic int findColumn(String name)
findColumn in interface DatabaseTablename - name of column to search forpublic int getColumnDisplaySize(int column)
getColumnDisplaySize in interface DatabaseTablecolumn - index of columnpublic String getColumnLabel(int column)
getColumnLabel in interface DatabaseTablecolumn - index of columnpublic String getColumnName(int column)
getColumnName in interface DatabaseTablecolumn - index of columnpublic int getColumnType(int column)
getColumnType in interface DatabaseTablecolumn - index of column
public void addColumn(String name,
int type,
int maxlen)
throws DatabaseException
addColumn in interface DatabaseTablename - name of new columntype - SQL type of new columnDatabaseException - in case of errorprivate void delimitFields()
public boolean next()
throws DatabaseException
next in interface DatabaseTableBaseDatabaseException - if an error occurs
public boolean findNext(int columnIndex,
Object data)
throws DatabaseException
columnIndex - index of column to contain datadata - data to search forDatabaseException - if an error occured
public void deleteRow()
throws DatabaseException
deleteRow in interface DatabaseTableBaseDatabaseException - if an error occured
public void addRow()
throws DatabaseException
addRow in interface DatabaseTableDatabaseException - if an error occured.public boolean isBeforeFirst()
isBeforeFirst in interface DatabaseTableBasepublic boolean isAfterLast()
isAfterLast in interface DatabaseTableBase
private void ResetTable(int file)
throws DatabaseException
Note that this does not mean that if you reset to before the beggining of file 2, that the pointer is actually at the end of file 1.
file - to position pointer beforeDatabaseException - if an error occurs
public void beforeFirst()
throws DatabaseException
beforeFirst in interface DatabaseTableBaseDatabaseException - if error occurs
public void afterLast()
throws DatabaseException
afterLast in interface DatabaseTableBaseDatabaseException - if error occurspublic Object getRowId()
Get the id of the current row.
The row id is of the form [offset][file][source] where offset is most significant and source is least significant. It is not valid to compare row id's to determine if one row is before or after another. You can compare row id's to determine if two rows are the same row.
getRowId in interface DatabaseTableBase
public boolean absolute(Object id)
throws DatabaseException
absolute in interface DatabaseTableid - row id to seek toDatabaseException - if an error occurs
private static Number Add(Number n,
double d)
throws DatabaseException
n - Number to addd - double to add to the NumberDatabaseException - if n is an invalid type
private static Number Multiply(Number n,
double d)
throws DatabaseException
n - Number to multiplyd - double to multiply to the NumberDatabaseException - if n is an invalid type
private static Number Divide(Number n,
double d)
throws DatabaseException
n - Number to divided - double to divide Number byDatabaseException - if n is an invalid type
private static Number Y2K(Number n,
double d)
throws DatabaseException
n - date to adjustd - maximum date to consider as 2000+dateDatabaseException - if n is an invalid type
private static String FilterForNumber(String s)
throws DatabaseException
Note: 2 is a hack to solve problems with our ROB database
s - string to filterDatabaseException - if an error occurs
public Object getObject(int column)
throws DatabaseException
getObject in interface DatabaseTableBasecolumn - index of column to readDatabaseException - if an error occurs
public void updateObject(int columnIndex,
Object x)
throws DatabaseException
updateObject in interface DatabaseTableBasecolumnIndex - index of column to changex - Object to set column toDatabaseException - if an error occurs
public void commitUpdates()
throws DatabaseException
DatabaseTableBasecommitUpdates in interface DatabaseTableBaseModSQL.DatabaseTableBaseDatabaseException - if a database-access error occurs
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||