Search in sources :

Example 61 with LongObjectId

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

the class KettleDatabaseRepositoryConnectionDelegate method getJobEntryAttributesWithPrefix.

public synchronized List<Object[]> getJobEntryAttributesWithPrefix(ObjectId jobId, ObjectId jobEntryId, String codePrefix) throws KettleException {
    String sql = "SELECT *" + " FROM " + databaseMeta.getQuotedSchemaTableCombination(null, KettleDatabaseRepository.TABLE_R_JOBENTRY_ATTRIBUTE) + " WHERE " + quote(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOB) + " = ?" + " AND " + quote(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOBENTRY) + " = ?" + " AND " + quote(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_CODE) + " LIKE '" + codePrefix + "%'";
    RowMetaAndData table = new RowMetaAndData();
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOB), new LongObjectId(jobId));
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOBENTRY), new LongObjectId(jobEntryId));
    return callRead(() -> database.getRows(sql, table.getRowMeta(), table.getData(), ResultSet.FETCH_FORWARD, false, 0, null));
}
Also used : 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 62 with LongObjectId

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

the class KettleDatabaseRepositoryConnectionDelegate method getJobAttributesWithPrefix.

public synchronized List<Object[]> getJobAttributesWithPrefix(ObjectId jobId, String codePrefix) throws KettleException {
    String sql = "SELECT *" + " FROM " + databaseMeta.getQuotedSchemaTableCombination(null, KettleDatabaseRepository.TABLE_R_JOB_ATTRIBUTE) + " WHERE " + quote(KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_ID_JOB) + " = ?" + " AND " + quote(KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_CODE) + " LIKE '" + codePrefix + "%'";
    RowMetaAndData table = new RowMetaAndData();
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_ID_JOB), new LongObjectId(jobId));
    return callRead(() -> database.getRows(sql, table.getRowMeta(), table.getData(), ResultSet.FETCH_FORWARD, false, 0, null));
}
Also used : 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 63 with LongObjectId

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

the class KettleDatabaseRepositoryConnectionDelegate method getDatabaseAttributes.

public Collection<RowMetaAndData> getDatabaseAttributes(ObjectId id_database) throws KettleDatabaseException, KettleValueException {
    String sql = "SELECT * FROM " + quoteTable(KettleDatabaseRepository.TABLE_R_DATABASE_ATTRIBUTE) + " WHERE " + quote(KettleDatabaseRepository.FIELD_DATABASE_ID_DATABASE) + " = ?";
    // Get the prepared statement
    // 
    PreparedStatement ps = getPreparedStatement(sql);
    // Assemble the parameter (if any)
    // 
    RowMetaInterface parameterMeta = new RowMeta();
    parameterMeta.addValueMeta(new ValueMetaInteger("id"));
    Object[] parameterData = new Object[] { ((LongObjectId) id_database).longValue() };
    List<RowMetaAndData> attrs = new ArrayList<RowMetaAndData>();
    return callRead(new Callable<Collection<RowMetaAndData>>() {

        @Override
        public Collection<RowMetaAndData> call() throws Exception {
            ResultSet resultSet = null;
            try {
                resultSet = database.openQuery(ps, parameterMeta, parameterData);
                List<Object[]> rows = database.getRows(resultSet, 0, null);
                for (Object[] row : rows) {
                    RowMetaAndData rowWithMeta = new RowMetaAndData(database.getReturnRowMeta(), row);
                    long id = rowWithMeta.getInteger(quote(KettleDatabaseRepository.FIELD_DATABASE_ATTRIBUTE_ID_DATABASE_ATTRIBUTE), 0);
                    if (id > 0) {
                        attrs.add(rowWithMeta);
                    }
                }
                return attrs;
            } catch (KettleDatabaseException e) {
                throw e;
            } finally {
                database.closeQuery(resultSet);
            }
        }
    });
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) 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) Collection(java.util.Collection) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) RepositoryObject(org.pentaho.di.repository.RepositoryObject) ArrayList(java.util.ArrayList) List(java.util.List)

Example 64 with LongObjectId

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

the class KettleDatabaseRepositoryConnectionDelegate method getIDsWithValues.

public LongObjectId[] getIDsWithValues(String tablename, String idfield, String lookupfield, String[] values) throws KettleException {
    String sql = createIdsWithValuesQuery(tablename, idfield, lookupfield, values.length);
    RowMeta params = new RowMeta();
    for (int i = 0; i < values.length; i++) {
        ValueMetaInterface value = new ValueMetaString(Integer.toString(i));
        params.addValueMeta(value);
    }
    List<Object[]> rows = callRead(() -> database.getRows(sql, params, values, ResultSet.FETCH_FORWARD, false, -1, null));
    LongObjectId[] result = new LongObjectId[rows.size()];
    int i = 0;
    for (Object[] row : rows) {
        result[i++] = new LongObjectId(((Number) row[0]).longValue());
    }
    return result;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) RowMeta(org.pentaho.di.core.row.RowMeta) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) RepositoryObject(org.pentaho.di.repository.RepositoryObject) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LongObjectId(org.pentaho.di.repository.LongObjectId) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 65 with LongObjectId

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

the class KettleDatabaseRepositoryConnectionDelegate method searchStepAttributeIndexInBuffer.

private synchronized int searchStepAttributeIndexInBuffer(ObjectId id_step, String code, long nr) throws KettleValueException {
    Object[] key = new Object[] { // ID_STEP
    new LongObjectId(id_step).longValue(), // CODE
    code, // NR
    new Long(nr) };
    int index = Collections.binarySearch(stepAttributesBuffer, key, new StepAttributeComparator());
    if (index >= stepAttributesBuffer.size() || index < 0) {
        return -1;
    }
    // 
    // Check this... If it is not in there, we didn't find it!
    // stepAttributesRowMeta.compare returns 0 when there are conversion issues
    // so the binarySearch could have 'found' a match when there really isn't
    // one
    // 
    Object[] look = stepAttributesBuffer.get(index);
    if (stepAttributesRowMeta.compare(look, key, KEY_POSITIONS) == 0) {
        return index;
    }
    return -1;
}
Also used : SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) RepositoryObject(org.pentaho.di.repository.RepositoryObject) 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