Commit aa929a77 authored by Matija Obreza's avatar Matija Obreza

Fixed deprecated HQL parameter notation

parent 595277ea
...@@ -44,7 +44,7 @@ public class Accession extends VersionedAuditedModel { ...@@ -44,7 +44,7 @@ public class Accession extends VersionedAuditedModel {
@Column(length = 36) @Column(length = 36)
private String uuid; private String uuid;
@Column(name = "instCode", length = 10) @Column(name = "instCode", length = 10, nullable = false)
private String instituteCode; private String instituteCode;
@ManyToOne(cascade = {}, optional = true) @ManyToOne(cascade = {}, optional = true)
......
...@@ -29,6 +29,7 @@ import org.springframework.data.domain.Sort; ...@@ -29,6 +29,7 @@ import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
public interface AccessionRepository extends JpaRepository<Accession, Long> { public interface AccessionRepository extends JpaRepository<Accession, Long> {
...@@ -107,8 +108,8 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> { ...@@ -107,8 +108,8 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
Accession findByInstituteCodeAndAccessionName(String instCode, String accessionName); Accession findByInstituteCodeAndAccessionName(String instCode, String accessionName);
@Query("select a from Accession a inner join a.taxonomy t where a.instituteCode=?1 and a.accessionName=?2 and t.genus=?3") @Query("select a from Accession a inner join a.taxonomy t where a.instituteCode=:instCode and a.accessionName=:acceNumb and t.genus=:genus")
Accession findOne(String holdingInstitute, String accessionName, String genus); Accession findOne(@Param("instCode") String holdingInstitute, @Param("acceNumb") String accessionName, @Param("genus") String genus);
@Query("select count(a.id) from Accession a where a.id in ( ?1 ) and a.availability = true") @Query("select count(a.id) from Accession a where a.id in ( ?1 ) and a.availability = true")
long countAvailable(Set<Long> accessionIds); long countAvailable(Set<Long> accessionIds);
...@@ -125,7 +126,7 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> { ...@@ -125,7 +126,7 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query("select distinct a.institute from Accession a where a.id in ( ?1 )") @Query("select distinct a.institute from Accession a where a.id in ( ?1 )")
List<FaoInstitute> findDistinctInstitutesFor(Set<Long> accessionIds); List<FaoInstitute> findDistinctInstitutesFor(Set<Long> accessionIds);
@Query("select distinct a.id from Accession a where a.institute = ?1 and a.id in ( ?2 )") @Query("select distinct a.id from Accession a where a.institute = :institute and a.id in ( :ids )")
Set<Long> findByInstituteAndIds(FaoInstitute institute, Set<Long> accessionIds); Set<Long> findByInstituteAndIds(@Param("institute") FaoInstitute institute, @Param("ids") Set<Long> accessionIds);
} }
...@@ -25,7 +25,9 @@ import org.springframework.data.domain.Page; ...@@ -25,7 +25,9 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
public interface FaoInstituteRepository extends JpaRepository<FaoInstitute, Long> { public interface FaoInstituteRepository extends JpaRepository<FaoInstitute, Long> {
...@@ -55,4 +57,8 @@ public interface FaoInstituteRepository extends JpaRepository<FaoInstitute, Long ...@@ -55,4 +57,8 @@ public interface FaoInstituteRepository extends JpaRepository<FaoInstitute, Long
@Query("from FaoInstitute fi where fi.id in ( ?1 )") @Query("from FaoInstitute fi where fi.id in ( ?1 )")
List<FaoInstitute> findByIds(List<Long> oids, Sort sort); List<FaoInstitute> findByIds(List<Long> oids, Sort sort);
@Modifying
@Query("update FaoInstitute fi set accessionCount=(select count(a) from Accession a where a.institute = :institute ) where fi=:institute")
void updateInstituteAccessionCount(@Param("institute") FaoInstitute institute);
} }
...@@ -29,8 +29,6 @@ public interface GenesysLowlevelRepository { ...@@ -29,8 +29,6 @@ public interface GenesysLowlevelRepository {
void updateFaoInstituteRefs(); void updateFaoInstituteRefs();
void updateInstituteAccessionCount(long instituteId);
/** /**
* Relink {@link FaoInstitute} with {@link Country} based on institute code * Relink {@link FaoInstitute} with {@link Country} based on institute code
*/ */
......
...@@ -71,24 +71,25 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository ...@@ -71,24 +71,25 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
LOG.info("Institute accession counts updated: " + count); LOG.info("Institute accession counts updated: " + count);
} }
@Override // @Override
@Transactional(readOnly = false) // @Transactional(readOnly = false, propagation = Propagation.SUPPORTS)
public void updateInstituteAccessionCount(long instituteId) { // public void updateInstituteAccessionCount(long instituteId) {
LOG.info("Updating institute accession count for instituteId=" + instituteId); // LOG.debug("Updating institute accession count for instituteId=" + instituteId);
// int count = jdbcTemplate // // int count = jdbcTemplate
// .update("UPDATE faoinstitute FI inner join (select instituteId, count(*) X from accession where instituteId= ? group by instituteId) A on A.instituteId=FI.id set FI.accessionCount=A.X where FI.id = ?;", // // .update("UPDATE faoinstitute FI inner join (select instituteId, count(*) X from accession where instituteId= ? group by instituteId) A on A.instituteId=FI.id set FI.accessionCount=A.X where FI.id = ?;",
// instituteId, instituteId); // // instituteId, instituteId);
final int count = jdbcTemplate.update("UPDATE faoinstitute SET accessionCount = (select count(*) from accession where instituteId=?) where id = ?;", // jdbcTemplate.update("UPDATE faoinstitute SET accessionCount = (select count(*) from accession where instituteId=?) where id = ?;",
instituteId, instituteId); // instituteId, instituteId);
LOG.info("Institute accession counts updated: " + count); // LOG.info("Institute accession count updated for " + instituteId);
} // }
@Override @Override
@PreAuthorize("hasRole('ADMINISTRATOR')") @PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false) @Transactional(readOnly = false)
public void updateCountryRefs() { public void updateCountryRefs() {
LOG.info("Updating country references"); LOG.info("Updating country references");
final int count = jdbcTemplate.update("UPDATE `accession` A inner join `country` C on C.code3=A.orgCty set A.orgCtyId=C.id WHERE A.orgCty IS NOT NULL;"); final int count = jdbcTemplate
.update("UPDATE `accession` A inner join `country` C on C.code3=A.orgCty set A.orgCtyId=C.id WHERE A.orgCty IS NOT NULL;");
LOG.info("Country references updated: " + count); LOG.info("Country references updated: " + count);
} }
...@@ -188,8 +189,8 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository ...@@ -188,8 +189,8 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
// Insert reference to metadatamethod // Insert reference to metadatamethod
try { try {
final int inserted = jdbcTemplate.update("insert into metadatamethod (metadataId, methodId) (select distinct metadataId, " + methodId + " from `" final int inserted = jdbcTemplate.update("insert into metadatamethod (metadataId, methodId) (select distinct metadataId, " + methodId
+ methodId + "`)"); + " from `" + methodId + "`)");
if (inserted == 0) { if (inserted == 0) {
LOG.warn("Method " + methodId + " has no entries?"); LOG.warn("Method " + methodId + " has no entries?");
} else { } else {
......
...@@ -53,12 +53,12 @@ public interface OAuthAccessTokenPersistence extends JpaRepository<OAuthAccessTo ...@@ -53,12 +53,12 @@ public interface OAuthAccessTokenPersistence extends JpaRepository<OAuthAccessTo
@Modifying @Modifying
void deleteByValue(@Param("value") String value); void deleteByValue(@Param("value") String value);
@Query("delete from OAuthAccessToken where clientId = ?") @Query("delete from OAuthAccessToken where clientId = ?1")
@Modifying @Modifying
void deleteByClientId(String clientId); void deleteByClientId(String clientId);
@Modifying @Modifying
@Query("delete from OAuthAccessToken where expiration < ?") @Query("delete from OAuthAccessToken where expiration < ?1")
int deleteOlderThan(Date date); int deleteOlderThan(Date date);
} }
...@@ -30,7 +30,7 @@ public interface OAuthCodePersistence extends JpaRepository<OAuthCode, Long> { ...@@ -30,7 +30,7 @@ public interface OAuthCodePersistence extends JpaRepository<OAuthCode, Long> {
OAuthCode findByCode(String code); OAuthCode findByCode(String code);
@Modifying @Modifying
@Query("delete from OAuthCode where createdDate < ?") @Query("delete from OAuthCode where createdDate < ?1")
int deleteOlderThan(Date date); int deleteOlderThan(Date date);
} }
...@@ -36,18 +36,18 @@ public interface OAuthRefreshTokenPersistence extends JpaRepository<OAuthRefresh ...@@ -36,18 +36,18 @@ public interface OAuthRefreshTokenPersistence extends JpaRepository<OAuthRefresh
OAuthRefreshToken findByValue(String value); OAuthRefreshToken findByValue(String value);
@Query("delete from OAuthRefreshToken where value = ?") @Query("delete from OAuthRefreshToken where value = ?1")
@Modifying @Modifying
void deleteByValue(String value); void deleteByValue(String value);
Collection<OAuthRefreshToken> findByClientId(String clientId); Collection<OAuthRefreshToken> findByClientId(String clientId);
@Query("delete from OAuthRefreshToken where clientId = ?") @Query("delete from OAuthRefreshToken where clientId = ?1")
@Modifying @Modifying
void deleteByClientId(String clientId); void deleteByClientId(String clientId);
@Modifying @Modifying
@Query("delete from OAuthRefreshToken where expiration < ?") @Query("delete from OAuthRefreshToken where expiration < ?1")
int deleteOlderThan(Date date); int deleteOlderThan(Date date);
} }
...@@ -493,7 +493,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset ...@@ -493,7 +493,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
@Override @Override
@Transactional(readOnly = false) @Transactional(readOnly = false)
public void updateAccessionCount(FaoInstitute institute) { public void updateAccessionCount(FaoInstitute institute) {
genesysLowlevelRepository.updateInstituteAccessionCount(institute.getId()); instituteRepository.updateInstituteAccessionCount(institute);
} }
@Override @Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment