use of org.springframework.data.relational.core.query.CriteriaDefinition in project gravitee-access-management by gravitee-io.
the class JdbcResourceRepository method findByDomainAndClient.
@Override
public Single<Page<Resource>> findByDomainAndClient(String domain, String client, int page, int size) {
LOGGER.debug("findByDomainAndClient({}, {}, {}, {})", domain, client, page, size);
CriteriaDefinition whereClause = from(where("domain").is(domain).and(where("client_id").is(client)));
return findResourcePage(domain, page, size, whereClause);
}
use of org.springframework.data.relational.core.query.CriteriaDefinition in project r2dbc-dsl by SevenParadigms.
the class DefaultStatementMapper method getMappedObject.
private PreparedOperation<Delete> getMappedObject(DeleteSpec deleteSpec, @Nullable RelationalPersistentEntity<?> entity) {
BindMarkers bindMarkers = this.dialect.getBindMarkersFactory().create();
Table table = Table.create(toSql(deleteSpec.getTable()));
DeleteBuilder.DeleteWhere deleteBuilder = StatementBuilder.delete(table);
Bindings bindings = Bindings.empty();
Delete delete;
CriteriaDefinition criteria = deleteSpec.getCriteria();
if (criteria != null && !criteria.isEmpty()) {
BoundCondition boundCondition = this.updateMapper.getMappedObject(bindMarkers, deleteSpec.getCriteria(), table, entity);
bindings = boundCondition.getBindings();
delete = deleteBuilder.where(boundCondition.getCondition()).build();
} else {
delete = deleteBuilder.build();
}
return new DefaultPreparedOperation<>(delete, this.renderContext, bindings);
}
use of org.springframework.data.relational.core.query.CriteriaDefinition in project r2dbc-dsl by SevenParadigms.
the class R2dbcEntityTemplate method doExists.
Mono<Boolean> doExists(Query query, Class<?> entityClass, SqlIdentifier tableName) {
StatementMapper statementMapper = dataAccessStrategy.getStatementMapper().forType(entityClass);
SqlIdentifier columnName = SqlIdentifier.unquoted("*");
if (isIdContains(entityClass)) {
columnName = new DefaultSqlIdentifier(SqlField.id, false);
} else {
RelationalPersistentEntity<?> entity = getRequiredEntity(entityClass);
if (entity.hasIdProperty()) {
columnName = entity.getRequiredIdProperty().getColumnName();
}
}
StatementMapper.SelectSpec selectSpec = //
statementMapper.createSelect(//
tableName).withProjection(//
columnName).limit(1);
Optional<CriteriaDefinition> criteria = query.getCriteria();
if (criteria.isPresent()) {
selectSpec = criteria.map(selectSpec::withCriteria).orElse(selectSpec);
}
PreparedOperation<?> operation = statementMapper.getMappedObject(selectSpec);
return //
this.databaseClient.sql(operation).map(//
(r, md) -> r).first().hasElement();
}
use of org.springframework.data.relational.core.query.CriteriaDefinition in project r2dbc-dsl by SevenParadigms.
the class QueryMapper method unroll.
private Condition unroll(CriteriaDefinition criteria, Table table, @Nullable RelationalPersistentEntity<?> entity, MutableBindings bindings) {
CriteriaDefinition current = criteria;
// reverse unroll criteria chain
Map<CriteriaDefinition, CriteriaDefinition> forwardChain = new HashMap<>();
while (current.hasPrevious()) {
forwardChain.put(current.getPrevious(), current);
current = current.getPrevious();
}
// perform the actual mapping
Condition mapped = getCondition(current, bindings, table, entity);
while (forwardChain.containsKey(current)) {
CriteriaDefinition criterion = forwardChain.get(current);
Condition result = null;
Condition condition = getCondition(criterion, bindings, table, entity);
if (condition != null) {
result = combine(criterion, mapped, criterion.getCombinator(), condition);
}
if (result != null) {
mapped = result;
}
current = criterion;
}
if (mapped == null) {
throw new IllegalStateException("Cannot map empty Criteria");
}
return mapped;
}
use of org.springframework.data.relational.core.query.CriteriaDefinition in project spring-data-jdbc by spring-projects.
the class QueryMapper method unroll.
private Condition unroll(CriteriaDefinition criteria, Table table, @Nullable RelationalPersistentEntity<?> entity, MapSqlParameterSource parameterSource) {
CriteriaDefinition current = criteria;
// reverse unroll criteria chain
Map<CriteriaDefinition, CriteriaDefinition> forwardChain = new HashMap<>();
while (current.hasPrevious()) {
forwardChain.put(current.getPrevious(), current);
current = current.getPrevious();
}
// perform the actual mapping
Condition mapped = getCondition(current, parameterSource, table, entity);
while (forwardChain.containsKey(current)) {
CriteriaDefinition criterion = forwardChain.get(current);
Condition result = null;
Condition condition = getCondition(criterion, parameterSource, table, entity);
if (condition != null) {
result = combine(mapped, criterion.getCombinator(), condition);
}
if (result != null) {
mapped = result;
}
current = criterion;
}
if (mapped == null) {
throw new IllegalStateException("Cannot map empty Criteria");
}
return mapped;
}
Aggregations