Search in sources :

Example 16 with LongObjectId

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

the class KettleDatabaseRepositoryConnectionDelegate method findStepAttributeID.

public synchronized ObjectId findStepAttributeID(ObjectId id_step, int nr, String code) throws KettleException {
    RowMetaAndData r = null;
    if (stepAttributesBuffer != null) {
        r = searchStepAttributeInBuffer(id_step, code, nr);
    } else {
        r = getStepAttributeRow(id_step, nr, code);
    }
    if (r == null) {
        return null;
    }
    long id = r.getInteger(KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_ID_STEP, -1L);
    if (id < 0) {
        return null;
    }
    return new LongObjectId(id);
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LongObjectId(org.pentaho.di.repository.LongObjectId)

Example 17 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) throws KettleException {
    RowMetaAndData par = new RowMetaAndData();
    par.addValue(new ValueMetaString("value"), value);
    RowMetaAndData result = getOneRow("SELECT " + idfield + " FROM " + tablename + " WHERE " + lookupfield + " = ?", 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) LongObjectId(org.pentaho.di.repository.LongObjectId)

Example 18 with LongObjectId

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

the class KettleDatabaseRepositoryConnectionDelegate method searchNrStepAttributes.

private synchronized int searchNrStepAttributes(ObjectId id_step, String code) throws KettleValueException {
    // Search the index of the first step attribute with the specified code...
    // 
    int idx = searchStepAttributeIndexInBuffer(id_step, code, 0L);
    if (idx < 0) {
        return 0;
    }
    int nr = 1;
    int offset = 1;
    if (idx + offset >= stepAttributesBuffer.size()) {
        // 
        return 1;
    }
    Object[] look = stepAttributesBuffer.get(idx + offset);
    RowMetaInterface rowMeta = stepAttributesRowMeta;
    long lookID = rowMeta.getInteger(look, 0);
    String lookCode = rowMeta.getString(look, 1);
    while (lookID == new LongObjectId(id_step).longValue() && code.equalsIgnoreCase(lookCode)) {
        // Find the maximum
        // 
        nr = rowMeta.getInteger(look, 2).intValue() + 1;
        offset++;
        if (idx + offset < stepAttributesBuffer.size()) {
            look = stepAttributesBuffer.get(idx + offset);
            lookID = rowMeta.getInteger(look, 0);
            lookCode = rowMeta.getString(look, 1);
        } else {
            return nr;
        }
    }
    return nr;
}
Also used : SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) RepositoryObject(org.pentaho.di.repository.RepositoryObject) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LongObjectId(org.pentaho.di.repository.LongObjectId)

Example 19 with LongObjectId

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

the class KettleDatabaseRepositoryConnectionDelegate method getIDs.

public ObjectId[] getIDs(String sql, ObjectId... objectId) throws KettleException {
    // Get the prepared statement
    // 
    PreparedStatement ps = getPreparedStatement(sql);
    // Assemble the parameters (if any)
    // 
    RowMetaInterface parameterMeta = new RowMeta();
    Object[] parameterData = new Object[objectId.length];
    for (int i = 0; i < objectId.length; i++) {
        parameterMeta.addValueMeta(new ValueMetaInteger("id" + (i + 1)));
        parameterData[i] = ((LongObjectId) objectId[i]).longValue();
    }
    return callRead(new Callable<ObjectId[]>() {

        @Override
        public ObjectId[] call() throws Exception {
            ResultSet resultSet = database.openQuery(ps, parameterMeta, parameterData);
            List<Object[]> rows = database.getRows(resultSet, 0, null);
            if (Utils.isEmpty(rows)) {
                return new ObjectId[0];
            }
            RowMetaInterface rowMeta = database.getReturnRowMeta();
            ObjectId[] ids = new ObjectId[rows.size()];
            for (int i = 0; i < ids.length; i++) {
                Object[] row = rows.get(i);
                ids[i] = new LongObjectId(rowMeta.getInteger(row, 0));
            }
            return ids;
        }
    });
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) PreparedStatement(java.sql.PreparedStatement) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) 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) ResultSet(java.sql.ResultSet) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) RepositoryObject(org.pentaho.di.repository.RepositoryObject) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with LongObjectId

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

the class KettleDatabaseRepositoryConnectionDelegate method getNextTableID.

private synchronized LongObjectId getNextTableID(String tablename, String idfield) throws KettleException {
    LongObjectId retval = null;
    RowMetaAndData r = callRead(() -> database.getOneRow("SELECT MAX(" + idfield + ") FROM " + tablename));
    if (r != null) {
        Long id = r.getInteger(0);
        if (id == null) {
            if (log.isDebug()) {
                log.logDebug("no max(" + idfield + ") found in table " + tablename);
            }
            retval = new LongObjectId(1);
        } else {
            if (log.isDebug()) {
                log.logDebug("max(" + idfield + ") found in table " + tablename + " --> " + idfield + " number: " + id);
            }
            retval = new LongObjectId(id.longValue() + 1L);
        }
    }
    return retval;
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) 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