use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.
the class DatabaseInformationMain method SYSTEM_TYPEINFO.
/**
* Retrieves a <code>Table</code> object describing the
* result expected by the JDBC DatabaseMetaData interface implementation
* for system-defined SQL types supported as table columns.
*
* <pre class="SqlCodeExample">
* TYPE_NAME VARCHAR the canonical name for DDL statements.
* DATA_TYPE SMALLINT data type code from DITypes.
* PRECISION INTEGER max column size.
* number => max precision.
* character => max characters.
* datetime => max chars incl. frac. component.
* LITERAL_PREFIX VARCHAR char(s) prefixing literal of this type.
* LITERAL_SUFFIX VARCHAR char(s) terminating literal of this type.
* CREATE_PARAMS VARCHAR Localized syntax-order list of domain
* create parameter keywords.
* - for human consumption only
* NULLABLE SMALLINT {No Nulls | Nullable | Unknown}
* CASE_SENSITIVE BOOLEAN case-sensitive in collations/comparisons?
* SEARCHABLE SMALLINT {None | Char (Only WHERE .. LIKE) |
* Basic (Except WHERE .. LIKE) |
* Searchable (All forms)}
* UNSIGNED_ATTRIBUTE BOOLEAN {TRUE (unsigned) | FALSE (signed) |
* NULL (non-numeric or not applicable)}
* FIXED_PREC_SCALE BOOLEAN {TRUE (fixed) | FALSE (variable) |
* NULL (non-numeric or not applicable)}
* AUTO_INCREMENT BOOLEAN automatic unique value generated for
* inserts and updates when no value or
* NULL specified?
* LOCAL_TYPE_NAME VARCHAR localized name of data type;
* - NULL if not supported.
* - for human consuption only
* MINIMUM_SCALE SMALLINT minimum scale supported.
* MAXIMUM_SCALE SMALLINT maximum scale supported.
* SQL_DATA_TYPE INTEGER value expected in SQL CLI SQL_DESC_TYPE
* field of the SQLDA.
* SQL_DATETIME_SUB INTEGER SQL CLI datetime/interval subcode.
* NUM_PREC_RADIX INTEGER numeric base w.r.t # of digits reported in
* PRECISION column (typically 10).
* TYPE_SUB INTEGER From DITypes:
* {TYPE_SUB_DEFAULT | TYPE_SUB_IDENTITY |
* TYPE_SUB_IGNORECASE}
* </pre> <p>
*
* @return a <code>Table</code> object describing the
* system-defined SQL types supported as table columns
*/
final Table SYSTEM_TYPEINFO() {
Table t = sysTables[SYSTEM_TYPEINFO];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SYSTEM_TYPEINFO]);
//-------------------------------------------
// required by JDBC:
// ------------------------------------------
addColumn(t, "TYPE_NAME", SQL_IDENTIFIER);
addColumn(t, "DATA_TYPE", Type.SQL_SMALLINT);
addColumn(t, "PRECISION", Type.SQL_INTEGER);
addColumn(t, "LITERAL_PREFIX", CHARACTER_DATA);
addColumn(t, "LITERAL_SUFFIX", CHARACTER_DATA);
addColumn(t, "CREATE_PARAMS", CHARACTER_DATA);
addColumn(t, "NULLABLE", Type.SQL_SMALLINT);
addColumn(t, "CASE_SENSITIVE", Type.SQL_BOOLEAN);
addColumn(t, "SEARCHABLE", Type.SQL_INTEGER);
addColumn(t, "UNSIGNED_ATTRIBUTE", Type.SQL_BOOLEAN);
addColumn(t, "FIXED_PREC_SCALE", Type.SQL_BOOLEAN);
addColumn(t, "AUTO_INCREMENT", Type.SQL_BOOLEAN);
addColumn(t, "LOCAL_TYPE_NAME", SQL_IDENTIFIER);
addColumn(t, "MINIMUM_SCALE", Type.SQL_SMALLINT);
addColumn(t, "MAXIMUM_SCALE", Type.SQL_SMALLINT);
addColumn(t, "SQL_DATA_TYPE", Type.SQL_INTEGER);
addColumn(t, "SQL_DATETIME_SUB", Type.SQL_INTEGER);
addColumn(t, "NUM_PREC_RADIX", Type.SQL_INTEGER);
//-------------------------------------------
// for JDBC sort contract:
//-------------------------------------------
addColumn(t, "TYPE_SUB", Type.SQL_INTEGER);
// order: DATA_TYPE, TYPE_SUB
// true PK
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_TYPEINFO].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 1, 18 }, true);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
Session sys = database.sessionManager.newSysSession(SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
Result rs = sys.executeDirectStatement("select TYPE_NAME, DATA_TYPE, PRECISION, LITERAL_PREFIX," + "LITERAL_SUFFIX, CREATE_PARAMS, NULLABLE, CASE_SENSITIVE," + "SEARCHABLE," + "UNSIGNED_ATTRIBUTE, FIXED_PREC_SCALE, AUTO_INCREMENT, LOCAL_TYPE_NAME, MINIMUM_SCALE, " + "MAXIMUM_SCALE, SQL_DATA_TYPE, SQL_DATETIME_SUB, NUM_PREC_RADIX, TYPE_SUB " + "from INFORMATION_SCHEMA.SYSTEM_ALLTYPEINFO where AS_TAB_COL = true;");
t.insertSys(store, rs);
sys.close();
return t;
}
use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.
the class DatabaseInformationFull method ROUTINE_SEQUENCE_USAGE.
Table ROUTINE_SEQUENCE_USAGE() {
Table t = sysTables[ROUTINE_SEQUENCE_USAGE];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[ROUTINE_SEQUENCE_USAGE]);
addColumn(t, "SPECIFIC_CATALOG", SQL_IDENTIFIER);
addColumn(t, "SPECIFIC_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "SPECIFIC_NAME", SQL_IDENTIFIER);
addColumn(t, "SEQUENCE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "SEQUENCE_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "SEQUENCE_NAME", SQL_IDENTIFIER);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ROUTINE_SEQUENCE_USAGE].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5 }, false);
return t;
}
// column number mappings
final int specific_catalog = 0;
final int specific_schema = 1;
final int specific_name = 2;
final int sequence_catalog = 3;
final int sequence_schema = 4;
final int sequence_name = 5;
//
PersistentStore store = database.persistentStoreCollection.getStore(t);
Iterator it;
Object[] row;
it = database.schemaManager.databaseObjectIterator(SchemaObject.ROUTINE);
while (it.hasNext()) {
RoutineSchema routine = (RoutineSchema) it.next();
if (!session.getGrantee().isAccessible(routine)) {
continue;
}
Routine[] specifics = routine.getSpecificRoutines();
for (int m = 0; m < specifics.length; m++) {
OrderedHashSet set = specifics[m].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[specific_catalog] = database.getCatalogName().name;
row[specific_schema] = specifics[m].getSchemaName().name;
row[specific_name] = specifics[m].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) {
}
}
}
}
return t;
}
use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.
the class DatabaseInformationFull method ROLE_COLUMN_GRANTS.
Table ROLE_COLUMN_GRANTS() {
Table t = sysTables[ROLE_COLUMN_GRANTS];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[ROLE_COLUMN_GRANTS]);
// 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, "COLUMN_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "PRIVILEGE_TYPE", CHARACTER_DATA);
// not null
addColumn(t, "IS_GRANTABLE", YES_OR_NO);
// order: COLUMN_NAME, PRIVILEGE
// for unique: GRANTEE, GRANTOR, TABLE_NAME, TABLE_SCHEMA, TABLE_CAT
// false PK, as TABLE_SCHEMA and/or TABLE_CAT may be null
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ROLE_COLUMN_GRANTS].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 5, 6, 1, 0, 4, 3, 2 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
Session sys = database.sessionManager.newSysSession(SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
Result rs = sys.executeDirectStatement("SELECT GRANTOR, GRANTEE, TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, PRIVILEGE_TYPE, IS_GRANTABLE " + "FROM INFORMATION_SCHEMA.COLUMN_PRIVILEGES " + "JOIN INFORMATION_SCHEMA.APPLICABLE_ROLES ON GRANTEE = ROLE_NAME;");
t.insertSys(store, rs);
sys.close();
return t;
}
use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.
the class DatabaseInformationFull method SQL_PACKAGES.
Table SQL_PACKAGES() {
Table t = sysTables[SQL_PACKAGES];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SQL_PACKAGES]);
addColumn(t, "ID", CHARACTER_DATA);
addColumn(t, "NAME", CHARACTER_DATA);
addColumn(t, "IS_SUPPORTED", YES_OR_NO);
addColumn(t, "IS_VERIFIED_BY", CHARACTER_DATA);
addColumn(t, "COMMENTS", CHARACTER_DATA);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SQL_PACKAGES].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());
String sql = (String) statementMap.get("/*sql_packages*/");
Result rs = sys.executeDirectStatement(sql);
t.insertSys(store, rs);
return t;
}
use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.
the class DatabaseInformationMain method COLUMN_PRIVILEGES.
// -----------------------------------------------------------------------------
// SQL SCHEMATA VIEWS
// limited to views used in JDBC DatabaseMetaData
/**
* Retrieves a <code>Table</code> object describing the visible
* access rights for all visible columns of all accessible
* tables defined within this database.<p>
*
* Each row is a column privilege 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
* GRANTOR VARCHAR grantor of access
* GRANTEE VARCHAR grantee of access
* PRIVILEGE VARCHAR name of access
* IS_GRANTABLE VARCHAR grantable?: "YES" - grant to others, else "NO"
* </pre>
*
* <b>Note:</b> From 1.9.0, HSQLDB supports column level
* privileges. <p>
*
* @return a <code>Table</code> object describing the visible
* access rights for all visible columns of
* all accessible tables defined within this
* database
*/
final Table COLUMN_PRIVILEGES() {
Table t = sysTables[COLUMN_PRIVILEGES];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[COLUMN_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, "COLUMN_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[COLUMN_PRIVILEGES].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 2, 3, 4, 5, 6, 1, 0 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
// calculated column values
String tableCatalog;
String tableSchema;
String tableName;
Grantee granteeObject;
// intermediate holders
User user;
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 column_name = 5;
final int privilege_type = 6;
final int is_grantable = 7;
// enumerations
OrderedHashSet grantees = session.getGrantee().getGranteeAndAllRolesWithPublic();
// Initialization
tables = allTables();
while (tables.hasNext()) {
table = (Table) tables.next();
tableName = table.getName().name;
tableCatalog = database.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++) {
OrderedHashSet columnList = right.getColumnsForPrivilege(table, Right.privilegeTypes[k]);
OrderedHashSet grantableList = grantableRight.getColumnsForPrivilege(table, Right.privilegeTypes[k]);
for (int l = 0; l < columnList.size(); l++) {
HsqlName fullName = ((HsqlName) columnList.get(l));
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[column_name] = fullName.name;
row[privilege_type] = Right.privilegeNames[k];
row[is_grantable] = right.getGrantee() == table.getOwner() || grantableList.contains(fullName) ? "YES" : "NO";
try {
t.insertSys(store, row);
} catch (HsqlException e) {
}
}
}
}
}
}
return t;
}
Aggregations