Top Description Fields Constructors Methods
org.h2.schema

public Class Schema

extends DbObject
Class Inheritance
Known Direct Subclasses
org.h2.schema.MetaSchema
Imports
java.util.ArrayList, .Collection, .HashSet, .Map, java.util.concurrent.ConcurrentHashMap, org.h2.api.ErrorCode, org.h2.command.ddl.CreateSynonymData, .CreateTableData, org.h2.constraint.Constraint, org.h2.engine.Database, .DbObject, .DbSettings, .Right, .RightOwner, .SessionLocal, .SysProperties, org.h2.index.Index, org.h2.message.DbException, .Trace, org.h2.table.MaterializedView, .MetaTable, .Table, .TableLink, .TableSynonym, org.h2.util.Utils

A schema as created by the SQL statement CREATE SCHEMA

Field Summary

Modifier and TypeField and Description
private final ConcurrentHashMap<String, Constant>
private final ConcurrentHashMap<String, Constraint>
private final ConcurrentHashMap<String, Domain>
private final ConcurrentHashMap<String, UserDefinedFunction>
private final ConcurrentHashMap<String, Index>
private RightOwner
private final ConcurrentHashMap<String, Sequence>
private final ConcurrentHashMap<String, TableSynonym>
private final boolean
private ArrayList<String>
private final ConcurrentHashMap<String, Table>
private final HashSet<String>
temporaryUniqueNames

The set of returned unique names that are not yet stored.

private final ConcurrentHashMap<String, TriggerObject>
Inherited from org.h2.engine.DbObject:
AGGREGATECOMMENTcommentCONSTANTCONSTRAINTdatabaseDOMAINFUNCTION_ALIASINDEXRIGHTROLESCHEMASEQUENCESETTINGSYNONYMTABLE_OR_VIEWtraceTRIGGERUSER

Constructor Summary

AccessConstructor and Description
public
Schema(Database
the database
database
,
int
the object id
id
,
String
the schema name
schemaName
,
RightOwner
the owner of the schema
owner
,
boolean
if this is a system schema (such a schema can not be dropped)
system
)

Create a new schema object.

Method Summary

Modifier and TypeMethod and Description
public void
add(SchemaObject
the object to add
obj
)

Add an object to this schema.

public boolean

Returns:

true if it can be dropped
canDrop
()

Check if this schema can be dropped.

public TableSynonym

Returns:

the created TableSynonym object
createSynonym
(CreateSynonymData
the create synonym information
data
)

Add a table synonym to the schema.

public Table

Returns:

the created Table object
createTable
(CreateTableData
the create table information
data
)

Add a table to the schema.

public UserAggregate

Returns:

the aggregate function or null
findAggregate
(String
the name of the user defined aggregate function
name
)

Get the user defined aggregate function if it exists.

public Constant

Returns:

the object or null
findConstant
(String
the object name
constantName
)

Try to find a user defined constant with this name.

public Constraint

Returns:

the object or null
findConstraint
(SessionLocal
the session
session
,
String
the object name
name
)

Try to find a constraint with this name.

public Domain

Returns:

the domain or null
findDomain
(String
the name of the domain
name
)

Get the domain if it exists, or null if not.

public FunctionAlias

Returns:

the object or null
findFunction
(String
the object name
functionAlias
)

Try to find a user defined function with this name.

public UserDefinedFunction

Returns:

the object or null
findFunctionOrAggregate
(String
the object name
name
)

Try to find a user defined function or aggregate function with the specified name.

public Index

Returns:

the object or null
findIndex
(SessionLocal
the session
session
,
String
the object name
name
)

Try to find an index with this name.

public Sequence

Returns:

the object or null
findSequence
(String
the object name
sequenceName
)

Try to find a sequence with this name.

public Table

Returns:

the object or null
findTableOrView
(SessionLocal
the session
session
,
String
the object name
name
)

Try to find a table or view with this name.

public TriggerObject

Returns:

the object or null
findTrigger
(String
the object name
name
)

Try to find a trigger with this name.

public void
freeUniqueName(String
the object name
name
)

Release a unique object name.

public ArrayList<SchemaObject>

Returns:

the specified list with added objects, or a new (possibly empty) list with all objects
getAll
(ArrayList<SchemaObject>
list to add objects to, or null to allocate a new list
addTo
)

Get all objects.

public void
getAll(int
the object type
type
,
ArrayList<SchemaObject>
list to add objects to
addTo
)

Get all objects of the given type.

public Collection<Constant>
public Collection<Constraint>
public Collection<Domain>
public Collection<UserDefinedFunction>
public Collection<Index>
public Collection<Sequence>
public Collection<TableSynonym>
public Collection<Table>

Returns:

a (possible empty) list of all objects
getAllTablesAndViews
(SessionLocal
the session, null to exclude meta tables
session
)

Get all tables and views.

public Collection<TriggerObject>
public ArrayList<DbObject>
getChildren()

Overrides org.h2.engine.DbObject.getChildren.

Get the list of dependent children (for tables, this includes indexes and so on).

public Constant

Returns:

the constant
getConstant
(String
the constant name
constantName
)

Get the user defined constant with the given name.

public Constraint

Returns:

the constraint
getConstraint
(String
the constraint name
name
)

Get the constraint with the given name.

public String
getCreateSQL()

Implements abstract org.h2.engine.DbObject.getCreateSQL.

Construct the CREATE ...

public Domain

Returns:

the domain
getDomain
(String
the domain name
name
)

Get the domain with the given name.

public Index

Returns:

the index
getIndex
(String
the index name
name
)

Get the index with the given name.

private Map<String, SchemaObject>
getMap(int type)

public RightOwner

Returns:

the owner
getOwner
()

Get the owner of this schema.

public Sequence

Returns:

the sequence
getSequence
(String
the sequence name
sequenceName
)

Get the sequence with the given name.

public TableSynonym

Returns:

the object or null
getSynonym
(String
the object name
name
)

Try to find a synonym with this name.

public ArrayList<String>

Returns:

default table engine params
getTableEngineParams
()

Get table engine params of this schema.

public Table

Returns:

the table or view
getTableOrView
(SessionLocal
the session
session
,
String
the table or view name
name
)

Get the table or view with the given name.

public Table

Returns:

the table or null if not found
getTableOrViewByName
(SessionLocal
the session
session
,
String
the table name
name
)

Get the table with the given name, if any.

public int
getType()

Implements abstract org.h2.engine.DbObject.getType.

Get the object type.

public String

Returns:

the unique name
getUniqueConstraintName
(SessionLocal
the session
session
,
Table
the constraint table
table
)

Create a unique constraint name.

public String

Returns:

the unique name
getUniqueDomainConstraintName
(SessionLocal
the session
session
,
Domain
the constraint domain
domain
)

Create a unique constraint name.

public String

Returns:

the unique name
getUniqueIndexName
(SessionLocal
the session
session
,
Table
the indexed table
table
,
String
the index name prefix
prefix
)

Create a unique index name.

private String
getUniqueName(DbObject obj, Map<String, ? extends SchemaObject> map, String prefix)

public boolean

Returns:

true if this schema is empty, false otherwise
isEmpty
()

Return whether is this schema is empty (does not contain any objects).

public void
remove(SchemaObject
the object to remove
obj
)

Remove an object from this schema.

public void
removeChildrenAndResources(SessionLocal
the session
session
)

Implements abstract org.h2.engine.DbObject.removeChildrenAndResources.

Delete all dependent children objects and resources of this object.

private void
public void
rename(SchemaObject
the object to rename
obj
,
String
the new name
newName
)

Rename an object.

public void
reserveUniqueName(String
the object name
name
)

Reserve a unique object name.

public Table

Returns:

the object or null
resolveTableOrView
(SessionLocal
the session
session
,
String
the object name
name
)

Try to find a table or view with this name.

public Table

Returns:

the object or null
resolveTableOrView
(SessionLocal
the session
session
,
String
the object name
name
,
boolean
if true, and the object is a materialized view, return the underlying Table object.
resolveMaterializedView
)

Try to find a table or view with this name.

public void
setTableEngineParams(ArrayList<String>
default table engine params
tableEngineParams
)

Set table engine params of this schema.

Inherited from org.h2.engine.DbObject:
checkRenamegetCommentgetCreateSQLForCopygetCreateSQLForMetagetDatabasegetDropSQLgetIdgetModificationIdgetNamegetSQLgetSQLinvalidateisTemporaryisValidrenamesetCommentsetModifiedsetObjectNamesetTemporarytoString

Field Detail

constantsback to summary
private final ConcurrentHashMap<String, Constant> constants
constraintsback to summary
private final ConcurrentHashMap<String, Constraint> constraints
domainsback to summary
private final ConcurrentHashMap<String, Domain> domains
functionsAndAggregatesback to summary
private final ConcurrentHashMap<String, UserDefinedFunction> functionsAndAggregates
indexesback to summary
private final ConcurrentHashMap<String, Index> indexes
ownerback to summary
private RightOwner owner
sequencesback to summary
private final ConcurrentHashMap<String, Sequence> sequences
synonymsback to summary
private final ConcurrentHashMap<String, TableSynonym> synonyms
systemback to summary
private final boolean system
tableEngineParamsback to summary
private ArrayList<String> tableEngineParams
tablesAndViewsback to summary
private final ConcurrentHashMap<String, Table> tablesAndViews
temporaryUniqueNamesback to summary
private final HashSet<String> temporaryUniqueNames

The set of returned unique names that are not yet stored. It is used to avoid returning the same unique name twice when multiple threads concurrently create objects.

triggersback to summary
private final ConcurrentHashMap<String, TriggerObject> triggers

Constructor Detail

Schemaback to summary
public Schema(Database database, int id, String schemaName, RightOwner owner, boolean system)

Create a new schema object.

Parameters
database:Database

the database

id:int

the object id

schemaName:String

the schema name

owner:RightOwner

the owner of the schema

system:boolean

if this is a system schema (such a schema can not be dropped)

Method Detail

addback to summary
public void add(SchemaObject obj)

Add an object to this schema. This method must not be called within CreateSchemaObject; use Database.addSchemaObject() instead

Parameters
obj:SchemaObject

the object to add

canDropback to summary
public boolean canDrop()

Check if this schema can be dropped. System schemas can not be dropped.

Returns:boolean

true if it can be dropped

createSynonymback to summary
public TableSynonym createSynonym(CreateSynonymData data)

Add a table synonym to the schema.

Parameters
data:CreateSynonymData

the create synonym information

Returns:TableSynonym

the created TableSynonym object

createTableback to summary
public Table createTable(CreateTableData data)

Add a table to the schema.

Parameters
data:CreateTableData

the create table information

Returns:Table

the created Table object

findAggregateback to summary
public UserAggregate findAggregate(String name)

Get the user defined aggregate function if it exists. This method returns null if no object with this name exists.

Parameters
name:String

the name of the user defined aggregate function

Returns:UserAggregate

the aggregate function or null

findConstantback to summary
public Constant findConstant(String constantName)

Try to find a user defined constant with this name. This method returns null if no object with this name exists.

Parameters
constantName:String

the object name

Returns:Constant

the object or null

findConstraintback to summary
public Constraint findConstraint(SessionLocal session, String name)

Try to find a constraint with this name. This method returns null if no object with this name exists.

Parameters
session:SessionLocal

the session

name:String

the object name

Returns:Constraint

the object or null

findDomainback to summary
public Domain findDomain(String name)

Get the domain if it exists, or null if not.

Parameters
name:String

the name of the domain

Returns:Domain

the domain or null

findFunctionback to summary
public FunctionAlias findFunction(String functionAlias)

Try to find a user defined function with this name. This method returns null if no object with this name exists.

Parameters
functionAlias:String

the object name

Returns:FunctionAlias

the object or null

findFunctionOrAggregateback to summary
public UserDefinedFunction findFunctionOrAggregate(String name)

Try to find a user defined function or aggregate function with the specified name. This method returns null if no object with this name exists.

Parameters
name:String

the object name

Returns:UserDefinedFunction

the object or null

findIndexback to summary
public Index findIndex(SessionLocal session, String name)

Try to find an index with this name. This method returns null if no object with this name exists.

Parameters
session:SessionLocal

the session

name:String

the object name

Returns:Index

the object or null

findSequenceback to summary
public Sequence findSequence(String sequenceName)

Try to find a sequence with this name. This method returns null if no object with this name exists.

Parameters
sequenceName:String

the object name

Returns:Sequence

the object or null

findTableOrViewback to summary
public Table findTableOrView(SessionLocal session, String name)

Try to find a table or view with this name. This method returns null if no object with this name exists. Local temporary tables are also returned. Synonyms are not returned or resolved.

Parameters
session:SessionLocal

the session

name:String

the object name

Returns:Table

the object or null

findTriggerback to summary
public TriggerObject findTrigger(String name)

Try to find a trigger with this name. This method returns null if no object with this name exists.

Parameters
name:String

the object name

Returns:TriggerObject

the object or null

freeUniqueNameback to summary
public void freeUniqueName(String name)

Release a unique object name.

Parameters
name:String

the object name

getAllback to summary
public ArrayList<SchemaObject> getAll(ArrayList<SchemaObject> addTo)

Get all objects.

Parameters
addTo:ArrayList<SchemaObject>

list to add objects to, or null to allocate a new list

Returns:ArrayList<SchemaObject>

the specified list with added objects, or a new (possibly empty) list with all objects

getAllback to summary
public void getAll(int type, ArrayList<SchemaObject> addTo)

Get all objects of the given type.

Parameters
type:int

the object type

addTo:ArrayList<SchemaObject>

list to add objects to

getAllConstantsback to summary
public Collection<Constant> getAllConstants()
getAllConstraintsback to summary
public Collection<Constraint> getAllConstraints()
getAllDomainsback to summary
public Collection<Domain> getAllDomains()
getAllFunctionsAndAggregatesback to summary
public Collection<UserDefinedFunction> getAllFunctionsAndAggregates()
getAllIndexesback to summary
public Collection<Index> getAllIndexes()
getAllSequencesback to summary
public Collection<Sequence> getAllSequences()
getAllSynonymsback to summary
public Collection<TableSynonym> getAllSynonyms()
getAllTablesAndViewsback to summary
public Collection<Table> getAllTablesAndViews(SessionLocal session)

Get all tables and views.

Parameters
session:SessionLocal

the session, null to exclude meta tables

Returns:Collection<Table>

a (possible empty) list of all objects

getAllTriggersback to summary
public Collection<TriggerObject> getAllTriggers()
getChildrenback to summary
public ArrayList<DbObject> getChildren()

Overrides org.h2.engine.DbObject.getChildren.

Doc from org.h2.engine.DbObject.getChildren.

Get the list of dependent children (for tables, this includes indexes and so on).

Returns:ArrayList<DbObject>

the list of children, or null

Annotations
@Override
getConstantback to summary
public Constant getConstant(String constantName)

Get the user defined constant with the given name.

Parameters
constantName:String

the constant name

Returns:Constant

the constant

Exceptions
DbException:
if no such object exists
getConstraintback to summary
public Constraint getConstraint(String name)

Get the constraint with the given name.

Parameters
name:String

the constraint name

Returns:Constraint

the constraint

Exceptions
DbException:
if no such object exists
getCreateSQLback to summary
public String getCreateSQL()

Implements abstract org.h2.engine.DbObject.getCreateSQL.

Doc from org.h2.engine.DbObject.getCreateSQL.

Construct the CREATE ... SQL statement for this object.

Returns:String

the SQL statement

Annotations
@Override
getDomainback to summary
public Domain getDomain(String name)

Get the domain with the given name.

Parameters
name:String

the domain name

Returns:Domain

the domain

Exceptions
DbException:
if no such object exists
getIndexback to summary
public Index getIndex(String name)

Get the index with the given name.

Parameters
name:String

the index name

Returns:Index

the index

Exceptions
DbException:
if no such object exists
getMapback to summary
private Map<String, SchemaObject> getMap(int type)
Annotations
@SuppressWarnings:unchecked
getOwnerback to summary
public RightOwner getOwner()

Get the owner of this schema.

Returns:RightOwner

the owner

getSequenceback to summary
public Sequence getSequence(String sequenceName)

Get the sequence with the given name.

Parameters
sequenceName:String

the sequence name

Returns:Sequence

the sequence

Exceptions
DbException:
if no such object exists
getSynonymback to summary
public TableSynonym getSynonym(String name)

Try to find a synonym with this name. This method returns null if no object with this name exists.

Parameters
name:String

the object name

Returns:TableSynonym

the object or null

getTableEngineParamsback to summary
public ArrayList<String> getTableEngineParams()

Get table engine params of this schema.

Returns:ArrayList<String>

default table engine params

getTableOrViewback to summary
public Table getTableOrView(SessionLocal session, String name)

Get the table or view with the given name. Local temporary tables are also returned.

Parameters
session:SessionLocal

the session

name:String

the table or view name

Returns:Table

the table or view

Exceptions
DbException:
if no such object exists
getTableOrViewByNameback to summary
public Table getTableOrViewByName(SessionLocal session, String name)

Get the table with the given name, if any.

Parameters
session:SessionLocal

the session

name:String

the table name

Returns:Table

the table or null if not found

getTypeback to summary
public int getType()

Implements abstract org.h2.engine.DbObject.getType.

Doc from org.h2.engine.DbObject.getType.

Get the object type.

Returns:int

the object type

Annotations
@Override
getUniqueConstraintNameback to summary
public String getUniqueConstraintName(SessionLocal session, Table table)

Create a unique constraint name.

Parameters
session:SessionLocal

the session

table:Table

the constraint table

Returns:String

the unique name

getUniqueDomainConstraintNameback to summary
public String getUniqueDomainConstraintName(SessionLocal session, Domain domain)

Create a unique constraint name.

Parameters
session:SessionLocal

the session

domain:Domain

the constraint domain

Returns:String

the unique name

getUniqueIndexNameback to summary
public String getUniqueIndexName(SessionLocal session, Table table, String prefix)

Create a unique index name.

Parameters
session:SessionLocal

the session

table:Table

the indexed table

prefix:String

the index name prefix

Returns:String

the unique name

getUniqueNameback to summary
private String getUniqueName(DbObject obj, Map<String, ? extends SchemaObject> map, String prefix)
isEmptyback to summary
public boolean isEmpty()

Return whether is this schema is empty (does not contain any objects).

Returns:boolean

true if this schema is empty, false otherwise

removeback to summary
public void remove(SchemaObject obj)

Remove an object from this schema.

Parameters
obj:SchemaObject

the object to remove

removeChildrenAndResourcesback to summary
public void removeChildrenAndResources(SessionLocal session)

Implements abstract org.h2.engine.DbObject.removeChildrenAndResources.

Doc from org.h2.engine.DbObject.removeChildrenAndResources.

Delete all dependent children objects and resources of this object.

Parameters
session:SessionLocal

the session

Annotations
@Override
removeChildrenFromMapback to summary
private void removeChildrenFromMap(SessionLocal session, ConcurrentHashMap<String, ? extends SchemaObject> map)
renameback to summary
public void rename(SchemaObject obj, String newName)

Rename an object.

Parameters
obj:SchemaObject

the object to rename

newName:String

the new name

reserveUniqueNameback to summary
public void reserveUniqueName(String name)

Reserve a unique object name.

Parameters
name:String

the object name

resolveTableOrViewback to summary
public Table resolveTableOrView(SessionLocal session, String name)

Try to find a table or view with this name. This method returns null if no object with this name exists. Local temporary tables are also returned. If a synonym with this name exists, the backing table of the synonym is returned

Parameters
session:SessionLocal

the session

name:String

the object name

Returns:Table

the object or null

resolveTableOrViewback to summary
public Table resolveTableOrView(SessionLocal session, String name, boolean resolveMaterializedView)

Try to find a table or view with this name. This method returns null if no object with this name exists. Local temporary tables are also returned. If a synonym with this name exists, the backing table of the synonym is returned

Parameters
session:SessionLocal

the session

name:String

the object name

resolveMaterializedView:boolean

if true, and the object is a materialized view, return the underlying Table object.

Returns:Table

the object or null

setTableEngineParamsback to summary
public void setTableEngineParams(ArrayList<String> tableEngineParams)

Set table engine params of this schema.

Parameters
tableEngineParams:ArrayList<String>

default table engine params