Search in sources :

Example 51 with LongObjectId

use of org.pentaho.di.repository.LongObjectId in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryCreationHelper method updateStepTypes.

/**
 * Update the list in R_STEP_TYPE using the StepLoader StepPlugin entries
 *
 * @throws KettleException
 *           if the update didn't go as planned.
 */
public List<String> updateStepTypes(List<String> statements, boolean dryrun, boolean create) throws KettleException {
    synchronized (repository) {
        // We should only do an update if something has changed...
        // 
        List<PluginInterface> plugins = pluginRegistry.getPlugins(StepPluginType.class);
        ObjectId[] ids = loadPluginsIds(plugins, create);
        for (int i = 0, idsLength = ids.length; i < idsLength; i++) {
            ObjectId id = ids[i];
            if (id == null) {
                if (!create) {
                    id = repository.connectionDelegate.getNextStepTypeID();
                } else {
                    id = new LongObjectId(i + 1);
                }
                PluginInterface sp = plugins.get(i);
                RowMetaAndData table = new RowMetaAndData();
                table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_STEP_TYPE_ID_STEP_TYPE), id);
                table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_STEP_TYPE_CODE), sp.getIds()[0]);
                table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_STEP_TYPE_DESCRIPTION), sp.getName());
                table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_STEP_TYPE_HELPTEXT), sp.getDescription());
                if (dryrun) {
                    String sql = database.getSQLOutput(null, KettleDatabaseRepository.TABLE_R_STEP_TYPE, table.getRowMeta(), table.getData(), null);
                    statements.add(sql);
                } else {
                    database.prepareInsert(table.getRowMeta(), null, KettleDatabaseRepository.TABLE_R_STEP_TYPE);
                    database.setValuesInsert(table);
                    database.insertRow();
                    database.closeInsert();
                }
            }
        }
    }
    return statements;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) LongObjectId(org.pentaho.di.repository.LongObjectId) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString)

Example 52 with LongObjectId

use of org.pentaho.di.repository.LongObjectId in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryTransDelegate method loadRepTrans.

/**
 * Load the transformation name & other details from a repository.
 *
 * @param rep
 *          The repository to load the details from.
 */
private void loadRepTrans(TransMeta transMeta) throws KettleException {
    try {
        RowMetaAndData r = getTransformation(transMeta.getObjectId());
        if (r != null) {
            transMeta.setName(r.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_NAME, null));
            // Trans description
            transMeta.setDescription(r.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_DESCRIPTION, null));
            transMeta.setExtendedDescription(r.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_EXTENDED_DESCRIPTION, null));
            transMeta.setTransversion(r.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_TRANS_VERSION, null));
            transMeta.setTransstatus((int) r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_TRANS_STATUS, -1L));
            TransLogTable logTable = transMeta.getTransLogTable();
            logTable.findField(TransLogTable.ID.LINES_READ).setSubject(StepMeta.findStep(transMeta.getSteps(), new LongObjectId(r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_STEP_READ, -1L))));
            logTable.findField(TransLogTable.ID.LINES_READ).setSubject(StepMeta.findStep(transMeta.getSteps(), new LongObjectId(r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_STEP_WRITE, -1L))));
            logTable.findField(TransLogTable.ID.LINES_READ).setSubject(StepMeta.findStep(transMeta.getSteps(), new LongObjectId(r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_STEP_INPUT, -1L))));
            logTable.findField(TransLogTable.ID.LINES_READ).setSubject(StepMeta.findStep(transMeta.getSteps(), new LongObjectId(r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_STEP_OUTPUT, -1L))));
            logTable.findField(TransLogTable.ID.LINES_READ).setSubject(StepMeta.findStep(transMeta.getSteps(), new LongObjectId(r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_STEP_UPDATE, -1L))));
            long id_rejected = getTransAttributeInteger(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_ID_STEP_REJECTED);
            if (id_rejected > 0) {
                logTable.findField(TransLogTable.ID.LINES_REJECTED).setSubject(StepMeta.findStep(transMeta.getSteps(), new LongObjectId(id_rejected)));
            }
            DatabaseMeta logDb = DatabaseMeta.findDatabase(transMeta.getDatabases(), new LongObjectId(r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_DATABASE_LOG, -1L)));
            if (logDb != null) {
                logTable.setConnectionName(logDb.getName());
            // TODO: save/load name as a string, allow variables!
            }
            logTable.setTableName(r.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_TABLE_NAME_LOG, null));
            logTable.setBatchIdUsed(r.getBoolean(KettleDatabaseRepository.FIELD_TRANSFORMATION_USE_BATCHID, false));
            logTable.setLogFieldUsed(r.getBoolean(KettleDatabaseRepository.FIELD_TRANSFORMATION_USE_LOGFIELD, false));
            transMeta.setMaxDateConnection(DatabaseMeta.findDatabase(transMeta.getDatabases(), new LongObjectId(r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_DATABASE_MAXDATE, -1L))));
            transMeta.setMaxDateTable(r.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_TABLE_NAME_MAXDATE, null));
            transMeta.setMaxDateField(r.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_FIELD_NAME_MAXDATE, null));
            transMeta.setMaxDateOffset(r.getNumber(KettleDatabaseRepository.FIELD_TRANSFORMATION_OFFSET_MAXDATE, 0.0));
            transMeta.setMaxDateDifference(r.getNumber(KettleDatabaseRepository.FIELD_TRANSFORMATION_DIFF_MAXDATE, 0.0));
            transMeta.setCreatedUser(r.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_CREATED_USER, null));
            transMeta.setCreatedDate(r.getDate(KettleDatabaseRepository.FIELD_TRANSFORMATION_CREATED_DATE, null));
            transMeta.setModifiedUser(r.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_MODIFIED_USER, null));
            transMeta.setModifiedDate(r.getDate(KettleDatabaseRepository.FIELD_TRANSFORMATION_MODIFIED_DATE, null));
            // Optional:
            transMeta.setSizeRowset(Const.ROWS_IN_ROWSET);
            Long val_size_rowset = r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_SIZE_ROWSET);
            if (val_size_rowset != null) {
                transMeta.setSizeRowset(val_size_rowset.intValue());
            }
            long id_directory = r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_DIRECTORY, -1L);
            if (id_directory >= 0) {
                if (log.isDetailed()) {
                    log.logDetailed("ID_DIRECTORY=" + id_directory);
                }
                // always reload the folder structure
                // 
                transMeta.setRepositoryDirectory(repository.loadRepositoryDirectoryTree().findDirectory(new LongObjectId(id_directory)));
            }
            transMeta.setUsingUniqueConnections(getTransAttributeBoolean(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_UNIQUE_CONNECTIONS));
            transMeta.setFeedbackShown(!"N".equalsIgnoreCase(getTransAttributeString(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_FEEDBACK_SHOWN)));
            transMeta.setFeedbackSize((int) getTransAttributeInteger(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_FEEDBACK_SIZE));
            transMeta.setUsingThreadPriorityManagment(!"N".equalsIgnoreCase(getTransAttributeString(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_USING_THREAD_PRIORITIES)));
            // Performance monitoring for steps...
            // 
            transMeta.setCapturingStepPerformanceSnapShots(getTransAttributeBoolean(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_CAPTURE_STEP_PERFORMANCE));
            transMeta.setStepPerformanceCapturingDelay(getTransAttributeInteger(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_STEP_PERFORMANCE_CAPTURING_DELAY));
            transMeta.setStepPerformanceCapturingSizeLimit(getTransAttributeString(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_STEP_PERFORMANCE_CAPTURING_SIZE_LIMIT));
            transMeta.getPerformanceLogTable().setTableName(getTransAttributeString(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_STEP_PERFORMANCE_LOG_TABLE));
            transMeta.getTransLogTable().setLogSizeLimit(getTransAttributeString(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_LOG_SIZE_LIMIT));
            transMeta.getTransLogTable().setLogInterval(getTransAttributeString(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_LOG_INTERVAL));
            transMeta.setTransformationType(TransformationType.getTransformationTypeByCode(getTransAttributeString(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_TRANSFORMATION_TYPE)));
            transMeta.setSleepTimeEmpty((int) getTransAttributeInteger(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_SLEEP_TIME_EMPTY));
            transMeta.setSleepTimeFull((int) getTransAttributeInteger(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_SLEEP_TIME_FULL));
            loadRepParameters(transMeta);
        }
    } catch (KettleDatabaseException dbe) {
        throw new KettleException(BaseMessages.getString(PKG, "TransMeta.Exception.UnableToLoadTransformationInfoFromRepository"), dbe);
    } finally {
        transMeta.initializeVariablesFrom(null);
        transMeta.setInternalKettleVariables();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) TransLogTable(org.pentaho.di.core.logging.TransLogTable) LongObjectId(org.pentaho.di.repository.LongObjectId) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Example 53 with LongObjectId

use of org.pentaho.di.repository.LongObjectId in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryTransDelegate method getTransformationsWithIDList.

public String[] getTransformationsWithIDList(List<Object[]> list, RowMetaInterface rowMeta) throws KettleException {
    String[] transList = new String[list.size()];
    for (int i = 0; i < list.size(); i++) {
        long id_transformation = rowMeta.getInteger(list.get(i), quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_TRANSFORMATION), -1L);
        if (id_transformation > 0) {
            RowMetaAndData transRow = getTransformation(new LongObjectId(id_transformation));
            if (transRow != null) {
                String transName = transRow.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_NAME, "<name not found>");
                long id_directory = transRow.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_DIRECTORY, -1L);
                RepositoryDirectoryInterface dir = repository.loadRepositoryDirectoryTree().findDirectory(new LongObjectId(id_directory));
                transList[i] = dir.getPathObjectCombination(transName);
            }
        }
    }
    return transList;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LongObjectId(org.pentaho.di.repository.LongObjectId)

Example 54 with LongObjectId

use of org.pentaho.di.repository.LongObjectId in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryMetaStore method getElementTypeByName.

@Override
public IMetaStoreElementType getElementTypeByName(String namespace, String elementTypeName) throws MetaStoreException {
    try {
        LongObjectId namespaceId = delegate.getNamespaceId(namespace);
        if (namespaceId == null) {
            return null;
        }
        LongObjectId elementTypeId = delegate.getElementTypeId(namespaceId, elementTypeName);
        if (elementTypeId == null) {
            return null;
        }
        RowMetaAndData elementTypeRow = delegate.getElementType(elementTypeId);
        return delegate.parseElementType(namespace, namespaceId, elementTypeRow);
    } catch (Exception e) {
        throw new MetaStoreException("Unable to get element type with name '" + elementTypeName + "' in namespace '" + namespace + "'", e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LongObjectId(org.pentaho.di.repository.LongObjectId) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException) MetaStoreElementExistException(org.pentaho.metastore.api.exceptions.MetaStoreElementExistException) MetaStoreElementTypeExistsException(org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)

Example 55 with LongObjectId

use of org.pentaho.di.repository.LongObjectId in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryMetaStore method deleteElementType.

@Override
public void deleteElementType(String namespace, IMetaStoreElementType elementType) throws MetaStoreException, MetaStoreDependenciesExistsException {
    try {
        Collection<RowMetaAndData> elementTypeRows = delegate.getElements(new LongObjectId(new StringObjectId(elementType.getId())));
        if (!elementTypeRows.isEmpty()) {
            List<String> dependencies = new ArrayList<String>();
            for (RowMetaAndData elementTypeRow : elementTypeRows) {
                Long elementTypeId = elementTypeRow.getInteger(KettleDatabaseRepository.FIELD_ELEMENT_TYPE_ID_ELEMENT_TYPE);
                dependencies.add(Long.toString(elementTypeId));
            }
            throw new MetaStoreDependenciesExistsException(dependencies, "The namespace to delete, '" + namespace + "' is not empty");
        }
        delegate.deleteElementType(new LongObjectId(new StringObjectId(elementType.getId())));
        repository.commit();
    } catch (MetaStoreDependenciesExistsException e) {
        throw e;
    } catch (Exception e) {
        repository.rollback();
        throw new MetaStoreException(e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ArrayList(java.util.ArrayList) LongObjectId(org.pentaho.di.repository.LongObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException) MetaStoreElementExistException(org.pentaho.metastore.api.exceptions.MetaStoreElementExistException) MetaStoreElementTypeExistsException(org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)

Aggregations

LongObjectId (org.pentaho.di.repository.LongObjectId)81 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)54 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)36 ObjectId (org.pentaho.di.repository.ObjectId)30 KettleException (org.pentaho.di.core.exception.KettleException)18 Test (org.junit.Test)17 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)17 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)14 Matchers.anyString (org.mockito.Matchers.anyString)10 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)10 ArrayList (java.util.ArrayList)9 RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)9 RepositoryObject (org.pentaho.di.repository.RepositoryObject)8 MetaStoreDependenciesExistsException (org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)8 MetaStoreElementExistException (org.pentaho.metastore.api.exceptions.MetaStoreElementExistException)8 MetaStoreElementTypeExistsException (org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)8 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)8 SimpleLoggingObject (org.pentaho.di.core.logging.SimpleLoggingObject)7 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)7 StringObjectId (org.pentaho.di.repository.StringObjectId)7