Search in sources :

Example 1 with TableInputData

use of org.pentaho.di.trans.steps.tableinput.TableInputData in project pdi-dataservice-server-plugin by pentaho.

the class TableInputParameterGeneration method getDatabaseWrapper.

private DatabaseWrapper getDatabaseWrapper(StepInterface stepInterface) throws PushDownOptimizationException {
    TableInputData stepDataInterface = getTableInputData(stepInterface);
    DatabaseWrapper db;
    if (stepDataInterface.db instanceof DatabaseWrapper) {
        // Use existing wrapper if available
        db = (DatabaseWrapper) stepDataInterface.db;
    } else {
        // Create a new wrapper
        db = new DatabaseWrapper(stepDataInterface.db);
    }
    return db;
}
Also used : TableInputData(org.pentaho.di.trans.steps.tableinput.TableInputData)

Example 2 with TableInputData

use of org.pentaho.di.trans.steps.tableinput.TableInputData in project pdi-dataservice-server-plugin by pentaho.

the class TableInputParameterGeneration method pushDown.

@Override
public void pushDown(Condition condition, ParameterGeneration parameterGeneration, StepInterface stepInterface) throws PushDownOptimizationException {
    DatabaseWrapper db = getDatabaseWrapper(stepInterface);
    verifyDbConnection(db);
    dbMeta = db.getDatabaseMeta();
    StringBuilder sqlFragment = new StringBuilder();
    RowMeta paramsMeta = new RowMeta();
    List<Object> params = new LinkedList<Object>();
    convertCondition(condition, sqlFragment, paramsMeta, params);
    // Save conversion results for injection at runtime
    String fragmentId = db.createRuntimePushDown(sqlFragment.toString(), paramsMeta, params, getParameterDefault());
    // Set variable to fragment ID
    stepInterface.setVariable(parameterGeneration.getParameterName(), fragmentId);
    TableInputData tableInput = getTableInputData(stepInterface);
    tableInput.db = db;
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) TableInputData(org.pentaho.di.trans.steps.tableinput.TableInputData) LinkedList(java.util.LinkedList)

Example 3 with TableInputData

use of org.pentaho.di.trans.steps.tableinput.TableInputData in project pdi-dataservice-server-plugin by pentaho.

the class TableInputParameterGenerationTest method setUp.

@Before
public void setUp() throws Exception {
    // Setup Mock Step and Data
    data = new TableInputData();
    when(stepInterface.getLogLevel()).thenReturn(LogLevel.NOTHING);
    data.db = new Database(stepInterface, databaseMeta);
    // Add mock connection to connection map, prevent an actual connection attempt
    data.db.setConnection(mock(Connection.class));
    data.db.setConnectionGroup(MOCK_CONNECTION_GROUP);
    data.db.setPartitionId(MOCK_PARTITION_ID);
    when(stepInterface.getStepDataInterface()).thenReturn(data);
    service.dbMeta = databaseMeta;
    when(databaseMeta.quoteField(anyString())).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return (String) invocation.getArguments()[0];
        }
    });
    DatabaseConnectionMap connectionMap = DatabaseConnectionMap.getInstance();
    connectionMap.getMap().clear();
    connectionMap.storeDatabase(MOCK_CONNECTION_GROUP, MOCK_PARTITION_ID, data.db);
    setupValueMetaResolverMock();
}
Also used : DatabaseConnectionMap(org.pentaho.di.core.database.map.DatabaseConnectionMap) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Database(org.pentaho.di.core.database.Database) Connection(java.sql.Connection) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) TableInputData(org.pentaho.di.trans.steps.tableinput.TableInputData) Before(org.junit.Before)

Aggregations

TableInputData (org.pentaho.di.trans.steps.tableinput.TableInputData)3 Connection (java.sql.Connection)1 LinkedList (java.util.LinkedList)1 Before (org.junit.Before)1 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)1 Matchers.anyString (org.mockito.Matchers.anyString)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Database (org.pentaho.di.core.database.Database)1 DatabaseConnectionMap (org.pentaho.di.core.database.map.DatabaseConnectionMap)1 RowMeta (org.pentaho.di.core.row.RowMeta)1