1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.persistence.dao.initializer;
|
10
|
|
11
|
import java.util.Optional;
|
12
|
|
13
|
import org.hibernate.Hibernate;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.agent.Person;
|
16
|
import eu.etaxonomy.cdm.model.agent.Team;
|
17
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
18
|
|
19
|
/**
|
20
|
* Initializes the the teamMembers of a Team
|
21
|
*
|
22
|
* @author a.kohlbecker
|
23
|
* @since 30.07.2010
|
24
|
*/
|
25
|
public class TeamAutoInitializer extends AutoPropertyInitializer<TeamOrPersonBase> {
|
26
|
|
27
|
@Override
|
28
|
public void initialize(TeamOrPersonBase bean) {
|
29
|
if(bean instanceof Team) {
|
30
|
Hibernate.initialize(((Team)bean).getTeamMembers());
|
31
|
}
|
32
|
}
|
33
|
|
34
|
@Override
|
35
|
public Optional<String> hibernateFetchJoin(Class<?> clazz, String beanAlias){
|
36
|
|
37
|
String result = "";
|
38
|
if(clazz.equals(Team.class)){
|
39
|
result += String.format(" LEFT JOIN FETCH %s.teamMembers ", beanAlias);
|
40
|
} else if(clazz.equals(Person.class)) {
|
41
|
// nothing to do in this case
|
42
|
} else {
|
43
|
// impossible to distinguish Team from Person due to polymorphism,
|
44
|
// need to initialize explicitly via the bean property.
|
45
|
return Optional.empty();
|
46
|
}
|
47
|
|
48
|
return Optional.of(result);
|
49
|
}
|
50
|
}
|