use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryConnectionDelegate method getStrings.
public String[] getStrings(String sql, ObjectId... objectId) throws KettleException {
// Get the prepared statement
//
PreparedStatement ps = getPreparedStatement(sql);
// Assemble the parameters (if any)
//
// 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<String[]>() {
@Override
public String[] call() throws Exception {
ResultSet resultSet = database.openQuery(ps, parameterMeta, parameterData);
List<Object[]> rows = database.getRows(resultSet, 0, null);
if (Utils.isEmpty(rows)) {
return new String[0];
}
// assemble the result
//
RowMetaInterface rowMeta = database.getReturnRowMeta();
String[] strings = new String[rows.size()];
for (int i = 0; i < strings.length; i++) {
Object[] row = rows.get(i);
strings[i] = rowMeta.getString(row, 0);
}
return strings;
}
});
}
use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryConnectionDelegate method getOneRow.
/**
* This method should be called WITH AN ALREADY QUOTED schema and table
*/
public RowMetaAndData getOneRow(String schemaAndTable, String keyfield, ObjectId id) throws KettleException {
String sql = "SELECT * FROM " + schemaAndTable + " WHERE " + keyfield + " = ?";
// 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[] { id != null ? Long.parseLong(id.getId()) : null };
try {
return callRead(new Callable<RowMetaAndData>() {
@Override
public RowMetaAndData call() throws Exception {
ResultSet resultSet = null;
resultSet = database.openQuery(ps, parameterMeta, parameterData);
Object[] result = database.getRow(resultSet);
if (resultSet != null) {
database.closeQuery(resultSet);
}
if (result == null) {
return new RowMetaAndData(database.getReturnRowMeta(), RowDataUtil.allocateRowData(database.getReturnRowMeta().size()));
}
return new RowMetaAndData(database.getReturnRowMeta(), result);
}
});
} catch (KettleException e) {
throw e;
}
}
use of org.pentaho.di.core.row.value.ValueMetaInteger 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;
}
use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryConnectionDelegate method getIDWithValue.
public synchronized ObjectId getIDWithValue(String tablename, String idfield, String lookupfield, String value, String lookupkey, ObjectId key) throws KettleException {
RowMetaAndData par = new RowMetaAndData();
par.addValue(new ValueMetaString("value"), value);
par.addValue(new ValueMetaInteger("key"), new LongObjectId(key));
RowMetaAndData result = getOneRow("SELECT " + idfield + " FROM " + tablename + " WHERE " + lookupfield + " = ? AND " + lookupkey + " = ?", 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;
}
use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryConnectionDelegate method getJobEntryAttributeRow.
private RowMetaAndData getJobEntryAttributeRow(ObjectId id_jobentry, int nr, String code) throws KettleException {
RowMetaAndData par = new RowMetaAndData();
par.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOBENTRY), id_jobentry);
par.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_CODE), code);
par.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_NR), new Long(nr));
if (pstmt_entry_attributes == null) {
setLookupJobEntryAttribute();
}
database.setValues(par.getRowMeta(), par.getData(), pstmt_entry_attributes);
return callRead(new Callable<RowMetaAndData>() {
@Override
public RowMetaAndData call() throws Exception {
Object[] lookup = database.getLookup(pstmt_entry_attributes);
return new RowMetaAndData(database.getReturnRowMeta(), lookup);
}
});
}
Aggregations