use of org.pentaho.di.core.RowMetaAndData 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.RowMetaAndData in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryConnectionDelegate method getParameterMetaData.
public RowMetaAndData getParameterMetaData(ObjectId... ids) throws KettleException {
RowMetaInterface parameterMeta = new RowMeta();
Object[] parameterData = new Object[ids.length];
for (int i = 0; i < ids.length; i++) {
parameterMeta.addValueMeta(new ValueMetaInteger("id" + (i + 1)));
parameterData[i] = Long.valueOf(ids[i].getId());
}
return new RowMetaAndData(parameterMeta, parameterData);
}
use of org.pentaho.di.core.RowMetaAndData in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryConnectionDelegate method getTransAttributeInteger.
public synchronized long getTransAttributeInteger(ObjectId id_transformation, int nr, String code) throws KettleException {
RowMetaAndData r = null;
r = getTransAttributeRow(id_transformation, nr, code);
if (r == null) {
return 0L;
}
return r.getInteger(KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_VALUE_NUM, 0L);
}
use of org.pentaho.di.core.RowMetaAndData in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryConnectionDelegate method countNrTransAttributes.
public synchronized int countNrTransAttributes(ObjectId id_transformation, String code) throws KettleException {
String sql = "SELECT COUNT(*) FROM " + databaseMeta.getQuotedSchemaTableCombination(null, KettleDatabaseRepository.TABLE_R_TRANS_ATTRIBUTE) + " WHERE " + quote(KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_ID_TRANSFORMATION) + " = ? AND " + quote(KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_CODE) + " = ?";
RowMetaAndData table = new RowMetaAndData();
table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_ID_TRANSFORMATION), id_transformation);
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_CODE), code);
RowMetaAndData r = callRead(() -> database.getOneRow(sql, table.getRowMeta(), table.getData()));
if (r == null || r.getData() == null) {
return 0;
}
return (int) r.getInteger(0, 0L);
}
use of org.pentaho.di.core.RowMetaAndData 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;
}
Aggregations