if (analysisRecord == null) {
analysisRecord = new AnalysisRecord(false, false);
}
if (context == null) {
context = new CommandContext();
}
if (!(capFinder instanceof TempCapabilitiesFinder)) {
capFinder = new TempCapabilitiesFinder(capFinder);
}
boolean debug = analysisRecord.recordDebug();
Map tempMetadata = command.getTemporaryMetadata();
metadata = new TempMetadataAdapter(metadata, new TempMetadataStore(tempMetadata));
// Create an ID generator that can be used for all plans to generate unique data node IDs
if(idGenerator == null) {
idGenerator = new IDGenerator();
idGenerator.setDefaultFactory(new IntegerIDFactory());
}
if(debug) {
analysisRecord.println("\n----------------------------------------------------------------------------"); //$NON-NLS-1$
analysisRecord.println("OPTIMIZE: \n" + command); //$NON-NLS-1$
}
ProcessorPlan result = null;
switch (command.getType()) {
case Command.TYPE_UPDATE_PROCEDURE:
CreateUpdateProcedureCommand cupc = (CreateUpdateProcedureCommand)command;
if (cupc.isUpdateProcedure()) {
result = planProcedure(command, metadata, idGenerator, capFinder, analysisRecord, context);
} else {
StoredProcedure c = (StoredProcedure)cupc.getUserCommand();
Object pid = cupc.getVirtualGroup().getMetadataID();
if (c != null) {
pid = c.getProcedureID();
}
String fullName = metadata.getFullName(pid);
fullName = "procedure cache:" + fullName; //$NON-NLS-1$
PreparedPlan pp = context.getPlan(fullName);
if (pp == null) {
Determinism determinismLevel = context.resetDeterminismLevel();
CommandContext clone = context.clone();
ProcessorPlan plan = planProcedure(command, metadata, idGenerator, capFinder, analysisRecord, clone);
//note that this is not a full prepared plan. It is not usable by user queries.
if (pid instanceof Procedure) {
clone.accessedPlanningObject(pid);
}
pp = new PreparedPlan();
pp.setPlan(plan, clone);
context.putPlan(fullName, pp, context.getDeterminismLevel());
context.setDeterminismLevel(determinismLevel);