Browse Source

Polishing.

Use consistent method and argument names for newly introduced methods. Reorder and group template API methods to keep related methods together.

See: #1315
Original pull request: #1324.
pull/1348/head
Mark Paluch 3 years ago committed by Jens Schauder
parent
commit
26c5c5dd93
  1. 213
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateOperations.java
  2. 51
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateTemplate.java
  3. 20
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/CascadingDataAccessStrategy.java
  4. 71
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DataAccessStrategy.java
  5. 26
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java
  6. 20
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DelegatingDataAccessStrategy.java
  7. 10
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/FetchableFluentQueryByExample.java
  8. 7
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/SimpleJdbcRepository.java

213
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateOperations.java

@ -82,95 +82,42 @@ public interface JdbcAggregateOperations { @@ -82,95 +82,42 @@ public interface JdbcAggregateOperations {
<T> T update(T instance);
/**
* Deletes a single Aggregate including all entities contained in that aggregate.
* <p>
* Since no version attribute is provided this method will never throw a
* {@link org.springframework.dao.OptimisticLockingFailureException}. If no rows match the generated delete operation
* this fact will be silently ignored.
* </p>
* Counts the number of aggregates of a given type.
*
* @param id the id of the aggregate root of the aggregate to be deleted. Must not be {@code null}.
* @param domainType the type of the aggregate root.
* @param <T> the type of the aggregate root.
* @param domainType the type of the aggregates to be counted.
* @return the number of instances stored in the database. Guaranteed to be not {@code null}.
*/
<T> void deleteById(Object id, Class<T> domainType);
long count(Class<?> domainType);
/**
* Deletes all aggregates identified by their aggregate root ids.
* <p>
* Since no version attribute is provided this method will never throw a
* {@link org.springframework.dao.OptimisticLockingFailureException}. If no rows match the generated delete operation
* this fact will be silently ignored.
* </p>
* Counts the number of aggregates of a given type that match the given <code>query</code>.
*
* @param ids the ids of the aggregate roots of the aggregates to be deleted. Must not be {@code null}.
* @param domainType the type of the aggregate root.
* @param <T> the type of the aggregate root.
* @param query must not be {@literal null}.
* @param domainType the entity type must not be {@literal null}.
* @return the number of instances stored in the database. Guaranteed to be not {@code null}.
* @since 3.0
*/
<T> void deleteAllById(Iterable<?> ids, Class<T> domainType);
<T> long count(Query query, Class<T> domainType);
/**
* Delete an aggregate identified by its aggregate root.
* Determine whether there are aggregates that match the {@link Query}
*
* @param aggregateRoot to delete. Must not be {@code null}.
* @param <T> the type of the aggregate root.
* @param query must not be {@literal null}.
* @param domainType the entity type must not be {@literal null}.
* @return {@literal true} if the object exists.
* @since 3.0
*/
<T> void delete(T aggregateRoot);
<T> boolean exists(Query query, Class<T> domainType);
/**
* Delete an aggregate identified by its aggregate root.
* Checks if an aggregate identified by type and id exists in the database.
*
* @param aggregateRoot to delete. Must not be {@code null}.
* @param domainType the type of the aggregate root. Must not be {@code null}.
* @param id the id of the aggregate root.
* @param domainType the type of the aggregate root.
* @param <T> the type of the aggregate root.
* @throws org.springframework.dao.OptimisticLockingFailureException when {@literal T} has a version attribute and the
* version attribute of the provided entity does not match the version attribute in the database, or when
* there is no aggregate root with matching id. In other cases a NOOP delete is silently ignored.
* @deprecated since 3.0 use {@link #delete(Object)} instead
*/
@Deprecated
default <T> void delete(T aggregateRoot, Class<T> domainType) {
delete(aggregateRoot);
}
/**
* Delete all aggregates of a given type.
*
* @param domainType type of the aggregate roots to be deleted. Must not be {@code null}.
*/
void deleteAll(Class<?> domainType);
/**
* Delete all aggregates identified by their aggregate roots.
*
* @param aggregateRoots to delete. Must not be {@code null}.
* @param <T> the type of the aggregate roots.
*/
<T> void deleteAll(Iterable<? extends T> aggregateRoots);
/**
* Delete all aggregates identified by their aggregate roots.
*
* @param aggregateRoots to delete. Must not be {@code null}.
* @param domainType type of the aggregate roots to be deleted. Must not be {@code null}.
* @param <T> the type of the aggregate roots.
* @throws org.springframework.dao.OptimisticLockingFailureException when {@literal T} has a version attribute and for at least on entity the
* version attribute of the entity does not match the version attribute in the database, or when
* there is no aggregate root with matching id. In other cases a NOOP delete is silently ignored.
* @deprecated since 3.0 use {@link #deleteAll(Iterable)} instead.
*/
@Deprecated
default <T> void deleteAll(Iterable<? extends T> aggregateRoots, Class<T> domainType) {
deleteAll(aggregateRoots);
}
/**
* Counts the number of aggregates of a given type.
*
* @param domainType the type of the aggregates to be counted.
* @return the number of instances stored in the database. Guaranteed to be not {@code null}.
* @return whether the aggregate exists.
*/
long count(Class<?> domainType);
<T> boolean existsById(Object id, Class<T> domainType);
/**
* Load an aggregate from the database.
@ -202,16 +149,6 @@ public interface JdbcAggregateOperations { @@ -202,16 +149,6 @@ public interface JdbcAggregateOperations {
*/
<T> Iterable<T> findAll(Class<T> domainType);
/**
* Checks if an aggregate identified by type and id exists in the database.
*
* @param id the id of the aggregate root.
* @param domainType the type of the aggregate root.
* @param <T> the type of the aggregate root.
* @return whether the aggregate exists.
*/
<T> boolean existsById(Object id, Class<T> domainType);
/**
* Load all aggregates of a given type, sorted.
*
@ -238,53 +175,117 @@ public interface JdbcAggregateOperations { @@ -238,53 +175,117 @@ public interface JdbcAggregateOperations {
* Execute a {@code SELECT} query and convert the resulting item to an entity ensuring exactly one result.
*
* @param query must not be {@literal null}.
* @param entityClass the entity type must not be {@literal null}.
* @param domainType the entity type must not be {@literal null}.
* @return exactly one result or {@link Optional#empty()} if no match found.
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if more than one match found.
* @since 3.0
*/
<T> Optional<T> selectOne(Query query, Class<T> entityClass);
<T> Optional<T> findOne(Query query, Class<T> domainType);
/**
* Execute a {@code SELECT} query and convert the resulting items to a {@link Iterable} that is sorted.
*
* @param query must not be {@literal null}.
* @param entityClass the entity type must not be {@literal null}.
* @param domainType the entity type must not be {@literal null}.
* @return a non-null sorted list with all the matching results.
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if more than one match found.
* @since 3.0
*/
<T> Iterable<T> select(Query query, Class<T> entityClass);
<T> Iterable<T> findAll(Query query, Class<T> domainType);
/**
* Determine whether there are aggregates that match the {@link Query}
* Returns a {@link Page} of entities matching the given {@link Query}. In case no match could be found, an empty
* {@link Page} is returned.
*
* @param query must not be {@literal null}.
* @param entityClass the entity type must not be {@literal null}.
* @return {@literal true} if the object exists.
* @param domainType the entity type must not be {@literal null}.
* @param pageable can be null.
* @return a {@link Page} of entities matching the given {@link Example}.
* @since 3.0
*/
<T> boolean exists(Query query, Class<T> entityClass);
<T> Page<T> findAll(Query query, Class<T> domainType, Pageable pageable);
/**
* Counts the number of aggregates of a given type that match the given <code>query</code>.
* Deletes a single Aggregate including all entities contained in that aggregate.
* <p>
* Since no version attribute is provided this method will never throw a
* {@link org.springframework.dao.OptimisticLockingFailureException}. If no rows match the generated delete operation
* this fact will be silently ignored.
* </p>
*
* @param query must not be {@literal null}.
* @param entityClass the entity type must not be {@literal null}.
* @return the number of instances stored in the database. Guaranteed to be not {@code null}.
* @since 3.0
* @param id the id of the aggregate root of the aggregate to be deleted. Must not be {@code null}.
* @param domainType the type of the aggregate root.
* @param <T> the type of the aggregate root.
*/
<T> long count(Query query, Class<T> entityClass);
<T> void deleteById(Object id, Class<T> domainType);
/**
* Returns a {@link Page} of entities matching the given {@link Query}. In case no match could be found, an empty
* {@link Page} is returned.
* Deletes all aggregates identified by their aggregate root ids.
* <p>
* Since no version attribute is provided this method will never throw a
* {@link org.springframework.dao.OptimisticLockingFailureException}. If no rows match the generated delete operation
* this fact will be silently ignored.
* </p>
*
* @param query must not be {@literal null}.
* @param entityClass the entity type must not be {@literal null}.
* @param pageable can be null.
* @return a {@link Page} of entities matching the given {@link Example}.
* @since 3.0
* @param ids the ids of the aggregate roots of the aggregates to be deleted. Must not be {@code null}.
* @param domainType the type of the aggregate root.
* @param <T> the type of the aggregate root.
*/
<T> Page<T> select(Query query, Class<T> entityClass, Pageable pageable);
<T> void deleteAllById(Iterable<?> ids, Class<T> domainType);
/**
* Delete an aggregate identified by its aggregate root.
*
* @param aggregateRoot to delete. Must not be {@code null}.
* @param <T> the type of the aggregate root.
*/
<T> void delete(T aggregateRoot);
/**
* Delete an aggregate identified by its aggregate root.
*
* @param aggregateRoot to delete. Must not be {@code null}.
* @param domainType the type of the aggregate root. Must not be {@code null}.
* @param <T> the type of the aggregate root.
* @throws org.springframework.dao.OptimisticLockingFailureException when {@literal T} has a version attribute and the
* version attribute of the provided entity does not match the version attribute in the database, or when
* there is no aggregate root with matching id. In other cases a NOOP delete is silently ignored.
* @deprecated since 3.0 use {@link #delete(Object)} instead
*/
@Deprecated(since = "3.0")
default <T> void delete(T aggregateRoot, Class<T> domainType) {
delete(aggregateRoot);
}
/**
* Delete all aggregates of a given type.
*
* @param domainType type of the aggregate roots to be deleted. Must not be {@code null}.
*/
void deleteAll(Class<?> domainType);
/**
* Delete all aggregates identified by their aggregate roots.
*
* @param aggregateRoots to delete. Must not be {@code null}.
* @param <T> the type of the aggregate roots.
*/
<T> void deleteAll(Iterable<? extends T> aggregateRoots);
/**
* Delete all aggregates identified by their aggregate roots.
*
* @param aggregateRoots to delete. Must not be {@code null}.
* @param domainType type of the aggregate roots to be deleted. Must not be {@code null}.
* @param <T> the type of the aggregate roots.
* @throws org.springframework.dao.OptimisticLockingFailureException when {@literal T} has a version attribute and for
* at least on entity the version attribute of the entity does not match the version attribute in the
* database, or when there is no aggregate root with matching id. In other cases a NOOP delete is silently
* ignored.
* @deprecated since 3.0 use {@link #deleteAll(Iterable)} instead.
*/
@Deprecated(since = "3.0")
default <T> void deleteAll(Iterable<? extends T> aggregateRoots, Class<T> domainType) {
deleteAll(aggregateRoots);
}
}

51
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateTemplate.java

@ -214,25 +214,35 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations { @@ -214,25 +214,35 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
}
@Override
public <T> T findById(Object id, Class<T> domainType) {
public <T> long count(Query query, Class<T> domainType) {
return accessStrategy.count(query, domainType);
}
@Override
public <T> boolean exists(Query query, Class<T> domainType) {
return accessStrategy.exists(query, domainType);
}
@Override
public <T> boolean existsById(Object id, Class<T> domainType) {
Assert.notNull(id, "Id must not be null");
Assert.notNull(domainType, "Domain type must not be null");
T entity = accessStrategy.findById(id, domainType);
if (entity == null) {
return null;
}
return triggerAfterConvert(entity);
return accessStrategy.existsById(id, domainType);
}
@Override
public <T> boolean existsById(Object id, Class<T> domainType) {
public <T> T findById(Object id, Class<T> domainType) {
Assert.notNull(id, "Id must not be null");
Assert.notNull(domainType, "Domain type must not be null");
return accessStrategy.existsById(id, domainType);
T entity = accessStrategy.findById(id, domainType);
if (entity == null) {
return null;
}
return triggerAfterConvert(entity);
}
@Override
@ -256,32 +266,22 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations { @@ -256,32 +266,22 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
}
@Override
public <T> Optional<T> selectOne(Query query, Class<T> entityClass) {
return accessStrategy.selectOne(query, entityClass);
public <T> Optional<T> findOne(Query query, Class<T> domainType) {
return accessStrategy.findOne(query, domainType);
}
@Override
public <T> Iterable<T> select(Query query, Class<T> entityClass) {
return accessStrategy.select(query, entityClass);
public <T> Iterable<T> findAll(Query query, Class<T> domainType) {
return accessStrategy.findAll(query, domainType);
}
@Override
public <T> boolean exists(Query query, Class<T> entityClass) {
return accessStrategy.exists(query, entityClass);
}
@Override
public <T> long count(Query query, Class<T> entityClass) {
return accessStrategy.count(query, entityClass);
}
public <T> Page<T> findAll(Query query, Class<T> domainType, Pageable pageable) {
@Override
public <T> Page<T> select(Query query, Class<T> entityClass, Pageable pageable) {
Iterable<T> items = triggerAfterConvert(accessStrategy.select(query, entityClass, pageable));
Iterable<T> items = triggerAfterConvert(accessStrategy.findAll(query, domainType, pageable));
List<T> content = StreamSupport.stream(items.spliterator(), false).collect(Collectors.toList());
return PageableExecutionUtils.getPage(content, pageable, () -> accessStrategy.count(query, entityClass));
return PageableExecutionUtils.getPage(content, pageable, () -> accessStrategy.count(query, domainType));
}
@Override
@ -373,7 +373,6 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations { @@ -373,7 +373,6 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
private <T> void doDeleteAll(Iterable<? extends T> instances, Class<T> domainType) {
BatchingAggregateChange<T, DeleteAggregateChange<T>> batchingAggregateChange = BatchingAggregateChange
.forDelete(domainType);
Map<Object, T> instancesBeforeExecute = new LinkedHashMap<>();

20
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/CascadingDataAccessStrategy.java

@ -159,28 +159,28 @@ public class CascadingDataAccessStrategy implements DataAccessStrategy { @@ -159,28 +159,28 @@ public class CascadingDataAccessStrategy implements DataAccessStrategy {
}
@Override
public <T> Optional<T> selectOne(Query query, Class<T> probeType) {
return collect(das -> das.selectOne(query, probeType));
public <T> Optional<T> findOne(Query query, Class<T> domainType) {
return collect(das -> das.findOne(query, domainType));
}
@Override
public <T> Iterable<T> select(Query query, Class<T> probeType) {
return collect(das -> das.select(query, probeType));
public <T> Iterable<T> findAll(Query query, Class<T> domainType) {
return collect(das -> das.findAll(query, domainType));
}
@Override
public <T> Iterable<T> select(Query query, Class<T> probeType, Pageable pageable) {
return collect(das -> das.select(query, probeType, pageable));
public <T> Iterable<T> findAll(Query query, Class<T> domainType, Pageable pageable) {
return collect(das -> das.findAll(query, domainType, pageable));
}
@Override
public <T> boolean exists(Query query, Class<T> probeType) {
return collect(das -> das.exists(query, probeType));
public <T> boolean exists(Query query, Class<T> domainType) {
return collect(das -> das.exists(query, domainType));
}
@Override
public <T> long count(Query query, Class<T> probeType) {
return collect(das -> das.count(query, probeType));
public <T> long count(Query query, Class<T> domainType) {
return collect(das -> das.count(query, domainType));
}
private <T> T collect(Function<DataAccessStrategy, T> function) {

71
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DataAccessStrategy.java

@ -200,6 +200,36 @@ public interface DataAccessStrategy extends RelationResolver { @@ -200,6 +200,36 @@ public interface DataAccessStrategy extends RelationResolver {
*/
long count(Class<?> domainType);
/**
* Counts the rows in the table representing the given probe type, that match the given <code>query</code>.
*
* @param domainType the probe type for which to count the elements. Must not be {@code null}.
* @param query the query which elements have to match.
* @return the count. Guaranteed to be not {@code null}.
* @since 3.0
*/
<T> long count(Query query, Class<T> domainType);
/**
* Determine whether there is an aggregate of type <code>domainType</code> that matches the provided {@link Query}.
*
* @param query must not be {@literal null}.
* @param domainType the type of entities. Must not be {@code null}.
* @return {@literal true} if the object exists.
* @since 3.0
*/
<T> boolean exists(Query query, Class<T> domainType);
/**
* returns if a row with the given id exists for the given type.
*
* @param id the id of the entity for which to check. Must not be {@code null}.
* @param domainType the type of the entity to check for. Must not be {@code null}.
* @param <T> the type of the entity.
* @return {@code true} if a matching row exists, otherwise {@code false}.
*/
<T> boolean existsById(Object id, Class<T> domainType);
/**
* Loads a single entity identified by type and id.
*
@ -235,16 +265,6 @@ public interface DataAccessStrategy extends RelationResolver { @@ -235,16 +265,6 @@ public interface DataAccessStrategy extends RelationResolver {
Iterable<Object> findAllByPath(Identifier identifier,
PersistentPropertyPath<? extends RelationalPersistentProperty> path);
/**
* returns if a row with the given id exists for the given type.
*
* @param id the id of the entity for which to check. Must not be {@code null}.
* @param domainType the type of the entity to check for. Must not be {@code null}.
* @param <T> the type of the entity.
* @return {@code true} if a matching row exists, otherwise {@code false}.
*/
<T> boolean existsById(Object id, Class<T> domainType);
/**
* Loads all entities of the given type, sorted.
*
@ -271,54 +291,35 @@ public interface DataAccessStrategy extends RelationResolver { @@ -271,54 +291,35 @@ public interface DataAccessStrategy extends RelationResolver {
* Execute a {@code SELECT} query and convert the resulting item to an entity ensuring exactly one result.
*
* @param query must not be {@literal null}.
* @param probeType the type of entities. Must not be {@code null}.
* @param domainType the type of entities. Must not be {@code null}.
* @return exactly one result or {@link Optional#empty()} if no match found.
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if more than one match found.
* @since 3.0
*/
<T> Optional<T> selectOne(Query query, Class<T> probeType);
<T> Optional<T> findOne(Query query, Class<T> domainType);
/**
* Execute a {@code SELECT} query and convert the resulting items to a {@link Iterable}.
*
* @param query must not be {@literal null}.
* @param probeType the type of entities. Must not be {@code null}.
* @param domainType the type of entities. Must not be {@code null}.
* @return a non-null list with all the matching results.
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if more than one match found.
* @since 3.0
*/
<T> Iterable<T> select(Query query, Class<T> probeType);
<T> Iterable<T> findAll(Query query, Class<T> domainType);
/**
* Execute a {@code SELECT} query and convert the resulting items to a {@link Iterable}. Applies the {@link Pageable}
* to the result.
*
* @param query must not be {@literal null}.
* @param probeType the type of entities. Must not be {@literal null}.
* @param domainType the type of entities. Must not be {@literal null}.
* @param pageable the pagination that should be applied. Must not be {@literal null}.
* @return a non-null list with all the matching results.
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if more than one match found.
* @since 3.0
*/
<T> Iterable<T> select(Query query, Class<T> probeType, Pageable pageable);
/**
* Determine whether there is an aggregate of type <code>probeType</code> that matches the provided {@link Query}.
*
* @param query must not be {@literal null}.
* @param probeType the type of entities. Must not be {@code null}.
* @return {@literal true} if the object exists.
* @since 3.0
*/
<T> boolean exists(Query query, Class<T> probeType);
<T> Iterable<T> findAll(Query query, Class<T> domainType, Pageable pageable);
/**
* Counts the rows in the table representing the given probe type, that match the given <code>query</code>.
*
* @param probeType the probe type for which to count the elements. Must not be {@code null}.
* @param query the query which elements have to match.
* @return the count. Guaranteed to be not {@code null}.
* @since 3.0
*/
<T> long count(Query query, Class<T> probeType);
}

26
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java

@ -333,42 +333,42 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy { @@ -333,42 +333,42 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy {
}
@Override
public <T> Optional<T> selectOne(Query query, Class<T> probeType) {
public <T> Optional<T> findOne(Query query, Class<T> domainType) {
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
String sqlQuery = sql(probeType).selectByQuery(query, parameterSource);
String sqlQuery = sql(domainType).selectByQuery(query, parameterSource);
try {
return Optional.ofNullable(
operations.queryForObject(sqlQuery, parameterSource, getEntityRowMapper(probeType)));
operations.queryForObject(sqlQuery, parameterSource, getEntityRowMapper(domainType)));
} catch (EmptyResultDataAccessException e) {
return Optional.empty();
}
}
@Override
public <T> Iterable<T> select(Query query, Class<T> probeType) {
public <T> Iterable<T> findAll(Query query, Class<T> domainType) {
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
String sqlQuery = sql(probeType).selectByQuery(query, parameterSource);
String sqlQuery = sql(domainType).selectByQuery(query, parameterSource);
return operations.query(sqlQuery, parameterSource, getEntityRowMapper(probeType));
return operations.query(sqlQuery, parameterSource, getEntityRowMapper(domainType));
}
@Override
public <T> Iterable<T> select(Query query, Class<T> probeType, Pageable pageable) {
public <T> Iterable<T> findAll(Query query, Class<T> domainType, Pageable pageable) {
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
String sqlQuery = sql(probeType).selectByQuery(query, parameterSource, pageable);
String sqlQuery = sql(domainType).selectByQuery(query, parameterSource, pageable);
return operations.query(sqlQuery, parameterSource, getEntityRowMapper(probeType));
return operations.query(sqlQuery, parameterSource, getEntityRowMapper(domainType));
}
@Override
public <T> boolean exists(Query query, Class<T> probeType) {
public <T> boolean exists(Query query, Class<T> domainType) {
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
String sqlQuery = sql(probeType).existsByQuery(query, parameterSource);
String sqlQuery = sql(domainType).existsByQuery(query, parameterSource);
Boolean result = operations.queryForObject(sqlQuery, parameterSource, Boolean.class);
@ -378,10 +378,10 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy { @@ -378,10 +378,10 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy {
}
@Override
public <T> long count(Query query, Class<T> probeType) {
public <T> long count(Query query, Class<T> domainType) {
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
String sqlQuery = sql(probeType).countByQuery(query, parameterSource);
String sqlQuery = sql(domainType).countByQuery(query, parameterSource);
Long result = operations.queryForObject(sqlQuery, parameterSource, Long.class);

20
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DelegatingDataAccessStrategy.java

@ -154,28 +154,28 @@ public class DelegatingDataAccessStrategy implements DataAccessStrategy { @@ -154,28 +154,28 @@ public class DelegatingDataAccessStrategy implements DataAccessStrategy {
}
@Override
public <T> Optional<T> selectOne(Query query, Class<T> probeType) {
return delegate.selectOne(query, probeType);
public <T> Optional<T> findOne(Query query, Class<T> domainType) {
return delegate.findOne(query, domainType);
}
@Override
public <T> Iterable<T> select(Query query, Class<T> probeType) {
return delegate.select(query, probeType);
public <T> Iterable<T> findAll(Query query, Class<T> domainType) {
return delegate.findAll(query, domainType);
}
@Override
public <T> Iterable<T> select(Query query, Class<T> probeType, Pageable pageable) {
return delegate.select(query, probeType, pageable);
public <T> Iterable<T> findAll(Query query, Class<T> domainType, Pageable pageable) {
return delegate.findAll(query, domainType, pageable);
}
@Override
public <T> boolean exists(Query query, Class<T> probeType) {
return delegate.exists(query, probeType);
public <T> boolean exists(Query query, Class<T> domainType) {
return delegate.exists(query, domainType);
}
@Override
public <T> long count(Query query, Class<T> probeType) {
return delegate.count(query, probeType);
public <T> long count(Query query, Class<T> domainType) {
return delegate.count(query, domainType);
}
/**

10
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/FetchableFluentQueryByExample.java

@ -58,7 +58,7 @@ class FetchableFluentQueryByExample<S, R> extends FluentQuerySupport<S, R> { @@ -58,7 +58,7 @@ class FetchableFluentQueryByExample<S, R> extends FluentQuerySupport<S, R> {
@Override
public R oneValue() {
return this.entityOperations.selectOne(createQuery(), getExampleType())
return this.entityOperations.findOne(createQuery(), getExampleType())
.map(item -> this.getConversionFunction().apply(item)).get();
}
@ -66,21 +66,21 @@ class FetchableFluentQueryByExample<S, R> extends FluentQuerySupport<S, R> { @@ -66,21 +66,21 @@ class FetchableFluentQueryByExample<S, R> extends FluentQuerySupport<S, R> {
public R firstValue() {
return this.getConversionFunction()
.apply(this.entityOperations.select(createQuery().sort(getSort()), getExampleType()).iterator().next());
.apply(this.entityOperations.findAll(createQuery().sort(getSort()), getExampleType()).iterator().next());
}
@Override
public List<R> all() {
return StreamSupport
.stream(this.entityOperations.select(createQuery().sort(getSort()), getExampleType()).spliterator(), false)
.stream(this.entityOperations.findAll(createQuery().sort(getSort()), getExampleType()).spliterator(), false)
.map(item -> this.getConversionFunction().apply(item)).collect(Collectors.toList());
}
@Override
public Page<R> page(Pageable pageable) {
return this.entityOperations.select(createQuery(p -> p.with(pageable)), getExampleType(), pageable)
return this.entityOperations.findAll(createQuery(p -> p.with(pageable)), getExampleType(), pageable)
.map(item -> this.getConversionFunction().apply(item));
}
@ -88,7 +88,7 @@ class FetchableFluentQueryByExample<S, R> extends FluentQuerySupport<S, R> { @@ -88,7 +88,7 @@ class FetchableFluentQueryByExample<S, R> extends FluentQuerySupport<S, R> {
public Stream<R> stream() {
return StreamSupport
.stream(this.entityOperations.select(createQuery().sort(getSort()), getExampleType()).spliterator(), false)
.stream(this.entityOperations.findAll(createQuery().sort(getSort()), getExampleType()).spliterator(), false)
.map(item -> this.getConversionFunction().apply(item));
}

7
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/SimpleJdbcRepository.java

@ -142,7 +142,7 @@ public class SimpleJdbcRepository<T, ID> @@ -142,7 +142,7 @@ public class SimpleJdbcRepository<T, ID>
Assert.notNull(example, "Example must not be null");
return this.entityOperations.selectOne(this.exampleMapper.getMappedExample(example), example.getProbeType());
return this.entityOperations.findOne(this.exampleMapper.getMappedExample(example), example.getProbeType());
}
@Override
@ -159,7 +159,7 @@ public class SimpleJdbcRepository<T, ID> @@ -159,7 +159,7 @@ public class SimpleJdbcRepository<T, ID>
Assert.notNull(example, "Example must not be null");
Assert.notNull(sort, "Sort must not be null");
return this.entityOperations.select(this.exampleMapper.getMappedExample(example).sort(sort),
return this.entityOperations.findAll(this.exampleMapper.getMappedExample(example).sort(sort),
example.getProbeType());
}
@ -168,7 +168,8 @@ public class SimpleJdbcRepository<T, ID> @@ -168,7 +168,8 @@ public class SimpleJdbcRepository<T, ID>
Assert.notNull(example, "Example must not be null");
return this.entityOperations.select(this.exampleMapper.getMappedExample(example), example.getProbeType(), pageable);
return this.entityOperations.findAll(this.exampleMapper.getMappedExample(example), example.getProbeType(),
pageable);
}
@Override

Loading…
Cancel
Save