use of org.hsqldb_voltpatches.Constraint in project voltdb by VoltDB.
the class DatabaseInformationFull method CHECK_CONSTRAINT_ROUTINE_USAGE.
/**
* The CHECK_CONSTRAINT_ROUTINE_USAGE view has one row for each
* SQL-invoked routine identified as the subject routine of either a
* <routine invocation>, a <method reference>, a
* <method invocation>, or a <static method invocation>
* contained in an <assertion definition>, a <domain
* constraint>, or a <table constraint definition>. <p>
*
* <b>Definition:</b> <p>
*
* <pre class="SqlCodeExample">
* CREATE TABLE SYSTEM_CHECK_ROUTINE_USAGE (
* CONSTRAINT_CATALOG VARCHAR NULL,
* CONSTRAINT_SCHEMA VARCHAR NULL,
* CONSTRAINT_NAME VARCHAR NOT NULL,
* SPECIFIC_CATALOG VARCHAR NULL,
* SPECIFIC_SCHEMA VARCHAR NULL,
* SPECIFIC_NAME VARCHAR NOT NULL,
* UNIQUE( CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, CONSTRAINT_NAME,
* SPECIFIC_CATALOG, SPECIFIC_SCHEMA, SPECIFIC_NAME )
* )
* </pre>
*
* <b>Description:</b> <p>
*
* <ol>
* <li> The CHECK_ROUTINE_USAGE table has one row for each
* SQL-invoked routine R identified as the subject routine of either a
* <routine invocation>, a <method reference>, a <method
* invocation>, or a <static method invocation> contained in
* an <assertion definition> or in the <check constraint
* definition> contained in either a <domain constraint> or a
* <table constraint definition>. <p>
*
* <li> The values of CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, and
* CONSTRAINT_NAME are the catalog name, unqualified schema name, and
* qualified identifier, respectively, of the assertion or check
* constraint being described. <p>
*
* <li> The values of SPECIFIC_CATALOG, SPECIFIC_SCHEMA, and SPECIFIC_NAME
* are the catalog name, unqualified schema name, and qualified
* identifier, respectively, of the specific name of R. <p>
*
* </ol>
*
* @return Table
*/
Table CHECK_CONSTRAINT_ROUTINE_USAGE() {
Table t = sysTables[CHECK_CONSTRAINT_ROUTINE_USAGE];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[CHECK_CONSTRAINT_ROUTINE_USAGE]);
addColumn(t, "CONSTRAINT_CATALOG", SQL_IDENTIFIER);
addColumn(t, "CONSTRAINT_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "CONSTRAINT_NAME", SQL_IDENTIFIER);
addColumn(t, "SPECIFIC_CATALOG", SQL_IDENTIFIER);
addColumn(t, "SPECIFIC_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "SPECIFIC_NAME", SQL_IDENTIFIER);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[CHECK_CONSTRAINT_ROUTINE_USAGE].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5 }, false);
return t;
}
// column number mappings
final int constraint_catalog = 0;
final int constraint_schema = 1;
final int constraint_name = 2;
final int specific_catalog = 3;
final int specific_schema = 4;
final int specific_name = 5;
//
PersistentStore store = database.persistentStoreCollection.getStore(t);
// calculated column values
String constraintCatalog;
String constraintSchema;
String constraintName;
String specificSchema;
// Intermediate holders
Iterator tables;
Table table;
Constraint[] constraints;
int constraintCount;
Constraint constraint;
OrderedHashSet collector;
Iterator iterator;
OrderedHashSet methodSet;
Method method;
Object[] row;
tables = database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
collector = new OrderedHashSet();
while (tables.hasNext()) {
collector.clear();
table = (Table) tables.next();
if (table.isView() || !session.getGrantee().isFullyAccessibleByRole(table)) {
continue;
}
constraints = table.getConstraints();
constraintCount = constraints.length;
constraintCatalog = database.getCatalogName().name;
constraintSchema = table.getSchemaName().name;
specificSchema = database.schemaManager.getDefaultSchemaHsqlName().name;
for (int i = 0; i < constraintCount; i++) {
constraint = constraints[i];
if (constraint.getConstraintType() != Constraint.CHECK) {
continue;
}
constraintName = constraint.getName().name;
constraint.getCheckExpression().collectAllFunctionExpressions(collector);
methodSet = new OrderedHashSet();
iterator = collector.iterator();
while (iterator.hasNext()) {
/*
Function expression = (Function) iterator.next();
String className =
expression.getMethod().getDeclaringClass().getName();
String schema =
database.schemaManager.getDefaultSchemaHsqlName().name;
SchemaObject object =
database.schemaManager.getSchemaObject(className,
schema, SchemaObject.FUNCTION);
if (!session.getGrantee().isAccessible(object)) {
continue;
}
methodSet.add(expression.getMethod());
*/
}
iterator = methodSet.iterator();
while (iterator.hasNext()) {
method = (Method) iterator.next();
row = t.getEmptyRowData();
row[constraint_catalog] = constraintCatalog;
row[constraint_schema] = constraintSchema;
row[constraint_name] = constraintName;
row[specific_catalog] = database.getCatalogName();
row[specific_schema] = specificSchema;
row[specific_name] = DINameSpace.getMethodSpecificName(method);
t.insertSys(store, row);
}
}
}
return t;
}
use of org.hsqldb_voltpatches.Constraint in project voltdb by VoltDB.
the class DatabaseInformationFull method COLLATIONS.
/**
* COLLATIONS<p>
*
* <b>Function<b><p>
*
* The COLLATIONS view has one row for each character collation
* descriptor. <p>
*
* <b>Definition</b>
*
* <pre class="SqlCodeExample">
* CREATE TABLE COLLATIONS (
* COLLATION_CATALOG INFORMATION_SCHEMA.SQL_IDENTIFIER,
* COLLATION_SCHEMA INFORMATION_SCHEMA.SQL_IDENTIFIER,
* COLLATION_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER,
* PAD_ATTRIBUTE INFORMATION_SCHEMA.CHARACTER_DATA
* CONSTRAINT COLLATIONS_PAD_ATTRIBUTE_CHECK
* CHECK ( PAD_ATTRIBUTE IN
* ( 'NO PAD', 'PAD SPACE' ) )
* )
* </pre>
*
* <b>Description</b><p>
*
* <ol>
* <li>The values of COLLATION_CATALOG, COLLATION_SCHEMA, and
* COLLATION_NAME are the catalog name, unqualified schema name,
* and qualified identifier, respectively, of the collation being
* described.<p>
*
* <li>The values of PAD_ATTRIBUTE have the following meanings:<p>
*
* <table border cellpadding="3">
* <tr>
* <td nowrap>NO PAD</td>
* <td nowrap>The collation being described has the NO PAD
* characteristic.</td>
* <tr>
* <tr>
* <td nowrap>PAD</td>
* <td nowrap>The collation being described has the PAD SPACE
* characteristic.</td>
* <tr>
* </table> <p>
* </ol>
*
* @return Table
*/
Table COLLATIONS() {
Table t = sysTables[COLLATIONS];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[COLLATIONS]);
addColumn(t, "COLLATION_CATALOG", SQL_IDENTIFIER);
// not null
addColumn(t, "COLLATION_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "COLLATION_NAME", SQL_IDENTIFIER);
addColumn(t, "PAD_ATTRIBUTE", CHARACTER_DATA);
// false PK, as rows may have NULL COLLATION_CATALOG
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[COLLATIONS].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2 }, false);
return t;
}
// Column number mappings
final int collation_catalog = 0;
final int collation_schema = 1;
final int collation_name = 2;
final int pad_attribute = 3;
//
PersistentStore store = database.persistentStoreCollection.getStore(t);
// Intermediate holders
Iterator collations;
String collation;
String collationSchema = SqlInvariants.PUBLIC_SCHEMA;
String padAttribute = "NO PAD";
Object[] row;
// Initialization
collations = Collation.nameToJavaName.keySet().iterator();
// Do it.
while (collations.hasNext()) {
row = t.getEmptyRowData();
collation = (String) collations.next();
row[collation_catalog] = database.getCatalogName().name;
row[collation_schema] = collationSchema;
row[collation_name] = collation;
row[pad_attribute] = padAttribute;
t.insertSys(store, row);
}
return t;
}
use of org.hsqldb_voltpatches.Constraint in project voltdb by VoltDB.
the class DatabaseInformationMain method SYSTEM_PRIMARYKEYS.
/**
* Retrieves a <code>Table</code> object describing the visible
* primary key columns of each accessible table defined within
* this database. <p>
*
* Each row is a PRIMARY KEY column description with the following
* columns: <p>
*
* <pre class="SqlCodeExample">
* TABLE_CAT VARCHAR table catalog
* TABLE_SCHEM VARCHAR table schema
* TABLE_NAME VARCHAR table name
* COLUMN_NAME VARCHAR column name
* KEY_SEQ SMALLINT sequence number within primary key
* PK_NAME VARCHAR primary key constraint name
* </pre> <p>
*
* @return a <code>Table</code> object describing the visible
* primary key columns of each accessible table
* defined within this database.
*/
final Table SYSTEM_PRIMARYKEYS() {
Table t = sysTables[SYSTEM_PRIMARYKEYS];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SYSTEM_PRIMARYKEYS]);
addColumn(t, "TABLE_CAT", SQL_IDENTIFIER);
addColumn(t, "TABLE_SCHEM", SQL_IDENTIFIER);
// not null
addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "KEY_SEQ", Type.SQL_SMALLINT);
addColumn(t, "PK_NAME", SQL_IDENTIFIER);
// order: COLUMN_NAME
// added for unique: TABLE_NAME, TABLE_SCHEM, TABLE_CAT
// false PK, as TABLE_SCHEM and/or TABLE_CAT may be null
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_PRIMARYKEYS].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 3, 2, 1, 0 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
// calculated column values
String tableCatalog;
String tableSchema;
String tableName;
//String columnName;
//Integer keySequence;
String primaryKeyName;
// Intermediate holders
Iterator tables;
Table table;
Object[] row;
Constraint constraint;
int[] cols;
int colCount;
HsqlProperties p;
// column number mappings
final int itable_cat = 0;
final int itable_schem = 1;
final int itable_name = 2;
final int icolumn_name = 3;
final int ikey_seq = 4;
final int ipk_name = 5;
// Initialization
p = database.getProperties();
tables = p.isPropertyTrue("hsqldb.system_table_primarykeys") ? allTables() : database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
while (tables.hasNext()) {
table = (Table) tables.next();
if (table.isView() || !isAccessibleTable(table) || !table.hasPrimaryKey()) {
continue;
}
constraint = table.getPrimaryConstraint();
tableCatalog = table.getCatalogName().name;
tableSchema = table.getSchemaName().name;
tableName = table.getName().name;
primaryKeyName = constraint.getName().name;
cols = constraint.getMainColumns();
colCount = cols.length;
for (int j = 0; j < colCount; j++) {
row = t.getEmptyRowData();
row[itable_cat] = tableCatalog;
row[itable_schem] = tableSchema;
row[itable_name] = tableName;
row[icolumn_name] = table.getColumn(cols[j]).getName().name;
row[ikey_seq] = ValuePool.getInt(j + 1);
row[ipk_name] = primaryKeyName;
t.insertSys(store, row);
}
}
return t;
}
use of org.hsqldb_voltpatches.Constraint in project voltdb by VoltDB.
the class UserTypeModifier method addConstraint.
public void addConstraint(Constraint c) {
int position = constraints.length;
constraints = (Constraint[]) ArrayUtil.resizeArray(constraints, position + 1);
constraints[position] = c;
setNotNull();
}
use of org.hsqldb_voltpatches.Constraint in project voltdb by VoltDB.
the class DatabaseInformationMain method SYSTEM_CROSSREFERENCE.
/**
* Retrieves a <code>Table</code> object describing, for each
* accessible referencing and referenced table, how the referencing
* tables import, for the purposes of referential integrity,
* the columns of the referenced tables.<p>
*
* Each row is a foreign key column description with the following
* columns: <p>
*
* <pre class="SqlCodeExample">
* PKTABLE_CAT VARCHAR referenced table catalog
* PKTABLE_SCHEM VARCHAR referenced table schema
* PKTABLE_NAME VARCHAR referenced table name
* PKCOLUMN_NAME VARCHAR referenced column name
* FKTABLE_CAT VARCHAR referencing table catalog
* FKTABLE_SCHEM VARCHAR referencing table schema
* FKTABLE_NAME VARCHAR referencing table name
* FKCOLUMN_NAME VARCHAR referencing column
* KEY_SEQ SMALLINT sequence number within foreign key
* UPDATE_RULE SMALLINT
* { Cascade | Set Null | Set Default | Restrict (No Action)}?
* DELETE_RULE SMALLINT
* { Cascade | Set Null | Set Default | Restrict (No Action)}?
* FK_NAME VARCHAR foreign key constraint name
* PK_NAME VARCHAR primary key or unique constraint name
* DEFERRABILITY SMALLINT
* { initially deferred | initially immediate | not deferrable }
* </pre> <p>
*
* @return a <code>Table</code> object describing how accessible tables
* import other accessible tables' primary key and/or unique
* constraint columns
*/
final Table SYSTEM_CROSSREFERENCE() {
Table t = sysTables[SYSTEM_CROSSREFERENCE];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SYSTEM_CROSSREFERENCE]);
addColumn(t, "PKTABLE_CAT", SQL_IDENTIFIER);
addColumn(t, "PKTABLE_SCHEM", SQL_IDENTIFIER);
// not null
addColumn(t, "PKTABLE_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "PKCOLUMN_NAME", SQL_IDENTIFIER);
addColumn(t, "FKTABLE_CAT", SQL_IDENTIFIER);
addColumn(t, "FKTABLE_SCHEM", SQL_IDENTIFIER);
// not null
addColumn(t, "FKTABLE_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "FKCOLUMN_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "KEY_SEQ", Type.SQL_SMALLINT);
// not null
addColumn(t, "UPDATE_RULE", Type.SQL_SMALLINT);
// not null
addColumn(t, "DELETE_RULE", Type.SQL_SMALLINT);
addColumn(t, "FK_NAME", SQL_IDENTIFIER);
addColumn(t, "PK_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "DEFERRABILITY", Type.SQL_SMALLINT);
// order: FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, and KEY_SEQ
// added for unique: FK_NAME
// false PK, as FKTABLE_CAT, FKTABLE_SCHEM and/or FK_NAME
// may be null
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_CROSSREFERENCE].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 4, 5, 6, 8, 11 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
// calculated column values
String pkTableCatalog;
String pkTableSchema;
String pkTableName;
String pkColumnName;
String fkTableCatalog;
String fkTableSchema;
String fkTableName;
String fkColumnName;
Integer keySequence;
Integer updateRule;
Integer deleteRule;
String fkName;
String pkName;
Integer deferrability;
// Intermediate holders
Iterator tables;
Table table;
Table fkTable;
Table pkTable;
int columnCount;
int[] mainCols;
int[] refCols;
Constraint[] constraints;
Constraint constraint;
int constraintCount;
HsqlArrayList fkConstraintsList;
Object[] row;
DITableInfo pkInfo;
DITableInfo fkInfo;
// column number mappings
final int ipk_table_cat = 0;
final int ipk_table_schem = 1;
final int ipk_table_name = 2;
final int ipk_column_name = 3;
final int ifk_table_cat = 4;
final int ifk_table_schem = 5;
final int ifk_table_name = 6;
final int ifk_column_name = 7;
final int ikey_seq = 8;
final int iupdate_rule = 9;
final int idelete_rule = 10;
final int ifk_name = 11;
final int ipk_name = 12;
final int ideferrability = 13;
tables = database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
pkInfo = new DITableInfo();
fkInfo = new DITableInfo();
// We must consider all the constraints in all the user tables, since
// this is where reference relationships are recorded. However, we
// are only concerned with Constraint.FOREIGN_KEY constraints here
// because their corresponing Constraint.MAIN entries are essentially
// duplicate data recorded in the referenced rather than the
// referencing table. Also, we skip constraints where either
// the referenced, referencing or both tables are not accessible
// relative to the session of the calling context
fkConstraintsList = new HsqlArrayList();
while (tables.hasNext()) {
table = (Table) tables.next();
if (table.isView() || !isAccessibleTable(table)) {
continue;
}
constraints = table.getConstraints();
constraintCount = constraints.length;
for (int i = 0; i < constraintCount; i++) {
constraint = (Constraint) constraints[i];
if (constraint.getConstraintType() == Constraint.FOREIGN_KEY && isAccessibleTable(constraint.getRef())) {
fkConstraintsList.add(constraint);
}
}
}
// Do it.
for (int i = 0; i < fkConstraintsList.size(); i++) {
constraint = (Constraint) fkConstraintsList.get(i);
pkTable = constraint.getMain();
pkInfo.setTable(pkTable);
pkTableName = pkInfo.getName();
fkTable = constraint.getRef();
fkInfo.setTable(fkTable);
fkTableName = fkInfo.getName();
pkTableCatalog = pkTable.getCatalogName().name;
pkTableSchema = pkTable.getSchemaName().name;
fkTableCatalog = fkTable.getCatalogName().name;
fkTableSchema = fkTable.getSchemaName().name;
mainCols = constraint.getMainColumns();
refCols = constraint.getRefColumns();
columnCount = refCols.length;
fkName = constraint.getRefName().name;
pkName = constraint.getMainName().name;
deferrability = ValuePool.getInt(constraint.getDeferability());
//pkName = constraint.getMainIndex().getName().name;
deleteRule = ValuePool.getInt(constraint.getDeleteAction());
updateRule = ValuePool.getInt(constraint.getUpdateAction());
for (int j = 0; j < columnCount; j++) {
keySequence = ValuePool.getInt(j + 1);
pkColumnName = pkInfo.getColName(mainCols[j]);
fkColumnName = fkInfo.getColName(refCols[j]);
row = t.getEmptyRowData();
row[ipk_table_cat] = pkTableCatalog;
row[ipk_table_schem] = pkTableSchema;
row[ipk_table_name] = pkTableName;
row[ipk_column_name] = pkColumnName;
row[ifk_table_cat] = fkTableCatalog;
row[ifk_table_schem] = fkTableSchema;
row[ifk_table_name] = fkTableName;
row[ifk_column_name] = fkColumnName;
row[ikey_seq] = keySequence;
row[iupdate_rule] = updateRule;
row[idelete_rule] = deleteRule;
row[ifk_name] = fkName;
row[ipk_name] = pkName;
row[ideferrability] = deferrability;
t.insertSys(store, row);
}
}
return t;
}
Aggregations