use of org.springframework.data.cassandra.core.mapping.event.AfterDeleteEvent in project spring-data-cassandra by spring-projects.
the class AsyncCassandraTemplate method deleteById.
/* (non-Javadoc)
* @see org.springframework.data.cassandra.core.AsyncCassandraOperations#deleteById(java.lang.Object, java.lang.Class)
*/
@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();
StatementBuilder<Delete> builder = getStatementFactory().deleteById(id, entity, tableName);
SimpleStatement delete = builder.build();
maybeEmitEvent(new BeforeDeleteEvent<>(delete, entityClass, tableName));
ListenableFuture<Boolean> future = doExecute(delete, AsyncResultSet::wasApplied);
future.addCallback(success -> maybeEmitEvent(new AfterDeleteEvent<>(delete, entityClass, tableName)), e -> {
});
return future;
}
use of org.springframework.data.cassandra.core.mapping.event.AfterDeleteEvent in project spring-data-cassandra by spring-projects.
the class AsyncCassandraTemplate method truncate.
/* (non-Javadoc)
* @see org.springframework.data.cassandra.core.AsyncCassandraOperations#truncate(java.lang.Class)
*/
@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);
SimpleStatement statement = truncate.build();
maybeEmitEvent(new BeforeDeleteEvent<>(statement, entityClass, tableName));
ListenableFuture<Boolean> future = doExecute(statement, AsyncResultSet::wasApplied);
future.addCallback(success -> maybeEmitEvent(new AfterDeleteEvent<>(statement, entityClass, tableName)), e -> {
});
return new MappingListenableFutureAdapter<>(future, aBoolean -> null);
}
use of org.springframework.data.cassandra.core.mapping.event.AfterDeleteEvent in project spring-data-cassandra by spring-projects.
the class ReactiveCassandraTemplate method truncate.
/* (non-Javadoc)
* @see org.springframework.data.cassandra.core.ReactiveCassandraOperations#truncate(java.lang.Class)
*/
@Override
public Mono<Void> truncate(Class<?> entityClass) {
Assert.notNull(entityClass, "Entity type must not be null");
CqlIdentifier tableName = getTableName(entityClass);
Truncate truncate = QueryBuilder.truncate(tableName);
SimpleStatement statement = truncate.build();
Mono<Boolean> result = doExecute(statement, ReactiveResultSet::wasApplied).doOnSubscribe(it -> maybeEmitEvent(new BeforeDeleteEvent<>(statement, entityClass, tableName)));
return result.doOnNext(it -> maybeEmitEvent(new AfterDeleteEvent<>(statement, entityClass, tableName))).then();
}
use of org.springframework.data.cassandra.core.mapping.event.AfterDeleteEvent in project spring-data-cassandra by spring-projects.
the class ReactiveCassandraTemplate method deleteById.
/* (non-Javadoc)
* @see org.springframework.data.cassandra.core.ReactiveCassandraOperations#deleteById(java.lang.Object, java.lang.Class)
*/
@Override
public Mono<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();
StatementBuilder<Delete> builder = getStatementFactory().deleteById(id, entity, tableName);
SimpleStatement delete = builder.build();
Mono<Boolean> result = doExecute(delete, ReactiveResultSet::wasApplied).doOnSubscribe(it -> maybeEmitEvent(new BeforeDeleteEvent<>(delete, entityClass, tableName)));
return result.doOnNext(it -> maybeEmitEvent(new AfterDeleteEvent<>(delete, entityClass, tableName)));
}
use of org.springframework.data.cassandra.core.mapping.event.AfterDeleteEvent in project spring-data-cassandra by spring-projects.
the class AsyncCassandraTemplate method doDelete.
private ListenableFuture<Boolean> doDelete(Query query, Class<?> entityClass, CqlIdentifier tableName) {
StatementBuilder<Delete> builder = getStatementFactory().delete(query, getRequiredPersistentEntity(entityClass), tableName);
SimpleStatement delete = builder.build();
maybeEmitEvent(new BeforeDeleteEvent<>(delete, entityClass, tableName));
ListenableFuture<Boolean> future = doExecute(delete, AsyncResultSet::wasApplied);
future.addCallback(success -> maybeEmitEvent(new AfterDeleteEvent<>(delete, entityClass, tableName)), e -> {
});
return future;
}
Aggregations