use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.
the class ParserDDL method compileCreateStream.
// skip Export to target of statment
// skip constraint ?
StatementSchema compileCreateStream(int type) {
HsqlName name = readNewSchemaObjectNameNoCheck(SchemaObject.TABLE);
HsqlArrayList tempConstraints = new HsqlArrayList();
name.setSchemaIfNull(session.getCurrentSchemaHsqlName());
Table table = TableUtil.newTable(database, type, name);
if (token.tokenType == Tokens.AS) {
return readTableAsSubqueryDefinition(table);
}
int position = getPosition();
readUntilThis(Tokens.OPENBRACKET);
readThis(Tokens.OPENBRACKET);
{
Constraint c = new Constraint(null, true, null, Constraint.TEMP);
tempConstraints.add(c);
}
boolean start = true;
boolean startPart = true;
boolean end = false;
while (!end) {
switch(token.tokenType) {
case Tokens.LIKE:
{
ColumnSchema[] likeColumns = readLikeTable(table);
for (int i = 0; i < likeColumns.length; i++) {
table.addColumn(likeColumns[i]);
}
start = false;
startPart = false;
break;
}
case Tokens.CONSTRAINT:
case Tokens.PRIMARY:
case Tokens.FOREIGN:
// A VoltDB extension to support the assume unique attribute
case Tokens.ASSUMEUNIQUE:
// End of VoltDB extension
case Tokens.UNIQUE:
case Tokens.CHECK:
// A VoltDB extension to support LIMIT PARTITION ROWS
case Tokens.LIMIT:
// End of VoltDB extension
if (!startPart) {
throw unexpectedToken();
}
readConstraint(table, tempConstraints);
start = false;
startPart = false;
break;
case Tokens.COMMA:
if (startPart) {
throw unexpectedToken();
}
read();
startPart = true;
break;
case Tokens.CLOSEBRACKET:
read();
end = true;
break;
default:
if (!startPart) {
throw unexpectedToken();
}
checkIsSchemaObjectName();
HsqlName hsqlName = database.nameManager.newColumnHsqlName(name, token.tokenString, isDelimitedIdentifier());
read();
ColumnSchema newcolumn = readColumnDefinitionOrNull(table, hsqlName, tempConstraints);
if (newcolumn == null) {
if (start) {
rewind(position);
return readTableAsSubqueryDefinition(table);
} else {
throw Error.error(ErrorCode.X_42000);
}
}
table.addColumn(newcolumn);
start = false;
startPart = false;
}
}
if (token.tokenType == Tokens.ON) {
if (!table.isTemp()) {
throw unexpectedToken();
}
read();
readThis(Tokens.COMMIT);
if (token.tokenType == Tokens.DELETE) {
} else if (token.tokenType == Tokens.PRESERVE) {
table.persistenceScope = TableBase.SCOPE_SESSION;
}
read();
readThis(Tokens.ROWS);
}
Object[] args = new Object[] { table, tempConstraints, null };
String sql = getLastPart();
return new StatementSchema(sql, StatementTypes.CREATE_TABLE, args, null, null);
}
use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.
the class ParserDDL method compileCreateSchema.
StatementSchema compileCreateSchema() {
HsqlName schemaName = null;
String authorisation = null;
read();
if (token.tokenType != Tokens.AUTHORIZATION) {
schemaName = readNewSchemaName();
}
if (token.tokenType == Tokens.AUTHORIZATION) {
read();
checkIsSimpleName();
authorisation = token.tokenString;
read();
if (schemaName == null) {
Grantee owner = database.getGranteeManager().get(authorisation);
if (owner == null) {
throw Error.error(ErrorCode.X_28501, authorisation);
}
schemaName = database.nameManager.newHsqlName(owner.getName().name, isDelimitedIdentifier(), SchemaObject.SCHEMA);
SqlInvariants.checkSchemaNameNotSystem(token.tokenString);
}
}
if (SqlInvariants.PUBLIC_ROLE_NAME.equals(authorisation)) {
throw Error.error(ErrorCode.X_28502, authorisation);
}
Grantee owner = authorisation == null ? session.getGrantee() : database.getGranteeManager().get(authorisation);
if (owner == null) {
throw Error.error(ErrorCode.X_28501, authorisation);
}
if (!session.getGrantee().isSchemaCreator()) {
throw Error.error(ErrorCode.X_0L000, session.getGrantee().getNameString());
}
if (database.schemaManager.schemaExists(schemaName.name)) {
throw Error.error(ErrorCode.X_42504, schemaName.name);
}
String sql = getLastPart();
Object[] args = new Object[] { schemaName, owner };
HsqlArrayList list = new HsqlArrayList();
StatementSchema cs = new StatementSchema(sql, StatementTypes.CREATE_SCHEMA, args, null, null);
cs.setSchemaHsqlName(schemaName);
list.add(cs);
getCompiledStatementBody(list);
StatementSchema[] array = new StatementSchema[list.size()];
list.toArray(array);
boolean swapped;
do {
swapped = false;
for (int i = 0; i < array.length - 1; i++) {
if (array[i].order > array[i + 1].order) {
StatementSchema temp = array[i + 1];
array[i + 1] = array[i];
array[i] = temp;
swapped = true;
}
}
} while (swapped);
return new StatementSchemaDefinition(array);
}
use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.
the class SessionContext method pushDynamicArguments.
public void pushDynamicArguments(Object[] args) {
if (stack == null) {
stack = new HsqlArrayList(true);
}
stack.add(dynamicArguments);
dynamicArguments = args;
}
use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.
the class StatementSchema method dropRole.
private static void dropRole(Session session, HsqlName name, boolean cascade) {
Grantee role = session.database.getGranteeManager().getRole(name.name);
if (!cascade && session.database.schemaManager.hasSchemas(role)) {
HsqlArrayList list = session.database.schemaManager.getSchemas(role);
Schema schema = (Schema) list.get(0);
throw Error.error(ErrorCode.X_42502, schema.getName().statementName);
}
session.database.schemaManager.dropSchemas(role, cascade);
session.database.getGranteeManager().dropRole(name.name);
}
use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.
the class DatabaseInformationMain method SYSTEM_PROCEDURES.
/**
* Retrieves a <code>Table</code> object describing the accessible
* routines defined within this database.
*
* Each row is a procedure description with the following
* columns: <p>
*
* <pre class="SqlCodeExample">
* PROCEDURE_CAT VARCHAR catalog in which routine is defined
* PROCEDURE_SCHEM VARCHAR schema in which routine is defined
* PROCEDURE_NAME VARCHAR simple routine identifier
* NUM_INPUT_PARAMS INTEGER number of input parameters
* NUM_OUTPUT_PARAMS INTEGER number of output parameters
* NUM_RESULT_SETS INTEGER number of result sets returned
* REMARKS VARCHAR explanatory comment on the routine
* PROCEDURE_TYPE SMALLINT { Unknown | No Result | Returns Result }
* // JDBC 4.0
* SPECIFIC_NAME VARCHAR The name which uniquely identifies this
* procedure within its schema.
* typically (but not restricted to) a
* fully qualified Java Method name
* and signature.
* // HSQLDB extension
* ORIGIN VARCHAR {ALIAS |
* [BUILTIN | USER DEFINED] ROUTINE |
* [BUILTIN | USER DEFINED] TRIGGER |
* ...}
* </pre> <p>
*
* @return a <code>Table</code> object describing the accessible
* routines defined within the this database
*/
Table SYSTEM_PROCEDURES() {
Table t = sysTables[SYSTEM_PROCEDURES];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SYSTEM_PROCEDURES]);
// ----------------------------------------------------------------
// required
// ----------------------------------------------------------------
// 0
addColumn(t, "PROCEDURE_CAT", SQL_IDENTIFIER);
// 1
addColumn(t, "PROCEDURE_SCHEM", SQL_IDENTIFIER);
// not null
addColumn(t, "PROCEDURE_NAME", SQL_IDENTIFIER);
// 3
addColumn(t, "NUM_INPUT_PARAMS", Type.SQL_INTEGER);
// 4
addColumn(t, "NUM_OUTPUT_PARAMS", Type.SQL_INTEGER);
// 5
addColumn(t, "NUM_RESULT_SETS", Type.SQL_INTEGER);
// 6
addColumn(t, "REMARKS", CHARACTER_DATA);
// basically: function (returns result), procedure (no return value)
// or unknown (say, a trigger callout routine)
// not null
addColumn(t, "PROCEDURE_TYPE", Type.SQL_SMALLINT);
// ----------------------------------------------------------------
// JDBC 4.0
// ----------------------------------------------------------------
// not null
addColumn(t, "SPECIFIC_NAME", SQL_IDENTIFIER);
// ----------------------------------------------------------------
// extended
// ----------------------------------------------------------------
// not null
addColumn(t, "ORIGIN", CHARACTER_DATA);
// ----------------------------------------------------------------
// order: PROCEDURE_SCHEM, PROCEDURE_NAME, SPECIFIC_NAME
// added for uniqe: PROCEDURE_CAT
// false PK, as PROCEDURE_SCHEM and/or PROCEDURE_CAT may be null
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_PROCEDURES].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 1, 2, 8, 0 }, false);
return t;
}
// calculated column values
// ------------------------
// required
// ------------------------
String catalog;
String schema;
String procName;
Integer numInputParams;
Integer numOutputParams;
Integer numResultSets;
String remarks;
Integer procRType;
// -------------------
// extended
// -------------------
String procOrigin;
String specificName;
// intermediate holders
String alias;
HsqlArrayList aliasList;
Iterator methods;
Object[] methodInfo;
Method method;
String methodOrigin;
Object[] row;
// Initialization
//and aliases
methods = ns.iterateAllAccessibleMethods(session, true);
catalog = database.getCatalogName().name;
schema = database.schemaManager.getDefaultSchemaHsqlName().name;
// Do it.
while (methods.hasNext()) {
methodInfo = (Object[]) methods.next();
method = (Method) methodInfo[0];
aliasList = (HsqlArrayList) methodInfo[1];
methodOrigin = (String) methodInfo[2];
pi.setMethod(method);
procName = pi.getFQN();
numInputParams = pi.getInputParmCount();
numOutputParams = pi.getOutputParmCount();
numResultSets = pi.getResultSetCount();
remarks = pi.getRemark();
procRType = pi.getResultType(methodOrigin);
specificName = pi.getSpecificName();
procOrigin = pi.getOrigin(methodOrigin);
addProcRows(t, aliasList, catalog, schema, procName, numInputParams, numOutputParams, numResultSets, remarks, procRType, specificName, procOrigin);
}
return t;
}
Aggregations