use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.
the class Table method createPrimaryKey.
/**
* Creates a single or multi-column primary key and index. sets the
* colTypes array. Finalises the creation of the table. (fredt@users)
*/
public void createPrimaryKey(HsqlName indexName, int[] columns, boolean columnsNotNull) {
if (primaryKeyCols != null) {
throw Error.runtimeError(ErrorCode.U_S0500, "Table");
}
if (columns == null) {
columns = ValuePool.emptyIntArray;
} else {
for (int i = 0; i < columns.length; i++) {
getColumn(columns[i]).setPrimaryKey(true);
}
}
primaryKeyCols = columns;
setColumnStructures();
primaryKeyTypes = new Type[primaryKeyCols.length];
ArrayUtil.projectRow(colTypes, primaryKeyCols, primaryKeyTypes);
primaryKeyColsSequence = new int[primaryKeyCols.length];
ArrayUtil.fillSequence(primaryKeyColsSequence);
HsqlName name = indexName;
if (name == null) {
name = database.nameManager.newAutoName("IDX", getSchemaName(), getName(), SchemaObject.INDEX);
}
createPrimaryIndex(primaryKeyCols, primaryKeyTypes, name);
setBestRowIdentifiers();
}
use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.
the class TableWorks method addLimitConstraint.
/* addUniqueExprConstraint */
// A VoltDB extension to support LIMIT PARTITION ROWS
void addLimitConstraint(Constraint c) {
// Find any pre-existing LIMIT constraint on the table and remove it
for (Constraint cst : table.constraintList) {
if (cst.getConstraintType() == Constraint.LIMIT) {
OrderedHashSet constraintNameSet = new OrderedHashSet();
HsqlName name = cst.getName();
constraintNameSet.add(name);
updateConstraints(table, constraintNameSet);
database.schemaManager.removeSchemaObject(name);
// Highlander rules for Constraint.LIMIT
break;
}
}
table.addConstraint(c);
database.schemaManager.addSchemaObject(c);
}
use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.
the class ScriptReaderText method readDDL.
protected void readDDL(Session session) throws IOException {
for (; readLoggedStatement(session); ) {
Statement cs = null;
Result result = null;
if (rowIn.getStatementType() == INSERT_STATEMENT) {
isInsert = true;
break;
}
try {
cs = session.compileStatement(statement);
result = session.executeCompiledStatement(cs, ValuePool.emptyObjectArray);
if (cs.getType() == StatementTypes.CREATE_SCHEMA) {
HsqlName name = cs.getSchemaName();
session.setSchema(name.name);
}
} catch (HsqlException e) {
result = Result.newErrorResult(e);
}
if (result.isError()) {
// handle grants on math and library routines in old versions
if (cs == null) {
} else {
if (cs.getType() == StatementTypes.GRANT) {
continue;
}
}
//
}
if (result.isError()) {
db.logger.appLog.logContext(SimpleLog.LOG_ERROR, result.getMainString());
throw Error.error(ErrorCode.ERROR_IN_SCRIPT_FILE, ErrorCode.M_DatabaseScriptReader_readDDL, new Object[] { new Integer(lineCount), result.getMainString() });
}
}
}
use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.
the class ParserDQL method readColumnOrFunctionExpression.
/**
* reads a Column or Function expression
*/
private Expression readColumnOrFunctionExpression() {
String name = token.tokenString;
boolean isSimpleQuoted = isDelimitedSimpleName();
String prefix = token.namePrefix;
String prePrefix = token.namePrePrefix;
if (isUndelimitedSimpleName()) {
// A VoltDB extension to augment the standard sql function set.
FunctionSQL function;
function = FunctionForVoltDB.newVoltDBFunction(name);
if (function == null) {
// These seem to be JDBC ("Open Group"?) aliases and extensions to the standard sql functions.
function = FunctionCustom.newCustomFunction(token.tokenString, token.tokenType);
}
if (function != null) {
int pos = getPosition();
// A VoltDB extension to avoid abusing the exception handling mechanism
// for normal flow control.
HsqlException ex = null;
try {
ExpressionOrException result = readSQLFunction(function, false);
ex = result.exception();
if (ex == null) {
return result.knownGood();
}
} catch (HsqlException caught) {
ex = caught;
}
if (ex != null) {
/* disable 3 lines ...
try {
return readSQLFunction(function);
} catch (HsqlException ex) {
... disabled 3 lines */
// End of VoltDB extension
ex.setLevel(compileContext.subQueryDepth);
if (lastError == null || lastError.getLevel() < ex.getLevel()) {
lastError = ex;
}
rewind(pos);
}
} else if (isReservedKey()) {
function = FunctionSQL.newSQLFunction(name, compileContext);
if (function != null) {
// but get post-processed in the similar call above for FunctionForVoltDB and FunctionCustom
return readSQLFunction(function);
}
}
}
read();
if (token.tokenType != Tokens.OPENBRACKET) {
Expression column = new ExpressionColumn(prePrefix, prefix, name);
return column;
}
checkValidCatalogName(prePrefix);
prefix = session.getSchemaName(prefix);
RoutineSchema routineSchema = (RoutineSchema) database.schemaManager.findSchemaObject(name, prefix, SchemaObject.FUNCTION);
if (routineSchema == null && isSimpleQuoted) {
HsqlName schema = database.schemaManager.getDefaultSchemaHsqlName();
routineSchema = (RoutineSchema) database.schemaManager.findSchemaObject(name, schema.name, SchemaObject.FUNCTION);
if (routineSchema == null) {
Method[] methods = Routine.getMethods(name);
Routine[] routines = Routine.newRoutines(methods);
HsqlName routineName = database.nameManager.newHsqlName(schema, name, true, SchemaObject.FUNCTION);
for (int i = 0; i < routines.length; i++) {
routines[i].setName(routineName);
session.database.schemaManager.addSchemaObject(routines[i]);
}
routineSchema = (RoutineSchema) database.schemaManager.findSchemaObject(name, schema.name, SchemaObject.FUNCTION);
}
}
if (routineSchema == null) {
throw Error.error(ErrorCode.X_42501, name);
}
HsqlArrayList list = new HsqlArrayList();
readThis(Tokens.OPENBRACKET);
if (token.tokenType == Tokens.CLOSEBRACKET) {
read();
} else {
while (true) {
Expression e = XreadValueExpression();
list.add(e);
if (token.tokenType == Tokens.COMMA) {
read();
} else {
readThis(Tokens.CLOSEBRACKET);
break;
}
}
}
FunctionSQLInvoked function = new FunctionSQLInvoked(routineSchema);
Expression[] arguments = new Expression[list.size()];
list.toArray(arguments);
function.setArguments(arguments);
compileContext.addRoutine(function);
return function;
}
use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.
the class ParserDQL method readNewSchemaObjectName.
HsqlName readNewSchemaObjectName(int type) {
checkIsSchemaObjectName();
HsqlName hsqlName = database.nameManager.newHsqlName(token.tokenString, isDelimitedIdentifier(), type);
if (token.namePrefix != null) {
if (type == SchemaObject.GRANTEE || type == SchemaObject.VARIABLE || type == SchemaObject.CATALOG) {
throw unexpectedToken();
}
HsqlName schemaName = session.getSchemaHsqlName(token.namePrefix);
hsqlName.setSchemaIfNull(schemaName);
}
read();
return hsqlName;
}
Aggregations