de.hpi.fgis.dude.database.util
Class Schema

java.lang.Object
  extended by de.hpi.fgis.dude.database.util.Schema
All Implemented Interfaces:
AutoJsonable, Iterable<ColumnInfo>

public class Schema
extends Object
implements Iterable<ColumnInfo>, AutoJsonable

The Schema encapsulates all the information concerning a database table schema.

Author:
Matthias Pohl

Field Summary
protected  List<ColumnInfo> columns
          A list of all column representations which are part of this schema.
 
Constructor Summary
Schema(Collection<ColumnInfo> cols)
          Initializes a Schema using a given collection of ColumnInfo instances.
Schema(Connection conn, String sqlSchema, String tableName)
          Initializes the Schema out of the passed table.
 
Method Summary
protected  boolean columnNamesAreUnique()
          Checks whether the set columns are unique.
protected  ColumnInfo getColumnInfo(int index)
          Returns the information of the column with the given index.
 String getColumnName(int columnIndex)
          Returns the name of the specified column.
 int getColumnSQLType(int columnIndex)
          Returns the data type of the specified column.
 boolean isEmpty()
          Checks whether the current schema contains no columns.
 Iterator<ColumnInfo> iterator()
          Returns an iterator that iterates over the Schema instance.
 int size()
          Returns the schema's column count.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

columns

protected final List<ColumnInfo> columns
A list of all column representations which are part of this schema.

Constructor Detail

Schema

public Schema(Collection<ColumnInfo> cols)
       throws InvalidSchemaException
Initializes a Schema using a given collection of ColumnInfo instances.

Parameters:
cols - A collection of ColumnInfo instances representing all columns of this Schema.
Throws:
InvalidSchemaException - If the column names are not unique.

Schema

public Schema(Connection conn,
              String sqlSchema,
              String tableName)
       throws InvalidSchemaException
Initializes the Schema out of the passed table.

Parameters:
conn - The connection to the table's database.
sqlSchema - The SQL schema of the table.
tableName - The name of the table.
Throws:
InvalidSchemaException - If an error occurred while extracting the Schema information.
Method Detail

columnNamesAreUnique

protected boolean columnNamesAreUnique()
Checks whether the set columns are unique.

Returns:
true, if each column has a unique name; otherwise false.

size

public int size()
Returns the schema's column count.

Returns:
The number of columns.

getColumnInfo

protected ColumnInfo getColumnInfo(int index)
Returns the information of the column with the given index.

Parameters:
index - The position of the column in the schema.
Returns:
A ColumnInfo of the column located at position index in the schema.

getColumnSQLType

public int getColumnSQLType(int columnIndex)
Returns the data type of the specified column.

Parameters:
columnIndex - The position of the column.
Returns:
The data type java.sql.Types representation of the column's data type.
See Also:
Types

getColumnName

public String getColumnName(int columnIndex)
Returns the name of the specified column.

Parameters:
columnIndex - The position of the column.
Returns:
The name of the column.

iterator

public Iterator<ColumnInfo> iterator()
Returns an iterator that iterates over the Schema instance.

Specified by:
iterator in interface Iterable<ColumnInfo>
See Also:
Iterable.iterator()

isEmpty

public boolean isEmpty()
Checks whether the current schema contains no columns.

Returns:
true, if no columns are part of this schema; otherwise false.


Copyright © 2011 Hasso Plattner Institute - Chair of Information Systems. All Rights Reserved.