Search in sources :

Example 1 with Truncate

use of com.datastax.oss.driver.api.querybuilder.truncate.Truncate 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 2 with Truncate

use of com.datastax.oss.driver.api.querybuilder.truncate.Truncate in project spring-data-cassandra by spring-projects.

the class CassandraTemplate method truncate.

/* (non-Javadoc)
	 * @see org.springframework.data.cassandra.core.CassandraOperations#truncate(java.lang.Class)
	 */
@Override
public 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));
    doExecute(statement);
    maybeEmitEvent(new AfterDeleteEvent<>(statement, entityClass, tableName));
}
Also used : 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 Truncate

use of com.datastax.oss.driver.api.querybuilder.truncate.Truncate 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)

Aggregations

CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)3 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)3 Truncate (com.datastax.oss.driver.api.querybuilder.truncate.Truncate)3 AfterDeleteEvent (org.springframework.data.cassandra.core.mapping.event.AfterDeleteEvent)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 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)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 Delete (com.datastax.oss.driver.api.querybuilder.delete.Delete)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 Collections (java.util.Collections)1