use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.
the class DatabaseInformationFull method CONSTRAINT_COLUMN_USAGE.
/**
* The CONSTRAINT_COLUMN_USAGE view has one row for each column identified by
* a table constraint or assertion.<p>
*
* <b>Definition:</b><p>
*
* TABLE_CATALOG VARCHAR
* TABLE_SCHEMA VARCHAR
* TABLE_NAME VARCHAR
* COLUMN_NAME VARCHAR
* CONSTRAINT_CATALOG VARCHAR
* CONSTRAINT_SCHEMA VARCHAR
* CONSTRAINT_NAME VARCHAR
*
* </pre>
*
* <b>Description:</b> <p>
*
* <ol>
* <li> The values of TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, and
* COLUMN_NAME are the catalog name, unqualified schema name,
* qualified identifier, and column name, respectively, of a column
* identified by a <column reference> explicitly or implicitly
* contained in the <search condition> of the constraint
* being described.
*
* <li> The values of CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, and
* CONSTRAINT_NAME are the catalog name, unqualified schema name,
* and qualified identifier, respectively, of the constraint being
* described. <p>
*
* </ol>
*
* @return Table
*/
Table CONSTRAINT_COLUMN_USAGE() {
Table t = sysTables[CONSTRAINT_COLUMN_USAGE];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[CONSTRAINT_COLUMN_USAGE]);
addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);
addColumn(t, "CONSTRAINT_CATALOG", SQL_IDENTIFIER);
addColumn(t, "CONSTRAINT_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "CONSTRAINT_NAME", SQL_IDENTIFIER);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[CONSTRAINT_COLUMN_USAGE].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5, 6 }, false);
return t;
}
// column number mappings
final int table_catalog = 0;
final int table_schems = 1;
final int table_name = 2;
final int column_name = 3;
final int constraint_catalog = 4;
final int constraint_schema = 5;
final int constraint_name = 6;
//
PersistentStore store = database.persistentStoreCollection.getStore(t);
// calculated column values
String constraintCatalog;
String constraintSchema;
String constraintName;
// Intermediate holders
Iterator tables;
Table table;
Constraint[] constraints;
int constraintCount;
Constraint constraint;
Iterator iterator;
Object[] row;
// Initialization
tables = database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
// Do it.
while (tables.hasNext()) {
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;
// process constraints
for (int i = 0; i < constraintCount; i++) {
constraint = constraints[i];
constraintName = constraint.getName().name;
switch(constraint.getConstraintType()) {
case Constraint.CHECK:
{
OrderedHashSet expressions = constraint.getCheckColumnExpressions();
if (expressions == null) {
break;
}
iterator = expressions.iterator();
// calculate distinct column references
while (iterator.hasNext()) {
ExpressionColumn expr = (ExpressionColumn) iterator.next();
HsqlName name = expr.getBaseColumnHsqlName();
if (name.type != SchemaObject.COLUMN) {
continue;
}
row = t.getEmptyRowData();
row[table_catalog] = database.getCatalogName().name;
row[table_schems] = name.schema.name;
row[table_name] = name.parent.name;
row[column_name] = name.name;
row[constraint_catalog] = constraintCatalog;
row[constraint_schema] = constraintSchema;
row[constraint_name] = constraintName;
try {
t.insertSys(store, row);
} catch (HsqlException e) {
}
}
break;
}
case Constraint.UNIQUE:
case Constraint.PRIMARY_KEY:
case Constraint.FOREIGN_KEY:
{
Table target = table;
int[] cols = constraint.getMainColumns();
if (constraint.getConstraintType() == Constraint.FOREIGN_KEY) {
target = constraint.getMain();
}
/*
checkme - it seems foreign key columns are not included
but columns of the referenced unique constraint are included
if (constraint.getType() == Constraint.FOREIGN_KEY) {
for (int j = 0; j < cols.length; j++) {
row = t.getEmptyRowData();
Table mainTable = constraint.getMain();
row[table_catalog] = database.getCatalog();
row[table_schems] =
mainTable.getSchemaName().name;
row[table_name] = mainTable.getName().name;
row[column_name] = mainTable.getColumn(
cols[j]).columnName.name;
row[constraint_catalog] = constraintCatalog;
row[constraint_schema] = constraintSchema;
row[constraint_name] = constraintName;
try {
t.insertSys(row);
} catch (HsqlException e) {}
}
cols = constraint.getRefColumns();
}
*/
for (int j = 0; j < cols.length; j++) {
row = t.getEmptyRowData();
row[table_catalog] = database.getCatalogName().name;
row[table_schems] = constraintSchema;
row[table_name] = target.getName().name;
row[column_name] = target.getColumn(cols[j]).getName().name;
row[constraint_catalog] = constraintCatalog;
row[constraint_schema] = constraintSchema;
row[constraint_name] = constraintName;
try {
t.insertSys(store, row);
} catch (HsqlException e) {
}
}
//
}
}
}
}
return t;
}
use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.
the class DatabaseInformationFull method TRIGGER_SEQUENCE_USAGE.
Table TRIGGER_SEQUENCE_USAGE() {
Table t = sysTables[TRIGGER_SEQUENCE_USAGE];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[TRIGGER_SEQUENCE_USAGE]);
addColumn(t, "TRIGGER_CATALOG", SQL_IDENTIFIER);
addColumn(t, "TRIGGER_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "TRIGGER_NAME", SQL_IDENTIFIER);
addColumn(t, "SEQUENCE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "SEQUENCE_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "SEQUENCE_NAME", SQL_IDENTIFIER);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[TRIGGER_SEQUENCE_USAGE].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
// column number mappings
final int trigger_catalog = 0;
final int trigger_schema = 1;
final int trigger_name = 2;
final int sequence_catalog = 3;
final int sequence_schema = 4;
final int sequence_name = 5;
Iterator it;
Object[] row;
it = database.schemaManager.databaseObjectIterator(SchemaObject.TRIGGER);
while (it.hasNext()) {
TriggerDef trigger = (TriggerDef) it.next();
if (!session.getGrantee().isAccessible(trigger)) {
continue;
}
OrderedHashSet set = trigger.getReferences();
for (int i = 0; i < set.size(); i++) {
HsqlName refName = (HsqlName) set.get(i);
if (refName.type != SchemaObject.SEQUENCE) {
continue;
}
if (!session.getGrantee().isAccessible(refName)) {
continue;
}
row = t.getEmptyRowData();
row[trigger_catalog] = database.getCatalogName().name;
row[trigger_schema] = trigger.getSchemaName().name;
row[trigger_name] = trigger.getName().name;
row[sequence_catalog] = database.getCatalogName().name;
row[sequence_schema] = refName.schema.name;
row[sequence_name] = refName.name;
try {
t.insertSys(store, row);
} catch (HsqlException e) {
}
}
}
// Initialization
return t;
}
use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.
the class DatabaseInformationFull method TRIGGER_TABLE_USAGE.
Table TRIGGER_TABLE_USAGE() {
Table t = sysTables[TRIGGER_TABLE_USAGE];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[TRIGGER_TABLE_USAGE]);
addColumn(t, "TRIGGER_CATALOG", SQL_IDENTIFIER);
addColumn(t, "TRIGGER_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "TRIGGER_NAME", SQL_IDENTIFIER);
addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[TRIGGER_TABLE_USAGE].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
// column number mappings
final int trigger_catalog = 0;
final int trigger_schema = 1;
final int trigger_name = 2;
final int table_catalog = 3;
final int table_schema = 4;
final int table_name = 5;
Iterator it;
Object[] row;
it = database.schemaManager.databaseObjectIterator(SchemaObject.TRIGGER);
while (it.hasNext()) {
TriggerDef trigger = (TriggerDef) it.next();
if (!session.getGrantee().isAccessible(trigger)) {
continue;
}
OrderedHashSet set = trigger.getReferences();
for (int i = 0; i < set.size(); i++) {
HsqlName refName = (HsqlName) set.get(i);
if (refName.type != SchemaObject.TABLE && refName.type != SchemaObject.VIEW) {
continue;
}
if (!session.getGrantee().isAccessible(refName)) {
continue;
}
row = t.getEmptyRowData();
row[trigger_catalog] = database.getCatalogName().name;
row[trigger_schema] = trigger.getSchemaName().name;
row[trigger_name] = trigger.getName().name;
row[table_catalog] = database.getCatalogName().name;
row[table_schema] = refName.schema.name;
row[table_name] = refName.name;
try {
t.insertSys(store, row);
} catch (HsqlException e) {
}
}
}
// Initialization
return t;
}
use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.
the class DatabaseInformationFull method VIEW_COLUMN_USAGE.
/**
* The VIEW_COLUMN_USAGE table has one row for each column of a
* table that is explicitly or implicitly referenced in the
* <query expression> of the view being described. <p>
*
* <b>Definition:</b> <p>
*
* <pre class="SqlCodeExample">
* CREATE TABLE SYSTEM_VIEW_COLUMN_USAGE (
* VIEW_CATALOG VARCHAR NULL,
* VIEW_SCHEMA VARCHAR NULL,
* VIEW_NAME VARCHAR NOT NULL,
* TABLE_CATALOG VARCHAR NULL,
* TABLE_SCHEMA VARCHAR NULL,
* TABLE_NAME VARCHAR NOT NULL,
* COLUMN_NAME VARCHAR NOT NULL,
* UNIQUE ( VIEW_CATALOG, VIEW_SCHEMA, VIEW_NAME,
* TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME,
* COLUMN_NAME )
* )
* </pre>
*
* <b>Description:</b> <p>
*
* <ol>
* <li> The values of VIEW_CATALOG, VIEW_SCHEMA, and VIEW_NAME are the
* catalog name, unqualified schema name, and qualified identifier,
* respectively, of the view being described. <p>
*
* <li> The values of TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, and
* COLUMN_NAME are the catalog name, unqualified schema name,
* qualified identifier, and column name, respectively, of a column
* of a table that is explicitly or implicitly referenced in the
* <query expression> of the view being described.
* </ol>
*
* @return Table
*/
Table VIEW_COLUMN_USAGE() {
Table t = sysTables[VIEW_COLUMN_USAGE];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[VIEW_COLUMN_USAGE]);
addColumn(t, "VIEW_CATALOG", SQL_IDENTIFIER);
addColumn(t, "VIEW_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "VIEW_NAME", SQL_IDENTIFIER);
addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[VIEW_COLUMN_USAGE].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5, 6 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
// Calculated column values
String viewCatalog;
String viewSchema;
String viewName;
// Intermediate holders
Iterator tables;
View view;
Table table;
Object[] row;
Iterator iterator;
// Column number mappings
final int view_catalog = 0;
final int view_schema = 1;
final int view_name = 2;
final int table_catalog = 3;
final int table_schema = 4;
final int table_name = 5;
final int column_name = 6;
// Initialization
tables = database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
// Do it.
while (tables.hasNext()) {
table = (Table) tables.next();
if (table.isView() && session.getGrantee().isFullyAccessibleByRole(table)) {
// $FALL-THROUGH$
} else {
continue;
}
viewCatalog = database.getCatalogName().name;
viewSchema = table.getSchemaName().name;
viewName = table.getName().name;
view = (View) table;
OrderedHashSet references = view.getReferences();
iterator = references.iterator();
while (iterator.hasNext()) {
HsqlName refName = (HsqlName) iterator.next();
if (refName.type == SchemaObject.COLUMN) {
row = t.getEmptyRowData();
row[view_catalog] = viewCatalog;
row[view_schema] = viewSchema;
row[view_name] = viewName;
row[table_catalog] = viewCatalog;
row[table_schema] = refName.parent.schema.name;
row[table_name] = refName.parent.name;
row[column_name] = refName.name;
try {
t.insertSys(store, row);
} catch (HsqlException e) {
}
}
}
}
return t;
}
use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.
the class DatabaseInformationFull method ROUTINE_PRIVILEGES.
Table ROUTINE_PRIVILEGES() {
Table t = sysTables[ROUTINE_PRIVILEGES];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[ROUTINE_PRIVILEGES]);
// not null
addColumn(t, "GRANTOR", SQL_IDENTIFIER);
// not null
addColumn(t, "GRANTEE", SQL_IDENTIFIER);
addColumn(t, "SPECIFIC_CATALOG", SQL_IDENTIFIER);
addColumn(t, "SPECIFIC_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "SPECIFIC_NAME", SQL_IDENTIFIER);
addColumn(t, "ROUTINE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "ROUTINE_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "ROUTINE_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "PRIVILEGE_TYPE", CHARACTER_DATA);
// not null
addColumn(t, "IS_GRANTABLE", YES_OR_NO);
//
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ROUTINE_PRIVILEGES].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, false);
return t;
}
// column number mappings
final int grantor = 0;
final int grantee = 1;
final int specific_catalog = 2;
final int specific_schema = 3;
final int specific_name = 4;
final int routine_catalog = 5;
final int routine_schema = 6;
final int routine_name = 7;
final int privilege_type = 8;
final int is_grantable = 9;
//
PersistentStore store = database.persistentStoreCollection.getStore(t);
// calculated column values
Grantee granteeObject;
String privilege;
// intermediate holders
Iterator routines;
RoutineSchema routine;
Object[] row;
OrderedHashSet grantees = session.getGrantee().getGranteeAndAllRolesWithPublic();
routines = database.schemaManager.databaseObjectIterator(SchemaObject.ROUTINE);
while (routines.hasNext()) {
routine = (RoutineSchema) routines.next();
for (int i = 0; i < grantees.size(); i++) {
granteeObject = (Grantee) grantees.get(i);
OrderedHashSet rights = granteeObject.getAllDirectPrivileges(routine);
OrderedHashSet grants = granteeObject.getAllGrantedPrivileges(routine);
if (!grants.isEmpty()) {
grants.addAll(rights);
rights = grants;
}
for (int j = 0; j < rights.size(); j++) {
Right right = (Right) rights.get(j);
Right grantableRight = right.getGrantableRights();
for (int k = 0; k < Right.privilegeTypes.length; k++) {
if (!right.canAccess(Right.privilegeTypes[k])) {
continue;
}
Routine[] specifics = routine.getSpecificRoutines();
for (int m = 0; m < specifics.length; m++) {
privilege = Right.privilegeNames[k];
row = t.getEmptyRowData();
//
row[grantor] = right.getGrantor().getName().name;
row[grantee] = right.getGrantee().getName().name;
row[specific_catalog] = database.getCatalogName().name;
row[specific_schema] = specifics[m].getSchemaName().name;
row[specific_name] = specifics[m].getName().name;
row[routine_catalog] = database.getCatalogName().name;
row[routine_schema] = routine.getSchemaName().name;
row[routine_name] = routine.getName().name;
row[privilege_type] = privilege;
row[is_grantable] = right.getGrantee() == routine.getOwner() || grantableRight.canAccess(Right.privilegeTypes[k]) ? "YES" : "NO";
try {
t.insertSys(store, row);
} catch (HsqlException e) {
}
}
}
}
}
}
return t;
}
Aggregations