use of org.hsqldb_voltpatches.NumberSequence 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.NumberSequence in project voltdb by VoltDB.
the class Grantee method getRightsSQL.
public HsqlArrayList getRightsSQL() {
HsqlArrayList list = new HsqlArrayList();
String roleString = getDirectRolesAsString();
if (roleString.length() != 0) {
list.add("GRANT " + roleString + " TO " + getStatementName());
}
MultiValueHashMap rightsMap = getRights();
Iterator dbObjects = rightsMap.keySet().iterator();
while (dbObjects.hasNext()) {
Object nameObject = dbObjects.next();
Iterator rights = rightsMap.get(nameObject);
while (rights.hasNext()) {
Right right = (Right) rights.next();
StringBuffer sb = new StringBuffer(128);
HsqlName hsqlname = (HsqlName) nameObject;
switch(hsqlname.type) {
case SchemaObject.TABLE:
case SchemaObject.VIEW:
Table table = granteeManager.database.schemaManager.findUserTable(null, hsqlname.name, hsqlname.schema.name);
if (table != null) {
sb.append(Tokens.T_GRANT).append(' ');
sb.append(right.getTableRightsSQL(table));
sb.append(' ').append(Tokens.T_ON).append(' ');
sb.append("TABLE ").append(hsqlname.getSchemaQualifiedStatementName());
}
break;
case SchemaObject.SEQUENCE:
NumberSequence sequence = (NumberSequence) granteeManager.database.schemaManager.findSchemaObject(hsqlname.name, hsqlname.schema.name, SchemaObject.SEQUENCE);
if (sequence != null) {
sb.append(Tokens.T_GRANT).append(' ');
sb.append(Tokens.T_USAGE);
sb.append(' ').append(Tokens.T_ON).append(' ');
sb.append("SEQUENCE ").append(hsqlname.getSchemaQualifiedStatementName());
}
break;
case SchemaObject.DOMAIN:
Type domain = (Type) granteeManager.database.schemaManager.findSchemaObject(hsqlname.name, hsqlname.schema.name, SchemaObject.DOMAIN);
if (domain != null) {
sb.append(Tokens.T_GRANT).append(' ');
sb.append(Tokens.T_USAGE);
sb.append(' ').append(Tokens.T_ON).append(' ');
sb.append("DOMAIN ").append(hsqlname.getSchemaQualifiedStatementName());
}
break;
case SchemaObject.TYPE:
Type type = (Type) granteeManager.database.schemaManager.findSchemaObject(hsqlname.name, hsqlname.schema.name, SchemaObject.DOMAIN);
if (type != null) {
sb.append(Tokens.T_GRANT).append(' ');
sb.append(Tokens.T_USAGE);
sb.append(' ').append(Tokens.T_ON).append(' ');
sb.append("TYPE ").append(hsqlname.getSchemaQualifiedStatementName());
}
break;
}
if (sb.length() == 0) {
continue;
}
sb.append(' ').append(Tokens.T_TO).append(' ');
sb.append(getStatementName());
list.add(sb.toString());
}
}
return list;
}
use of org.hsqldb_voltpatches.NumberSequence in project voltdb by VoltDB.
the class DatabaseInformationMain method SYSTEM_SEQUENCES.
final Table SYSTEM_SEQUENCES() {
Table t = sysTables[SYSTEM_SEQUENCES];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SYSTEM_SEQUENCES]);
addColumn(t, "SEQUENCE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "SEQUENCE_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "SEQUENCE_NAME", SQL_IDENTIFIER);
addColumn(t, "DATA_TYPE", CHARACTER_DATA);
addColumn(t, "NUMERIC_PRECISION", CARDINAL_NUMBER);
addColumn(t, "NUMERIC_PRECISION_RADIX", CARDINAL_NUMBER);
addColumn(t, "NUMERIC_SCALE", CARDINAL_NUMBER);
addColumn(t, "MAXIMUM_VALUE", CHARACTER_DATA);
addColumn(t, "MINIMUM_VALUE", CHARACTER_DATA);
addColumn(t, "INCREMENT", CHARACTER_DATA);
addColumn(t, "CYCLE_OPTION", YES_OR_NO);
addColumn(t, "DECLARED_DATA_TYPE", CHARACTER_DATA);
addColumn(t, "DECLARED_NUMERIC_PRECISION", CARDINAL_NUMBER);
addColumn(t, "DECLARED_NUMERIC_SCLAE", CARDINAL_NUMBER);
// HSQLDB-specific
addColumn(t, "START_WITH", CHARACTER_DATA);
addColumn(t, "NEXT_VALUE", CHARACTER_DATA);
// order SEQUENCE_CATALOG, SEQUENCE_SCHEMA, SEQUENCE_NAME
// false PK, as CATALOG may be null
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_SEQUENCES].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
//
final int sequence_catalog = 0;
final int sequence_schema = 1;
final int sequence_name = 2;
final int data_type = 3;
final int numeric_precision = 4;
final int numeric_precision_radix = 5;
final int numeric_scale = 6;
final int maximum_value = 7;
final int minimum_value = 8;
final int increment = 9;
final int cycle_option = 10;
final int declared_data_type = 11;
final int declared_numeric_precision = 12;
final int declared_numeric_scale = 13;
final int start_with = 14;
final int next_value = 15;
//
Iterator it;
Object[] row;
NumberSequence sequence;
it = database.schemaManager.databaseObjectIterator(SchemaObject.SEQUENCE);
while (it.hasNext()) {
sequence = (NumberSequence) it.next();
if (!session.getGrantee().isAccessible(sequence)) {
continue;
}
row = t.getEmptyRowData();
NumberType type = (NumberType) sequence.getDataType();
int radix = (type.typeCode == Types.SQL_NUMERIC || type.typeCode == Types.SQL_DECIMAL) ? 10 : 2;
row[sequence_catalog] = database.getCatalogName().name;
row[sequence_schema] = sequence.getSchemaName().name;
row[sequence_name] = sequence.getName().name;
row[data_type] = sequence.getDataType().getFullNameString();
row[numeric_precision] = ValuePool.getInt((int) type.getPrecision());
row[numeric_precision_radix] = ValuePool.getInt(radix);
row[numeric_scale] = ValuePool.INTEGER_0;
row[maximum_value] = String.valueOf(sequence.getMaxValue());
row[minimum_value] = String.valueOf(sequence.getMinValue());
row[increment] = String.valueOf(sequence.getIncrement());
row[cycle_option] = sequence.isCycle() ? "YES" : "NO";
row[declared_data_type] = row[data_type];
row[declared_numeric_precision] = row[numeric_precision];
row[declared_numeric_scale] = row[declared_numeric_scale];
row[start_with] = String.valueOf(sequence.getStartValue());
row[next_value] = String.valueOf(sequence.peek());
t.insertSys(store, row);
}
return t;
}
use of org.hsqldb_voltpatches.NumberSequence in project voltdb by VoltDB.
the class DatabaseInformationMain method SEQUENCES.
/**
* The SEQUENCES view has one row for each external sequence
* generator. <p>
*
* <b>Definition:</b> <p>
*
* <pre class="SqlCodeExample">
*
* SEQUENCE_CATALOG VARCHAR NULL,
* SEQUENCE_SCHEMA VARCHAR NULL,
* SEQUENCE_NAME VARCHAR NOT NULL,
* DATA_TYPE CHARACTER_DATA
* DATA_TYPE CHARACTER_DATA
* NUMERIC_PRECISION CARDINAL_NUMBER
* NUMERIC_PRECISION_RADIX CARDINAL_NUMBER
* NUMERIC_SCALE CARDINAL_NUMBER
* MAXIMUM_VALUE VARCHAR NOT NULL,
* MINIMUM_VALUE VARCHAR NOT NULL,
* INCREMENT VARCHAR NOT NULL,
* CYCLE_OPTION VARCHAR {'YES', 'NO'},
* START_WITH VARCHAR NOT NULL,
* DECLARED_DATA_TYPE CHARACTER_DATA
* DECLARED_NUMERIC_PRECISION CARDINAL_NUMBER
* DECLARED_NUMERIC_SCLAE CARDINAL_NUMBER
*
* </pre>
*
* <b>DESCRIPTION:</b><p>
*
* <ol>
* <li> The values of SEQUENCE_CATALOG, SEQUENCE_SCHEMA, and
* SEQUENCE_NAME are the catalog name, unqualified schema name,
* and qualified identifier, respectively, of the sequence generator
* being described. <p>
*
* <li> The values of SEQUENCE_CATALOG, SEQUENCE_SCHEMA, SEQUENCE_NAME, and
* DTD_IDENTIFIER are the values of OBJECT_CATALOG, OBJECT_SCHEMA,
* OBJECT_NAME, and DTD_IDENTIFIER, respectively, of the row in
* DATA_TYPE_DESCRIPTOR (not yet implemented) that describes the data
* type of the sequence generator. <p>
*
* <li> The values of MAXIMUM_VALUE, MINIMUM_VALUE, and INCREMENT are the
* character representations of maximum value, minimum value,
* and increment, respectively, of the sequence generator being
* described. <p>
*
* <li> The values of CYCLE_OPTION have the following meanings: <p>
*
* <table border cellpadding="3">
* <tr>
* <td nowrap>YES</td>
* <td nowrap>The cycle option of the sequence generator
* is CYCLE.</td>
* <tr>
* <td nowrap>NO</td>
* <td nowrap>The cycle option of the sequence generator is
* NO CYCLE.</td>
* </tr>
* </table> <p>
*
* <li> The value of START_WITH is HSQLDB-specific (not in the SQL 200n
* spec). <p>
*
* It is the character representation of the START WITH value. <p>
*
* <li> The value of NEXT_VALUE is HSQLDB-specific (not in the SQL 200n)<p>
* This is the character representation of the value that
* would be generated by NEXT VALUE FOR when this sequence
* is materialized in an SQL statement. <p>
* </ol>
*
* @return Table
*/
final Table SEQUENCES() {
Table t = sysTables[SEQUENCES];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SEQUENCES]);
addColumn(t, "SEQUENCE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "SEQUENCE_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "SEQUENCE_NAME", SQL_IDENTIFIER);
addColumn(t, "DATA_TYPE", CHARACTER_DATA);
addColumn(t, "NUMERIC_PRECISION", CARDINAL_NUMBER);
addColumn(t, "NUMERIC_PRECISION_RADIX", CARDINAL_NUMBER);
addColumn(t, "NUMERIC_SCALE", CARDINAL_NUMBER);
addColumn(t, "MAXIMUM_VALUE", CHARACTER_DATA);
addColumn(t, "MINIMUM_VALUE", CHARACTER_DATA);
addColumn(t, "INCREMENT", CHARACTER_DATA);
addColumn(t, "CYCLE_OPTION", YES_OR_NO);
addColumn(t, "DECLARED_DATA_TYPE", CHARACTER_DATA);
addColumn(t, "DECLARED_NUMERIC_PRECISION", CARDINAL_NUMBER);
addColumn(t, "DECLARED_NUMERIC_SCLAE", CARDINAL_NUMBER);
// HSQLDB-specific
addColumn(t, "START_WITH", CHARACTER_DATA);
addColumn(t, "NEXT_VALUE", CHARACTER_DATA);
// order SEQUENCE_CATALOG, SEQUENCE_SCHEMA, SEQUENCE_NAME
// false PK, as CATALOG may be null
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SEQUENCES].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
//
final int sequence_catalog = 0;
final int sequence_schema = 1;
final int sequence_name = 2;
final int data_type = 3;
final int numeric_precision = 4;
final int numeric_precision_radix = 5;
final int numeric_scale = 6;
final int maximum_value = 7;
final int minimum_value = 8;
final int increment = 9;
final int cycle_option = 10;
final int declared_data_type = 11;
final int declared_numeric_precision = 12;
final int declared_numeric_scale = 13;
final int start_with = 14;
final int next_value = 15;
//
Iterator it;
Object[] row;
NumberSequence sequence;
it = database.schemaManager.databaseObjectIterator(SchemaObject.SEQUENCE);
while (it.hasNext()) {
sequence = (NumberSequence) it.next();
if (!session.getGrantee().isAccessible(sequence)) {
continue;
}
row = t.getEmptyRowData();
NumberType type = (NumberType) sequence.getDataType();
int radix = (type.typeCode == Types.SQL_NUMERIC || type.typeCode == Types.SQL_DECIMAL) ? 10 : 2;
row[sequence_catalog] = database.getCatalogName().name;
row[sequence_schema] = sequence.getSchemaName().name;
row[sequence_name] = sequence.getName().name;
row[data_type] = sequence.getDataType().getFullNameString();
row[numeric_precision] = ValuePool.getInt((int) type.getPrecision());
row[numeric_precision_radix] = ValuePool.getInt(radix);
row[numeric_scale] = ValuePool.INTEGER_0;
row[maximum_value] = String.valueOf(sequence.getMaxValue());
row[minimum_value] = String.valueOf(sequence.getMinValue());
row[increment] = String.valueOf(sequence.getIncrement());
row[cycle_option] = sequence.isCycle() ? "YES" : "NO";
row[declared_data_type] = row[data_type];
row[declared_numeric_precision] = row[numeric_precision];
row[declared_numeric_scale] = row[declared_numeric_scale];
row[start_with] = String.valueOf(sequence.getStartValue());
row[next_value] = String.valueOf(sequence.peek());
t.insertSys(store, row);
}
return t;
}
Aggregations