use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.
the class DatabaseInformationMain method TABLE_PRIVILEGES.
/*
WHERE ( GRANTEE IN ( 'PUBLIC', CURRENT_USER )
OR GRANTEE IN ( SELECT ROLE_NAME FROM ENABLED_ROLES )
OR GRANTOR = CURRENT_USER
OR GRANTOR IN ( SELECT ROLE_NAME FROM ENABLED_ROLES ) )
*/
/**
* The TABLE_PRIVILEGES view has one row for each visible access
* right for each accessible table definied within this database. <p>
*
* Each row is a table privilege description with the following columns: <p>
*
* <pre class="SqlCodeExample">
* GRANTOR VARCHAR grantor of access
* GRANTEE VARCHAR grantee of access
* TABLE_CATALOG VARCHAR table catalog
* TABLE_SCHEMA VARCHAR table schema
* TABLE_NAME VARCHAR table name
* PRIVILEGE_TYPE VARCHAR { "SELECT" | "INSERT" | "UPDATE" | "DELETE" | "REFERENCES" | "TRIGGER" }
* IS_GRANTABLE VARCHAR { "YES" | "NO" }
* WITH_HIERARCHY { "YES" | "NO" }
* </pre>
*
* @return a <code>Table</code> object describing the visible
* access rights for each accessible table
* defined within this database
*/
final Table TABLE_PRIVILEGES() {
Table t = sysTables[TABLE_PRIVILEGES];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[TABLE_PRIVILEGES]);
// not null
addColumn(t, "GRANTOR", SQL_IDENTIFIER);
// not null
addColumn(t, "GRANTEE", SQL_IDENTIFIER);
addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "PRIVILEGE_TYPE", CHARACTER_DATA);
// not null
addColumn(t, "IS_GRANTABLE", YES_OR_NO);
addColumn(t, "WITH_HIERARCHY", YES_OR_NO);
//
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SEQUENCES].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 tableCatalog;
String tableSchema;
String tableName;
Grantee granteeObject;
String privilege;
// intermediate holders
Iterator tables;
Table table;
Object[] row;
// column number mappings
final int grantor = 0;
final int grantee = 1;
final int table_catalog = 2;
final int table_schema = 3;
final int table_name = 4;
final int privilege_type = 5;
final int is_grantable = 6;
final int with_hierarchy = 7;
OrderedHashSet grantees = session.getGrantee().getGranteeAndAllRolesWithPublic();
tables = allTables();
while (tables.hasNext()) {
table = (Table) tables.next();
tableName = table.getName().name;
tableCatalog = table.getCatalogName().name;
tableSchema = table.getSchemaName().name;
for (int i = 0; i < grantees.size(); i++) {
granteeObject = (Grantee) grantees.get(i);
OrderedHashSet rights = granteeObject.getAllDirectPrivileges(table);
OrderedHashSet grants = granteeObject.getAllGrantedPrivileges(table);
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;
}
privilege = Right.privilegeNames[k];
row = t.getEmptyRowData();
row[grantor] = right.getGrantor().getName().name;
row[grantee] = right.getGrantee().getName().name;
row[table_catalog] = tableCatalog;
row[table_schema] = tableSchema;
row[table_name] = tableName;
row[privilege_type] = privilege;
row[is_grantable] = right.getGrantee() == table.getOwner() || grantableRight.canAccess(Right.privilegeTypes[k]) ? "YES" : "NO";
row[with_hierarchy] = "NO";
try {
t.insertSys(store, row);
} catch (HsqlException e) {
}
}
}
}
}
return t;
}
use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.
the class DatabaseInformationFull method SQL_IMPLEMENTATION_INFO.
Table SQL_IMPLEMENTATION_INFO() {
Table t = sysTables[SQL_IMPLEMENTATION_INFO];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SQL_IMPLEMENTATION_INFO]);
addColumn(t, "IMPLEMENTATION_INFO_ID", CHARACTER_DATA);
addColumn(t, "IMPLEMENTATION_INFO_NAME", CHARACTER_DATA);
addColumn(t, "INTEGER_VALUE", CARDINAL_NUMBER);
addColumn(t, "CHARACTER_VALUE", CHARACTER_DATA);
addColumn(t, "COMMENTS", CHARACTER_DATA);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SQL_IMPLEMENTATION_INFO].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
Session sys = database.sessionManager.newSysSession(SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
/*
Result rs = sys.executeDirectStatement(
"VALUES "
+ ";");
t.insertSys(store, rs);
*/
return t;
}
use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.
the class DatabaseInformationFull method VIEW_ROUTINE_USAGE.
/**
* The VIEW_ROUTINE_USAGE table 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 a <view
* definition>. <p>
*
* <b>Definition</b><p>
*
* <pre class="SqlCodeExample">
* CREATE TABLE VIEW_ROUTINE_USAGE (
* TABLE_CATALOG VARCHAR NULL,
* TABLE_SCHEMA VARCHAR NULL,
* TABLE_NAME VARCHAR NOT NULL,
* SPECIFIC_CATALOG VARCHAR NULL,
* SPECIFIC_SCHEMA VARCHAR NULL,
* SPECIFIC_NAME VARCHAR NOT NULL,
* UNIQUE( TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME,
* SPECIFIC_CATALOG, SPECIFIC_SCHEMA,
* SPECIFIC_NAME )
* )
* </pre>
*
* <b>Description</b><p>
*
* <ol>
* <li> The values of TABLE_CATALOG, TABLE_SCHEMA, and TABLE_NAME are the
* catalog name, unqualified schema name, and qualified identifier,
* respectively, of the viewed table 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 VIEW_ROUTINE_USAGE() {
Table t = sysTables[VIEW_ROUTINE_USAGE];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[VIEW_ROUTINE_USAGE]);
addColumn(t, "VIEW_CATALOG", SQL_IDENTIFIER);
addColumn(t, "VIEW_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "VIEW_NAME", SQL_IDENTIFIER);
addColumn(t, "SPECIFIC_CATALOG", SQL_IDENTIFIER);
addColumn(t, "SPECIFIC_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "SPECIFIC_NAME", SQL_IDENTIFIER);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[VIEW_ROUTINE_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);
// Intermediate holders
Iterator tables;
Table table;
Object[] row;
// Column number mappings
final int view_catalog = 0;
final int view_schema = 1;
final int view_name = 2;
final int specific_catalog = 3;
final int specific_schema = 4;
final int specific_name = 5;
// 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;
}
OrderedHashSet set = table.getReferences();
for (int i = 0; i < set.size(); i++) {
HsqlName refName = (HsqlName) set.get(i);
if (!session.getGrantee().isFullyAccessibleByRole(refName)) {
continue;
}
row = t.getEmptyRowData();
row[view_catalog] = database.getCatalogName().name;
row[view_schema] = table.getSchemaName().name;
row[view_name] = table.getName().name;
row[specific_catalog] = database.getCatalogName().name;
row[specific_schema] = refName.schema.name;
row[specific_name] = refName.name;
try {
t.insertSys(store, row);
} catch (HsqlException e) {
}
}
}
return t;
}
use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.
the class DatabaseInformationFull method SYSTEM_TEXTTABLES.
/**
* Retrieves a <code>Table</code> object describing the TEXT TABLE objects
* defined within this database. The table contains one row for each row
* in the SYSTEM_TABLES table with a HSQLDB_TYPE of TEXT . <p>
*
* Each row is a description of the attributes that defines its TEXT TABLE,
* with the following columns:
*
* <pre class="SqlCodeExample">
* TABLE_CAT VARCHAR table's catalog name
* TABLE_SCHEM VARCHAR table's simple schema name
* TABLE_NAME VARCHAR table's simple name
* DATA_SOURCE_DEFINITION VARCHAR the "spec" proption of the table's
* SET TABLE ... SOURCE DDL declaration
* FILE_PATH VARCHAR absolute file path.
* FILE_ENCODING VARCHAR endcoding of table's text file
* FIELD_SEPARATOR VARCHAR default field separator
* VARCHAR_SEPARATOR VARCAHR varchar field separator
* LONGVARCHAR_SEPARATOR VARCHAR longvarchar field separator
* IS_IGNORE_FIRST BOOLEAN ignores first line of file?
* IS_QUOTED BOOLEAN fields are quoted if necessary?
* IS_ALL_QUOTED BOOLEAN all fields are quoted?
* IS_DESC BOOLEAN read rows starting at end of file?
* </pre> <p>
*
* @return a <code>Table</code> object describing the text attributes
* of the accessible text tables defined within this database
*
*/
Table SYSTEM_TEXTTABLES() {
Table t = sysTables[SYSTEM_TEXTTABLES];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SYSTEM_TEXTTABLES]);
addColumn(t, "TABLE_CAT", SQL_IDENTIFIER);
addColumn(t, "TABLE_SCHEM", SQL_IDENTIFIER);
// not null
addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
addColumn(t, "DATA_SOURCE_DEFINTION", CHARACTER_DATA);
addColumn(t, "FILE_PATH", CHARACTER_DATA);
addColumn(t, "FILE_ENCODING", CHARACTER_DATA);
addColumn(t, "FIELD_SEPARATOR", CHARACTER_DATA);
addColumn(t, "VARCHAR_SEPARATOR", CHARACTER_DATA);
addColumn(t, "LONGVARCHAR_SEPARATOR", CHARACTER_DATA);
addColumn(t, "IS_IGNORE_FIRST", Type.SQL_BOOLEAN);
addColumn(t, "IS_ALL_QUOTED", Type.SQL_BOOLEAN);
addColumn(t, "IS_QUOTED", Type.SQL_BOOLEAN);
addColumn(t, "IS_DESC", Type.SQL_BOOLEAN);
// ------------------------------------------------------------
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_TEXTTABLES].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2 }, false);
return t;
}
// column number mappings
final int itable_cat = 0;
final int itable_schem = 1;
final int itable_name = 2;
final int idsd = 3;
final int ifile_path = 4;
final int ifile_enc = 5;
final int ifs = 6;
final int ivfs = 7;
final int ilvfs = 8;
final int iif = 9;
final int iiq = 10;
final int iiaq = 11;
final int iid = 12;
//
PersistentStore store = database.persistentStoreCollection.getStore(t);
// intermediate holders
Iterator tables;
Table table;
Object[] row;
// Initialization
tables = database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
// Do it.
while (tables.hasNext()) {
table = (Table) tables.next();
PersistentStore currentStore = database.persistentStoreCollection.getStore(t);
if (!table.isText() || !isAccessibleTable(table)) {
continue;
}
row = t.getEmptyRowData();
row[itable_cat] = database.getCatalogName().name;
row[itable_schem] = table.getSchemaName().name;
row[itable_name] = table.getName().name;
row[idsd] = ((TextTable) table).getDataSource();
TextCache cache = (TextCache) currentStore.getCache();
if (cache != null) {
row[ifile_path] = FileUtil.getDefaultInstance().canonicalOrAbsolutePath(cache.getFileName());
row[ifile_enc] = cache.stringEncoding;
row[ifs] = cache.fs;
row[ivfs] = cache.vs;
row[ilvfs] = cache.lvs;
row[iif] = ValuePool.getBoolean(cache.ignoreFirst);
row[iiq] = ValuePool.getBoolean(cache.isQuoted);
row[iiaq] = ValuePool.getBoolean(cache.isAllQuoted);
row[iid] = ((TextTable) table).isDescDataSource() ? Boolean.TRUE : Boolean.FALSE;
}
t.insertSys(store, row);
}
return t;
}
use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.
the class DatabaseInformationFull method KEY_COLUMN_USAGE.
/**
* Retrieves a <code>Table</code> object describing the
* primary key and unique constraint columns of each accessible table
* defined within this database. <p>
*
* Each row is a PRIMARY KEY or UNIQUE column description with the following
* columns: <p>
*
* <pre class="SqlCodeExample">
* CONSTRAINT_CATALOG VARCHAR NULL,
* CONSTRAINT_SCHEMA VARCHAR NULL,
* CONSTRAINT_NAME VARCHAR NOT NULL,
* TABLE_CATALOG VARCHAR table catalog
* TABLE_SCHEMA VARCHAR table schema
* TABLE_NAME VARCHAR table name
* COLUMN_NAME VARCHAR column name
* ORDINAL_POSITION INT
* POSITION_IN_UNIQUE_CONSTRAINT INT
* </pre> <p>
*
* @return a <code>Table</code> object describing the visible
* primary key and unique columns of each accessible table
* defined within this database.
*/
Table KEY_COLUMN_USAGE() {
Table t = sysTables[KEY_COLUMN_USAGE];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[KEY_COLUMN_USAGE]);
addColumn(t, "CONSTRAINT_CATALOG", SQL_IDENTIFIER);
addColumn(t, "CONSTRAINT_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "CONSTRAINT_NAME", SQL_IDENTIFIER);
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);
// not null
addColumn(t, "ORDINAL_POSITION", CARDINAL_NUMBER);
// not null
addColumn(t, "POSITION_IN_UNIQUE_CONSTRAINT", CARDINAL_NUMBER);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[KEY_COLUMN_USAGE].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 2, 1, 0, 6, 7 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
// Intermediate holders
Iterator tables;
Object[] row;
// column number mappings
final int constraint_catalog = 0;
final int constraint_schema = 1;
final int constraint_name = 2;
final int table_catalog = 3;
final int table_schema = 4;
final int table_name = 5;
final int column_name = 6;
final int ordinal_position = 7;
final int position_in_unique_constraint = 8;
// Initialization
tables = database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
while (tables.hasNext()) {
Table table = (Table) tables.next();
String tableCatalog = database.getCatalogName().name;
String tableSchema = table.getSchemaName().name;
String tableName = table.getName().name;
/** @todo - requires access to the actual columns */
if (table.isView() || !isAccessibleTable(table)) {
continue;
}
Constraint[] constraints = table.getConstraints();
for (int i = 0; i < constraints.length; i++) {
Constraint constraint = constraints[i];
if (constraint.getConstraintType() == Constraint.PRIMARY_KEY || constraint.getConstraintType() == Constraint.UNIQUE || constraint.getConstraintType() == Constraint.FOREIGN_KEY) {
String constraintName = constraint.getName().name;
int[] cols = constraint.getMainColumns();
int[] uniqueColMap = null;
if (constraint.getConstraintType() == Constraint.FOREIGN_KEY) {
Table uniqueConstTable = constraint.getMain();
Constraint uniqueConstraint = uniqueConstTable.getConstraint(constraint.getUniqueName().name);
int[] uniqueConstIndexes = uniqueConstraint.getMainColumns();
uniqueColMap = new int[cols.length];
for (int j = 0; j < cols.length; j++) {
uniqueColMap[j] = ArrayUtil.find(uniqueConstIndexes, cols[j]);
}
cols = constraint.getRefColumns();
}
for (int j = 0; j < cols.length; j++) {
row = t.getEmptyRowData();
row[constraint_catalog] = tableCatalog;
row[constraint_schema] = tableSchema;
row[constraint_name] = constraintName;
row[table_catalog] = tableCatalog;
row[table_schema] = tableSchema;
row[table_name] = tableName;
row[column_name] = table.getColumn(cols[j]).getName().name;
row[ordinal_position] = ValuePool.getInt(j + 1);
if (constraint.getConstraintType() == Constraint.FOREIGN_KEY) {
row[position_in_unique_constraint] = ValuePool.getInt(uniqueColMap[j] + 1);
}
t.insertSys(store, row);
}
}
}
}
return t;
}
Aggregations