public class DbSpec extends Object
Note, you generally do not want to mix objects from different specs because they may have conflicting aliases.
The DbSpec also acts as the "factory" for creating other DbObject instances
(via the various create*()
methods). All the other DbObject types
delegate object creation to the referenced DbSpec. Thus, custom model
classes can easily be plugged in by creating a subclass of this class which
overrides the relevant creation methods.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_ALIAS_PREFIX
the default alias prefix used by a db spec if none is specified
|
Modifier and Type | Method and Description |
---|---|
DbSchema |
addDefaultSchema()
Creates and adds a schema with no name to this spec (often referred to as
the default schema).
|
DbJoin |
addJoin(String schemaFrom,
String tableFrom,
String schemaTo,
String tableTo,
String... colNames)
Creates and adds a join with the given parameters to this spec.
|
DbJoin |
addJoin(String schemaFrom,
String tableFrom,
String schemaTo,
String tableTo,
String[] fromColNames,
String[] toColNames)
Creates and adds a join with the given parameters to this spec.
|
<T extends DbJoin> |
addJoin(T join)
Adds the given join to this schema.
|
DbSchema |
addSchema(String name)
Creates and adds a schema with the given name to this spec.
|
<T extends DbSchema> |
addSchema(T schema)
Adds the given schema to this schema.
|
protected <T extends DbObject<?>> |
checkOwnership(T obj) |
DbColumn |
createColumn(DbTable parent,
String name,
String typeName,
Object... typeQualifiers)
Creates and returns a new
DbColumn with the given parameters. |
DbCheckConstraint |
createColumnCheckConstraint(DbColumn parent,
String name,
Condition condition)
Creates and returns a new column
DbCheckConstraint with the given
parameters. |
DbConstraint |
createColumnConstraint(DbColumn parent,
String name,
Constraint.Type type)
Creates and returns a new column
DbConstraint with the given
parameters. |
DbForeignKeyConstraint |
createColumnForeignKeyConstraint(DbColumn parent,
String name,
DbTable referencedTable,
DbColumn referencedColumn)
Creates and returns a new column
DbForeignKeyConstraint with the
given parameters. |
DbForeignKeyConstraint |
createColumnForeignKeyConstraint(DbColumn parent,
String name,
DbTable referencedTable,
String refColName)
Deprecated.
|
DbFunction |
createFunction(DbFunctionPackage parent,
String name)
Creates and returns a new
DbFunction with the given parameters. |
DbFunctionPackage |
createFunctionPackage(DbSchema parent,
String name)
Creates and returns a new
DbFunctionPackage with the given
parameters. |
DbIndex |
createIndex(DbTable table,
String name,
String... colNames)
Creates and returns a new
DbIndex with the given parameters. |
DbJoin |
createJoin(DbTable fromTable,
DbTable toTable,
String[] fromColNames,
String[] toColNames)
Creates and returns a new
DbJoin with the given parameters. |
DbSchema |
createSchema(String name)
Creates and returns a new
DbSchema with the given parameters. |
DbTable |
createTable(DbSchema parent,
String name)
Creates and returns a new
DbTable with the given parameters. |
DbCheckConstraint |
createTableCheckConstraint(DbTable parent,
String name,
Condition condition)
Creates and returns a new table
DbCheckConstraint with the given
parameters. |
DbConstraint |
createTableConstraint(DbTable parent,
String name,
Constraint.Type type,
String... colNames)
Creates and returns a new table
DbConstraint with the given
parameters. |
DbForeignKeyConstraint |
createTableForeignKeyConstraint(DbTable parent,
String name,
DbTable referencedTable,
DbColumn[] columns,
DbColumn[] refColumns)
Creates and returns a new table
DbForeignKeyConstraint with the
given parameters. |
DbForeignKeyConstraint |
createTableForeignKeyConstraint(DbTable parent,
String name,
DbTable referencedTable,
String[] colNames,
String[] refColNames)
Deprecated.
|
DbSchema |
findSchema(String name) |
DbSchema |
getDefaultSchema() |
List<DbJoin> |
getJoins() |
String |
getNextAlias() |
List<DbSchema> |
getSchemas() |
public static final String DEFAULT_ALIAS_PREFIX
public DbSpec()
public DbSpec(String aliasPrefix)
public String getNextAlias()
public DbSchema getDefaultSchema()
null
if none.public DbSchema findSchema(String name)
name
- name of the schema to findnull
if none.public DbSchema addDefaultSchema()
Note, no effort is made to make sure the schema is unique.
public DbSchema addSchema(String name)
Note, no effort is made to make sure the given name is unique.
name
- the name of the new schemapublic <T extends DbSchema> T addSchema(T schema)
Note, no effort is made to make sure the given schema is unique.
schema
- the schema to be addedpublic DbJoin addJoin(String schemaFrom, String tableFrom, String schemaTo, String tableTo, String... colNames)
Note, no effort is made to make sure the given join is unique.
schemaFrom
- schema for the left side of the jointableFrom
- table for the left side of the joinschemaTo
- schema for the right side of the jointableTo
- table for the right side of the joincolNames
- the column names for the join (same for both tables)public DbJoin addJoin(String schemaFrom, String tableFrom, String schemaTo, String tableTo, String[] fromColNames, String[] toColNames)
Note, no effort is made to make sure the given join is unique.
schemaFrom
- schema for the left side of the jointableFrom
- table for the left side of the joinschemaTo
- schema for the right side of the jointableTo
- table for the right side of the joinfromColNames
- the column names for the left side of the jointoColNames
- the column names for the right side of the joinpublic <T extends DbJoin> T addJoin(T join)
Note, no effort is made to make sure the given join is unique.
join
- the join to be addedpublic DbSchema createSchema(String name)
DbSchema
with the given parameters.
This method can be overriden to utilize custom model subclasses.
public DbTable createTable(DbSchema parent, String name)
DbTable
with the given parameters.
This method can be overriden to utilize custom model subclasses.
public DbColumn createColumn(DbTable parent, String name, String typeName, Object... typeQualifiers)
DbColumn
with the given parameters.
This method can be overriden to utilize custom model subclasses.
public DbJoin createJoin(DbTable fromTable, DbTable toTable, String[] fromColNames, String[] toColNames)
DbJoin
with the given parameters.
This method can be overriden to utilize custom model subclasses.
public DbIndex createIndex(DbTable table, String name, String... colNames)
DbIndex
with the given parameters.
This method can be overriden to utilize custom model subclasses.
public DbFunctionPackage createFunctionPackage(DbSchema parent, String name)
DbFunctionPackage
with the given
parameters.
This method can be overriden to utilize custom model subclasses.
public DbFunction createFunction(DbFunctionPackage parent, String name)
DbFunction
with the given parameters.
This method can be overriden to utilize custom model subclasses.
public DbConstraint createColumnConstraint(DbColumn parent, String name, Constraint.Type type)
DbConstraint
with the given
parameters.
This method can be overriden to utilize custom model subclasses.
public DbConstraint createTableConstraint(DbTable parent, String name, Constraint.Type type, String... colNames)
DbConstraint
with the given
parameters.
This method can be overriden to utilize custom model subclasses.
@Deprecated public DbForeignKeyConstraint createColumnForeignKeyConstraint(DbColumn parent, String name, DbTable referencedTable, String refColName)
createColumnForeignKeyConstraint(DbColumn,String,DbTable,DbColumn)
insteadDbForeignKeyConstraint
with the
given parameters.
This method can be overriden to utilize custom model subclasses.
public DbForeignKeyConstraint createColumnForeignKeyConstraint(DbColumn parent, String name, DbTable referencedTable, DbColumn referencedColumn)
DbForeignKeyConstraint
with the
given parameters.
This method can be overriden to utilize custom model subclasses.
@Deprecated public DbForeignKeyConstraint createTableForeignKeyConstraint(DbTable parent, String name, DbTable referencedTable, String[] colNames, String[] refColNames)
createTableForeignKeyConstraint(DbTable,String,DbTable,DbColumn[],DbColumn[])
insteadDbForeignKeyConstraint
with the
given parameters.
This method can be overriden to utilize custom model subclasses.
public DbForeignKeyConstraint createTableForeignKeyConstraint(DbTable parent, String name, DbTable referencedTable, DbColumn[] columns, DbColumn[] refColumns)
DbForeignKeyConstraint
with the
given parameters.
This method can be overriden to utilize custom model subclasses.
public DbCheckConstraint createColumnCheckConstraint(DbColumn parent, String name, Condition condition)
DbCheckConstraint
with the given
parameters.
This method can be overriden to utilize custom model subclasses.
public DbCheckConstraint createTableCheckConstraint(DbTable parent, String name, Condition condition)
DbCheckConstraint
with the given
parameters.
This method can be overriden to utilize custom model subclasses.
protected <T extends DbObject<?>> T checkOwnership(T obj)
IllegalArgumentException
- if the parent of the given object is not
this objectCopyright © 2006–2021 OpenHMS. All rights reserved.