org.fcrepo.server.utilities
Class TableSpec

java.lang.Object
  extended by org.fcrepo.server.utilities.TableSpec

public class TableSpec
extends Object

A holder of table specification information that helps in producing RDBMS-generic DDL "CREATE TABLE" commands.

An application constructs a TableSpec without regard to the underlying database kind, and then the TableSpec is converted to a DB-specific CREATE TABLE DDL command by a DDLConverter before the command is issued via JDBC.

Author:
Chris Wilper

Constructor Summary
TableSpec(String name, List<ColumnSpec> columnSpecs, String primaryColumnName)
          Constructs a TableSpec given a name, a set of ColumnSpecs, and the name of the primary key column.
TableSpec(String name, List<ColumnSpec> columnSpecs, String primaryColumnName, String type)
          Constructs a TableSpec given a name, a set of ColumnSpecs, the name of the primary key column, and a table type.
 
Method Summary
 void assertConsistent()
          Ensures that the TableSpec is internally consistent.
 Iterator<ColumnSpec> columnSpecIterator()
          Gets an iterator over the columns.
 String getName()
          Gets the name of the table.
 String getPrimaryColumnName()
          Gets the name of the primary key column.
static List<TableSpec> getTableSpecs(InputStream in)
          Gets a TableSpec for each table element in the stream, where the stream contains a valid XML document containing one or more table elements, wrapped in the root element.
 String getType()
          Gets the type of the table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableSpec

public TableSpec(String name,
                 List<ColumnSpec> columnSpecs,
                 String primaryColumnName)
          throws InconsistentTableSpecException
Constructs a TableSpec given a name, a set of ColumnSpecs, and the name of the primary key column.

Parameters:
name - The table name.
columnSpecs - ColumnSpec objects describing columns in the table.
primaryColumnName - The column that is the primary key for the table.
Throws:
InconsistentTableSpecException - if inconsistencies are detected in table specifications.

TableSpec

public TableSpec(String name,
                 List<ColumnSpec> columnSpecs,
                 String primaryColumnName,
                 String type)
          throws InconsistentTableSpecException
Constructs a TableSpec given a name, a set of ColumnSpecs, the name of the primary key column, and a table type. Table type specification is not supported by all RDBMS software, and is usually software-specific. When a tableSpec is used to create a table, if the type is understood it is used. Otherwise it is ignored.

Parameters:
name - The table name.
columnSpecs - ColumnSpec objects describing columns in the table.
primaryColumnName - The column that is the primary key for the table.
type - The table type.
Throws:
InconsistentTableSpecException - if inconsistencies are detected in table specifications.
Method Detail

getTableSpecs

public static List<TableSpec> getTableSpecs(InputStream in)
                                     throws InconsistentTableSpecException,
                                            IOException
Gets a TableSpec for each table element in the stream, where the stream contains a valid XML document containing one or more table elements, wrapped in the root element.

Input is of the form:

 <database>
   <table name="tableName" primaryKey="primaryColumnName" type="tableType">
     <column name="columnName"
                type="typeSpec"
                autoIncrement="isAutoIncremented"
                index="indexName"
                notNull="isNotNull"
                unique="isUnique"
                default="defaultValue"
                foreignKey="foreignTableName.columnName onDeleteAction"/>
   </table>
 </database>
 
About the attributes:

Parameters:
in - The xml-encoded table specs.
Returns:
TableSpec objects.
Throws:
InconsistentTableSpecException - if inconsistencies are detected in table specifications.
IOException - if an IO error occurs.

assertConsistent

public void assertConsistent()
                      throws InconsistentTableSpecException
Ensures that the TableSpec is internally consistent.

Throws:
InconsistentTableSpecException - If it's inconsistent.

getName

public String getName()
Gets the name of the table.

Returns:
The name.

getPrimaryColumnName

public String getPrimaryColumnName()
Gets the name of the primary key column.

Returns:
The name.

getType

public String getType()
Gets the type of the table.

Returns:
The name.

columnSpecIterator

public Iterator<ColumnSpec> columnSpecIterator()
Gets an iterator over the columns.

Returns:
An Iterator over ColumnSpec objects.


Copyright © 2011 DuraSpace. All Rights Reserved.