Search in sources :

Example 96 with PluginRegistry

use of org.pentaho.di.core.plugins.PluginRegistry in project pentaho-kettle by pentaho.

the class SynchronizeAfterMergeIT method setUp.

@Before
public void setUp() throws KettleDatabaseException, SQLException {
    connection = DriverManager.getConnection("jdbc:h2:mem:PERSON;");
    connection.setAutoCommit(false);
    PreparedStatement stmt = connection.prepareStatement("CREATE TABLE PERSON (ID INT PRIMARY KEY, personName VARCHAR(64) )");
    stmt.execute();
    stmt.close();
    stmt = connection.prepareStatement("INSERT INTO PERSON (ID, personName) VALUES (?, ?)");
    for (int i = 0; i < ROW_FOR_UPDATE + ROW_FOR_DELETE; i++) {
        stmt.setInt(1, i);
        stmt.setString(2, "personName" + i);
        stmt.addBatch();
    }
    stmt.executeBatch();
    stmt.close();
    connection.commit();
    PluginRegistry pluginRegistry = PluginRegistry.getInstance();
    transMeta = new TransMeta();
    transMeta.setName("SynchronizeAfterMerge");
    InjectorMeta injectorMeta = new InjectorMeta();
    String injectorPid = pluginRegistry.getPluginId(StepPluginType.class, injectorMeta);
    StepMeta injectorStep = new StepMeta(injectorPid, injectorStepname, injectorMeta);
    transMeta.addStep(injectorStep);
    DatabaseMeta dbMeta = spy(new DatabaseMeta());
    dbMeta.setDatabaseType("H2");
    when(dbMeta.getURL()).thenReturn("jdbc:h2:mem:PERSON;");
    when(dbMeta.supportsErrorHandlingOnBatchUpdates()).thenReturn(false);
    SynchronizeAfterMergeMeta synchronizeAfterMergeMeta = new SynchronizeAfterMergeMeta();
    // set commit size
    synchronizeAfterMergeMeta.setCommitSize(COMMIT_SIZE);
    synchronizeAfterMergeMeta.setDatabaseMeta(dbMeta);
    synchronizeAfterMergeMeta.setKeyCondition(new String[] { "=" });
    synchronizeAfterMergeMeta.setKeyLookup(new String[] { "ID" });
    synchronizeAfterMergeMeta.setKeyStream(new String[] { "personName" });
    synchronizeAfterMergeMeta.setKeyStream2(new String[] { null });
    synchronizeAfterMergeMeta.setUpdate(new Boolean[] { Boolean.TRUE });
    synchronizeAfterMergeMeta.setOperationOrderField("flag");
    synchronizeAfterMergeMeta.setOrderDelete(DELETE_FLAG);
    synchronizeAfterMergeMeta.setOrderInsert(INSERT_FLAG);
    synchronizeAfterMergeMeta.setOrderUpdate(UPDATE_FLAG);
    synchronizeAfterMergeMeta.setPerformLookup(true);
    synchronizeAfterMergeMeta.setTableName("PERSON");
    synchronizeAfterMergeMeta.settablenameInField(false);
    synchronizeAfterMergeMeta.settablenameField(null);
    synchronizeAfterMergeMeta.setUseBatchUpdate(true);
    synchronizeAfterMergeMeta.setUpdateLookup(new String[] { "ID" });
    synchronizeAfterMergeMeta.setUpdateStream(new String[] { "personName" });
    String synchronizeAfterMergePid = pluginRegistry.getPluginId(StepPluginType.class, synchronizeAfterMergeStepname);
    StepMeta synchronizeAfterMerge = new StepMeta(synchronizeAfterMergePid, synchronizeAfterMergeStepname, synchronizeAfterMergeMeta);
    transMeta.addStep(synchronizeAfterMerge);
    String dummyResultStepName = "dummyResultStepName";
    DummyTransMeta dummyResultTransMeta = new DummyTransMeta();
    String dummyResultPid = pluginRegistry.getPluginId(StepPluginType.class, dummyResultTransMeta);
    StepMeta dummyResultStep = new StepMeta(dummyResultPid, dummyResultStepName, dummyResultTransMeta);
    transMeta.addStep(dummyResultStep);
    String dummyErrorStepName = "dummyErrorStepName";
    DummyTransMeta dummyErrorTransMeta = new DummyTransMeta();
    String dummyErrorPid = pluginRegistry.getPluginId(StepPluginType.class, dummyErrorTransMeta);
    StepMeta dummyErrorStep = new StepMeta(dummyErrorPid, dummyErrorStepName, dummyErrorTransMeta);
    transMeta.addStep(dummyErrorStep);
    StepErrorMeta stepErrorMeta = new StepErrorMeta(transMeta, synchronizeAfterMerge, dummyErrorStep);
    stepErrorMeta.setEnabled(true);
    synchronizeAfterMerge.setStepErrorMeta(stepErrorMeta);
    TransHopMeta injSynch = new TransHopMeta(injectorStep, synchronizeAfterMerge);
    transMeta.addTransHop(injSynch);
    TransHopMeta synchDummyResult = new TransHopMeta(synchronizeAfterMerge, dummyResultStep);
    transMeta.addTransHop(synchDummyResult);
    TransHopMeta synchDummyError = new TransHopMeta(synchronizeAfterMerge, dummyErrorStep);
    transMeta.addTransHop(synchDummyError);
}
Also used : PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) StepErrorMeta(org.pentaho.di.trans.step.StepErrorMeta) PreparedStatement(java.sql.PreparedStatement) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Before(org.junit.Before)

Example 97 with PluginRegistry

use of org.pentaho.di.core.plugins.PluginRegistry in project pentaho-kettle by pentaho.

the class KettleEnvironment method init.

public static void init(List<PluginTypeInterface> pluginClasses, boolean simpleJndi) throws KettleException {
    SettableFuture<Boolean> ready;
    if (initialized.compareAndSet(null, ready = SettableFuture.create())) {
        try {
            // 
            if (!KettleClientEnvironment.isInitialized()) {
                KettleClientEnvironment.init();
            }
            // 
            if (simpleJndi) {
                JndiUtil.initJNDI();
            }
            // Register the native types and the plugins for the various plugin types...
            // 
            pluginClasses.forEach(PluginRegistry::addPluginType);
            PluginRegistry.init();
            // Also read the list of variables.
            // 
            KettleVariablesList.init();
            // Initialize the Lifecycle Listeners
            // 
            initLifecycleListeners();
            ready.set(true);
        } catch (Throwable t) {
            ready.setException(t);
            // If it's a KettleException, throw it, otherwise wrap it in a KettleException
            throw ((t instanceof KettleException) ? (KettleException) t : new KettleException(t));
        }
    } else {
        // A different thread is initializing
        ready = initialized.get();
        // Block until environment is initialized
        try {
            ready.get();
        } catch (Throwable t) {
            throw new KettleException(t);
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry)

Example 98 with PluginRegistry

use of org.pentaho.di.core.plugins.PluginRegistry in project pentaho-kettle by pentaho.

the class StringSearcher method findMetaData.

public static final void findMetaData(Object object, int level, List<StringSearchResult> stringList, Object parentObject, Object grandParentObject) {
    if ((object == null) || level > 5) {
        return;
    }
    PluginRegistry registry = PluginRegistry.getInstance();
    if (stepPluginPackages == null) {
        stepPluginPackages = registry.getPluginPackages(StepPluginType.class);
    }
    if (jobEntryPluginPackages == null) {
        jobEntryPluginPackages = registry.getPluginPackages(JobEntryPluginType.class);
    }
    Class<? extends Object> baseClass = object.getClass();
    Field[] fields = baseClass.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        boolean processThisOne = true;
        if ((field.getModifiers() & Modifier.FINAL) > 0) {
            processThisOne = false;
        }
        if ((field.getModifiers() & Modifier.STATIC) > 0) {
            processThisOne = false;
        }
        // Investigate only if we're dealing with a sanctioned package.
        // A sanctioned package is either the local package (org.pentaho.di) or
        // a package of one of the plugins.
        // 
        boolean sanctionedPackage = false;
        String fieldToString = field.toString();
        if (fieldToString.indexOf(LOCAL_PACKAGE) >= 0) {
            sanctionedPackage = true;
        }
        for (int x = 0; x < JAVA_PACKAGES.length && !sanctionedPackage; x++) {
            if (fieldToString.indexOf(JAVA_PACKAGES[x]) >= 0) {
                sanctionedPackage = true;
            }
        }
        for (int x = 0; x < stepPluginPackages.size() && !sanctionedPackage; x++) {
            if (fieldToString.indexOf(stepPluginPackages.get(x)) >= 0) {
                sanctionedPackage = true;
            }
        }
        for (int x = 0; x < jobEntryPluginPackages.size() && !sanctionedPackage; x++) {
            if (fieldToString.indexOf(jobEntryPluginPackages.get(x)) >= 0) {
                sanctionedPackage = true;
            }
        }
        if (!sanctionedPackage) {
            // Stay in the sanctioned code-base.
            processThisOne = false;
        }
        // 
        if (processThisOne) {
            try {
                Object obj = field.get(object);
                if (obj != null) {
                    stringSearchInObject(obj, level, stringList, parentObject, grandParentObject, field);
                }
            } catch (IllegalAccessException e) {
                // OK, how do we get the value now?
                try {
                    Method method = findMethod(baseClass, field.getName());
                    if (method != null) {
                        // String fullMethod =
                        // baseClass.getName()+"."+method.getName()+"()";
                        Object string = method.invoke(object, (Object[]) null);
                        if (string != null) {
                            stringSearchInObject(string, level, stringList, parentObject, grandParentObject, field);
                        }
                    }
                } catch (Throwable ex) {
                // Ignore this error silently. If we can't access the method there
                // is nothing you can do about it.
                }
            }
        }
    }
}
Also used : Method(java.lang.reflect.Method) JobEntryPluginType(org.pentaho.di.core.plugins.JobEntryPluginType) Field(java.lang.reflect.Field) StepPluginType(org.pentaho.di.core.plugins.StepPluginType) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry)

Example 99 with PluginRegistry

use of org.pentaho.di.core.plugins.PluginRegistry in project pentaho-kettle by pentaho.

the class ImportRules method loadXML.

public void loadXML(Node rulesNode) throws KettleException {
    List<Node> ruleNodes = XMLHandler.getNodes(rulesNode, BaseImportRule.XML_TAG);
    for (Node ruleNode : ruleNodes) {
        String id = XMLHandler.getTagValue(ruleNode, "id");
        PluginRegistry registry = PluginRegistry.getInstance();
        PluginInterface plugin = registry.findPluginWithId(ImportRulePluginType.class, id);
        if (plugin == null) {
            throw new KettleException("The import rule of type '" + id + "' could not be found in the plugin registry.");
        }
        ImportRuleInterface rule = (ImportRuleInterface) registry.loadClass(plugin);
        rule.loadXML(ruleNode);
        getRules().add(rule);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ImportRuleInterface(org.pentaho.di.imp.rule.ImportRuleInterface) Node(org.w3c.dom.Node) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface)

Example 100 with PluginRegistry

use of org.pentaho.di.core.plugins.PluginRegistry in project pentaho-kettle by pentaho.

the class MonetDBBulkLoaderMetaTest method setUp.

@Before
public void setUp() throws Exception {
    KettleEnvironment.init();
    PluginRegistry.init(false);
    TransMeta transMeta = new TransMeta();
    transMeta.setName("loader");
    lm = new MonetDBBulkLoaderMeta();
    ld = new MonetDBBulkLoaderData();
    PluginRegistry plugReg = PluginRegistry.getInstance();
    String loaderPid = plugReg.getPluginId(StepPluginType.class, lm);
    stepMeta = new StepMeta(loaderPid, "loader", lm);
    Trans trans = new Trans(transMeta);
    transMeta.addStep(stepMeta);
    loader = new MonetDBBulkLoader(stepMeta, ld, 1, transMeta, trans);
    List<String> attributes = Arrays.asList("dbConnectionName", "schemaName", "tableName", "logFile", "fieldSeparator", "fieldEnclosure", "NULLrepresentation", "encoding", "truncate", "fullyQuoteSQL", "fieldTable", "fieldStream", "fieldFormatOk");
    // Important note - the "databaseMeta" is not tested here as it's tied to the dbConnectionName. Since the loader
    // has assymetry here, we have to not test the databaseMeta, or we have to do surgery on the MonetDBBulkLoaderMeta
    // so that it's symmetric (and has no dependent variables like this).
    // MB -5/2016
    // Note - autoSchema is not persisted and neither is autoStringWidths. (Old functionality).
    FieldLoadSaveValidator<String[]> stringArrayLoadSaveValidator = new ArrayLoadSaveValidator<String>(new StringLoadSaveValidator(), 5);
    Map<String, FieldLoadSaveValidator<?>> attrValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
    attrValidatorMap.put("fieldTable", stringArrayLoadSaveValidator);
    attrValidatorMap.put("fieldStream", stringArrayLoadSaveValidator);
    attrValidatorMap.put("fieldFormatOk", new PrimitiveBooleanArrayLoadSaveValidator(new BooleanLoadSaveValidator(), 5));
    Map<String, FieldLoadSaveValidator<?>> typeValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
    loadSaveTester = new LoadSaveTester(testMetaClass, attributes, new ArrayList<String>(), new ArrayList<String>(), new HashMap<String, String>(), new HashMap<String, String>(), attrValidatorMap, typeValidatorMap, this);
}
Also used : ArrayLoadSaveValidator(org.pentaho.di.trans.steps.loadsave.validator.ArrayLoadSaveValidator) PrimitiveBooleanArrayLoadSaveValidator(org.pentaho.di.trans.steps.loadsave.validator.PrimitiveBooleanArrayLoadSaveValidator) HashMap(java.util.HashMap) LoadSaveTester(org.pentaho.di.trans.steps.loadsave.LoadSaveTester) FieldLoadSaveValidator(org.pentaho.di.trans.steps.loadsave.validator.FieldLoadSaveValidator) TransMeta(org.pentaho.di.trans.TransMeta) ArrayList(java.util.ArrayList) PrimitiveBooleanArrayLoadSaveValidator(org.pentaho.di.trans.steps.loadsave.validator.PrimitiveBooleanArrayLoadSaveValidator) StepMeta(org.pentaho.di.trans.step.StepMeta) BooleanLoadSaveValidator(org.pentaho.di.trans.steps.loadsave.validator.BooleanLoadSaveValidator) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) Trans(org.pentaho.di.trans.Trans) StringLoadSaveValidator(org.pentaho.di.trans.steps.loadsave.validator.StringLoadSaveValidator) Before(org.junit.Before)

Aggregations

PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)154 StepMeta (org.pentaho.di.trans.step.StepMeta)103 TransMeta (org.pentaho.di.trans.TransMeta)101 Trans (org.pentaho.di.trans.Trans)82 TransHopMeta (org.pentaho.di.trans.TransHopMeta)77 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)74 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)71 StepInterface (org.pentaho.di.trans.step.StepInterface)69 RowStepCollector (org.pentaho.di.trans.RowStepCollector)67 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)54 InjectorMeta (org.pentaho.di.trans.steps.injector.InjectorMeta)52 RowProducer (org.pentaho.di.trans.RowProducer)47 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)46 Test (org.junit.Test)33 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)26 KettleException (org.pentaho.di.core.exception.KettleException)26 ArrayList (java.util.ArrayList)14 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)13 Before (org.junit.Before)11 HashMap (java.util.HashMap)7