Search in sources :

Example 66 with LongObjectId

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

the class KettleDatabaseRepositoryDatabaseDelegate method loadDatabaseMeta.

/**
 * Load the Database Info
 */
public DatabaseMeta loadDatabaseMeta(ObjectId id_database) throws KettleException {
    DatabaseMeta databaseMeta = new DatabaseMeta();
    try {
        RowMetaAndData r = getDatabase(id_database);
        if (r != null) {
            ObjectId id_database_type = // con_type
            new LongObjectId(r.getInteger(KettleDatabaseRepository.FIELD_DATABASE_ID_DATABASE_TYPE, 0));
            String dbTypeDesc = getDatabaseTypeCode(id_database_type);
            if (dbTypeDesc != null) {
                databaseMeta.setDatabaseInterface(DatabaseMeta.getDatabaseInterface(dbTypeDesc));
                // new attributes
                databaseMeta.setAttributes(new Properties());
            }
            databaseMeta.setObjectId(id_database);
            databaseMeta.setName(r.getString(KettleDatabaseRepository.FIELD_DATABASE_NAME, ""));
            ObjectId id_database_contype = new LongObjectId(// con_access
            r.getInteger(KettleDatabaseRepository.FIELD_DATABASE_ID_DATABASE_CONTYPE, 0));
            databaseMeta.setAccessType(DatabaseMeta.getAccessType(getDatabaseConTypeCode(id_database_contype)));
            databaseMeta.setHostname(r.getString(KettleDatabaseRepository.FIELD_DATABASE_HOST_NAME, ""));
            databaseMeta.setDBName(r.getString(KettleDatabaseRepository.FIELD_DATABASE_DATABASE_NAME, ""));
            databaseMeta.setDBPort(r.getString(KettleDatabaseRepository.FIELD_DATABASE_PORT, ""));
            databaseMeta.setUsername(r.getString(KettleDatabaseRepository.FIELD_DATABASE_USERNAME, ""));
            databaseMeta.setPassword(Encr.decryptPasswordOptionallyEncrypted(r.getString(KettleDatabaseRepository.FIELD_DATABASE_PASSWORD, "")));
            databaseMeta.setServername(r.getString(KettleDatabaseRepository.FIELD_DATABASE_SERVERNAME, ""));
            databaseMeta.setDataTablespace(r.getString(KettleDatabaseRepository.FIELD_DATABASE_DATA_TBS, ""));
            databaseMeta.setIndexTablespace(r.getString(KettleDatabaseRepository.FIELD_DATABASE_INDEX_TBS, ""));
            // Also, load all the properties we can find...
            final Collection<RowMetaAndData> attrs = repository.connectionDelegate.getDatabaseAttributes(id_database);
            for (RowMetaAndData row : attrs) {
                String code = row.getString(KettleDatabaseRepository.FIELD_DATABASE_ATTRIBUTE_CODE, "");
                String attribute = row.getString(KettleDatabaseRepository.FIELD_DATABASE_ATTRIBUTE_VALUE_STR, "");
                databaseMeta.getAttributes().put(code, Const.NVL(attribute, ""));
            }
        }
        return databaseMeta;
    } catch (KettleDatabaseException dbe) {
        throw new KettleException("Error loading database connection from repository (id_database=" + id_database + ")", dbe);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) LongObjectId(org.pentaho.di.repository.LongObjectId) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Properties(java.util.Properties) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Example 67 with LongObjectId

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

the class KettleDatabaseRepositoryJobEntryDelegate method loadJobEntryBase.

public void loadJobEntryBase(JobEntryBase jobEntryBase, ObjectId id_jobentry, List<DatabaseMeta> databases, List<SlaveServer> slaveServers) throws KettleException {
    try {
        RowMetaAndData r = getJobEntry(id_jobentry);
        if (r != null) {
            jobEntryBase.setName(r.getString("NAME", null));
            jobEntryBase.setDescription(r.getString("DESCRIPTION", null));
            long id_jobentry_type = r.getInteger("ID_JOBENTRY_TYPE", 0);
            RowMetaAndData jetrow = getJobEntryType(new LongObjectId(id_jobentry_type));
            if (jetrow != null) {
                jobEntryBase.setPluginId(jetrow.getString("CODE", null));
            }
        }
    } catch (KettleDatabaseException dbe) {
        throw new KettleException("Unable to load base job entry information from the repository for id_jobentry=" + id_jobentry, dbe);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) LongObjectId(org.pentaho.di.repository.LongObjectId)

Example 68 with LongObjectId

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

the class KettleDatabaseRepositoryMetaStoreDelegate method insertElementType.

public ObjectId insertElementType(KDBRMetaStoreElementType type) throws KettleException {
    ObjectId idType = repository.connectionDelegate.getNextID(quoteTable(KettleDatabaseRepository.TABLE_R_ELEMENT_TYPE), quote(KettleDatabaseRepository.FIELD_ELEMENT_TYPE_ID_ELEMENT_TYPE));
    RowMetaAndData table = new RowMetaAndData();
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_ELEMENT_TYPE_ID_ELEMENT_TYPE), idType);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_ELEMENT_TYPE_ID_NAMESPACE), type.getNamespaceId());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_ELEMENT_TYPE_NAME), type.getName());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_ELEMENT_TYPE_DESCRIPTION), type.getDescription());
    repository.connectionDelegate.getDatabase().prepareInsert(table.getRowMeta(), KettleDatabaseRepository.TABLE_R_ELEMENT_TYPE);
    repository.connectionDelegate.getDatabase().setValuesInsert(table);
    repository.connectionDelegate.getDatabase().insertRow();
    repository.connectionDelegate.getDatabase().closeInsert();
    type.setId(new LongObjectId(idType));
    if (log.isDebug()) {
        log.logDebug("Saved element type [" + type.getName() + "]");
    }
    return idType;
}
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) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) LongObjectId(org.pentaho.di.repository.LongObjectId)

Example 69 with LongObjectId

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

the class KettleDatabaseRepositoryMetaStoreDelegate method insertElement.

public ObjectId insertElement(IMetaStoreElementType elementType, IMetaStoreElement element) throws MetaStoreException {
    try {
        LongObjectId elementId = repository.connectionDelegate.getNextID(quoteTable(KettleDatabaseRepository.TABLE_R_ELEMENT), quote(KettleDatabaseRepository.FIELD_ELEMENT_ID_ELEMENT));
        RowMetaAndData table = new RowMetaAndData();
        table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_ELEMENT_ID_ELEMENT), elementId.longValue());
        table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_ELEMENT_ID_ELEMENT_TYPE), Long.valueOf(elementType.getId()));
        table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_ELEMENT_NAME), element.getName());
        repository.connectionDelegate.getDatabase().prepareInsert(table.getRowMeta(), KettleDatabaseRepository.TABLE_R_ELEMENT);
        repository.connectionDelegate.getDatabase().setValuesInsert(table);
        repository.connectionDelegate.getDatabase().insertRow();
        repository.connectionDelegate.getDatabase().closeInsert();
        element.setId(elementId.toString());
        // Now save the attributes
        // 
        insertAttributes(element.getChildren(), elementId, new LongObjectId(0L));
        if (log.isDebug()) {
            log.logDebug("Saved element with name [" + element.getName() + "]");
        }
        return elementId;
    } catch (Exception e) {
        throw new MetaStoreException("Unable to create new element with name '" + element.getName() + "'", e);
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) LongObjectId(org.pentaho.di.repository.LongObjectId) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettleValueException(org.pentaho.di.core.exception.KettleValueException)

Example 70 with LongObjectId

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

the class KettleDatabaseRepositoryMetaStoreDelegate method insertAttributes.

private void insertAttributes(List<IMetaStoreAttribute> children, LongObjectId elementId, LongObjectId parentAttributeId) throws Exception {
    for (IMetaStoreAttribute child : children) {
        LongObjectId attributeId = repository.connectionDelegate.getNextID(quoteTable(KettleDatabaseRepository.TABLE_R_ELEMENT_ATTRIBUTE), quote(KettleDatabaseRepository.FIELD_ELEMENT_ATTRIBUTE_ID_ELEMENT_ATTRIBUTE));
        RowMetaAndData table = new RowMetaAndData();
        table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_ELEMENT_ATTRIBUTE_ID_ELEMENT_ATTRIBUTE), attributeId.longValue());
        table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_ELEMENT_ATTRIBUTE_ID_ELEMENT), elementId.longValue());
        table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_ELEMENT_ATTRIBUTE_ID_ELEMENT_ATTRIBUTE_PARENT), parentAttributeId.longValue());
        table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_ELEMENT_ATTRIBUTE_KEY), child.getId());
        table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_ELEMENT_ATTRIBUTE_VALUE), encodeAttributeValue(child.getValue()));
        repository.connectionDelegate.getDatabase().prepareInsert(table.getRowMeta(), KettleDatabaseRepository.TABLE_R_ELEMENT_ATTRIBUTE);
        repository.connectionDelegate.getDatabase().setValuesInsert(table);
        repository.connectionDelegate.getDatabase().insertRow();
        repository.connectionDelegate.getDatabase().closeInsert();
        child.setId(attributeId.toString());
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) LongObjectId(org.pentaho.di.repository.LongObjectId)

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