use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.
the class ExpressionLogical method getAllAnyValue.
/** @todo - null value in rows */
private Boolean getAllAnyValue(Session session, Object[] data, SubQuery subquery) {
Table table = subquery.getTable();
boolean empty = table.isEmpty(session);
Index index = table.getFullIndex();
RowIterator it;
Row firstrow;
PersistentStore store = session.sessionData.getRowStore(table);
Row lastrow = index.lastRow(session, store);
Object[] lastdata;
Object[] firstdata;
switch(exprSubType) {
case OpTypes.ANY_QUANTIFIED:
{
if (empty) {
return Boolean.FALSE;
}
if (countNulls(data) == data.length) {
return null;
}
lastdata = lastrow.getData();
if (countNulls(lastdata) == data.length) {
return null;
}
convertToType(session, data, nodes[LEFT].nodeDataTypes, nodes[RIGHT].nodeDataTypes);
if (opType == OpTypes.EQUAL) {
it = index.findFirstRow(session, store, data);
return it.hasNext() ? Boolean.TRUE : Boolean.FALSE;
}
it = index.findFirstRowNotNull(session, store);
firstrow = it.getNextRow();
firstdata = firstrow.getData();
Boolean comparefirst = compareValues(session, data, firstdata);
Boolean comparelast = compareValues(session, data, lastdata);
switch(opType) {
case OpTypes.NOT_EQUAL:
return Boolean.TRUE.equals(comparefirst) || Boolean.TRUE.equals(comparelast) ? Boolean.TRUE : Boolean.FALSE;
case OpTypes.GREATER:
return comparefirst;
case OpTypes.GREATER_EQUAL:
return comparefirst;
case OpTypes.SMALLER:
return comparelast;
case OpTypes.SMALLER_EQUAL:
return comparelast;
}
break;
}
case OpTypes.ALL_QUANTIFIED:
{
if (empty) {
return Boolean.TRUE;
}
if (countNulls(data) == data.length) {
return null;
}
it = index.firstRow(session, store);
firstrow = it.getNextRow();
firstdata = firstrow.getData();
if (countNulls(firstdata) == data.length) {
return null;
}
convertToType(session, data, nodes[LEFT].nodeDataTypes, nodes[RIGHT].nodeDataTypes);
it = index.findFirstRow(session, store, data);
if (opType == OpTypes.EQUAL) {
if (it.hasNext()) {
return subquery.getTable().getRowCount(store) == 1 ? Boolean.TRUE : Boolean.FALSE;
} else {
return Boolean.FALSE;
}
}
if (opType == OpTypes.NOT_EQUAL) {
return it.hasNext() ? Boolean.FALSE : Boolean.TRUE;
}
lastdata = lastrow.getData();
Boolean comparefirst = compareValues(session, data, firstdata);
Boolean comparelast = compareValues(session, data, lastdata);
switch(opType) {
case OpTypes.GREATER:
return comparelast;
case OpTypes.GREATER_EQUAL:
return comparelast;
case OpTypes.SMALLER:
return comparefirst;
case OpTypes.SMALLER_EQUAL:
return comparefirst;
}
break;
}
}
return null;
}
use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.
the class DatabaseInformationFull method ROLE_ROUTINE_GRANTS.
Table ROLE_ROUTINE_GRANTS() {
Table t = sysTables[ROLE_ROUTINE_GRANTS];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[ROLE_ROUTINE_GRANTS]);
// 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);
addColumn(t, "ROUTINE_NAME", SQL_IDENTIFIER);
addColumn(t, "PRIVILEGE_TYPE", CHARACTER_DATA);
addColumn(t, "IS_GRANTABLE", YES_OR_NO);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ROLE_ROUTINE_GRANTS].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 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, SPECIFIC_CATALOG, SPECIFIC_SCHEMA, " + "SPECIFIC_NAME, ROUTINE_CATALOG, ROUTINE_SCHEMA, ROUTINE_NAME, " + "PRIVILEGE_TYPE, IS_GRANTABLE, 'NO' " + "FROM INFORMATION_SCHEMA.ROUTINE_PRIVILEGES " + "JOIN INFORMATION_SCHEMA.APPLICABLE_ROLES ON GRANTEE = ROLE_NAME;");
t.insertSys(store, rs);
sys.close();
// Column number mappings
final int grantor = 0;
final int grantee = 1;
final int table_name = 2;
final int specific_catalog = 3;
final int specific_schema = 4;
final int specific_name = 5;
final int routine_catalog = 6;
final int routine_schema = 7;
final int routine_name = 8;
final int privilege_type = 9;
final int is_grantable = 10;
//
return t;
}
use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.
the class DatabaseInformationFull method SCHEMATA.
/**
* SCHEMATA<p>
*
* <b>Function</b><p>
*
* The SCHEMATA view has one row for each accessible schema. <p>
*
* <b>Definition</b><p>
*
* <pre class="SqlCodeExample">
* CREATE TABLE SCHEMATA (
* CATALOG_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER,
* SCHEMA_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER,
* SCHEMA_OWNER INFORMATION_SCHEMA.SQL_IDENTIFIER
* CONSTRAINT SCHEMA_OWNER_NOT_NULL
* NOT NULL,
* DEFAULT_CHARACTER_SET_CATALOG INFORMATION_SCHEMA.SQL_IDENTIFIER
* CONSTRAINT DEFAULT_CHARACTER_SET_CATALOG_NOT_NULL
* NOT NULL,
* DEFAULT_CHARACTER_SET_SCHEMA INFORMATION_SCHEMA.SQL_IDENTIFIER
* CONSTRAINT DEFAULT_CHARACTER_SET_SCHEMA_NOT_NULL
* NOT NULL,
* DEFAULT_CHARACTER_SET_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER
* CONSTRAINT DEFAULT_CHARACTER_SET_NAME_NOT_NULL
* NOT NULL,
* SQL_PATH INFORMATION_SCHEMA.CHARACTER_DATA,
*
* CONSTRAINT SCHEMATA_PRIMARY_KEY
* PRIMARY KEY ( CATALOG_NAME, SCHEMA_NAME ),
* CONSTRAINT SCHEMATA_FOREIGN_KEY_AUTHORIZATIONS
* FOREIGN KEY ( SCHEMA_OWNER )
* REFERENCES AUTHORIZATIONS,
* CONSTRAINT SCHEMATA_FOREIGN_KEY_CATALOG_NAMES
* FOREIGN KEY ( CATALOG_NAME )
* REFERENCES CATALOG_NAMES
* )
* </pre>
*
* <b>Description</b><p>
*
* <ol>
* <li>The value of CATALOG_NAME is the name of the catalog of the
* schema described by this row.<p>
*
* <li>The value of SCHEMA_NAME is the unqualified schema name of
* the schema described by this row.<p>
*
* <li>The values of SCHEMA_OWNER are the authorization identifiers
* that own the schemata.<p>
*
* <li>The values of DEFAULT_CHARACTER_SET_CATALOG,
* DEFAULT_CHARACTER_SET_SCHEMA, and DEFAULT_CHARACTER_SET_NAME
* are the catalog name, unqualified schema name, and qualified
* identifier, respectively, of the default character set for
* columns and domains in the schemata.<p>
*
* <li>Case:<p>
* <ul>
* <li>If <schema path specification> was specified in
* the <schema definition> that defined the schema
* described by this row and the character representation
* of the <schema path specification> can be
* represented without truncation, then the value of
* SQL_PATH is that character representation.<p>
*
* <li>Otherwise, the value of SQL_PATH is the null value.
* </ul>
* </ol>
*
* @return Table
*/
Table SCHEMATA() {
Table t = sysTables[SCHEMATA];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SCHEMATA]);
addColumn(t, "CATALOG_NAME", SQL_IDENTIFIER);
addColumn(t, "SCHEMA_NAME", SQL_IDENTIFIER);
addColumn(t, "SCHEMA_OWNER", SQL_IDENTIFIER);
addColumn(t, "DEFAULT_CHARACTER_SET_CATALOG", SQL_IDENTIFIER);
addColumn(t, "DEFAULT_CHARACTER_SET_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "DEFAULT_CHARACTER_SET_NAME", SQL_IDENTIFIER);
addColumn(t, "SQL_PATH", CHARACTER_DATA);
// order: CATALOG_NAME, SCHEMA_NAME
// false PK, as rows may have NULL CATALOG_NAME
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SCHEMATA].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
// Intermediate holders
Iterator schemas;
String schema;
String dcsSchema = SqlInvariants.INFORMATION_SCHEMA;
String dcsName = ValuePool.getString("UTF16");
String sqlPath = null;
Grantee user = session.getGrantee();
Object[] row;
// column number mappings
final int schema_catalog = 0;
final int schema_name = 1;
final int schema_owner = 2;
final int default_character_set_catalog = 3;
final int default_character_set_schema = 4;
final int default_character_set_name = 5;
final int sql_path = 6;
// Initialization
schemas = database.schemaManager.fullSchemaNamesIterator();
// Do it.
while (schemas.hasNext()) {
schema = (String) schemas.next();
if (!user.hasSchemaUpdateOrGrantRights(schema)) {
continue;
}
row = t.getEmptyRowData();
row[schema_catalog] = database.getCatalogName().name;
row[schema_name] = schema;
row[schema_owner] = database.schemaManager.toSchemaOwner(schema).getNameString();
row[default_character_set_catalog] = database.getCatalogName().name;
row[default_character_set_schema] = dcsSchema;
row[default_character_set_name] = dcsName;
row[sql_path] = sqlPath;
t.insertSys(store, row);
}
return t;
}
use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.
the class DatabaseInformationFull method ROLE_AUTHORIZATION_DESCRIPTORS.
//------------------------------------------------------------------------------
// SQL SCHEMATA BASE TABLES
/**
* ROLE_AUTHORIZATION_DESCRIPTORS<p>
*
* <b>Function</b><p>
*
* Contains a representation of the role authorization descriptors.<p>
* <b>Definition</b>
*
* <pre class="SqlCodeExample">
* CREATE TABLE ROLE_AUTHORIZATION_DESCRIPTORS (
* ROLE_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER,
* GRANTEE INFORMATION_SCHEMA.SQL_IDENTIFIER,
* GRANTOR INFORMATION_SCHEMA.SQL_IDENTIFIER,
* IS_GRANTABLE INFORMATION_SCHEMA.CHARACTER_DATA
* CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_IS_GRANTABLE_CHECK
* CHECK ( IS_GRANTABLE IN
* ( 'YES', 'NO' ) ),
* CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_PRIMARY_KEY
* PRIMARY KEY ( ROLE_NAME, GRANTEE ),
* CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_CHECK_ROLE_NAME
* CHECK ( ROLE_NAME IN
* ( SELECT AUTHORIZATION_NAME
* FROM AUTHORIZATIONS
* WHERE AUTHORIZATION_TYPE = 'ROLE' ) ),
* CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_FOREIGN_KEY_AUTHORIZATIONS_GRANTOR
* FOREIGN KEY ( GRANTOR )
* REFERENCES AUTHORIZATIONS,
* CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_FOREIGN_KEY_AUTHORIZATIONS_GRANTEE
* FOREIGN KEY ( GRANTEE )
* REFERENCES AUTHORIZATIONS
* )
* </pre>
*
* <b>Description</b><p>
*
* <ol>
* <li>The value of ROLE_NAME is the <role name> of some
* <role granted> by the <grant role statement> or
* the <role name> of a <role definition>. <p>
*
* <li>The value of GRANTEE is an <authorization identifier>,
* possibly PUBLIC, or <role name> specified as a
* <grantee> contained in a <grant role statement>,
* or the <authorization identifier> of the current
* SQLsession when the <role definition> is executed. <p>
*
* <li>The value of GRANTOR is the <authorization identifier>
* of the user or role who granted the role identified by
* ROLE_NAME to the user or role identified by the value of
* GRANTEE. <p>
*
* <li>The values of IS_GRANTABLE have the following meanings:<p>
*
* <table border cellpadding="3">
* <tr>
* <td nowrap>YES</td>
* <td nowrap>The described role is grantable.</td>
* <tr>
* <tr>
* <td nowrap>NO</td>
* <td nowrap>The described role is not grantable.</td>
* <tr>
* </table> <p>
* </ol>
*
* @return Table
*/
Table ROLE_AUTHORIZATION_DESCRIPTORS() {
Table t = sysTables[ROLE_AUTHORIZATION_DESCRIPTORS];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[ROLE_AUTHORIZATION_DESCRIPTORS]);
// not null
addColumn(t, "ROLE_NAME", SQL_IDENTIFIER);
// not null
addColumn(t, "GRANTEE", SQL_IDENTIFIER);
// not null
addColumn(t, "GRANTOR", SQL_IDENTIFIER);
// not null
addColumn(t, "IS_GRANTABLE", YES_OR_NO);
// true PK
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ROLE_AUTHORIZATION_DESCRIPTORS].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1 }, true);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
// Intermediate holders
String grantorName = SqlInvariants.SYSTEM_AUTHORIZATION_NAME;
Iterator grantees;
Grantee granteeObject;
String granteeName;
Iterator roles;
String roleName;
String isGrantable;
Object[] row;
// Column number mappings
final int role_name = 0;
final int grantee = 1;
final int grantor = 2;
final int is_grantable = 3;
// Initialization
grantees = session.getGrantee().visibleGrantees().iterator();
//
while (grantees.hasNext()) {
granteeObject = (Grantee) grantees.next();
granteeName = granteeObject.getNameString();
roles = granteeObject.getDirectRoles().iterator();
isGrantable = granteeObject.isAdmin() ? Tokens.T_YES : Tokens.T_NO;
;
while (roles.hasNext()) {
Grantee role = (Grantee) roles.next();
row = t.getEmptyRowData();
row[role_name] = role.getNameString();
row[grantee] = granteeName;
row[grantor] = grantorName;
row[is_grantable] = isGrantable;
t.insertSys(store, row);
}
}
return t;
}
use of org.hsqldb_voltpatches.persist.PersistentStore 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;
}
Aggregations