Search in sources :

Example 56 with LongObjectId

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

the class KettleDatabaseRepositoryMetaStore method deleteElement.

@Override
public void deleteElement(String namespace, IMetaStoreElementType elementType, String elementId) throws MetaStoreException {
    try {
        IMetaStoreElementType type = getElementTypeByName(namespace, elementType.getName());
        if (type == null) {
            throw new MetaStoreException("Unable to find element type with name '" + elementType.getName() + "'");
        }
        delegate.deleteElement(new LongObjectId(new StringObjectId(elementId)));
        repository.commit();
    } catch (Exception e) {
        repository.rollback();
        throw new MetaStoreException("Unable to delete element with id '" + elementId + "' of type '" + elementType.getName() + "'", e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) LongObjectId(org.pentaho.di.repository.LongObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) 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 57 with LongObjectId

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

the class KettleDatabaseRepositoryMetaStore method getElementTypes.

@Override
public List<IMetaStoreElementType> getElementTypes(String namespace) throws MetaStoreException {
    try {
        LongObjectId namespaceId = delegate.getNamespaceId(namespace);
        if (namespaceId == null) {
            return new ArrayList<IMetaStoreElementType>();
        }
        Collection<RowMetaAndData> elementTypeRows = delegate.getElementTypes(namespaceId);
        List<IMetaStoreElementType> list = new ArrayList<IMetaStoreElementType>();
        for (RowMetaAndData elementTypeRow : elementTypeRows) {
            KDBRMetaStoreElementType elementType = delegate.parseElementType(namespace, namespaceId, elementTypeRow);
            list.add(elementType);
        }
        return list;
    } catch (Exception e) {
        throw new MetaStoreException("Unable to get list of element types for namespace '" + namespace + "'", e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ArrayList(java.util.ArrayList) 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 58 with LongObjectId

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

the class KettleDatabaseRepositoryConnectionDelegate method getIDWithValue.

public synchronized LongObjectId getIDWithValue(String tablename, String idfield, String lookupfield, String value, String[] lookupkey, ObjectId[] key) throws KettleException {
    RowMetaAndData par = new RowMetaAndData();
    par.addValue(new ValueMetaString(lookupfield), value);
    String sql = "SELECT " + idfield + " FROM " + tablename + " WHERE " + lookupfield + " = ? ";
    for (int i = 0; i < lookupkey.length; i++) {
        par.addValue(new ValueMetaInteger(lookupkey[i]), new LongObjectId(key[i]));
        sql += "AND " + lookupkey[i] + " = ? ";
    }
    RowMetaAndData result = getOneRow(sql, par.getRowMeta(), par.getData());
    if (result != null && result.getRowMeta() != null && result.getData() != null && result.isNumeric(0)) {
        return new LongObjectId(result.getInteger(0, 0));
    }
    return null;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LongObjectId(org.pentaho.di.repository.LongObjectId)

Example 59 with LongObjectId

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

the class KettleDatabaseRepositoryConnectionDelegate method getNextID.

public synchronized LongObjectId getNextID(String tableName, String fieldName) throws KettleException {
    String counterName = tableName + "." + fieldName;
    Counter counter = Counters.getInstance().getCounter(counterName);
    if (counter == null) {
        LongObjectId id = getNextTableID(tableName, fieldName);
        counter = new Counter(id.longValue());
        Counters.getInstance().setCounter(counterName, counter);
        return new LongObjectId(counter.next());
    } else {
        return new LongObjectId(counter.next());
    }
}
Also used : Counter(org.pentaho.di.core.Counter) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LongObjectId(org.pentaho.di.repository.LongObjectId)

Example 60 with LongObjectId

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

the class KettleDatabaseRepositoryConnectionDelegate method getRepositoryObjects.

/**
 * @param id_directory
 * @return A list of RepositoryObjects
 *
 * @throws KettleException
 */
public synchronized List<RepositoryElementMetaInterface> getRepositoryObjects(String tableName, RepositoryObjectType objectType, ObjectId id_directory) throws KettleException {
    try {
        String idField;
        if (RepositoryObjectType.TRANSFORMATION.equals(objectType)) {
            idField = KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_TRANSFORMATION;
        } else {
            idField = KettleDatabaseRepository.FIELD_JOB_ID_JOB;
        }
        if (id_directory == null) {
            // root!
            id_directory = new LongObjectId(0L);
        }
        RepositoryDirectoryInterface repositoryDirectory = repository.directoryDelegate.loadPathToRoot(id_directory);
        // RepositoryDirectoryInterface repositoryDirectory =
        // repository.loadRepositoryDirectoryTree().findDirectory(id_directory);
        String sql = "SELECT " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_NAME) + ", " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_MODIFIED_USER) + ", " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_MODIFIED_DATE) + ", " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_DESCRIPTION) + ", " + quote(idField) + " " + "FROM " + tableName + " " + "WHERE " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_DIRECTORY) + " = ? ";
        RowMetaAndData directoryIdRow = getParameterMetaData(id_directory);
        return callRead(new Callable<List<RepositoryElementMetaInterface>>() {

            @Override
            public List<RepositoryElementMetaInterface> call() throws Exception {
                List<RepositoryElementMetaInterface> repositoryObjects = new ArrayList<RepositoryElementMetaInterface>();
                ResultSet rs = database.openQuery(sql, directoryIdRow.getRowMeta(), directoryIdRow.getData());
                if (rs != null) {
                    List<Object[]> rows = database.getRows(rs, -1, null);
                    if (rs != null) {
                        database.closeQuery(rs);
                    }
                    RowMetaInterface rowMeta = database.getReturnRowMeta();
                    for (Object[] r : rows) {
                        ObjectId id = new LongObjectId(rowMeta.getInteger(r, 4));
                        repositoryObjects.add(new RepositoryObject(id, rowMeta.getString(r, 0), repositoryDirectory, rowMeta.getString(r, 1), rowMeta.getDate(r, 2), objectType, rowMeta.getString(r, 3), false));
                    }
                }
                return repositoryObjects;
            }
        });
    } catch (Exception e) {
        throw new KettleException("Unable to get list of repository objects", e);
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObject(org.pentaho.di.repository.RepositoryObject) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LongObjectId(org.pentaho.di.repository.LongObjectId) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) SQLException(java.sql.SQLException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) RepositoryObject(org.pentaho.di.repository.RepositoryObject) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

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