Skip to content

Commit

Permalink
[#1466] Fix compatibility issues with Spring Data 2.5 series due to n…
Browse files Browse the repository at this point in the history
…ewly added methods
  • Loading branch information
beikov committed Aug 4, 2022
1 parent 2844f06 commit 39785f5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Not yet released
* Fix CTE rendering issues in Querydsl integration
* Support joins in queries with multiple FROM nodes in Querydsl
* Fix compatibility issues with Spring Data 2.3 series due to newly added methods in 2.3.1
* Fix compatibility issues with Spring Data 2.5 series due to newly added methods

### Backwards-incompatible changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public abstract class AbstractEntityViewAwareRepository<V, E, ID extends Seriali

private static final String ID_MUST_NOT_BE_NULL = "The given id must not be null!";
private static final String DELETE_ALL_QUERY_STRING = "delete from %s x";
private static final String DELETE_ALL_QUERY_BY_ID_STRING = "delete from %s x where %s in :ids";
private static final String[] EMPTY = new String[0];

private final JpaEntityInformation<E, ?> entityInformation;
Expand Down Expand Up @@ -149,6 +150,13 @@ public <S extends E> List<S> saveAll(Iterable<S> entities) {
return save(entities);
}

@Transactional
public <S extends E> List<S> saveAllAndFlush(Iterable<S> entities) {
List<S> result = saveAll(entities);
flush();
return result;
}

@Transactional
public <S extends E> List<S> save(Iterable<S> entities) {
List<S> result = new ArrayList<S>();
Expand Down Expand Up @@ -239,6 +247,29 @@ public void deleteInBatch(Iterable<E> entities) {
.executeUpdate();
}

@Transactional
public void deleteAllInBatch(Iterable<E> entities) {
deleteInBatch(entities);
}

@Transactional
public void deleteAllByIdInBatch(Iterable<ID> ids) {

Assert.notNull(ids, "Ids must not be null!");

if (!ids.iterator().hasNext()) {
return;
}

String queryTemplate = DELETE_ALL_QUERY_BY_ID_STRING;
String queryString = String.format(queryTemplate, entityInformation.getEntityName(), entityInformation.getIdAttribute().getName());

Query query = entityManager.createQuery(queryString);
query.setParameter("ids", ids);

query.executeUpdate();
}

@Transactional
public void deleteAllInBatch() {
entityManager.createQuery(getQueryString(DELETE_ALL_QUERY_STRING, entityInformation.getEntityName())).executeUpdate();
Expand All @@ -248,6 +279,14 @@ public E getOne(ID id) {
return (E) getReference(id);
}

public E getById(ID id) {
return (E) getReference(id);
}

public E getReferenceById(ID id) {
return (E) getReference(id);
}

public <S extends E> long count(Example<S> example) {
return executeCountQuery(getCountQuery(new ExampleSpecification<>(example), example.getProbeType()));
}
Expand Down

0 comments on commit 39785f5

Please sign in to comment.