use of org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta in project pdi-dataservice-server-plugin by pentaho.
the class ParameterPushdownFactory method createModel.
public ParameterPushdownModel createModel(final DataServiceModel dialogModel) {
List<PushDownOptimizationMeta> optimizations = dialogModel.getPushDownOptimizations(ParameterPushdown.class);
ParameterPushdown parameterPushdown;
if (optimizations.isEmpty()) {
parameterPushdown = createPushDown();
PushDownOptimizationMeta optimizationMeta = new PushDownOptimizationMeta();
optimizationMeta.setStepName(dialogModel.getServiceStep());
optimizationMeta.setType(parameterPushdown);
dialogModel.add(optimizationMeta);
} else {
parameterPushdown = (ParameterPushdown) optimizations.get(0).getType();
}
if (optimizations.size() > 1) {
dialogModel.removeAll(optimizations.subList(1, optimizations.size()));
}
final ParameterPushdownModel parameterPushdownModel = new ParameterPushdownModel(parameterPushdown);
parameterPushdownModel.setFieldList(dialogModel.getStepFields());
dialogModel.addPropertyChangeListener("serviceStep", new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
parameterPushdownModel.setFieldList(dialogModel.getStepFields());
}
});
return parameterPushdownModel;
}
use of org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceMetaFactory method createDataService.
@Override
public DataServiceMeta createDataService(StepMeta step, Integer rowLimit) throws KettleException {
TransMeta transformation = step.getParentTransMeta();
DataServiceMeta dataServiceMeta = new DataServiceMeta(transformation);
dataServiceMeta.setName(createDataServiceName(step, rowLimit, false));
dataServiceMeta.setStepname(step.getName());
dataServiceMeta.setRowLimit(rowLimit != null ? rowLimit : 0);
PushDownOptimizationMeta pushDownMeta = new PushDownOptimizationMeta();
pushDownMeta.setStepName(step.getName());
pushDownMeta.setType(getCacheFactory().createPushDown());
dataServiceMeta.setPushDownOptimizationMeta(Collections.singletonList(pushDownMeta));
return dataServiceMeta;
}
use of org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceDialogTest method testBuilder.
@Test
public void testBuilder() throws Exception {
final DataServiceDelegate mockDelegate = mock(DataServiceDelegate.class);
final DataServiceDialog dialog = mock(DataServiceDialog.class);
when(dialog.getController()).thenReturn(controller);
// Intercept actual creation so we can inject our mock
DataServiceDialog.Builder builder = new DataServiceDialog.Builder(model) {
@Override
protected DataServiceDialog createDialog(DataServiceDelegate delegate) {
assertThat(delegate, sameInstance(mockDelegate));
assertThat(super.createDialog(delegate), isA(DataServiceDialog.class));
return dialog;
}
};
builder.serviceStep("step");
verify(model).setServiceStep("step");
builder.serviceStep("");
builder.serviceStep(null);
verify(model, times(2)).setServiceStep("");
DataServiceMeta dataService = mock(DataServiceMeta.class);
when(dataService.getName()).thenReturn("Service");
when(dataService.getStepname()).thenReturn("OUTPUT");
ArrayList<PushDownOptimizationMeta> optimizations = Lists.newArrayList(mock(PushDownOptimizationMeta.class));
when(dataService.getPushDownOptimizationMeta()).thenReturn(optimizations);
builder.edit(dataService);
verify(model).setServiceName("Service");
verify(model).setServiceStep("OUTPUT");
verify(model).setPushDownOptimizations(optimizations);
Shell shell = mock(Shell.class);
ArrayList<PushDownFactory> factories = Lists.newArrayList(mock(PushDownFactory.class));
when(mockDelegate.getShell()).thenReturn(shell);
when(mockDelegate.getPushDownFactories()).thenReturn(factories);
assertThat(builder.build(mockDelegate), sameInstance(dialog));
verify(controller).setDataService(dataService);
verify(dialog).loadXul(same(shell), any(KettleXulLoader.class), any(SwtXulRunner.class));
verify(dialog).initOptimizations(factories);
Throwable xulException = new XulException();
when(dialog.loadXul(same(shell), any(KettleXulLoader.class), any(SwtXulRunner.class))).thenThrow(xulException);
try {
builder.build(mockDelegate);
fail("Expected exception was not thrown");
} catch (KettleException e) {
assertThat(e.getCause(), equalTo(xulException));
}
}
use of org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceModelTest method testGetDataService.
@Test
public void testGetDataService() throws Exception {
model.setServiceName("service");
model.setServiceStep("step");
PushDownOptimizationMeta optimizationMeta = mock(PushDownOptimizationMeta.class);
model.setPushDownOptimizations(Lists.newArrayList(optimizationMeta));
PushDownType pushDownType = mock(PushDownType.class);
when(optimizationMeta.getType()).thenReturn(pushDownType);
DataServiceMeta dataService = model.getDataService();
assertThat(dataService, allOf(hasProperty("name", equalTo("service")), hasProperty("stepname", equalTo("step")), hasProperty("pushDownOptimizationMeta", contains(optimizationMeta))));
verify(pushDownType).init(transMeta, dataService, optimizationMeta);
}
use of org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceModelTest method testPushDownOptimizations.
@Test
public void testPushDownOptimizations() throws Exception {
List<PushDownOptimizationMeta> emptyList = Collections.emptyList();
List<PushDownOptimizationMeta> optimizations = Lists.newArrayList(mock(PushDownOptimizationMeta.class));
model.setPushDownOptimizations(optimizations);
verify(propertyChangeSupport).firePropertyChange("pushDownOptimizations", emptyList, optimizations);
ImmutableList<PushDownOptimizationMeta> init = ImmutableList.copyOf(optimizations);
PushDownOptimizationMeta optimizationMeta = mock(PushDownOptimizationMeta.class);
optimizations.add(optimizationMeta);
assertTrue(model.add(optimizationMeta));
verify(propertyChangeSupport).firePropertyChange("pushDownOptimizations", init, optimizations);
PushDownType pushDownType = mock(PushDownType.class);
when(optimizationMeta.getType()).thenReturn(pushDownType);
assertThat(model.getPushDownOptimizations(pushDownType.getClass()), contains(optimizationMeta));
assertThat(model.getPushDownOptimizations(), equalTo(optimizations));
assertTrue(model.remove(optimizationMeta));
verify(propertyChangeSupport).firePropertyChange("pushDownOptimizations", optimizations, init);
assertFalse(model.remove(optimizationMeta));
verifyNoMoreInteractions(propertyChangeSupport);
assertTrue(model.removeAll(optimizations));
verify(propertyChangeSupport).firePropertyChange("pushDownOptimizations", init, emptyList);
assertFalse(model.removeAll(optimizations));
verifyNoMoreInteractions(propertyChangeSupport);
}
Aggregations