use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.
the class ParserDDL method compileCreateType.
StatementSchema compileCreateType() {
read();
HsqlName name = readNewSchemaObjectNameNoCheck(SchemaObject.TYPE);
readThis(Tokens.AS);
Type type = readTypeDefinition(false).duplicate();
readIfThis(Tokens.FINAL);
UserTypeModifier userTypeModifier = new UserTypeModifier(name, SchemaObject.TYPE, type);
type.userTypeModifier = userTypeModifier;
String sql = getLastPart();
Object[] args = new Object[] { type };
return new StatementSchema(sql, StatementTypes.CREATE_TYPE, args, null, null);
}
use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.
the class ParserDDL method readColumnConstraints.
/**
* Reads column constraints
*/
void readColumnConstraints(Table table, ColumnSchema column, HsqlArrayList constraintList) {
boolean end = false;
boolean isAutogeneratedName = true;
while (true) {
HsqlName constName = null;
if (token.tokenType == Tokens.CONSTRAINT) {
read();
constName = readNewDependentSchemaObjectName(table.getName(), SchemaObject.CONSTRAINT);
isAutogeneratedName = false;
}
// A VoltDB extension to support indexed expressions and the assume unique attribute
// For VoltDB
boolean assumeUnique = false;
// End of VoltDB extension
switch(token.tokenType) {
case Tokens.PRIMARY:
{
read();
readThis(Tokens.KEY);
Constraint existingConst = (Constraint) constraintList.get(0);
if (existingConst.constType == Constraint.PRIMARY_KEY) {
throw Error.error(ErrorCode.X_42532);
}
OrderedHashSet set = new OrderedHashSet();
set.add(column.getName().name);
if (constName == null) {
constName = database.nameManager.newAutoName("PK", table.getSchemaName(), table.getName(), SchemaObject.CONSTRAINT);
}
Constraint c = new Constraint(constName, isAutogeneratedName, set, Constraint.PRIMARY_KEY);
constraintList.set(0, c);
column.setPrimaryKey(true);
break;
}
// A VoltDB extension to support indexed expressions and the assume unique attribute
case Tokens.ASSUMEUNIQUE:
assumeUnique = true;
// End of VoltDB extension
case Tokens.UNIQUE:
{
read();
OrderedHashSet set = new OrderedHashSet();
set.add(column.getName().name);
if (constName == null) {
constName = database.nameManager.newAutoName("CT", table.getSchemaName(), table.getName(), SchemaObject.CONSTRAINT);
}
Constraint c = new Constraint(constName, isAutogeneratedName, set, Constraint.UNIQUE);
// A VoltDB extension to support indexed expressions and the assume unique attribute
c.setAssumeUnique(assumeUnique);
// End of VoltDB extension
constraintList.add(c);
break;
}
case Tokens.FOREIGN:
{
read();
readThis(Tokens.KEY);
}
// $FALL-THROUGH$
case Tokens.REFERENCES:
{
OrderedHashSet set = new OrderedHashSet();
set.add(column.getName().name);
Constraint c = readFKReferences(table, constName, set);
constraintList.add(c);
break;
}
case Tokens.CHECK:
{
read();
if (constName == null) {
constName = database.nameManager.newAutoName("CT", table.getSchemaName(), table.getName(), SchemaObject.CONSTRAINT);
}
Constraint c = new Constraint(constName, isAutogeneratedName, null, Constraint.CHECK);
readCheckConstraintCondition(c);
OrderedHashSet set = c.getCheckColumnExpressions();
for (int i = 0; i < set.size(); i++) {
ExpressionColumn e = (ExpressionColumn) set.get(i);
if (column.getName().name.equals(e.getColumnName())) {
if (e.getSchemaName() != null && e.getSchemaName() != table.getSchemaName().name) {
throw Error.error(ErrorCode.X_42505);
}
} else {
throw Error.error(ErrorCode.X_42501);
}
}
constraintList.add(c);
break;
}
case Tokens.NOT:
{
read();
readThis(Tokens.NULL);
if (constName == null) {
constName = database.nameManager.newAutoName("CT", table.getSchemaName(), table.getName(), SchemaObject.CONSTRAINT);
}
Constraint c = new Constraint(constName, isAutogeneratedName, null, Constraint.CHECK);
c.check = new ExpressionLogical(column);
constraintList.add(c);
break;
}
default:
end = true;
break;
}
if (end) {
break;
}
}
}
use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.
the class ParserDDL method compileCreateTrigger.
StatementSchema compileCreateTrigger() {
Table table;
boolean isForEachRow = false;
boolean isNowait = false;
boolean hasQueueSize = false;
Integer queueSize = TriggerDef.defaultQueueSize;
String beforeOrAfter;
int beforeOrAfterType;
String operation;
int operationType;
String className;
TriggerDef td;
HsqlName name;
HsqlName otherName = null;
OrderedHashSet columns = null;
int[] updateColumnIndexes = null;
read();
name = readNewSchemaObjectName(SchemaObject.TRIGGER);
switch(token.tokenType) {
case Tokens.INSTEAD:
beforeOrAfter = token.tokenString;
beforeOrAfterType = token.tokenType;
read();
readThis(Tokens.OF);
break;
case Tokens.BEFORE:
case Tokens.AFTER:
beforeOrAfter = token.tokenString;
beforeOrAfterType = token.tokenType;
read();
break;
default:
throw unexpectedToken();
}
switch(token.tokenType) {
case Tokens.INSERT:
case Tokens.DELETE:
operation = token.tokenString;
operationType = token.tokenType;
read();
break;
case Tokens.UPDATE:
operation = token.tokenString;
operationType = token.tokenType;
read();
if (token.tokenType == Tokens.OF && beforeOrAfterType != Tokens.INSTEAD) {
read();
columns = readColumnNames(false);
}
break;
default:
throw unexpectedToken();
}
readThis(Tokens.ON);
table = readTableName();
if (token.tokenType == Tokens.BEFORE) {
read();
checkIsSimpleName();
otherName = readNewSchemaObjectName(SchemaObject.TRIGGER);
}
name.setSchemaIfNull(table.getSchemaName());
checkSchemaUpdateAuthorisation(name.schema);
if (beforeOrAfterType == Tokens.INSTEAD) {
if (!table.isView() || ((View) table).getCheckOption() == SchemaObject.ViewCheckModes.CHECK_CASCADE) {
throw Error.error(ErrorCode.X_42538, name.schema.name);
}
} else {
if (table.isView()) {
throw Error.error(ErrorCode.X_42538, name.schema.name);
}
}
if (name.schema != table.getSchemaName()) {
throw Error.error(ErrorCode.X_42505, name.schema.name);
}
name.parent = table.getName();
database.schemaManager.checkSchemaObjectNotExists(name);
if (columns != null) {
updateColumnIndexes = table.getColumnIndexes(columns);
for (int i = 0; i < updateColumnIndexes.length; i++) {
if (updateColumnIndexes[i] == -1) {
throw Error.error(ErrorCode.X_42544, (String) columns.get(i));
}
}
}
Expression condition = null;
String oldTableName = null;
String newTableName = null;
String oldRowName = null;
String newRowName = null;
Table[] transitions = new Table[4];
RangeVariable[] rangeVars = new RangeVariable[4];
HsqlArrayList compiledStatements = new HsqlArrayList();
String conditionSQL = null;
String procedureSQL = null;
if (token.tokenType == Tokens.REFERENCING) {
read();
if (token.tokenType != Tokens.OLD && token.tokenType != Tokens.NEW) {
throw unexpectedToken();
}
while (true) {
if (token.tokenType == Tokens.OLD) {
if (operationType == Tokens.INSERT) {
throw unexpectedToken();
}
read();
if (token.tokenType == Tokens.TABLE) {
if (oldTableName != null || beforeOrAfterType == Tokens.BEFORE) {
throw unexpectedToken();
}
read();
readIfThis(Tokens.AS);
checkIsSimpleName();
oldTableName = token.tokenString;
String n = oldTableName;
if (n.equals(newTableName) || n.equals(oldRowName) || n.equals(newRowName)) {
throw unexpectedToken();
}
HsqlName hsqlName = database.nameManager.newHsqlName(table.getSchemaName(), n, isDelimitedIdentifier(), SchemaObject.TRANSITION);
Table transition = new Table(table, hsqlName);
RangeVariable range = new RangeVariable(transition, null, null, null, compileContext);
transitions[TriggerDef.OLD_TABLE] = transition;
rangeVars[TriggerDef.OLD_TABLE] = range;
} else if (token.tokenType == Tokens.ROW) {
if (oldRowName != null) {
throw unexpectedToken();
}
read();
readIfThis(Tokens.AS);
checkIsSimpleName();
oldRowName = token.tokenString;
String n = oldRowName;
if (n.equals(newTableName) || n.equals(oldTableName) || n.equals(newRowName)) {
throw unexpectedToken();
}
isForEachRow = true;
HsqlName hsqlName = database.nameManager.newHsqlName(table.getSchemaName(), n, isDelimitedIdentifier(), SchemaObject.TRANSITION);
Table transition = new Table(table, hsqlName);
RangeVariable range = new RangeVariable(transition, null, null, null, compileContext);
transitions[TriggerDef.OLD_ROW] = transition;
rangeVars[TriggerDef.OLD_ROW] = range;
} else {
throw unexpectedToken();
}
} else if (token.tokenType == Tokens.NEW) {
if (operationType == Tokens.DELETE) {
throw unexpectedToken();
}
read();
if (token.tokenType == Tokens.TABLE) {
if (newTableName != null || beforeOrAfterType == Tokens.BEFORE) {
throw unexpectedToken();
}
read();
readIfThis(Tokens.AS);
checkIsSimpleName();
newTableName = token.tokenString;
String n = newTableName;
if (n.equals(oldTableName) || n.equals(oldRowName) || n.equals(newRowName)) {
throw unexpectedToken();
}
HsqlName hsqlName = database.nameManager.newHsqlName(table.getSchemaName(), n, isDelimitedIdentifier(), SchemaObject.TRANSITION);
Table transition = new Table(table, hsqlName);
RangeVariable range = new RangeVariable(transition, null, null, null, compileContext);
transitions[TriggerDef.NEW_TABLE] = transition;
rangeVars[TriggerDef.NEW_TABLE] = range;
} else if (token.tokenType == Tokens.ROW) {
if (newRowName != null) {
throw unexpectedToken();
}
read();
readIfThis(Tokens.AS);
checkIsSimpleName();
newRowName = token.tokenString;
isForEachRow = true;
String n = newRowName;
if (n.equals(oldTableName) || n.equals(newTableName) || n.equals(oldRowName)) {
throw unexpectedToken();
}
HsqlName hsqlName = database.nameManager.newHsqlName(table.getSchemaName(), n, isDelimitedIdentifier(), SchemaObject.TRANSITION);
Table transition = new Table(table, hsqlName);
RangeVariable range = new RangeVariable(transition, null, null, null, compileContext);
transitions[TriggerDef.NEW_ROW] = transition;
rangeVars[TriggerDef.NEW_ROW] = range;
} else {
throw unexpectedToken();
}
} else {
break;
}
read();
}
}
if (isForEachRow && token.tokenType != Tokens.FOR) {
throw unexpectedToken();
}
// "FOR EACH ROW" or "CALL"
if (token.tokenType == Tokens.FOR) {
read();
readThis(Tokens.EACH);
if (token.tokenType == Tokens.ROW) {
isForEachRow = true;
} else if (token.tokenType == Tokens.STATEMENT) {
if (isForEachRow) {
throw unexpectedToken();
}
} else {
throw unexpectedToken();
}
read();
}
//
if (rangeVars[TriggerDef.OLD_TABLE] != null) {
}
if (rangeVars[TriggerDef.NEW_TABLE] != null) {
}
//
if (Tokens.T_NOWAIT.equals(token.tokenString)) {
read();
isNowait = true;
} else if (Tokens.T_QUEUE.equals(token.tokenString)) {
read();
queueSize = readInteger();
hasQueueSize = true;
}
if (token.tokenType == Tokens.WHEN && beforeOrAfterType != Tokens.INSTEAD) {
read();
readThis(Tokens.OPENBRACKET);
int position = getPosition();
isCheckOrTriggerCondition = true;
condition = XreadBooleanValueExpression();
conditionSQL = getLastPart(position);
isCheckOrTriggerCondition = false;
readThis(Tokens.CLOSEBRACKET);
HsqlList unresolved = condition.resolveColumnReferences(rangeVars, null);
ExpressionColumn.checkColumnsResolved(unresolved);
condition.resolveTypes(session, null);
if (condition.getDataType() != Type.SQL_BOOLEAN) {
throw Error.error(ErrorCode.X_42568);
}
}
if (token.tokenType == Tokens.CALL) {
read();
checkIsSimpleName();
checkIsDelimitedIdentifier();
className = token.tokenString;
read();
td = new TriggerDef(name, beforeOrAfter, operation, isForEachRow, table, transitions, rangeVars, condition, conditionSQL, updateColumnIndexes, className, isNowait, queueSize);
String sql = getLastPart();
Object[] args = new Object[] { td, otherName };
return new StatementSchema(sql, StatementTypes.CREATE_TRIGGER, args, null, table.getName());
}
//
if (isNowait) {
throw unexpectedToken(Tokens.T_NOWAIT);
}
if (hasQueueSize) {
throw unexpectedToken(Tokens.T_QUEUE);
}
// procedure
boolean isBlock = false;
if (readIfThis(Tokens.BEGIN)) {
readThis(Tokens.ATOMIC);
isBlock = true;
}
int position = getPosition();
while (true) {
StatementDMQL cs = null;
switch(token.tokenType) {
case Tokens.INSERT:
if (beforeOrAfterType == Tokens.BEFORE) {
throw unexpectedToken();
}
cs = compileInsertStatement(rangeVars);
compiledStatements.add(cs);
if (isBlock) {
readThis(Tokens.SEMICOLON);
}
break;
case Tokens.UPDATE:
if (beforeOrAfterType == Tokens.BEFORE) {
throw unexpectedToken();
}
cs = compileUpdateStatement(rangeVars);
compiledStatements.add(cs);
if (isBlock) {
readThis(Tokens.SEMICOLON);
}
break;
case Tokens.DELETE:
if (beforeOrAfterType == Tokens.BEFORE) {
throw unexpectedToken();
}
cs = compileDeleteStatement(rangeVars);
compiledStatements.add(cs);
if (isBlock) {
readThis(Tokens.SEMICOLON);
}
break;
case Tokens.MERGE:
if (beforeOrAfterType == Tokens.BEFORE) {
throw unexpectedToken();
}
cs = compileMergeStatement(rangeVars);
compiledStatements.add(cs);
if (isBlock) {
readThis(Tokens.SEMICOLON);
}
break;
case Tokens.SET:
if (beforeOrAfterType != Tokens.BEFORE || operationType == Tokens.DELETE) {
throw unexpectedToken();
}
cs = compileTriggerSetStatement(table, rangeVars);
compiledStatements.add(cs);
if (isBlock) {
readThis(Tokens.SEMICOLON);
}
break;
case Tokens.END:
break;
default:
throw unexpectedToken();
}
if (!isBlock || token.tokenType == Tokens.END) {
break;
}
}
procedureSQL = getLastPart(position);
if (isBlock) {
readThis(Tokens.END);
}
StatementDMQL[] csArray = new StatementDMQL[compiledStatements.size()];
compiledStatements.toArray(csArray);
OrderedHashSet references = compileContext.getSchemaObjectNames();
for (int i = 0; i < csArray.length; i++) {
Table targetTable = csArray[i].targetTable;
boolean[] check = csArray[i].getInsertOrUpdateColumnCheckList();
if (check != null) {
targetTable.getColumnNames(check, references);
}
}
references.remove(table.getName());
td = new TriggerDefSQL(name, beforeOrAfter, operation, isForEachRow, table, transitions, rangeVars, condition, conditionSQL, updateColumnIndexes, csArray, procedureSQL, references);
String sql = getLastPart();
Object[] args = new Object[] { td, otherName };
return new StatementSchema(sql, StatementTypes.CREATE_TRIGGER, args, null, table.getName());
}
use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.
the class ParserDDL method readFKReferences.
private Constraint readFKReferences(Table refTable, HsqlName constraintName, OrderedHashSet refColSet) {
HsqlName mainTableName;
OrderedHashSet mainColSet = null;
readThis(Tokens.REFERENCES);
HsqlName schema;
if (token.namePrefix == null) {
schema = refTable.getSchemaName();
} else {
schema = database.schemaManager.getSchemaHsqlName(token.namePrefix);
}
if (refTable.getSchemaName() == schema && refTable.getName().name.equals(token.tokenString)) {
mainTableName = refTable.getName();
read();
} else {
mainTableName = readFKTableName(schema);
}
if (token.tokenType == Tokens.OPENBRACKET) {
mainColSet = readColumnNames(false);
} else {
// columns are resolved in the calling method
if (mainTableName == refTable.getName()) {
// fredt - FK statement is part of CREATE TABLE and is self-referencing
// reference must be to same table being created
} else {
/*
if (!mainTable.hasPrimaryKey()) {
throw Trace.error(Trace.CONSTRAINT_NOT_FOUND,
Trace.TABLE_HAS_NO_PRIMARY_KEY);
}
*/
}
}
int matchType = OpTypes.MATCH_SIMPLE;
if (token.tokenType == Tokens.MATCH) {
read();
switch(token.tokenType) {
case Tokens.SIMPLE:
read();
break;
case Tokens.PARTIAL:
throw super.unsupportedFeature();
case Tokens.FULL:
read();
matchType = OpTypes.MATCH_FULL;
break;
default:
throw unexpectedToken();
}
}
// -- In a while loop we parse a maximium of two
// -- "ON" statements following the foreign key
// -- definition this can be
// -- ON [UPDATE|DELETE] [NO ACTION|RESTRICT|CASCADE|SET [NULL|DEFAULT]]
int deleteAction = Constraint.NO_ACTION;
int updateAction = Constraint.NO_ACTION;
OrderedIntHashSet set = new OrderedIntHashSet();
while (token.tokenType == Tokens.ON) {
read();
if (!set.add(token.tokenType)) {
throw unexpectedToken();
}
if (token.tokenType == Tokens.DELETE) {
read();
if (token.tokenType == Tokens.SET) {
read();
switch(token.tokenType) {
case Tokens.DEFAULT:
{
read();
deleteAction = Constraint.SET_DEFAULT;
break;
}
case Tokens.NULL:
read();
deleteAction = Constraint.SET_NULL;
break;
default:
throw unexpectedToken();
}
} else if (token.tokenType == Tokens.CASCADE) {
read();
deleteAction = Constraint.CASCADE;
} else if (token.tokenType == Tokens.RESTRICT) {
read();
} else {
readThis(Tokens.NO);
readThis(Tokens.ACTION);
}
} else if (token.tokenType == Tokens.UPDATE) {
read();
if (token.tokenType == Tokens.SET) {
read();
switch(token.tokenType) {
case Tokens.DEFAULT:
{
read();
deleteAction = Constraint.SET_DEFAULT;
break;
}
case Tokens.NULL:
read();
deleteAction = Constraint.SET_NULL;
break;
default:
throw unexpectedToken();
}
} else if (token.tokenType == Tokens.CASCADE) {
read();
updateAction = Constraint.CASCADE;
} else if (token.tokenType == Tokens.RESTRICT) {
read();
} else {
readThis(Tokens.NO);
readThis(Tokens.ACTION);
}
} else {
throw unexpectedToken();
}
}
if (constraintName == null) {
constraintName = database.nameManager.newAutoName("FK", refTable.getSchemaName(), refTable.getName(), SchemaObject.CONSTRAINT);
}
return new Constraint(constraintName, refTable.getName(), refColSet, mainTableName, mainColSet, Constraint.FOREIGN_KEY, deleteAction, updateAction, matchType);
}
use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.
the class ParserDDL method readFKTableName.
private HsqlName readFKTableName(HsqlName schema) {
HsqlName name;
checkIsSchemaObjectName();
Table table = database.schemaManager.findUserTable(session, token.tokenString, schema.name);
if (table == null) {
name = database.nameManager.newHsqlName(schema, token.tokenString, isDelimitedIdentifier(), SchemaObject.TABLE);
} else {
name = table.getName();
}
read();
return name;
}
Aggregations