wpi.associations.arminerSequence
Class DBWriter

java.lang.Object
  extended bywpi.associations.arminerSequence.DBWriter

public class DBWriter
extends java.lang.Object

Used to write itemsets into a database.

Author:
Dana Cristofor, Laurentiu Cristofor

Field Summary
private static int ATTRIB_INDEX_SIZE
           
private  long attribIndexOffset
           
private static int CHAR_SIZE
           
private static int COLUMN_LENGTH
           
private static int COLUMN_NAME_OFFSET
           
private static int COLUMN_SIZE
           
private  int CRC
           
private static int CRC_SIZE
           
private  java.lang.String description
           
private static int DESCRIPTION_LENGTH
           
private static int DESCRIPTION_SIZE
           
private  long descriptionOffset
           
private static int HEAD_SIZE_OFFSET
           
private static int HEADER_SIZE
           
private  long headerSize
           
private static java.lang.String ID
           
private static int ID_SIZE
           
private static int INT_SIZE
           
private  long lastPosition
           
private static int LONG_SIZE
           
private  boolean needReposition
           
private  long numAttribs
           
private static int NUMATTRIBS_OFFSET
           
private static int NUMATTRIBS_SIZE
           
private  long numColumns
           
private static int NUMCOLUMNS_OFFSET
           
private static int NUMCOLUMNS_SIZE
           
private  long numRows
           
private static int NUMROWS_OFFSET
           
private static int NUMROWS_SIZE
           
private  java.io.RandomAccessFile outStream
           
private  boolean rowsWritten
           
private static int VERSION_OFFSET
           
private static int VERSION_SIZE
           
private  boolean wroteAttribIndexes
           
private  boolean wroteColumnNames
           
 
Constructor Summary
DBWriter(java.lang.String fileName)
          Create a new DBWriter according to the input file name.
 
Method Summary
 void addRow(ARMinerItemset itemset)
          Add a new row to the database.
private  void checkID()
           
 void close()
          Close the I/O stream and save any unsaved data.
static void main(java.lang.String[] args)
           
 void setAttributeIndexes(java.util.Vector indexes)
          Set the indexes of the attributes.
 void setColumnNames(java.util.Vector names)
          Set the column names for the database.
 void setDescription(java.lang.String description)
          Set the description of the database.
static int updateCRC(int crc, int value)
          Update a CRC-16 value.
private  void writeAttributeIndexes(java.util.Vector indexes)
           
private  void writeColumnNames(java.util.Vector names)
           
private  void writeDescription()
           
private  void writeVersion()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHAR_SIZE

private static final int CHAR_SIZE
See Also:
Constant Field Values

INT_SIZE

private static final int INT_SIZE
See Also:
Constant Field Values

LONG_SIZE

private static final int LONG_SIZE
See Also:
Constant Field Values

CRC_SIZE

private static final int CRC_SIZE
See Also:
Constant Field Values

COLUMN_LENGTH

private static final int COLUMN_LENGTH
See Also:
Constant Field Values

DESCRIPTION_LENGTH

private static final int DESCRIPTION_LENGTH
See Also:
Constant Field Values

ID_SIZE

private static final int ID_SIZE
See Also:
Constant Field Values

VERSION_SIZE

private static final int VERSION_SIZE
See Also:
Constant Field Values

HEADER_SIZE

private static final int HEADER_SIZE
See Also:
Constant Field Values

NUMROWS_SIZE

private static final int NUMROWS_SIZE
See Also:
Constant Field Values

NUMCOLUMNS_SIZE

private static final int NUMCOLUMNS_SIZE
See Also:
Constant Field Values

COLUMN_SIZE

private static final int COLUMN_SIZE
See Also:
Constant Field Values

DESCRIPTION_SIZE

private static final int DESCRIPTION_SIZE
See Also:
Constant Field Values

NUMATTRIBS_SIZE

private static final int NUMATTRIBS_SIZE
See Also:
Constant Field Values

ATTRIB_INDEX_SIZE

private static final int ATTRIB_INDEX_SIZE
See Also:
Constant Field Values

VERSION_OFFSET

private static final int VERSION_OFFSET
See Also:
Constant Field Values

HEAD_SIZE_OFFSET

private static final int HEAD_SIZE_OFFSET
See Also:
Constant Field Values

NUMROWS_OFFSET

private static final int NUMROWS_OFFSET
See Also:
Constant Field Values

NUMCOLUMNS_OFFSET

private static final int NUMCOLUMNS_OFFSET
See Also:
Constant Field Values

NUMATTRIBS_OFFSET

private static final int NUMATTRIBS_OFFSET
See Also:
Constant Field Values

COLUMN_NAME_OFFSET

private static final int COLUMN_NAME_OFFSET
See Also:
Constant Field Values

ID

private static final java.lang.String ID
See Also:
Constant Field Values

outStream

private java.io.RandomAccessFile outStream

description

private java.lang.String description

numRows

private long numRows

numColumns

private long numColumns

numAttribs

private long numAttribs

CRC

private int CRC

headerSize

private long headerSize

wroteColumnNames

private boolean wroteColumnNames

wroteAttribIndexes

private boolean wroteAttribIndexes

needReposition

private boolean needReposition

rowsWritten

private boolean rowsWritten

lastPosition

private long lastPosition

descriptionOffset

private long descriptionOffset

attribIndexOffset

private long attribIndexOffset
Constructor Detail

DBWriter

public DBWriter(java.lang.String fileName)
         throws java.io.IOException
Create a new DBWriter according to the input file name.

Parameters:
fileName - the name of the file
Throws:
java.io.FileNotFoundException - from library call
java.io.IOException - from library call or if file is corrupted
Method Detail

checkID

private void checkID()
              throws java.io.IOException
Throws:
java.io.IOException

writeVersion

private void writeVersion()
                   throws java.io.IOException
Throws:
java.io.IOException

writeColumnNames

private void writeColumnNames(java.util.Vector names)
                       throws java.io.IOException
Throws:
java.io.IOException

writeDescription

private void writeDescription()
                       throws java.io.IOException
Throws:
java.io.IOException

writeAttributeIndexes

private void writeAttributeIndexes(java.util.Vector indexes)
                            throws java.io.IOException
Throws:
java.io.IOException

setColumnNames

public void setColumnNames(java.util.Vector names)
                    throws java.io.IOException,
                           DBException
Set the column names for the database.

Parameters:
names - the column names
Throws:
java.io.IOException - from library call
DBException - size of names does not match number of columns

setAttributeIndexes

public void setAttributeIndexes(java.util.Vector indexes)
                         throws java.io.IOException,
                                DBException
Set the indexes of the attributes. This must be calles AFTER setColumnNames, and BEFORE any rows are added, but it may be called again, after rows are added, to change the attribute indexes. However, the number of attributes must remain the same.

Parameters:
indexes - a Vector of Longs - the indexes of the attributes
Throws:
java.io.IOException - from library call
DBException

setDescription

public void setDescription(java.lang.String description)
                    throws java.io.IOException
Set the description of the database.

Parameters:
description - the description of the database
Throws:
java.io.IOException - from library call

addRow

public void addRow(ARMinerItemset itemset)
            throws java.io.IOException,
                   DBException
Add a new row to the database. If this is to be the first row added to the database you must have called setColumnNames() and setAttributeIndexes() before.

Parameters:
itemset - the new row to be added to the data file
Throws:
java.io.IOException - from library call
DBException - column names have not been set or an invalid item was contained in the itemset

close

public void close()
           throws java.io.IOException
Close the I/O stream and save any unsaved data.

Throws:
java.io.IOException - from library call

updateCRC

public static int updateCRC(int crc,
                            int value)
Update a CRC-16 value.

Parameters:
crc - the previous CRC value
value - the value for which we update the CRC
Returns:
the updated CRC value

main

public static void main(java.lang.String[] args)