use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.
the class DatabaseInformationFull method insertRoles.
private void insertRoles(Table t, Grantee role, boolean isGrantable) {
final int grantee = 0;
final int role_name = 1;
final int is_grantable = 2;
PersistentStore store = database.persistentStoreCollection.getStore(t);
if (isGrantable) {
Set roles = database.getGranteeManager().getRoleNames();
Iterator it = roles.iterator();
while (it.hasNext()) {
String roleName = (String) it.next();
Object[] row = t.getEmptyRowData();
row[grantee] = role.getNameString();
row[role_name] = roleName;
row[is_grantable] = "YES";
t.insertSys(store, row);
}
} else {
OrderedHashSet roles = role.getDirectRoles();
for (int i = 0; i < roles.size(); i++) {
String roleName = (String) roles.get(i);
Object[] row = t.getEmptyRowData();
row[grantee] = role.getNameString();
row[role_name] = roleName;
row[is_grantable] = Tokens.T_NO;
t.insertSys(store, row);
role = database.getGranteeManager().getRole(roleName);
insertRoles(t, role, isGrantable);
}
}
}
use of org.hsqldb_voltpatches.persist.PersistentStore 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.persist.PersistentStore in project voltdb by VoltDB.
the class DatabaseInformationFull method COLUMNS.
Table COLUMNS() {
Table t = sysTables[COLUMNS];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[COLUMNS]);
//0
addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);
addColumn(t, "ORDINAL_POSITION", CARDINAL_NUMBER);
addColumn(t, "COLUMN_DEFAULT", CHARACTER_DATA);
addColumn(t, "IS_NULLABLE", YES_OR_NO);
addColumn(t, "DATA_TYPE", CHARACTER_DATA);
addColumn(t, "CHARACTER_MAXIMUM_LENGTH", CARDINAL_NUMBER);
addColumn(t, "CHARACTER_OCTET_LENGTH", CARDINAL_NUMBER);
//10
addColumn(t, "NUMERIC_PRECISION", CARDINAL_NUMBER);
addColumn(t, "NUMERIC_PRECISION_RADIX", CARDINAL_NUMBER);
addColumn(t, "NUMERIC_SCALE", CARDINAL_NUMBER);
addColumn(t, "DATETIME_PRECISION", CARDINAL_NUMBER);
addColumn(t, "INTERVAL_TYPE", CHARACTER_DATA);
addColumn(t, "INTERVAL_PRECISION", CARDINAL_NUMBER);
addColumn(t, "CHARACTER_SET_CATALOG", CHARACTER_DATA);
addColumn(t, "CHARACTER_SET_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "CHARACTER_SET_NAME", SQL_IDENTIFIER);
addColumn(t, "COLLATION_CATALOG", SQL_IDENTIFIER);
//20
addColumn(t, "COLLATION_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "COLLATION_NAME", SQL_IDENTIFIER);
addColumn(t, "DOMAIN_CATALOG", SQL_IDENTIFIER);
addColumn(t, "DOMAIN_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "DOMAIN_NAME", SQL_IDENTIFIER);
addColumn(t, "UDT_CATALOG", SQL_IDENTIFIER);
addColumn(t, "UDT_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "UDT_NAME", SQL_IDENTIFIER);
addColumn(t, "SCOPE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "SCOPE_SCHEMA", SQL_IDENTIFIER);
//30
addColumn(t, "SCOPE_NAME", SQL_IDENTIFIER);
// NULL (only for array tyes)
addColumn(t, "MAXIMUM_CARDINALITY", CARDINAL_NUMBER);
addColumn(t, "DTD_IDENTIFIER", SQL_IDENTIFIER);
addColumn(t, "IS_SELF_REFERENCING", YES_OR_NO);
addColumn(t, "IS_IDENTITY", YES_OR_NO);
// ALLWAYS / BY DEFAULT
addColumn(t, "IDENTITY_GENERATION", CHARACTER_DATA);
addColumn(t, "IDENTITY_START", CHARACTER_DATA);
addColumn(t, "IDENTITY_INCREMENT", CHARACTER_DATA);
addColumn(t, "IDENTITY_MAXIMUM", CHARACTER_DATA);
addColumn(t, "IDENTITY_MINIMUM", CHARACTER_DATA);
//40
addColumn(t, "IDENTITY_CYCLE", YES_OR_NO);
// ALLWAYS / NEVER
addColumn(t, "IS_GENERATED", CHARACTER_DATA);
addColumn(t, "GENERATION_EXPRESSION", CHARACTER_DATA);
addColumn(t, "IS_UPDATABLE", YES_OR_NO);
addColumn(t, "DECLARED_DATA_TYPE", CHARACTER_DATA);
addColumn(t, "DECLARED_NUMERIC_PRECISION", CARDINAL_NUMBER);
addColumn(t, "DECLARED_NUMERIC_SCALE", CARDINAL_NUMBER);
// order: TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION
// added for unique: TABLE_CAT
// false PK, as TABLE_SCHEM and/or TABLE_CAT may be null
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[COLUMNS].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 3, 2, 1, 4 }, false);
return t;
}
// column number mappings
final int table_cat = 0;
final int table_schem = 1;
final int table_name = 2;
final int column_name = 3;
final int ordinal_position = 4;
final int column_default = 5;
final int is_nullable = 6;
final int data_type = 7;
final int character_maximum_length = 8;
final int character_octet_length = 9;
final int numeric_precision = 10;
final int numeric_precision_radix = 11;
final int numeric_scale = 12;
final int datetime_precision = 13;
final int interval_type = 14;
final int interval_precision = 15;
final int character_set_catalog = 16;
final int character_set_schema = 17;
final int character_set_name = 18;
final int collation_catalog = 19;
final int collation_schema = 20;
final int collation_name = 21;
final int domain_catalog = 22;
final int domain_schema = 23;
final int domain_name = 24;
final int udt_catalog = 25;
final int udt_schema = 26;
final int udt_name = 27;
final int scope_catalog = 28;
final int scope_schema = 29;
final int scope_name = 30;
final int maximum_cardinality = 31;
final int dtd_identifier = 32;
final int is_self_referencing = 33;
final int is_identity = 34;
final int identity_generation = 35;
final int identity_start = 36;
final int identity_increment = 37;
final int identity_maximum = 38;
final int identity_minimum = 39;
final int identity_cycle = 40;
final int is_generated = 41;
final int generation_expression = 42;
final int is_updatable = 43;
final int declared_data_type = 44;
final int declared_numeric_precision = 45;
final int declared_numeric_scale = 46;
//
PersistentStore store = database.persistentStoreCollection.getStore(t);
// intermediate holders
int columnCount;
Iterator tables;
Table table;
Object[] row;
DITableInfo ti;
OrderedHashSet columnList;
Type type;
// Initialization
tables = allTables();
ti = new DITableInfo();
while (tables.hasNext()) {
table = (Table) tables.next();
columnList = session.getGrantee().getColumnsForAllPrivileges(table);
if (columnList.isEmpty()) {
continue;
}
ti.setTable(table);
columnCount = table.getColumnCount();
for (int i = 0; i < columnCount; i++) {
ColumnSchema column = table.getColumn(i);
type = column.getDataType();
if (!columnList.contains(column.getName())) {
continue;
}
row = t.getEmptyRowData();
row[table_cat] = table.getCatalogName().name;
row[table_schem] = table.getSchemaName().name;
row[table_name] = table.getName().name;
row[column_name] = column.getName().name;
row[ordinal_position] = ValuePool.getInt(i + 1);
row[column_default] = column.getDefaultSQL();
row[is_nullable] = column.isNullable() ? "YES" : "NO";
row[data_type] = type.getFullNameString();
if (type.isCharacterType()) {
row[character_maximum_length] = ValuePool.getLong(type.precision);
row[character_octet_length] = ValuePool.getLong(type.precision * 2);
row[character_set_catalog] = database.getCatalogName().name;
row[character_set_schema] = ((CharacterType) type).getCharacterSet().getSchemaName().name;
row[character_set_name] = ((CharacterType) type).getCharacterSet().getName().name;
row[collation_catalog] = database.getCatalogName().name;
row[collation_schema] = ((CharacterType) type).getCollation().getSchemaName().name;
row[collation_name] = ((CharacterType) type).getCollation().getName().name;
}
if (type.isBinaryType()) {
row[character_maximum_length] = ValuePool.getLong(type.precision);
row[character_octet_length] = ValuePool.getLong(type.precision);
}
if (type.isNumberType()) {
row[numeric_precision] = ValuePool.getLong(type.precision);
row[numeric_precision_radix] = ValuePool.getLong(((NumberType) type).getPrecisionRadix());
row[numeric_scale] = ValuePool.getLong(type.scale);
}
if (type.isDateTimeType()) {
row[datetime_precision] = ValuePool.getLong(type.scale);
}
if (type.isIntervalType()) {
row[interval_type] = IntervalType.getQualifier(type.typeCode);
row[interval_precision] = ValuePool.getLong(type.precision);
row[datetime_precision] = ValuePool.getLong(type.scale);
}
if (type.isDomainType()) {
row[domain_catalog] = database.getCatalogName().name;
row[domain_schema] = type.getSchemaName().name;
row[domain_name] = type.getName().name;
}
if (type.isDistinctType()) {
row[udt_catalog] = database.getCatalogName().name;
row[udt_schema] = type.getSchemaName().name;
row[udt_name] = type.getName().name;
}
row[scope_catalog] = null;
row[scope_schema] = null;
row[scope_name] = null;
row[maximum_cardinality] = null;
row[dtd_identifier] = null;
row[is_self_referencing] = null;
row[is_identity] = column.isIdentity() ? "YES" : "NO";
if (column.isIdentity()) {
NumberSequence sequence = column.getIdentitySequence();
row[identity_generation] = sequence.isAlways() ? "ALWAYS" : "BY DEFAULT";
row[identity_start] = Long.toString(sequence.getStartValue());
row[identity_increment] = Long.toString(sequence.getIncrement());
row[identity_maximum] = Long.toString(sequence.getMaxValue());
row[identity_minimum] = Long.toString(sequence.getMinValue());
row[identity_cycle] = sequence.isCycle() ? "YES" : "NO";
}
row[is_generated] = "NEVER";
row[generation_expression] = null;
row[is_updatable] = table.isWritable() ? "YES" : "NO";
row[declared_data_type] = row[data_type];
if (type.isNumberType()) {
row[declared_numeric_precision] = row[numeric_precision];
row[declared_numeric_scale] = row[numeric_scale];
}
t.insertSys(store, row);
}
}
return t;
}
use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.
the class DatabaseInformationFull method SYSTEM_SESSIONS.
/**
* Retrieves a <code>Table</code> object describing all visible
* sessions. ADMIN users see *all* sessions
* while non-admin users see only their own session.<p>
*
* Each row is a session state description with the following columns: <p>
*
* <pre class="SqlCodeExample">
* SESSION_ID INTEGER session identifier
* CONNECTED TIMESTAMP time at which session was created
* USER_NAME VARCHAR db user name of current session user
* IS_ADMIN BOOLEAN is session user an admin user?
* AUTOCOMMIT BOOLEAN is session in autocommit mode?
* READONLY BOOLEAN is session in read-only mode?
* MAXROWS INTEGER session's MAXROWS setting
* LAST_IDENTITY INTEGER last identity value used by this session
* TRANSACTION_SIZE INTEGER # of undo items in current transaction
* SCHEMA VARCHAR current schema for session
* </pre> <p>
*
* @return a <code>Table</code> object describing all visible
* sessions
*/
Table SYSTEM_SESSIONS() {
Table t = sysTables[SYSTEM_SESSIONS];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SYSTEM_SESSIONS]);
addColumn(t, "SESSION_ID", CARDINAL_NUMBER);
addColumn(t, "CONNECTED", TIME_STAMP);
addColumn(t, "USER_NAME", SQL_IDENTIFIER);
addColumn(t, "IS_ADMIN", Type.SQL_BOOLEAN);
addColumn(t, "AUTOCOMMIT", Type.SQL_BOOLEAN);
addColumn(t, "READONLY", Type.SQL_BOOLEAN);
addColumn(t, "MAXROWS", CARDINAL_NUMBER);
// Note: some sessions may have a NULL LAST_IDENTITY value
addColumn(t, "LAST_IDENTITY", CARDINAL_NUMBER);
addColumn(t, "TRANSACTION_SIZE", CARDINAL_NUMBER);
addColumn(t, "SCHEMA", SQL_IDENTIFIER);
// order: SESSION_ID
// true primary key
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_SESSIONS].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0 }, true);
return t;
}
// column number mappings
final int isid = 0;
final int ict = 1;
final int iuname = 2;
final int iis_admin = 3;
final int iautocmt = 4;
final int ireadonly = 5;
final int imaxrows = 6;
final int ilast_id = 7;
final int it_size = 8;
final int it_schema = 9;
//
PersistentStore store = database.persistentStoreCollection.getStore(t);
// intermediate holders
Session[] sessions;
Session s;
Object[] row;
// Initialisation
sessions = ns.listVisibleSessions(session);
// Do it.
for (int i = 0; i < sessions.length; i++) {
s = sessions[i];
row = t.getEmptyRowData();
row[isid] = ValuePool.getLong(s.getId());
row[ict] = new TimestampData(s.getConnectTime() / 1000);
row[iuname] = s.getUsername();
row[iis_admin] = ValuePool.getBoolean(s.isAdmin());
row[iautocmt] = ValuePool.getBoolean(s.isAutoCommit());
row[ireadonly] = ValuePool.getBoolean(s.isReadOnlyDefault());
row[imaxrows] = ValuePool.getInt(s.getSQLMaxRows());
row[ilast_id] = ValuePool.getLong(((Number) s.getLastIdentity()).longValue());
row[it_size] = ValuePool.getInt(s.getTransactionSize());
row[it_schema] = s.getCurrentSchemaHsqlName().name;
t.insertSys(store, row);
}
return t;
}
use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.
the class DatabaseInformationFull method JARS.
Table JARS() {
Table t = sysTables[JARS];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[JARS]);
addColumn(t, "JAR_CATALOG", SQL_IDENTIFIER);
addColumn(t, "JAR_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "JAR_NAME", SQL_IDENTIFIER);
addColumn(t, "JAR_PATH", CHARACTER_DATA);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[JARS].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2, 3 }, false);
return t;
}
// column number mappings
final int jar_catalog = 0;
final int jar_schema = 1;
final int jar_name = 2;
final int jar_path = 3;
//
PersistentStore store = database.persistentStoreCollection.getStore(t);
Iterator it;
Object[] row;
return t;
}
Aggregations