Search in sources :

Example 1 with CassandraPersistentEntity

use of org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity in project spring-data-cassandra by spring-projects.

the class StatementFactory method createSelect.

private StatementBuilder<Select> createSelect(Query query, CassandraPersistentEntity<?> entity, Filter filter, List<Selector> selectors, CqlIdentifier tableName) {
    Sort sort = Optional.of(query.getSort()).map(querySort -> getQueryMapper().getMappedSort(querySort, entity)).orElse(Sort.unsorted());
    StatementBuilder<Select> select = createSelectAndOrder(selectors, tableName, filter, sort);
    if (query.getLimit() > 0) {
        select.apply(it -> it.limit(Math.toIntExact(query.getLimit())));
    }
    if (query.isAllowFiltering()) {
        select.apply(Select::allowFiltering);
    }
    select.onBuild(statementBuilder -> query.getPagingState().ifPresent(statementBuilder::setPagingState));
    query.getQueryOptions().ifPresent(it -> select.transform(statement -> QueryOptionsUtil.addQueryOptions(statement, it)));
    return select;
}
Also used : QueryBuilder(com.datastax.oss.driver.api.querybuilder.QueryBuilder) QueryOptions(org.springframework.data.cassandra.core.cql.QueryOptions) TermFactory(org.springframework.data.cassandra.core.cql.util.TermFactory) Relation(com.datastax.oss.driver.api.querybuilder.relation.Relation) Assignment(com.datastax.oss.driver.api.querybuilder.update.Assignment) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) Insert(com.datastax.oss.driver.api.querybuilder.insert.Insert) Delete(com.datastax.oss.driver.api.querybuilder.delete.Delete) SetAtIndexOp(org.springframework.data.cassandra.core.query.Update.SetAtIndexOp) SetOp(org.springframework.data.cassandra.core.query.Update.SetOp) UpdateWithAssignments(com.datastax.oss.driver.api.querybuilder.update.UpdateWithAssignments) EntityProjection(org.springframework.data.projection.EntityProjection) DeleteSelection(com.datastax.oss.driver.api.querybuilder.delete.DeleteSelection) CassandraPersistentEntity(org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity) PersistentPropertyTranslator(org.springframework.data.cassandra.core.mapping.PersistentPropertyTranslator) Predicates(org.springframework.data.util.Predicates) Map(java.util.Map) RemoveOp(org.springframework.data.cassandra.core.query.Update.RemoveOp) Sort(org.springframework.data.domain.Sort) ColumnSelector(org.springframework.data.cassandra.core.query.Columns.ColumnSelector) Select(com.datastax.oss.driver.api.querybuilder.select.Select) PersistentProperty(org.springframework.data.mapping.PersistentProperty) BindMarker(com.datastax.oss.driver.api.querybuilder.BindMarker) ClassUtils(org.springframework.util.ClassUtils) ColumnRelationBuilder(com.datastax.oss.driver.api.querybuilder.relation.ColumnRelationBuilder) Collection(java.util.Collection) Set(java.util.Set) Predicate(org.springframework.data.cassandra.core.query.CriteriaDefinition.Predicate) Collectors(java.util.stream.Collectors) Selector(org.springframework.data.cassandra.core.query.Columns.Selector) List(java.util.List) UpdateMapper(org.springframework.data.cassandra.core.convert.UpdateMapper) PropertyDescriptor(java.beans.PropertyDescriptor) QueryMapper(org.springframework.data.cassandra.core.convert.QueryMapper) Optional(java.util.Optional) AddToOp(org.springframework.data.cassandra.core.query.Update.AddToOp) NonNull(org.springframework.lang.NonNull) AssignmentOp(org.springframework.data.cassandra.core.query.Update.AssignmentOp) IncrOp(org.springframework.data.cassandra.core.query.Update.IncrOp) SetAtKeyOp(org.springframework.data.cassandra.core.query.Update.SetAtKeyOp) WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) AddToMapOp(org.springframework.data.cassandra.core.query.Update.AddToMapOp) UpdateStart(com.datastax.oss.driver.api.querybuilder.update.UpdateStart) OngoingAssignment(com.datastax.oss.driver.api.querybuilder.update.OngoingAssignment) Condition(com.datastax.oss.driver.api.querybuilder.condition.Condition) ClusteringOrder(com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder) CriteriaDefinition(org.springframework.data.cassandra.core.query.CriteriaDefinition) Filter(org.springframework.data.cassandra.core.query.Filter) Function(java.util.function.Function) CassandraPersistentProperty(org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ProjectionInformation(org.springframework.data.projection.ProjectionInformation) FunctionCall(org.springframework.data.cassandra.core.query.Columns.FunctionCall) StatementBuilder(org.springframework.data.cassandra.core.cql.util.StatementBuilder) Nullable(org.springframework.lang.Nullable) Mode(org.springframework.data.cassandra.core.query.Update.AddToOp.Mode) ConditionBuilder(com.datastax.oss.driver.api.querybuilder.condition.ConditionBuilder) EntityWriter(org.springframework.data.convert.EntityWriter) RegularInsert(com.datastax.oss.driver.api.querybuilder.insert.RegularInsert) Update(org.springframework.data.cassandra.core.query.Update) CassandraConverter(org.springframework.data.cassandra.core.convert.CassandraConverter) Query(org.springframework.data.cassandra.core.query.Query) QueryOptionsUtil(org.springframework.data.cassandra.core.cql.QueryOptionsUtil) Term(com.datastax.oss.driver.api.querybuilder.term.Term) Collections(java.util.Collections) Where(org.springframework.data.cassandra.core.convert.Where) Columns(org.springframework.data.cassandra.core.query.Columns) Assert(org.springframework.util.Assert) Select(com.datastax.oss.driver.api.querybuilder.select.Select) Sort(org.springframework.data.domain.Sort)

Example 2 with CassandraPersistentEntity

use of org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity in project spring-data-cassandra by spring-projects.

the class StatementFactory method delete.

/**
 * Create a {@literal DELETE} statement by mapping {@link Query} to {@link Delete}.
 *
 * @param query must not be {@literal null}.
 * @param persistentEntity must not be {@literal null}.
 * @param tableName must not be {@literal null}.
 * @return the delete builder.
 * @see 2.1
 */
public StatementBuilder<Delete> delete(Query query, CassandraPersistentEntity<?> persistentEntity, CqlIdentifier tableName) {
    Assert.notNull(query, "Query must not be null");
    Assert.notNull(persistentEntity, "CassandraPersistentEntity must not be null");
    Assert.notNull(tableName, "Table name must not be null");
    Filter filter = getQueryMapper().getMappedObject(query, persistentEntity);
    List<CqlIdentifier> columnNames = getQueryMapper().getMappedColumnNames(query.getColumns(), persistentEntity);
    StatementBuilder<Delete> builder = delete(columnNames, tableName, filter);
    query.getQueryOptions().filter(DeleteOptions.class::isInstance).map(DeleteOptions.class::cast).map(DeleteOptions::getIfCondition).ifPresent(criteriaDefinitions -> applyDeleteIfCondition(builder, criteriaDefinitions));
    query.getQueryOptions().filter(WriteOptions.class::isInstance).map(WriteOptions.class::cast).ifPresent(writeOptions -> builder.apply(statement -> addWriteOptions(statement, writeOptions)));
    query.getQueryOptions().ifPresent(options -> builder.transform(statement -> QueryOptionsUtil.addQueryOptions(statement, options)));
    return builder;
}
Also used : Delete(com.datastax.oss.driver.api.querybuilder.delete.Delete) QueryBuilder(com.datastax.oss.driver.api.querybuilder.QueryBuilder) QueryOptions(org.springframework.data.cassandra.core.cql.QueryOptions) TermFactory(org.springframework.data.cassandra.core.cql.util.TermFactory) Relation(com.datastax.oss.driver.api.querybuilder.relation.Relation) Assignment(com.datastax.oss.driver.api.querybuilder.update.Assignment) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) Insert(com.datastax.oss.driver.api.querybuilder.insert.Insert) Delete(com.datastax.oss.driver.api.querybuilder.delete.Delete) SetAtIndexOp(org.springframework.data.cassandra.core.query.Update.SetAtIndexOp) SetOp(org.springframework.data.cassandra.core.query.Update.SetOp) UpdateWithAssignments(com.datastax.oss.driver.api.querybuilder.update.UpdateWithAssignments) EntityProjection(org.springframework.data.projection.EntityProjection) DeleteSelection(com.datastax.oss.driver.api.querybuilder.delete.DeleteSelection) CassandraPersistentEntity(org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity) PersistentPropertyTranslator(org.springframework.data.cassandra.core.mapping.PersistentPropertyTranslator) Predicates(org.springframework.data.util.Predicates) Map(java.util.Map) RemoveOp(org.springframework.data.cassandra.core.query.Update.RemoveOp) Sort(org.springframework.data.domain.Sort) ColumnSelector(org.springframework.data.cassandra.core.query.Columns.ColumnSelector) Select(com.datastax.oss.driver.api.querybuilder.select.Select) PersistentProperty(org.springframework.data.mapping.PersistentProperty) BindMarker(com.datastax.oss.driver.api.querybuilder.BindMarker) ClassUtils(org.springframework.util.ClassUtils) ColumnRelationBuilder(com.datastax.oss.driver.api.querybuilder.relation.ColumnRelationBuilder) Collection(java.util.Collection) Set(java.util.Set) Predicate(org.springframework.data.cassandra.core.query.CriteriaDefinition.Predicate) Collectors(java.util.stream.Collectors) Selector(org.springframework.data.cassandra.core.query.Columns.Selector) List(java.util.List) UpdateMapper(org.springframework.data.cassandra.core.convert.UpdateMapper) PropertyDescriptor(java.beans.PropertyDescriptor) QueryMapper(org.springframework.data.cassandra.core.convert.QueryMapper) Optional(java.util.Optional) AddToOp(org.springframework.data.cassandra.core.query.Update.AddToOp) NonNull(org.springframework.lang.NonNull) AssignmentOp(org.springframework.data.cassandra.core.query.Update.AssignmentOp) IncrOp(org.springframework.data.cassandra.core.query.Update.IncrOp) SetAtKeyOp(org.springframework.data.cassandra.core.query.Update.SetAtKeyOp) WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) AddToMapOp(org.springframework.data.cassandra.core.query.Update.AddToMapOp) UpdateStart(com.datastax.oss.driver.api.querybuilder.update.UpdateStart) OngoingAssignment(com.datastax.oss.driver.api.querybuilder.update.OngoingAssignment) Condition(com.datastax.oss.driver.api.querybuilder.condition.Condition) ClusteringOrder(com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder) CriteriaDefinition(org.springframework.data.cassandra.core.query.CriteriaDefinition) Filter(org.springframework.data.cassandra.core.query.Filter) Function(java.util.function.Function) CassandraPersistentProperty(org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ProjectionInformation(org.springframework.data.projection.ProjectionInformation) FunctionCall(org.springframework.data.cassandra.core.query.Columns.FunctionCall) StatementBuilder(org.springframework.data.cassandra.core.cql.util.StatementBuilder) Nullable(org.springframework.lang.Nullable) Mode(org.springframework.data.cassandra.core.query.Update.AddToOp.Mode) ConditionBuilder(com.datastax.oss.driver.api.querybuilder.condition.ConditionBuilder) EntityWriter(org.springframework.data.convert.EntityWriter) RegularInsert(com.datastax.oss.driver.api.querybuilder.insert.RegularInsert) Update(org.springframework.data.cassandra.core.query.Update) CassandraConverter(org.springframework.data.cassandra.core.convert.CassandraConverter) Query(org.springframework.data.cassandra.core.query.Query) QueryOptionsUtil(org.springframework.data.cassandra.core.cql.QueryOptionsUtil) Term(com.datastax.oss.driver.api.querybuilder.term.Term) Collections(java.util.Collections) Where(org.springframework.data.cassandra.core.convert.Where) Columns(org.springframework.data.cassandra.core.query.Columns) Assert(org.springframework.util.Assert) WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) Filter(org.springframework.data.cassandra.core.query.Filter) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier)

Example 3 with CassandraPersistentEntity

use of org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity in project spring-data-cassandra by spring-projects.

the class StatementFactory method update.

/**
 * Create an {@literal UPDATE} statement by mapping {@link Query} to {@link Update}.
 *
 * @param query must not be {@literal null}.
 * @param update must not be {@literal null}.
 * @param persistentEntity must not be {@literal null}.
 * @param tableName must not be {@literal null}.
 * @return the update builder.
 * @since 2.1
 */
StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update(Query query, Update update, CassandraPersistentEntity<?> persistentEntity, CqlIdentifier tableName) {
    Assert.notNull(query, "Query must not be null");
    Assert.notNull(update, "Update must not be null");
    Assert.notNull(persistentEntity, "CassandraPersistentEntity must not be null");
    Assert.notNull(tableName, "Table name must not be null");
    Filter filter = getQueryMapper().getMappedObject(query, persistentEntity);
    Update mappedUpdate = getUpdateMapper().getMappedObject(update, persistentEntity);
    StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> builder = update(tableName, mappedUpdate, filter);
    query.getQueryOptions().filter(UpdateOptions.class::isInstance).map(UpdateOptions.class::cast).map(UpdateOptions::getIfCondition).ifPresent(criteriaDefinitions -> applyUpdateIfCondition(builder, criteriaDefinitions));
    query.getQueryOptions().filter(WriteOptions.class::isInstance).map(WriteOptions.class::cast).ifPresent(writeOptions -> builder.apply(statement -> addWriteOptions(statement, writeOptions)));
    query.getQueryOptions().ifPresent(options -> builder.transform(statementBuilder -> QueryOptionsUtil.addQueryOptions(statementBuilder, options)));
    return builder;
}
Also used : QueryBuilder(com.datastax.oss.driver.api.querybuilder.QueryBuilder) QueryOptions(org.springframework.data.cassandra.core.cql.QueryOptions) TermFactory(org.springframework.data.cassandra.core.cql.util.TermFactory) Relation(com.datastax.oss.driver.api.querybuilder.relation.Relation) Assignment(com.datastax.oss.driver.api.querybuilder.update.Assignment) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) Insert(com.datastax.oss.driver.api.querybuilder.insert.Insert) Delete(com.datastax.oss.driver.api.querybuilder.delete.Delete) SetAtIndexOp(org.springframework.data.cassandra.core.query.Update.SetAtIndexOp) SetOp(org.springframework.data.cassandra.core.query.Update.SetOp) UpdateWithAssignments(com.datastax.oss.driver.api.querybuilder.update.UpdateWithAssignments) EntityProjection(org.springframework.data.projection.EntityProjection) DeleteSelection(com.datastax.oss.driver.api.querybuilder.delete.DeleteSelection) CassandraPersistentEntity(org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity) PersistentPropertyTranslator(org.springframework.data.cassandra.core.mapping.PersistentPropertyTranslator) Predicates(org.springframework.data.util.Predicates) Map(java.util.Map) RemoveOp(org.springframework.data.cassandra.core.query.Update.RemoveOp) Sort(org.springframework.data.domain.Sort) ColumnSelector(org.springframework.data.cassandra.core.query.Columns.ColumnSelector) Select(com.datastax.oss.driver.api.querybuilder.select.Select) PersistentProperty(org.springframework.data.mapping.PersistentProperty) BindMarker(com.datastax.oss.driver.api.querybuilder.BindMarker) ClassUtils(org.springframework.util.ClassUtils) ColumnRelationBuilder(com.datastax.oss.driver.api.querybuilder.relation.ColumnRelationBuilder) Collection(java.util.Collection) Set(java.util.Set) Predicate(org.springframework.data.cassandra.core.query.CriteriaDefinition.Predicate) Collectors(java.util.stream.Collectors) Selector(org.springframework.data.cassandra.core.query.Columns.Selector) List(java.util.List) UpdateMapper(org.springframework.data.cassandra.core.convert.UpdateMapper) PropertyDescriptor(java.beans.PropertyDescriptor) QueryMapper(org.springframework.data.cassandra.core.convert.QueryMapper) Optional(java.util.Optional) AddToOp(org.springframework.data.cassandra.core.query.Update.AddToOp) NonNull(org.springframework.lang.NonNull) AssignmentOp(org.springframework.data.cassandra.core.query.Update.AssignmentOp) IncrOp(org.springframework.data.cassandra.core.query.Update.IncrOp) SetAtKeyOp(org.springframework.data.cassandra.core.query.Update.SetAtKeyOp) WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) AddToMapOp(org.springframework.data.cassandra.core.query.Update.AddToMapOp) UpdateStart(com.datastax.oss.driver.api.querybuilder.update.UpdateStart) OngoingAssignment(com.datastax.oss.driver.api.querybuilder.update.OngoingAssignment) Condition(com.datastax.oss.driver.api.querybuilder.condition.Condition) ClusteringOrder(com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder) CriteriaDefinition(org.springframework.data.cassandra.core.query.CriteriaDefinition) Filter(org.springframework.data.cassandra.core.query.Filter) Function(java.util.function.Function) CassandraPersistentProperty(org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ProjectionInformation(org.springframework.data.projection.ProjectionInformation) FunctionCall(org.springframework.data.cassandra.core.query.Columns.FunctionCall) StatementBuilder(org.springframework.data.cassandra.core.cql.util.StatementBuilder) Nullable(org.springframework.lang.Nullable) Mode(org.springframework.data.cassandra.core.query.Update.AddToOp.Mode) ConditionBuilder(com.datastax.oss.driver.api.querybuilder.condition.ConditionBuilder) EntityWriter(org.springframework.data.convert.EntityWriter) RegularInsert(com.datastax.oss.driver.api.querybuilder.insert.RegularInsert) Update(org.springframework.data.cassandra.core.query.Update) CassandraConverter(org.springframework.data.cassandra.core.convert.CassandraConverter) Query(org.springframework.data.cassandra.core.query.Query) QueryOptionsUtil(org.springframework.data.cassandra.core.cql.QueryOptionsUtil) Term(com.datastax.oss.driver.api.querybuilder.term.Term) Collections(java.util.Collections) Where(org.springframework.data.cassandra.core.convert.Where) Columns(org.springframework.data.cassandra.core.query.Columns) Assert(org.springframework.util.Assert) WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) Filter(org.springframework.data.cassandra.core.query.Filter) Update(org.springframework.data.cassandra.core.query.Update)

Example 4 with CassandraPersistentEntity

use of org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity in project spring-data-cassandra by spring-projects.

the class StatementFactory method update.

/**
 * Create an {@literal UPDATE} statement by mapping {@code objectToUpdate} to {@link Update} considering
 * {@link UpdateOptions}.
 *
 * @param objectToUpdate must not be {@literal null}.
 * @param options must not be {@literal null}.
 * @param entity must not be {@literal null}.
 * @param tableName must not be {@literal null}.
 * @return the update builder.
 */
StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update(Object objectToUpdate, WriteOptions options, CassandraPersistentEntity<?> entity, CqlIdentifier tableName) {
    Assert.notNull(tableName, "TableName must not be null");
    Assert.notNull(objectToUpdate, "Object to builder must not be null");
    Assert.notNull(options, "WriteOptions must not be null");
    Assert.notNull(entity, "CassandraPersistentEntity must not be null");
    Where where = new Where();
    cassandraConverter.write(objectToUpdate, where, entity);
    Map<CqlIdentifier, Object> object = new LinkedHashMap<>();
    cassandraConverter.write(objectToUpdate, object, entity);
    where.forEach((cqlIdentifier, o) -> object.remove(cqlIdentifier));
    StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> builder = StatementBuilder.of(QueryBuilder.update(tableName).set().where()).bind((statement, factory) -> ((UpdateWithAssignments) statement).set(toAssignments(object, factory)).where(toRelations(where, factory))).apply(update -> addWriteOptions(update, options));
    Optional.of(options).filter(UpdateOptions.class::isInstance).map(UpdateOptions.class::cast).map(UpdateOptions::getIfCondition).ifPresent(criteriaDefinitions -> applyUpdateIfCondition(builder, criteriaDefinitions));
    builder.transform(statement -> QueryOptionsUtil.addQueryOptions(statement, options));
    return builder;
}
Also used : QueryBuilder(com.datastax.oss.driver.api.querybuilder.QueryBuilder) QueryOptions(org.springframework.data.cassandra.core.cql.QueryOptions) TermFactory(org.springframework.data.cassandra.core.cql.util.TermFactory) Relation(com.datastax.oss.driver.api.querybuilder.relation.Relation) Assignment(com.datastax.oss.driver.api.querybuilder.update.Assignment) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) Insert(com.datastax.oss.driver.api.querybuilder.insert.Insert) Delete(com.datastax.oss.driver.api.querybuilder.delete.Delete) SetAtIndexOp(org.springframework.data.cassandra.core.query.Update.SetAtIndexOp) SetOp(org.springframework.data.cassandra.core.query.Update.SetOp) UpdateWithAssignments(com.datastax.oss.driver.api.querybuilder.update.UpdateWithAssignments) EntityProjection(org.springframework.data.projection.EntityProjection) DeleteSelection(com.datastax.oss.driver.api.querybuilder.delete.DeleteSelection) CassandraPersistentEntity(org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity) PersistentPropertyTranslator(org.springframework.data.cassandra.core.mapping.PersistentPropertyTranslator) Predicates(org.springframework.data.util.Predicates) Map(java.util.Map) RemoveOp(org.springframework.data.cassandra.core.query.Update.RemoveOp) Sort(org.springframework.data.domain.Sort) ColumnSelector(org.springframework.data.cassandra.core.query.Columns.ColumnSelector) Select(com.datastax.oss.driver.api.querybuilder.select.Select) PersistentProperty(org.springframework.data.mapping.PersistentProperty) BindMarker(com.datastax.oss.driver.api.querybuilder.BindMarker) ClassUtils(org.springframework.util.ClassUtils) ColumnRelationBuilder(com.datastax.oss.driver.api.querybuilder.relation.ColumnRelationBuilder) Collection(java.util.Collection) Set(java.util.Set) Predicate(org.springframework.data.cassandra.core.query.CriteriaDefinition.Predicate) Collectors(java.util.stream.Collectors) Selector(org.springframework.data.cassandra.core.query.Columns.Selector) List(java.util.List) UpdateMapper(org.springframework.data.cassandra.core.convert.UpdateMapper) PropertyDescriptor(java.beans.PropertyDescriptor) QueryMapper(org.springframework.data.cassandra.core.convert.QueryMapper) Optional(java.util.Optional) AddToOp(org.springframework.data.cassandra.core.query.Update.AddToOp) NonNull(org.springframework.lang.NonNull) AssignmentOp(org.springframework.data.cassandra.core.query.Update.AssignmentOp) IncrOp(org.springframework.data.cassandra.core.query.Update.IncrOp) SetAtKeyOp(org.springframework.data.cassandra.core.query.Update.SetAtKeyOp) WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) AddToMapOp(org.springframework.data.cassandra.core.query.Update.AddToMapOp) UpdateStart(com.datastax.oss.driver.api.querybuilder.update.UpdateStart) OngoingAssignment(com.datastax.oss.driver.api.querybuilder.update.OngoingAssignment) Condition(com.datastax.oss.driver.api.querybuilder.condition.Condition) ClusteringOrder(com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder) CriteriaDefinition(org.springframework.data.cassandra.core.query.CriteriaDefinition) Filter(org.springframework.data.cassandra.core.query.Filter) Function(java.util.function.Function) CassandraPersistentProperty(org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ProjectionInformation(org.springframework.data.projection.ProjectionInformation) FunctionCall(org.springframework.data.cassandra.core.query.Columns.FunctionCall) StatementBuilder(org.springframework.data.cassandra.core.cql.util.StatementBuilder) Nullable(org.springframework.lang.Nullable) Mode(org.springframework.data.cassandra.core.query.Update.AddToOp.Mode) ConditionBuilder(com.datastax.oss.driver.api.querybuilder.condition.ConditionBuilder) EntityWriter(org.springframework.data.convert.EntityWriter) RegularInsert(com.datastax.oss.driver.api.querybuilder.insert.RegularInsert) Update(org.springframework.data.cassandra.core.query.Update) CassandraConverter(org.springframework.data.cassandra.core.convert.CassandraConverter) Query(org.springframework.data.cassandra.core.query.Query) QueryOptionsUtil(org.springframework.data.cassandra.core.cql.QueryOptionsUtil) Term(com.datastax.oss.driver.api.querybuilder.term.Term) Collections(java.util.Collections) Where(org.springframework.data.cassandra.core.convert.Where) Columns(org.springframework.data.cassandra.core.query.Columns) Assert(org.springframework.util.Assert) Update(org.springframework.data.cassandra.core.query.Update) Where(org.springframework.data.cassandra.core.convert.Where) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with CassandraPersistentEntity

use of org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity in project spring-data-cassandra by spring-projects.

the class AsyncCassandraTemplate method selectOneById.

/* (non-Javadoc)
	 * @see org.springframework.data.cassandra.core.AsyncCassandraOperations#selectOneById(java.lang.Object, java.lang.Class)
	 */
@Override
public <T> ListenableFuture<T> selectOneById(Object id, Class<T> 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<Select> select = getStatementFactory().selectOneById(id, entity, tableName);
    Function<Row, T> mapper = getMapper(entityClass, entityClass, tableName);
    return new MappingListenableFutureAdapter<>(doQuery(select.build(), (row, rowNum) -> mapper.apply(row)), it -> it.isEmpty() ? null : it.get(0));
}
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) BeforeSaveCallback(org.springframework.data.cassandra.core.mapping.event.BeforeSaveCallback) 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) PersistenceExceptionTranslator(org.springframework.dao.support.PersistenceExceptionTranslator) AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) OptimisticLockingFailureException(org.springframework.dao.OptimisticLockingFailureException) DriverException(com.datastax.oss.driver.api.core.DriverException) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) AfterDeleteEvent(org.springframework.data.cassandra.core.mapping.event.AfterDeleteEvent) AsyncResult(org.springframework.scheduling.annotation.AsyncResult) Select(com.datastax.oss.driver.api.querybuilder.select.Select) Update(com.datastax.oss.driver.api.querybuilder.update.Update) BoundStatement(com.datastax.oss.driver.api.core.cql.BoundStatement) CassandraMappingEvent(org.springframework.data.cassandra.core.mapping.event.CassandraMappingEvent) Truncate(com.datastax.oss.driver.api.querybuilder.truncate.Truncate) Collectors(java.util.stream.Collectors) org.springframework.data.cassandra.core.cql(org.springframework.data.cassandra.core.cql) Slice(org.springframework.data.domain.Slice) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) BeforeDeleteEvent(org.springframework.data.cassandra.core.mapping.event.BeforeDeleteEvent) Streamable(org.springframework.data.util.Streamable) 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) SessionFactory(org.springframework.data.cassandra.SessionFactory) DefaultSessionFactory(org.springframework.data.cassandra.core.cql.session.DefaultSessionFactory) DataAccessException(org.springframework.dao.DataAccessException) ListenableFuture(org.springframework.util.concurrent.ListenableFuture) AfterConvertEvent(org.springframework.data.cassandra.core.mapping.event.AfterConvertEvent) ProjectionFactory(org.springframework.data.projection.ProjectionFactory) Function(java.util.function.Function) BeforeConvertCallback(org.springframework.data.cassandra.core.mapping.event.BeforeConvertCallback) CassandraFutureAdapter(org.springframework.data.cassandra.core.cql.util.CassandraFutureAdapter) DefaultDriverOption(com.datastax.oss.driver.api.core.config.DefaultDriverOption) CqlSession(com.datastax.oss.driver.api.core.CqlSession) StatementBuilder(org.springframework.data.cassandra.core.cql.util.StatementBuilder) AfterSaveEvent(org.springframework.data.cassandra.core.mapping.event.AfterSaveEvent) StreamSupport(java.util.stream.StreamSupport) 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) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) 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) Consumer(java.util.function.Consumer) 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) Assert(org.springframework.util.Assert) Select(com.datastax.oss.driver.api.querybuilder.select.Select) Row(com.datastax.oss.driver.api.core.cql.Row) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier)

Aggregations

CassandraPersistentEntity (org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity)8 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)7 Collections (java.util.Collections)7 List (java.util.List)7 CassandraPersistentProperty (org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty)7 ArrayList (java.util.ArrayList)6 Optional (java.util.Optional)6 Set (java.util.Set)6 Nullable (org.springframework.lang.Nullable)6 Assert (org.springframework.util.Assert)6 QueryBuilder (com.datastax.oss.driver.api.querybuilder.QueryBuilder)5 Delete (com.datastax.oss.driver.api.querybuilder.delete.Delete)5 Insert (com.datastax.oss.driver.api.querybuilder.insert.Insert)5 RegularInsert (com.datastax.oss.driver.api.querybuilder.insert.RegularInsert)5 Select (com.datastax.oss.driver.api.querybuilder.select.Select)5 Function (java.util.function.Function)5 Collectors (java.util.stream.Collectors)5 CassandraConverter (org.springframework.data.cassandra.core.convert.CassandraConverter)5 StatementBuilder (org.springframework.data.cassandra.core.cql.util.StatementBuilder)5 Columns (org.springframework.data.cassandra.core.query.Columns)5