Search in sources :

Example 6 with PushDownOptimizationMeta

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;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) ParameterPushdownModel(org.pentaho.di.trans.dataservice.optimization.pushdown.ui.ParameterPushdownModel)

Example 7 with PushDownOptimizationMeta

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;
}
Also used : PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) TransMeta(org.pentaho.di.trans.TransMeta)

Example 8 with PushDownOptimizationMeta

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));
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) KettleXulLoader(org.pentaho.di.ui.xul.KettleXulLoader) PushDownFactory(org.pentaho.di.trans.dataservice.optimization.PushDownFactory) Shell(org.eclipse.swt.widgets.Shell) XulException(org.pentaho.ui.xul.XulException) PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) SwtXulRunner(org.pentaho.ui.xul.swt.SwtXulRunner) Test(org.junit.Test)

Example 9 with PushDownOptimizationMeta

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);
}
Also used : DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) PushDownType(org.pentaho.di.trans.dataservice.optimization.PushDownType) Test(org.junit.Test)

Example 10 with PushDownOptimizationMeta

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);
}
Also used : PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) PushDownType(org.pentaho.di.trans.dataservice.optimization.PushDownType) Test(org.junit.Test)

Aggregations

PushDownOptimizationMeta (org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta)41 Test (org.junit.Test)23 ParameterGeneration (org.pentaho.di.trans.dataservice.optimization.paramgen.ParameterGeneration)10 DataServiceMeta (org.pentaho.di.trans.dataservice.DataServiceMeta)8 SQL (org.pentaho.di.core.sql.SQL)7 IMetaStore (org.pentaho.metastore.api.IMetaStore)7 Matchers.anyString (org.mockito.Matchers.anyString)5 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 DataOutputStream (java.io.DataOutputStream)3 Set (java.util.Set)3 RowProducer (org.pentaho.di.trans.RowProducer)3 PushDownType (org.pentaho.di.trans.dataservice.optimization.PushDownType)3 DataServiceModel (org.pentaho.di.trans.dataservice.ui.model.DataServiceModel)3 XulException (org.pentaho.ui.xul.XulException)3 Shell (org.eclipse.swt.widgets.Shell)2 Before (org.junit.Before)2 InOrder (org.mockito.InOrder)2 KettleException (org.pentaho.di.core.exception.KettleException)2