Search in sources :

Example 1 with AfterDeleteEvent

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;
}
Also used : Delete(com.datastax.oss.driver.api.querybuilder.delete.Delete) AfterDeleteEvent(org.springframework.data.cassandra.core.mapping.event.AfterDeleteEvent) AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier)

Example 2 with AfterDeleteEvent

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);
}
Also used : AfterDeleteEvent(org.springframework.data.cassandra.core.mapping.event.AfterDeleteEvent) AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) Truncate(com.datastax.oss.driver.api.querybuilder.truncate.Truncate) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier)

Example 3 with AfterDeleteEvent

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();
}
Also used : QueryBuilder(com.datastax.oss.driver.api.querybuilder.QueryBuilder) EntityCallbacks(org.springframework.data.mapping.callback.EntityCallbacks) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) SimpleUserTypeResolver(org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver) Insert(com.datastax.oss.driver.api.querybuilder.insert.Insert) Delete(com.datastax.oss.driver.api.querybuilder.delete.Delete) AfterLoadEvent(org.springframework.data.cassandra.core.mapping.event.AfterLoadEvent) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) EntityProjection(org.springframework.data.projection.EntityProjection) CassandraPersistentEntity(org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity) OptimisticLockingFailureException(org.springframework.dao.OptimisticLockingFailureException) ReactiveSessionFactory(org.springframework.data.cassandra.ReactiveSessionFactory) DriverException(com.datastax.oss.driver.api.core.DriverException) BatchType(com.datastax.oss.driver.api.core.cql.BatchType) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) AfterDeleteEvent(org.springframework.data.cassandra.core.mapping.event.AfterDeleteEvent) Select(com.datastax.oss.driver.api.querybuilder.select.Select) ReactiveEntityCallbacks(org.springframework.data.mapping.callback.ReactiveEntityCallbacks) DriverContext(com.datastax.oss.driver.api.core.context.DriverContext) Update(com.datastax.oss.driver.api.querybuilder.update.Update) ReactiveBeforeSaveCallback(org.springframework.data.cassandra.core.mapping.event.ReactiveBeforeSaveCallback) BoundStatement(com.datastax.oss.driver.api.core.cql.BoundStatement) DefaultReactiveSessionFactory(org.springframework.data.cassandra.core.cql.session.DefaultReactiveSessionFactory) CassandraMappingEvent(org.springframework.data.cassandra.core.mapping.event.CassandraMappingEvent) Truncate(com.datastax.oss.driver.api.querybuilder.truncate.Truncate) org.springframework.data.cassandra.core.cql(org.springframework.data.cassandra.core.cql) Slice(org.springframework.data.domain.Slice) BeforeDeleteEvent(org.springframework.data.cassandra.core.mapping.event.BeforeDeleteEvent) LogFactory(org.apache.commons.logging.LogFactory) BeforeSaveEvent(org.springframework.data.cassandra.core.mapping.event.BeforeSaveEvent) SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) ApplicationContextAware(org.springframework.context.ApplicationContextAware) DataAccessException(org.springframework.dao.DataAccessException) AfterConvertEvent(org.springframework.data.cassandra.core.mapping.event.AfterConvertEvent) SliceImpl(org.springframework.data.domain.SliceImpl) ProjectionFactory(org.springframework.data.projection.ProjectionFactory) Function(java.util.function.Function) ReactiveBeforeConvertCallback(org.springframework.data.cassandra.core.mapping.event.ReactiveBeforeConvertCallback) DefaultDriverOption(com.datastax.oss.driver.api.core.config.DefaultDriverOption) BiConsumer(java.util.function.BiConsumer) StatementBuilder(org.springframework.data.cassandra.core.cql.util.StatementBuilder) AfterSaveEvent(org.springframework.data.cassandra.core.mapping.event.AfterSaveEvent) ReactiveSession(org.springframework.data.cassandra.ReactiveSession) Nullable(org.springframework.lang.Nullable) Row(com.datastax.oss.driver.api.core.cql.Row) MappingCassandraConverter(org.springframework.data.cassandra.core.convert.MappingCassandraConverter) DataAccessUtils(org.springframework.dao.support.DataAccessUtils) RegularInsert(com.datastax.oss.driver.api.querybuilder.insert.RegularInsert) ApplicationEventPublisherAware(org.springframework.context.ApplicationEventPublisherAware) CassandraConverter(org.springframework.data.cassandra.core.convert.CassandraConverter) Publisher(org.reactivestreams.Publisher) ReactiveResultSet(org.springframework.data.cassandra.ReactiveResultSet) Mono(reactor.core.publisher.Mono) BeansException(org.springframework.beans.BeansException) Query(org.springframework.data.cassandra.core.query.Query) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) ApplicationContext(org.springframework.context.ApplicationContext) SynchronousSink(reactor.core.publisher.SynchronousSink) Flux(reactor.core.publisher.Flux) AdaptibleEntity(org.springframework.data.cassandra.core.EntityOperations.AdaptibleEntity) Log(org.apache.commons.logging.Log) Collections(java.util.Collections) Statement(com.datastax.oss.driver.api.core.cql.Statement) Columns(org.springframework.data.cassandra.core.query.Columns) Assert(org.springframework.util.Assert) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) Truncate(com.datastax.oss.driver.api.querybuilder.truncate.Truncate) BeforeDeleteEvent(org.springframework.data.cassandra.core.mapping.event.BeforeDeleteEvent) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier)

Example 4 with AfterDeleteEvent

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)));
}
Also used : Delete(com.datastax.oss.driver.api.querybuilder.delete.Delete) AfterDeleteEvent(org.springframework.data.cassandra.core.mapping.event.AfterDeleteEvent) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) BeforeDeleteEvent(org.springframework.data.cassandra.core.mapping.event.BeforeDeleteEvent) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier)

Example 5 with AfterDeleteEvent

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;
}
Also used : Delete(com.datastax.oss.driver.api.querybuilder.delete.Delete) AfterDeleteEvent(org.springframework.data.cassandra.core.mapping.event.AfterDeleteEvent) AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement)

Aggregations

SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)6 AfterDeleteEvent (org.springframework.data.cassandra.core.mapping.event.AfterDeleteEvent)6 Delete (com.datastax.oss.driver.api.querybuilder.delete.Delete)5 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)4 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)3 BeforeDeleteEvent (org.springframework.data.cassandra.core.mapping.event.BeforeDeleteEvent)3 Truncate (com.datastax.oss.driver.api.querybuilder.truncate.Truncate)2 DriverException (com.datastax.oss.driver.api.core.DriverException)1 DefaultDriverOption (com.datastax.oss.driver.api.core.config.DefaultDriverOption)1 DriverContext (com.datastax.oss.driver.api.core.context.DriverContext)1 BatchType (com.datastax.oss.driver.api.core.cql.BatchType)1 BoundStatement (com.datastax.oss.driver.api.core.cql.BoundStatement)1 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)1 Row (com.datastax.oss.driver.api.core.cql.Row)1 Statement (com.datastax.oss.driver.api.core.cql.Statement)1 QueryBuilder (com.datastax.oss.driver.api.querybuilder.QueryBuilder)1 Insert (com.datastax.oss.driver.api.querybuilder.insert.Insert)1 RegularInsert (com.datastax.oss.driver.api.querybuilder.insert.RegularInsert)1 Select (com.datastax.oss.driver.api.querybuilder.select.Select)1 Update (com.datastax.oss.driver.api.querybuilder.update.Update)1