Package com.mckoi.database
Class DataTableDef
- java.lang.Object
-
- com.mckoi.database.DataTableDef
-
public class DataTableDef extends java.lang.Object
A definition of a table. Every table in the database has a definition that describes how it is stored on disk, the column definitions, primary keys/foreign keys, and any check constraints.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Object
COL_LOOKUP_LOCK
private java.util.HashMap
col_name_lookup
private java.util.ArrayList
column_list
The list of DataTableColumnDef objects that are the definitions of each column in the table.private boolean
immutable
Set to true if this data table def is immutable.private TableName
table_name
A TableName object that represents this data table def.private java.lang.String
table_type_class
The type of table this is (this is the class name of the object that maintains the underlying database files).
-
Constructor Summary
Constructors Constructor Description DataTableDef()
Constructs this DataTableDef file.DataTableDef(DataTableDef table_def)
Copy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addColumn(DataTableColumnDef col_def)
void
addVirtualColumn(DataTableColumnDef col_def)
Same as 'addColumn' only this does not perform a check to ensure no two columns are the same.private void
checkMutable()
Checks that this object is mutable.DataTableColumnDef
columnAt(int column)
int
columnCount()
void
dump(java.io.PrintStream out)
Outputs to the PrintStream for debugging.int
fastFindColumnName(java.lang.String col)
A faster way to find a column index given a string column name.int
findColumnName(java.lang.String column_name)
java.lang.String
getName()
java.lang.String
getSchema()
java.lang.String
getTableClass()
TableName
getTableName()
boolean
immutable()
Returns true if this is immutable.DataTableDef
noColumnCopy()
Returns a copy of this object, except with no columns or constraints.(package private) static DataTableDef
read(java.io.DataInput in)
Reads this DataTableDef file from the data input stream.java.lang.String
resolveColumnName(java.lang.String col_name, boolean ignore_case)
Resolves a single column name to its correct form.(package private) void
resolveColumns(boolean ignore_case, Expression exp)
Resolves variables in a column so that any unresolved column names point to this table.void
resolveColumnsInArray(DatabaseConnection connection, java.util.ArrayList list)
Given a list of column names referencing entries in this table, this will resolve each one to its correct form.void
setImmutable()
Sets this DataTableDef to immutable which means nothing is able to change it.void
setTableClass(java.lang.String clazz)
void
setTableName(TableName name)
(package private) void
write(java.io.DataOutput out)
Writes this DataTableDef file to the data output stream.
-
-
-
Field Detail
-
table_name
private TableName table_name
A TableName object that represents this data table def.
-
table_type_class
private java.lang.String table_type_class
The type of table this is (this is the class name of the object that maintains the underlying database files).
-
column_list
private java.util.ArrayList column_list
The list of DataTableColumnDef objects that are the definitions of each column in the table.
-
immutable
private boolean immutable
Set to true if this data table def is immutable.
-
col_name_lookup
private transient java.util.HashMap col_name_lookup
-
COL_LOOKUP_LOCK
private transient java.lang.Object COL_LOOKUP_LOCK
-
-
Constructor Detail
-
DataTableDef
public DataTableDef()
Constructs this DataTableDef file.
-
DataTableDef
public DataTableDef(DataTableDef table_def)
Copy constructor.
-
-
Method Detail
-
setImmutable
public void setImmutable()
Sets this DataTableDef to immutable which means nothing is able to change it.
-
immutable
public boolean immutable()
Returns true if this is immutable.
-
checkMutable
private void checkMutable()
Checks that this object is mutable. If it isn't an exception is thrown.
-
dump
public void dump(java.io.PrintStream out)
Outputs to the PrintStream for debugging.
-
resolveColumns
void resolveColumns(boolean ignore_case, Expression exp)
Resolves variables in a column so that any unresolved column names point to this table. Used to resolve columns in the 'check_expression'.
-
resolveColumnName
public java.lang.String resolveColumnName(java.lang.String col_name, boolean ignore_case) throws DatabaseException
Resolves a single column name to its correct form. For example, if the database is in case insensitive mode it'll resolve ID to 'id' if 'id' is in this table. Throws a database exception if a column couldn't be resolved (ambiguous or not found).- Throws:
DatabaseException
-
resolveColumnsInArray
public void resolveColumnsInArray(DatabaseConnection connection, java.util.ArrayList list) throws DatabaseException
Given a list of column names referencing entries in this table, this will resolve each one to its correct form. Throws a database exception if a column couldn't be resolved.- Throws:
DatabaseException
-
setTableName
public void setTableName(TableName name)
-
setTableClass
public void setTableClass(java.lang.String clazz)
-
addColumn
public void addColumn(DataTableColumnDef col_def)
-
addVirtualColumn
public void addVirtualColumn(DataTableColumnDef col_def)
Same as 'addColumn' only this does not perform a check to ensure no two columns are the same.
-
getSchema
public java.lang.String getSchema()
-
getName
public java.lang.String getName()
-
getTableName
public TableName getTableName()
-
getTableClass
public java.lang.String getTableClass()
-
columnCount
public int columnCount()
-
columnAt
public DataTableColumnDef columnAt(int column)
-
findColumnName
public int findColumnName(java.lang.String column_name)
-
fastFindColumnName
public final int fastFindColumnName(java.lang.String col)
A faster way to find a column index given a string column name. This caches column name -> column index in a HashMap.
-
noColumnCopy
public DataTableDef noColumnCopy()
Returns a copy of this object, except with no columns or constraints.
-
write
void write(java.io.DataOutput out) throws java.io.IOException
Writes this DataTableDef file to the data output stream.- Throws:
java.io.IOException
-
read
static DataTableDef read(java.io.DataInput in) throws java.io.IOException
Reads this DataTableDef file from the data input stream.- Throws:
java.io.IOException
-
-