/** * @see java.lang.Object#clone() * @since 4.2 */ public BatchedUpdatePlan clone() { List<ProcessorPlan> clonedPlans = new ArrayList<ProcessorPlan>(updatePlans.length); clonedPlans.add(updatePlans[0].clone()); for (int i = 1; i <updatePlans.length; i++) { if (contexts == null) { clonedPlans.add(updatePlans[1].clone()); } else { clonedPlans.add(clonedPlans.get(0)); } } BatchedUpdatePlan clone = new BatchedUpdatePlan(clonedPlans, updateCounts.length, contexts, singleResult); return clone; }
/** * @see org.teiid.query.processor.ProcessorPlan#open() * @since 4.2 */ public void open() throws TeiidComponentException, TeiidProcessingException { try { // It's ok to open() the first plan, as it is not dependent on any prior commands. // See note for defect 16166 in the nextBatch() method. openPlan(); } catch (BlockedException e){ //should not happen throw e; } catch (TeiidComponentException | TeiidProcessingException e) { if (singleResult) { throw e; } Throwable cause = e; if (e.getCause() instanceof TranslatorBatchException) { TranslatorBatchException tbe = (TranslatorBatchException)e.getCause(); for (int i = 0; i < tbe.getUpdateCounts().length; i++) { updateCounts[commandIndex++] = Arrays.asList(updateCounts[i]); } } updateCounts = Arrays.copyOf(updateCounts, commandIndex); getContext().setBatchUpdateException(cause); } }
/** * @see org.teiid.query.processor.ProcessorPlan#initialize(org.teiid.query.util.CommandContext, org.teiid.query.processor.ProcessorDataManager, org.teiid.common.buffer.BufferManager) * @since 4.2 */ public void initialize(CommandContext context, ProcessorDataManager dataMgr, BufferManager bufferMgr) { context = context.clone(); context.setVariableContext(new VariableContext()); //start a new root variable context this.setContext(context); // Initialize all the child plans for (int i = 0; i < getPlanCount(); i++) { updatePlans[i].initialize(context, dataMgr, bufferMgr); } }
BatchedUpdatePlan plan = new BatchedUpdatePlan(Arrays.asList(plans), plans.length, null, false); plan.requiresTransaction(false); plan.initialize(context, null, null); plan.open(); TupleBatch batch = plan.nextBatch(); assertEquals(4, batch.getRowCount());
@Test public void testOpen() throws Exception { FakeProcessorPlan[] plans = new FakeProcessorPlan[4]; for (int i = 0; i < plans.length; i++) { plans[i] = new FakeProcessorPlan(1); } BatchedUpdatePlan plan = new BatchedUpdatePlan(Arrays.asList(plans), plans.length, null, false); plan.initialize(new CommandContext(), null, null); plan.open(); // First plan may or may not be opened, but all subsequent plans should not be opened. for (int i = 1; i < plans.length; i++) { assertFalse(plans[i].isOpened()); } }
private void helpTestNextBatch(int[] commandsPerPlan) throws Exception { List plans = new ArrayList(commandsPerPlan.length); int totalCommands = 0; for (int i = 0; i < commandsPerPlan.length; i++) { totalCommands += commandsPerPlan[i]; plans.add(new FakeProcessorPlan(commandsPerPlan[i])); } BatchedUpdatePlan plan = new BatchedUpdatePlan(plans, totalCommands, null, false); plan.initialize(new CommandContext(), null, null); TupleBatch batch = plan.nextBatch(); assertEquals(totalCommands, batch.getRowCount()); for (int i = 1; i <= totalCommands; i++) { assertEquals(new Integer(1), batch.getTuple(i).get(0)); } }
@Test public void testRequiresTransaction() throws Exception { ProcessorPlan[] plans = new ProcessorPlan[2]; plans[0] = new FakeProcessorPlan(1); plans[1] = new FakeProcessorPlan(1) { public Boolean requiresTransaction(boolean transactionalReads) { return true; } }; BatchedUpdatePlan plan = new BatchedUpdatePlan(Arrays.asList(plans), plans.length, null, true); assertTrue(plan.requiresTransaction(false)); }
public String toString() { StringBuffer val = new StringBuffer("BatchedUpdatePlan {\n"); //$NON-NLS-1$ for (int i = 0; i < getPlanCount(); i++) { val.append(updatePlans[i]) .append("\n"); //$NON-NLS-1$ } val.append("}\n"); //$NON-NLS-1$ return val.toString(); }
private void openPlan() throws TeiidComponentException, TeiidProcessingException { //reset prior to updating the context updatePlans[planIndex].reset(); if (this.contexts != null && !this.contexts.isEmpty()) { CommandContext context = updatePlans[planIndex].getContext(); VariableContext vc = context.getVariableContext(); //ensure that we're dealing with the global context //this is just a safe guard against the plan not correctly resetting the context while (vc.getParentContext() != null) { vc = vc.getParentContext(); } vc.clear(); VariableContext currentValues = this.contexts.get(planIndex); vc.putAll(currentValues); } TransactionContext tc = this.getContext().getTransactionContext(); if (startTxn[planIndex] && tc != null && tc.getTransactionType() == Scope.NONE) { this.getContext().getTransactionServer().begin(tc); this.planContexts[planIndex] = tc; } updatePlans[planIndex].open(); planOpened[planIndex] = true; }
private void helpTestPlanner(String[] sql, boolean[] expectedBatching, CapabilitiesFinder capFinder) throws QueryMetadataException, TeiidComponentException, TeiidProcessingException { BatchedUpdatePlan plan = helpPlan(sql, RealMetadataFactory.example1Cached(), capFinder, true); List plans = plan.getUpdatePlans(); assertEquals("Number of child plans did not match expected", expectedBatching.length, plans.size()); //$NON-NLS-1$ for (int i = 0; i < expectedBatching.length; i++) { helpAssertIsBatchedPlan((RelationalPlan)plans.get(i), expectedBatching[i]); } }
@Test public void testMultipleBatches() throws Exception { FakeProcessorPlan[] plans = new FakeProcessorPlan[4]; for (int i = 0; i < plans.length; i++) { TupleBatch last = new TupleBatch(2, Arrays.asList(Arrays.asList(1))); last.setTerminationFlag(true); plans[i] = new FakeProcessorPlan(Arrays.asList(Command.getUpdateCommandSymbol()), Arrays.asList(new TupleBatch(1, Arrays.asList(Arrays.asList(1))), BlockedException.INSTANCE, last)); } BatchedUpdatePlan plan = new BatchedUpdatePlan(Arrays.asList(plans), plans.length*2, null, false); plan.initialize(new CommandContext(), null, null); plan.open(); // First plan may or may not be opened, but all subsequent plans should not be opened. for (int i = 1; i < plans.length; i++) { assertFalse(plans[i].isOpened()); } for (int i = 0; i < 4; i++) { try { plan.nextBatch(); fail(); } catch (BlockedException e) { } } TupleBatch batch = plan.nextBatch(); assertEquals(8, batch.getRowCount()); assertTrue(batch.getTerminationFlag()); }
public String toString() { StringBuffer val = new StringBuffer("BatchedUpdatePlan {\n"); //$NON-NLS-1$ for (int i = 0; i < getPlanCount(); i++) { val.append(updatePlans[i]) .append("\n"); //$NON-NLS-1$ } val.append("}\n"); //$NON-NLS-1$ return val.toString(); }
private void openPlan() throws TeiidComponentException, TeiidProcessingException { //reset prior to updating the context updatePlans[planIndex].reset(); if (this.contexts != null && !this.contexts.isEmpty()) { CommandContext context = updatePlans[planIndex].getContext(); VariableContext vc = context.getVariableContext(); //ensure that we're dealing with the global context //this is just a safe guard against the plan not correctly resetting the context while (vc.getParentContext() != null) { vc = vc.getParentContext(); } vc.clear(); VariableContext currentValues = this.contexts.get(planIndex); vc.putAll(currentValues); } TransactionContext tc = this.getContext().getTransactionContext(); if (startTxn[planIndex] && tc != null && tc.getTransactionType() == Scope.NONE) { this.getContext().getTransactionServer().begin(tc); this.planContexts[planIndex] = tc; } updatePlans[planIndex].open(); planOpened[planIndex] = true; }
private void helpTestPlanner(String[] sql, boolean[] expectedBatching) throws QueryMetadataException, TeiidComponentException, TeiidProcessingException { BatchedUpdatePlan plan = helpPlan(sql, RealMetadataFactory.example1Cached()); List plans = plan.getUpdatePlans(); assertEquals("Number of child plans did not match expected", expectedBatching.length, plans.size()); //$NON-NLS-1$ for (int i = 0; i < expectedBatching.length; i++) { helpAssertIsBatchedPlan((RelationalPlan)plans.get(i), expectedBatching[i]); } }
/** * @see org.teiid.query.processor.ProcessorPlan#open() * @since 4.2 */ public void open() throws TeiidComponentException, TeiidProcessingException { try { // It's ok to open() the first plan, as it is not dependent on any prior commands. // See note for defect 16166 in the nextBatch() method. openPlan(); } catch (BlockedException e){ //should not happen throw e; } catch (TeiidComponentException | TeiidProcessingException e) { if (singleResult) { throw e; } Throwable cause = e; if (e.getCause() instanceof TranslatorBatchException) { TranslatorBatchException tbe = (TranslatorBatchException)e.getCause(); for (int i = 0; i < tbe.getUpdateCounts().length; i++) { updateCounts[commandIndex++] = Arrays.asList(updateCounts[i]); } } updateCounts = Arrays.copyOf(updateCounts, commandIndex); getContext().setBatchUpdateException(cause); } }
/** * @see java.lang.Object#clone() * @since 4.2 */ public BatchedUpdatePlan clone() { List<ProcessorPlan> clonedPlans = new ArrayList<ProcessorPlan>(updatePlans.length); clonedPlans.add(updatePlans[0].clone()); for (int i = 1; i <updatePlans.length; i++) { if (contexts == null) { clonedPlans.add(updatePlans[1].clone()); } else { clonedPlans.add(clonedPlans.get(0)); } } BatchedUpdatePlan clone = new BatchedUpdatePlan(clonedPlans, updateCounts.length, contexts, singleResult); return clone; }
/** * @see org.teiid.query.processor.ProcessorPlan#initialize(org.teiid.query.util.CommandContext, org.teiid.query.processor.ProcessorDataManager, org.teiid.common.buffer.BufferManager) * @since 4.2 */ public void initialize(CommandContext context, ProcessorDataManager dataMgr, BufferManager bufferMgr) { context = context.clone(); context.setVariableContext(new VariableContext()); //start a new root variable context this.setContext(context); // Initialize all the child plans for (int i = 0; i < getPlanCount(); i++) { updatePlans[i].initialize(context, dataMgr, bufferMgr); } }
public String toString() { StringBuffer val = new StringBuffer("BatchedUpdatePlan {\n"); //$NON-NLS-1$ for (int i = 0; i < getPlanCount(); i++) { val.append(updatePlans[i]) .append("\n"); //$NON-NLS-1$ } val.append("}\n"); //$NON-NLS-1$ return val.toString(); }
private void openPlan() throws TeiidComponentException, TeiidProcessingException { //reset prior to updating the context updatePlans[planIndex].reset(); if (this.contexts != null && !this.contexts.isEmpty()) { CommandContext context = updatePlans[planIndex].getContext(); VariableContext vc = context.getVariableContext(); //ensure that we're dealing with the global context //this is just a safe guard against the plan not correctly resetting the context while (vc.getParentContext() != null) { vc = vc.getParentContext(); } vc.clear(); VariableContext currentValues = this.contexts.get(planIndex); vc.putAll(currentValues); } TransactionContext tc = this.getContext().getTransactionContext(); if (startTxn[planIndex] && tc != null && tc.getTransactionType() == Scope.NONE) { this.getContext().getTransactionServer().begin(tc); this.planContexts[planIndex] = tc; } updatePlans[planIndex].open(); planOpened[planIndex] = true; }
/** * @see org.teiid.query.processor.ProcessorPlan#open() * @since 4.2 */ public void open() throws TeiidComponentException, TeiidProcessingException { try { // It's ok to open() the first plan, as it is not dependent on any prior commands. // See note for defect 16166 in the nextBatch() method. openPlan(); } catch (BlockedException e){ //should not happen throw e; } catch (TeiidComponentException | TeiidProcessingException e) { if (singleResult) { throw e; } Throwable cause = e; if (e.getCause() instanceof TranslatorBatchException) { TranslatorBatchException tbe = (TranslatorBatchException)e.getCause(); for (int i = 0; i < tbe.getUpdateCounts().length; i++) { updateCounts[commandIndex++] = Arrays.asList(updateCounts[i]); } } updateCounts = Arrays.copyOf(updateCounts, commandIndex); getContext().setBatchUpdateException(cause); } }