Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
0065da86
Commit
0065da86
authored
Jan 02, 2015
by
Matija Obreza
Browse files
Added AccessionCustomRepository, use Collection<Long> instead of List<Long> in Accession*Repository
parent
33f36d56
Changes
10
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/persistence/domain/AccessionAliasRepository.java
View file @
0065da86
...
...
@@ -40,5 +40,5 @@ public interface AccessionAliasRepository extends JpaRepository<AccessionAlias,
Accession
findAccession
(
String
instCode
,
String
name
,
int
aliasType
);
@Query
(
"from AccessionAlias aa where aa.accession.id in ?1"
)
List
<
AccessionAlias
>
findAllFor
(
List
<
Long
>
accessionIds
);
List
<
AccessionAlias
>
findAllFor
(
Collection
<
Long
>
accessionIds
);
}
src/main/java/org/genesys2/server/persistence/domain/AccessionBreedingRepository.java
View file @
0065da86
...
...
@@ -34,5 +34,5 @@ public interface AccessionBreedingRepository extends JpaRepository<AccessionBree
void
deleteForAccessions
(
Collection
<
Long
>
accessionIds
);
@Query
(
"from AccessionBreeding ab where ab.accession.id in ?1"
)
List
<
AccessionBreeding
>
findAllFor
(
List
<
Long
>
accessionIds
);
List
<
AccessionBreeding
>
findAllFor
(
Collection
<
Long
>
accessionIds
);
}
src/main/java/org/genesys2/server/persistence/domain/AccessionCollectRepository.java
View file @
0065da86
...
...
@@ -34,5 +34,5 @@ public interface AccessionCollectRepository extends JpaRepository<AccessionColle
void
deleteForAccessions
(
Collection
<
Long
>
accessionIds
);
@Query
(
"from AccessionCollect ac where ac.accession.id in ?1"
)
List
<
AccessionCollect
>
findAllFor
(
List
<
Long
>
accessionId
);
List
<
AccessionCollect
>
findAllFor
(
Collection
<
Long
>
accessionId
s
);
}
src/main/java/org/genesys2/server/persistence/domain/AccessionCustomRepository.java
0 → 100644
View file @
0065da86
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.genesys2.server.persistence.domain
;
import
java.util.List
;
import
org.genesys2.server.model.genesys.Accession
;
import
org.genesys2.server.model.impl.FaoInstitute
;
import
org.genesys2.server.service.impl.NonUniqueAccessionException
;
public
interface
AccessionCustomRepository
{
List
<
Accession
>
find
(
FaoInstitute
institute
,
List
<
String
>
acceNumbs
,
List
<
String
>
genera
)
throws
NonUniqueAccessionException
;
}
src/main/java/org/genesys2/server/persistence/domain/AccessionCustomRepositoryImpl.java
0 → 100644
View file @
0065da86
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.genesys2.server.persistence.domain
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
javax.persistence.EntityManager
;
import
javax.persistence.PersistenceContext
;
import
javax.persistence.criteria.CriteriaBuilder
;
import
javax.persistence.criteria.CriteriaQuery
;
import
javax.persistence.criteria.JoinType
;
import
javax.persistence.criteria.Predicate
;
import
javax.persistence.criteria.Root
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.genesys2.server.model.genesys.Accession
;
import
org.genesys2.server.model.impl.FaoInstitute
;
import
org.genesys2.server.service.impl.NonUniqueAccessionException
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.stereotype.Repository
;
import
org.springframework.transaction.annotation.Transactional
;
@Repository
@Transactional
(
readOnly
=
true
)
public
class
AccessionCustomRepositoryImpl
implements
AccessionCustomRepository
,
InitializingBean
{
public
static
final
Log
LOG
=
LogFactory
.
getLog
(
AccessionCustomRepositoryImpl
.
class
);
@PersistenceContext
private
EntityManager
em
;
private
CriteriaBuilder
criteriaBuilder
;
@Override
public
List
<
Accession
>
find
(
FaoInstitute
institute
,
List
<
String
>
acceNumbs
,
List
<
String
>
genera
)
throws
NonUniqueAccessionException
{
boolean
uniqueAcceNumbs
=
institute
.
hasUniqueAcceNumbs
();
CriteriaQuery
<
Accession
>
cq
=
criteriaBuilder
.
createQuery
(
Accession
.
class
);
Root
<
Accession
>
root
=
cq
.
from
(
Accession
.
class
);
cq
.
select
(
root
);
root
.
fetch
(
"stoRage"
,
JoinType
.
LEFT
);
// Join<Accession, Taxonomy2> tax = root.join("taxonomy");
List
<
Predicate
>
restrictions
=
new
ArrayList
<
Predicate
>();
if
(
uniqueAcceNumbs
)
{
restrictions
.
add
(
root
.
get
(
"accessionName"
).
in
(
acceNumbs
));
if
(
LOG
.
isDebugEnabled
())
LOG
.
debug
(
"*** "
+
institute
.
getCode
()
+
" "
+
acceNumbs
);
}
else
{
// A lot of .. (acceNumb=? and genus=?)
for
(
int
i
=
0
;
i
<
acceNumbs
.
size
();
i
++)
{
restrictions
.
add
(
criteriaBuilder
.
and
(
criteriaBuilder
.
equal
(
root
.
get
(
"accessionName"
),
acceNumbs
.
get
(
i
)),
criteriaBuilder
.
equal
(
root
.
get
(
"taxonomy.genus"
),
genera
.
get
(
i
))));
}
}
cq
.
where
(
criteriaBuilder
.
and
(
criteriaBuilder
.
equal
(
root
.
get
(
"institute"
),
institute
),
criteriaBuilder
.
or
(
restrictions
.
toArray
(
new
Predicate
[]
{}))));
cq
.
distinct
(
true
);
List
<
Accession
>
res
=
em
.
createQuery
(
cq
).
getResultList
();
if
(
LOG
.
isDebugEnabled
())
LOG
.
debug
(
"*** Loaded accessions "
+
res
.
size
()
+
" of "
+
acceNumbs
.
size
());
// Check for duplicate names if institute is using unique acceNumbs
if
(
uniqueAcceNumbs
)
{
Set
<
String
>
s
=
new
HashSet
<
String
>();
for
(
Accession
a
:
res
)
{
if
(
s
.
contains
(
a
.
getAccessionName
()))
{
LOG
.
error
(
"Duplicate accession name instCode="
+
a
.
getInstituteCode
()
+
" acceNumb="
+
a
.
getAccessionName
());
throw
new
NonUniqueAccessionException
(
a
.
getInstituteCode
(),
a
.
getAccessionName
());
}
s
.
add
(
a
.
getAccessionName
());
}
}
return
res
;
}
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
this
.
criteriaBuilder
=
em
.
getCriteriaBuilder
();
}
}
src/main/java/org/genesys2/server/persistence/domain/AccessionExchangeRepository.java
View file @
0065da86
...
...
@@ -34,5 +34,5 @@ public interface AccessionExchangeRepository extends JpaRepository<AccessionExch
void
deleteForAccessions
(
Collection
<
Long
>
accessionIds
);
@Query
(
"from AccessionExchange ae where ae.accession.id in ?1"
)
List
<
AccessionExchange
>
findAllFor
(
List
<
Long
>
accessionIds
);
List
<
AccessionExchange
>
findAllFor
(
Collection
<
Long
>
accessionIds
);
}
src/main/java/org/genesys2/server/persistence/domain/AccessionGeoRepository.java
View file @
0065da86
...
...
@@ -38,6 +38,6 @@ public interface AccessionGeoRepository extends JpaRepository<AccessionGeo, Long
void
deleteForAccessions
(
Collection
<
Long
>
accessionIds
);
@Query
(
"from AccessionGeo ag where ag.accession.id in ?1"
)
List
<
AccessionGeo
>
findAllFor
(
List
<
Long
>
accessionIds
);
List
<
AccessionGeo
>
findAllFor
(
Collection
<
Long
>
accessionIds
);
}
src/main/java/org/genesys2/server/persistence/domain/AccessionRemarkRepository.java
View file @
0065da86
...
...
@@ -38,5 +38,5 @@ public interface AccessionRemarkRepository extends JpaRepository<AccessionRemark
void
deleteForAccessions
(
@Param
(
"ids"
)
Collection
<
Long
>
accessionIds
);
@Query
(
"from AccessionRemark ar where ar.accession.id in ?1"
)
List
<
AccessionRemark
>
findAllFor
(
List
<
Long
>
accessionIds
);
List
<
AccessionRemark
>
findAllFor
(
Collection
<
Long
>
accessionIds
);
}
src/main/java/org/genesys2/server/persistence/domain/AccessionRepository.java
View file @
0065da86
...
...
@@ -62,6 +62,8 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
List
<
Accession
>
findByInstituteAndAccessionName
(
FaoInstitute
faoInstitute
,
String
accessionName
);
public
List
<
Accession
>
findByInstituteAndAccessionName
(
FaoInstitute
institute
,
List
<
String
>
acceNumbs
);
@Query
(
"from Accession a where a.id in ( ?1 )"
)
Page
<
Accession
>
findById
(
Collection
<
Long
>
accessionIds
,
Pageable
pageable
);
...
...
@@ -75,6 +77,7 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query
(
"select a from Accession a where a.taxonomy in ( ?1 )"
)
Page
<
Accession
>
findByTaxonomy
(
Collection
<
Taxonomy2
>
taxonomies
,
Pageable
pageable
);
@Query
(
"select a from Accession a where a.institute.code = ?1 and a.accessionName = ?2"
)
Accession
findByInstituteCodeAndAccessionName
(
String
instCode
,
String
accessionName
);
@Query
(
"select a from Accession a where a.accessionName=?2 and (a.institute.code=?1 or a.institute.codeSGSV=?1) and a.taxonomy.genus=?3"
)
...
...
src/main/java/org/genesys2/server/persistence/domain/SvalbardRepository.java
View file @
0065da86
...
...
@@ -16,6 +16,8 @@
package
org.genesys2.server.persistence.domain
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Set
;
import
org.genesys2.server.model.genesys.SvalbardData
;
...
...
@@ -29,4 +31,7 @@ public interface SvalbardRepository extends JpaRepository<SvalbardData, Long> {
@Query
(
"delete from SvalbardData sd where sd.id in ?1"
)
void
deleteForAccessions
(
Set
<
Long
>
accessionIds
);
@Query
(
"from SvalbardData sd where sd.id in ?1"
)
List
<
SvalbardData
>
findAllFor
(
Collection
<
Long
>
accessionIds
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment