Search in sources :

Example 16 with ObjectId

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

the class KettleDatabaseRepositoryClusterSchemaDelegate method saveClusterSchema.

public void saveClusterSchema(ClusterSchema clusterSchema, String versionComment, ObjectId id_transformation, boolean isUsedByTransformation, boolean overwrite) throws KettleException {
    ObjectId existingClusterSchemaId = getClusterID(clusterSchema.getName());
    if (existingClusterSchemaId != null) {
        clusterSchema.setObjectId(existingClusterSchemaId);
    }
    if (clusterSchema.getObjectId() == null) {
        // New Slave Server
        clusterSchema.setObjectId(insertCluster(clusterSchema));
    } else {
        // If we received a clusterSchemaId and it is different from the cluster schema we are working with...
        if (existingClusterSchemaId != null && !clusterSchema.getObjectId().equals(existingClusterSchemaId)) {
            // A cluster with this name already exists
            if (overwrite) {
                // Proceed with save, removing the original version from the repository first
                repository.deleteClusterSchema(existingClusterSchemaId);
                updateCluster(clusterSchema);
            } else {
                throw new KettleObjectExistsException("Failed to save object to repository. Object [" + clusterSchema.getName() + "] already exists.");
            }
        } else {
            // There are no naming collisions (either it is the same object or the name is unique)
            updateCluster(clusterSchema);
        }
    }
    repository.delClusterSlaves(clusterSchema.getObjectId());
    // Also save the used slave server references.
    for (int i = 0; i < clusterSchema.getSlaveServers().size(); i++) {
        SlaveServer slaveServer = clusterSchema.getSlaveServers().get(i);
        if (slaveServer.getObjectId() == null) {
            // oops, not yet saved!
            repository.save(slaveServer, versionComment, null, id_transformation, isUsedByTransformation, overwrite);
        }
        repository.insertClusterSlave(clusterSchema, slaveServer);
    }
    // Only save it if it's really used by the transformation
    if (isUsedByTransformation) {
        repository.insertTransformationCluster(id_transformation, clusterSchema.getObjectId());
    }
}
Also used : ObjectId(org.pentaho.di.repository.ObjectId) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException) SlaveServer(org.pentaho.di.cluster.SlaveServer)

Example 17 with ObjectId

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

the class KettleDatabaseRepositoryConnectionDelegate method insertJobAttribute.

public synchronized ObjectId insertJobAttribute(ObjectId id_job, long nr, String code, long value_num, String value_str) throws KettleException {
    ObjectId id = getNextJobAttributeID();
    // System.out.println("Insert job attribute : id_job="+id_job+", code="+code+", value_str="+value_str);
    RowMetaAndData table = new RowMetaAndData();
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_ID_JOB_ATTRIBUTE), id);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_ID_JOB), id_job);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_NR), new Long(nr));
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_CODE), code);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_VALUE_NUM), new Long(value_num));
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_VALUE_STR), value_str);
    if (psJobAttributesInsert == null) {
        String sql = database.getInsertStatement(KettleDatabaseRepository.TABLE_R_JOB_ATTRIBUTE, table.getRowMeta());
        psJobAttributesInsert = database.prepareSQL(sql);
    }
    database.setValues(table, psJobAttributesInsert);
    database.insertRow(psJobAttributesInsert, useBatchProcessing);
    if (log.isDebug()) {
        log.logDebug("saved job attribute [" + code + "]");
    }
    return id;
}
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) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString)

Example 18 with ObjectId

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

the class KettleDatabaseRepositoryConnectionDelegate method insertJobEntryAttribute.

public synchronized ObjectId insertJobEntryAttribute(ObjectId id_job, ObjectId id_jobentry, long nr, String code, double value_num, String value_str) throws KettleException {
    ObjectId id = getNextJobEntryAttributeID();
    RowMetaAndData table = new RowMetaAndData();
    // CHECKSTYLE:LineLength:OFF
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOBENTRY_ATTRIBUTE), id);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOB), id_job);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOBENTRY), id_jobentry);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_NR), new Long(nr));
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_CODE), code);
    table.addValue(new ValueMetaNumber(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_VALUE_NUM), new Double(value_num));
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_VALUE_STR), value_str);
    database.prepareInsert(table.getRowMeta(), KettleDatabaseRepository.TABLE_R_JOBENTRY_ATTRIBUTE);
    database.setValuesInsert(table);
    database.insertRow();
    database.closeInsert();
    return id;
}
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) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger)

Example 19 with ObjectId

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

the class KettleDatabaseRepositoryDatabaseDelegate method insertDatabase.

public synchronized ObjectId insertDatabase(String name, String type, String access, String host, String dbname, String port, String user, String pass, String servername, String data_tablespace, String index_tablespace) throws KettleException {
    ObjectId id = repository.connectionDelegate.getNextDatabaseID();
    ObjectId id_database_type = getDatabaseTypeID(type);
    if (id_database_type == null) {
        // New support database type: add it!
        id_database_type = repository.connectionDelegate.getNextDatabaseTypeID();
        String tablename = KettleDatabaseRepository.TABLE_R_DATABASE_TYPE;
        RowMetaInterface tableMeta = new RowMeta();
        tableMeta.addValueMeta(new ValueMetaInteger(KettleDatabaseRepository.FIELD_DATABASE_TYPE_ID_DATABASE_TYPE, 5, 0));
        tableMeta.addValueMeta(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_TYPE_CODE, KettleDatabaseRepository.REP_STRING_CODE_LENGTH, 0));
        tableMeta.addValueMeta(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_TYPE_DESCRIPTION, KettleDatabaseRepository.REP_STRING_LENGTH, 0));
        repository.connectionDelegate.getDatabase().prepareInsert(tableMeta, tablename);
        Object[] tableData = new Object[3];
        int tableIndex = 0;
        tableData[tableIndex++] = new LongObjectId(id_database_type).longValue();
        tableData[tableIndex++] = type;
        tableData[tableIndex++] = type;
        repository.connectionDelegate.getDatabase().setValuesInsert(tableMeta, tableData);
        repository.connectionDelegate.getDatabase().insertRow();
        repository.connectionDelegate.getDatabase().closeInsert();
    }
    ObjectId id_database_contype = getDatabaseConTypeID(access);
    RowMetaAndData table = new RowMetaAndData();
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_DATABASE_ID_DATABASE), id);
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_NAME), name);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_DATABASE_ID_DATABASE_TYPE), id_database_type);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_DATABASE_ID_DATABASE_CONTYPE), id_database_contype);
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_HOST_NAME), host);
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_DATABASE_NAME), dbname);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_DATABASE_PORT), Long.valueOf(Const.toLong(port, -1)));
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_USERNAME), user);
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_PASSWORD), Encr.encryptPasswordIfNotUsingVariables(pass));
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_SERVERNAME), servername);
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_DATA_TBS), data_tablespace);
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_INDEX_TBS), index_tablespace);
    repository.connectionDelegate.getDatabase().prepareInsert(table.getRowMeta(), KettleDatabaseRepository.TABLE_R_DATABASE);
    repository.connectionDelegate.getDatabase().setValuesInsert(table);
    repository.connectionDelegate.getDatabase().insertRow();
    repository.connectionDelegate.getDatabase().closeInsert();
    return id;
}
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) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LongObjectId(org.pentaho.di.repository.LongObjectId)

Example 20 with ObjectId

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

the class KettleDatabaseRepositoryDatabaseDelegate method createAttributeRow.

private RowMetaAndData createAttributeRow(ObjectId idDatabase, String code, String strValue) throws KettleException {
    ObjectId id = repository.connectionDelegate.getNextDatabaseAttributeID();
    RowMetaAndData table = new RowMetaAndData();
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_DATABASE_ATTRIBUTE_ID_DATABASE_ATTRIBUTE), id);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_DATABASE_ATTRIBUTE_ID_DATABASE), idDatabase);
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_ATTRIBUTE_CODE), code);
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_ATTRIBUTE_VALUE_STR), strValue);
    return table;
}
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)

Aggregations

ObjectId (org.pentaho.di.repository.ObjectId)200 KettleException (org.pentaho.di.core.exception.KettleException)91 LongObjectId (org.pentaho.di.repository.LongObjectId)76 StringObjectId (org.pentaho.di.repository.StringObjectId)52 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)49 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)36 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)33 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)32 ArrayList (java.util.ArrayList)28 Test (org.junit.Test)28 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)28 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)25 MessageBox (org.eclipse.swt.widgets.MessageBox)24 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)18 SlaveServer (org.pentaho.di.cluster.SlaveServer)15 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)14 Matchers.anyString (org.mockito.Matchers.anyString)13 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)13 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)13 KettleFileException (org.pentaho.di.core.exception.KettleFileException)12