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));
}
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));
}
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);
}
}
});
}
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;
}
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;
}
Aggregations