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 {
@Column(length = 36)
private String uuid;
@Column(name = "instCode", length = 10)
@Column(name = "instCode", length = 10, nullable = false)
private String instituteCode;
@ManyToOne(cascade = {}, optional = true)
......
......@@ -29,6 +29,7 @@ import org.springframework.data.domain.Sort;
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.repository.query.Param;
public interface AccessionRepository extends JpaRepository<Accession, Long> {
......@@ -107,8 +108,8 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
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")
Accession findOne(String holdingInstitute, String accessionName, String genus);
@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(@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")
long countAvailable(Set<Long> accessionIds);
......@@ -125,7 +126,7 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query("select distinct a.institute from Accession a where a.id in ( ?1 )")
List<FaoInstitute> findDistinctInstitutesFor(Set<Long> accessionIds);
@Query("select distinct a.id from Accession a where a.institute = ?1 and a.id in ( ?2 )")
Set<Long> findByInstituteAndIds(FaoInstitute institute, Set<Long> accessionIds);
@Query("select distinct a.id from Accession a where a.institute = :institute and a.id in ( :ids )")
Set<Long> findByInstituteAndIds(@Param("institute") FaoInstitute institute, @Param("ids") Set<Long> accessionIds);
}
......@@ -25,7 +25,9 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
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.repository.query.Param;
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 )")
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 {
void updateFaoInstituteRefs();
void updateInstituteAccessionCount(long instituteId);
/**
* Relink {@link FaoInstitute} with {@link Country} based on institute code
*/
......
......@@ -71,24 +71,25 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
LOG.info("Institute accession counts updated: " + count);
}
@Override
@Transactional(readOnly = false)
public void updateInstituteAccessionCount(long instituteId) {
LOG.info("Updating institute accession count for instituteId=" + instituteId);
// 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 = ?;",
// instituteId, instituteId);
final int count = jdbcTemplate.update("UPDATE faoinstitute SET accessionCount = (select count(*) from accession where instituteId=?) where id = ?;",
instituteId, instituteId);
LOG.info("Institute accession counts updated: " + count);
}
// @Override
// @Transactional(readOnly = false, propagation = Propagation.SUPPORTS)
// public void updateInstituteAccessionCount(long instituteId) {
// LOG.debug("Updating institute accession count for instituteId=" + instituteId);
// // 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 = ?;",
// // instituteId, instituteId);
// jdbcTemplate.update("UPDATE faoinstitute SET accessionCount = (select count(*) from accession where instituteId=?) where id = ?;",
// instituteId, instituteId);
// LOG.info("Institute accession count updated for " + instituteId);
// }
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
public void updateCountryRefs() {
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);
}
......@@ -188,8 +189,8 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
// Insert reference to metadatamethod
try {
final int inserted = jdbcTemplate.update("insert into metadatamethod (metadataId, methodId) (select distinct metadataId, " + methodId + " from `"
+ methodId + "`)");
final int inserted = jdbcTemplate.update("insert into metadatamethod (metadataId, methodId) (select distinct metadataId, " + methodId
+ " from `" + methodId + "`)");
if (inserted == 0) {
LOG.warn("Method " + methodId + " has no entries?");
} else {
......
......@@ -53,12 +53,12 @@ public interface OAuthAccessTokenPersistence extends JpaRepository<OAuthAccessTo
@Modifying
void deleteByValue(@Param("value") String value);
@Query("delete from OAuthAccessToken where clientId = ?")
@Query("delete from OAuthAccessToken where clientId = ?1")
@Modifying
void deleteByClientId(String clientId);
@Modifying
@Query("delete from OAuthAccessToken where expiration < ?")
@Query("delete from OAuthAccessToken where expiration < ?1")
int deleteOlderThan(Date date);
}
......@@ -30,7 +30,7 @@ public interface OAuthCodePersistence extends JpaRepository<OAuthCode, Long> {
OAuthCode findByCode(String code);
@Modifying
@Query("delete from OAuthCode where createdDate < ?")
@Query("delete from OAuthCode where createdDate < ?1")
int deleteOlderThan(Date date);
}
......@@ -36,18 +36,18 @@ public interface OAuthRefreshTokenPersistence extends JpaRepository<OAuthRefresh
OAuthRefreshToken findByValue(String value);
@Query("delete from OAuthRefreshToken where value = ?")
@Query("delete from OAuthRefreshToken where value = ?1")
@Modifying
void deleteByValue(String value);
Collection<OAuthRefreshToken> findByClientId(String clientId);
@Query("delete from OAuthRefreshToken where clientId = ?")
@Query("delete from OAuthRefreshToken where clientId = ?1")
@Modifying
void deleteByClientId(String clientId);
@Modifying
@Query("delete from OAuthRefreshToken where expiration < ?")
@Query("delete from OAuthRefreshToken where expiration < ?1")
int deleteOlderThan(Date date);
}
......@@ -493,7 +493,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
@Override
@Transactional(readOnly = false)
public void updateAccessionCount(FaoInstitute institute) {
genesysLowlevelRepository.updateInstituteAccessionCount(institute.getId());
instituteRepository.updateInstituteAccessionCount(institute);
}
@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