@Override public ListenableFuture<Boolean> update(Query query, org.springframework.data.cassandra.core.query.Update update, Class<?> entityClass) throws DataAccessException { Assert.notNull(query, "Query must not be null"); Assert.notNull(update, "Update must not be null"); Assert.notNull(entityClass, "Entity type must not be null"); return getAsyncCqlOperations().execute( getStatementFactory().update(query, update, getRequiredPersistentEntity(entityClass))); }
@Override public ListenableFuture<WriteResult> delete(Object entity, QueryOptions options) { Assert.notNull(entity, "Entity must not be null"); Assert.notNull(options, "QueryOptions must not be null"); CqlIdentifier tableName = getTableName(entity); Delete delete = QueryUtils.createDeleteQuery(tableName.toCql(), entity, options, getConverter()); maybeEmitEvent(new BeforeDeleteEvent<>(delete, entity.getClass(), tableName)); return new MappingListenableFutureAdapter<>(getAsyncCqlOperations().execute(new AsyncStatementCallback(delete)), resultSet -> { maybeEmitEvent(new AfterDeleteEvent<>(delete, entity.getClass(), tableName)); return WriteResult.of(resultSet); }); }
@Override public ListenableFuture<Void> truncate(Class<?> entityClass) { Assert.notNull(entityClass, "Entity type must not be null"); CqlIdentifier tableName = getTableName(entityClass); Truncate truncate = QueryBuilder.truncate(tableName.toCql()); maybeEmitEvent(new BeforeDeleteEvent<>(truncate, entityClass, tableName)); ListenableFuture<Boolean> future = getAsyncCqlOperations().execute(truncate); future.addCallback(success -> maybeEmitEvent(new AfterDeleteEvent<>(truncate, entityClass, tableName)), e -> {}); return new MappingListenableFutureAdapter<>(future, aBoolean -> null); }
@Override public <T> ListenableFuture<EntityWriteResult<T>> insert(T entity, InsertOptions options) { Assert.notNull(entity, "Entity must not be null"); Assert.notNull(options, "InsertOptions must not be null"); CassandraPersistentEntity<?> persistentEntity = getRequiredPersistentEntity(entity.getClass()); CqlIdentifier tableName = persistentEntity.getTableName(); Insert insert = QueryUtils.createInsertQuery(tableName.toCql(), entity, options, getConverter(), persistentEntity); maybeEmitEvent(new BeforeSaveEvent<>(entity, tableName, insert)); return new MappingListenableFutureAdapter<>(getAsyncCqlOperations().execute(new AsyncStatementCallback(insert)), resultSet -> { maybeEmitEvent(new AfterSaveEvent<>(entity, tableName)); return EntityWriteResult.of(resultSet, entity); }); }
@SuppressWarnings("ConstantConditions") private int getEffectiveFetchSize(Statement statement) { if (statement.getFetchSize() > 0) { return statement.getFetchSize(); } if (getAsyncCqlOperations() instanceof CassandraAccessor) { CassandraAccessor accessor = (CassandraAccessor) getAsyncCqlOperations(); if (accessor.getFetchSize() != -1) { return accessor.getFetchSize(); } } return getAsyncCqlOperations() .execute((AsyncSessionCallback<Integer>) session -> AsyncResult.forValue(getConfiguredFetchSize(session))) .completable().join(); }
@Override public ListenableFuture<Boolean> deleteById(Object id, Class<?> entityClass) { Assert.notNull(id, "Id must not be null"); Assert.notNull(entityClass, "Entity type must not be null"); CassandraPersistentEntity<?> entity = getRequiredPersistentEntity(entityClass); CqlIdentifier tableName = entity.getTableName(); Delete delete = QueryBuilder.delete().from(tableName.toCql()); getConverter().write(id, delete.where(), entity); maybeEmitEvent(new BeforeDeleteEvent<>(delete, entityClass, tableName)); ListenableFuture<Boolean> future = getAsyncCqlOperations().execute(delete); future.addCallback(success -> maybeEmitEvent(new AfterDeleteEvent<>(delete, entityClass, tableName)), e -> {}); return future; }
@Override public <T> ListenableFuture<EntityWriteResult<T>> update(T entity, UpdateOptions options) { Assert.notNull(entity, "Entity must not be null"); Assert.notNull(options, "UpdateOptions must not be null"); CqlIdentifier tableName = getTableName(entity); Update update = QueryUtils.createUpdateQuery(tableName.toCql(), entity, options, getConverter()); maybeEmitEvent(new BeforeSaveEvent<>(entity, tableName, update)); return new MappingListenableFutureAdapter<>(getAsyncCqlOperations().execute(new AsyncStatementCallback(update)), resultSet -> { maybeEmitEvent(new AfterSaveEvent<>(entity, tableName)); return EntityWriteResult.of(resultSet, entity); }); }
private ListenableFuture<Boolean> doDelete(Query query, Class<?> entityClass, CqlIdentifier tableName) { RegularStatement delete = getStatementFactory().delete(query, getRequiredPersistentEntity(entityClass), tableName); maybeEmitEvent(new BeforeDeleteEvent<>(delete, entityClass, tableName)); ListenableFuture<Boolean> future = getAsyncCqlOperations() .execute(getStatementFactory().delete(query, getRequiredPersistentEntity(entityClass))); future.addCallback(success -> maybeEmitEvent(new AfterDeleteEvent<>(delete, entityClass, tableName)), e -> {}); return future; }