use of org.voltdb.compiler.VoltCompiler.ProcedureDescriptor in project voltdb by VoltDB.
the class CreateProcedureFromClass method processStatement.
@Override
protected boolean processStatement(DDLStatement ddlStatement, Database db, DdlProceduresToLoad whichProcs) throws VoltCompilerException {
// Matches if it is CREATE PROCEDURE [ALLOW <role> ...] [PARTITION ON ...] FROM CLASS <class-name>;
Matcher statementMatcher = SQLParser.matchCreateProcedureFromClass(ddlStatement.statement);
if (!statementMatcher.matches()) {
return false;
}
if (whichProcs != DdlProceduresToLoad.ALL_DDL_PROCEDURES) {
return true;
}
String className = checkIdentifierStart(statementMatcher.group(2), ddlStatement.statement);
Class<?> clazz;
try {
clazz = Class.forName(className, true, m_classLoader);
} catch (Throwable cause) {
// wrap the error with a runtime exception that we can trap in our code.
if (CoreUtils.isStoredProcThrowableFatalToServer(cause)) {
throw (Error) cause;
} else {
throw m_compiler.new VoltCompilerException(String.format("Cannot load class for procedure: %s", className), cause);
}
}
ProcedureDescriptor descriptor = m_compiler.new ProcedureDescriptor(new ArrayList<String>(), null, clazz);
// Parse the ALLOW and PARTITION clauses.
// Populate descriptor roles and returned partition data as needed.
CreateProcedurePartitionData partitionData = parseCreateProcedureClauses(descriptor, statementMatcher.group(1));
// track the defined procedure
String procName = m_tracker.add(descriptor);
// add partitioning if specified
addProcedurePartitionInfo(procName, partitionData, ddlStatement.statement);
return true;
}
use of org.voltdb.compiler.VoltCompiler.ProcedureDescriptor in project voltdb by VoltDB.
the class VoltDDLElementTracker method addProcedurePartitionInfoTo.
/**
* Associates the given partition info to the given tracked procedure
* @param procedureName the short name of the procedure name
* @param partitionInfo the partition info to associate with the procedure
* @throws VoltCompilerException when there is no corresponding tracked
* procedure
*/
public void addProcedurePartitionInfoTo(String procedureName, String partitionInfo) throws VoltCompilerException {
assert procedureName != null && !procedureName.trim().isEmpty();
assert partitionInfo != null && !partitionInfo.trim().isEmpty();
ProcedureDescriptor descriptor = m_procedureMap.get(procedureName);
if (descriptor == null) {
throw m_compiler.new VoltCompilerException(String.format("Partition references an undefined procedure \"%s\"", procedureName));
}
// need to re-instantiate as descriptor fields are final
if (descriptor.m_singleStmt == null) {
// the longer form costructor asserts on singleStatement
descriptor = m_compiler.new ProcedureDescriptor(descriptor.m_authGroups, descriptor.m_class, partitionInfo);
} else {
descriptor = m_compiler.new ProcedureDescriptor(descriptor.m_authGroups, descriptor.m_className, descriptor.m_singleStmt, descriptor.m_joinOrder, partitionInfo, false, descriptor.m_class);
}
m_procedureMap.put(procedureName, descriptor);
}
use of org.voltdb.compiler.VoltCompiler.ProcedureDescriptor in project voltdb by VoltDB.
the class CreateProcedureAsSQL method processStatement.
@Override
protected boolean processStatement(DDLStatement ddlStatement, Database db, DdlProceduresToLoad whichProcs) throws VoltCompilerException {
// Matches if it is CREATE PROCEDURE <proc-name> [ALLOW <role> ...] [PARTITION ON ...] AS <select-or-dml-statement>
Matcher statementMatcher = SQLParser.matchCreateProcedureAsSQL(ddlStatement.statement);
if (!statementMatcher.matches()) {
return false;
}
String clazz = checkProcedureIdentifier(statementMatcher.group(1), ddlStatement.statement);
String sqlStatement = statementMatcher.group(3) + ";";
ProcedureDescriptor descriptor = m_compiler.new ProcedureDescriptor(new ArrayList<String>(), clazz, sqlStatement, null, null, false, null);
// Parse the ALLOW and PARTITION clauses.
// Populate descriptor roles and returned partition data as needed.
CreateProcedurePartitionData partitionData = parseCreateProcedureClauses(descriptor, statementMatcher.group(2));
m_tracker.add(descriptor);
// add partitioning if specified
addProcedurePartitionInfo(clazz, partitionData, ddlStatement.statement);
return true;
}
Aggregations