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