I'm using the datastax object mapper and accessor to insert data into my cassandra tables. In the documentation linked, it says that the return type specification affects how the query gets executed. I want the query to execute asynchronously, so I choose to use ResultSetFuture
:
@Accessor
interface MyTableAccessor {
@Query("INSERT INOT MY_TABLE " +
"SET value = :v " +
"WHERE $ID = :id ")
fun insertValue(@Param("v") value: String, @Param("id") id: String): ResultSetFuture
}
My insert call is:
val id = ...
val insertFutures = myList.map {
myTableAccessor.insertValue(it, id)
}
I also have added a callback for these futures:
insertFutures.forEach {
Futures.addCallback(it, MyCallback(stats, tags))
}
where MyCallback
implements the FutureCallback
interface. I finish the call with:
return Futures.inCompletionOrder(insertFutures)
.map { it.get() }
This returns to me a List<ResultSet>
.
But I want to return a Boolean
for the insert call to indicate that the insert operation succeeded. I'm not sure how I can do that with the returned List<ResultSet>
.
insert queries return result only if the lightweight transactions (LWTs) are used. In other cases, insert queries don't return anything, and the success of operation is that fact that you got ResultSet
instead of exception. So in your case, you just add the onSuccess
callback that always returns true, and onFailure
that returns false.