use of com.datastax.oss.driver.api.querybuilder.delete.DeleteSelection in project rocketmq-externals by apache.
the class Updater method deleteRow.
private boolean deleteRow(String dbName, String tableName, Map<Field, Object[]> fieldMap) {
DeleteSelection deleteSelection = QueryBuilder.deleteFrom(dbName, tableName);
Delete delete = null;
int count = 0;
for (Map.Entry<Field, Object[]> entry : fieldMap.entrySet()) {
count++;
String fieldName = entry.getKey().getName();
FieldType fieldType = entry.getKey().getType();
Object fieldValue = entry.getValue()[1];
if (count == 1) {
delete = deleteSelection.whereColumn(fieldName).isEqualTo(buildTerm(fieldType, fieldValue));
} else {
delete = delete.whereColumn(fieldName).isEqualTo(buildTerm(fieldType, fieldValue));
}
}
boolean finishDelete = false;
SimpleStatement stmt = delete.build();
try {
while (!cqlSession.isClosed() && !finishDelete) {
ResultSet result = cqlSession.execute(stmt);
if (result.wasApplied()) {
log.info("delete from table success, executed query {}", delete);
return true;
}
finishDelete = true;
}
} catch (Exception e) {
log.error("delete from table error,{}", e);
}
return false;
}
Aggregations