Revision a47b46ac
Added by Andreas Müller about 3 years ago
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v523_525/CollectorTitleUpdater.java | ||
---|---|---|
19 | 19 |
import eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep; |
20 | 20 |
import eu.etaxonomy.cdm.database.update.SchemaUpdateResult; |
21 | 21 |
import eu.etaxonomy.cdm.database.update.SchemaUpdaterStepBase; |
22 |
import eu.etaxonomy.cdm.model.agent.Person; |
|
23 |
import eu.etaxonomy.cdm.model.agent.Team; |
|
24 |
import eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy; |
|
25 |
import eu.etaxonomy.cdm.strategy.cache.agent.TeamDefaultCacheStrategy; |
|
22 | 26 |
|
23 | 27 |
/** |
24 | 28 |
* #4311 |
... | ... | |
65 | 69 |
datasource.executeUpdate(caseType.replaceTableNames(sql)); |
66 | 70 |
}else{ |
67 | 71 |
//for each team member handle like persons below |
68 |
sql = "SELECT p.* FROM @@AgentBase_AgentBase@@ MN INNER JOIN @@AgentBase@@ p ON p.id = MN.teamMembers_id WHERE MN.team_ID = " + id; |
|
72 |
sql = "SELECT p.* FROM @@AgentBase_AgentBase@@ MN INNER JOIN @@AgentBase@@ p ON p.id = MN.teamMembers_id WHERE MN.team_ID = " + id + " ORDER BY sortIndex ";
|
|
69 | 73 |
ResultSet rs2 = datasource.executeQuery(caseType.replaceTableNames(sql)); |
74 |
Team team = Team.NewInstance(); |
|
70 | 75 |
while (rs2.next()){ |
71 |
handlePerson(rs2, datasource, caseType, result); |
|
76 |
Person member = handlePerson(rs2, datasource, caseType); |
|
77 |
team.addTeamMember(member); |
|
72 | 78 |
} |
73 | 79 |
rs2.close(); |
80 |
String collectorTitleCache = TeamDefaultCacheStrategy.INSTANCE().getCollectorTitleCache(team); |
|
81 |
sql = " UPDATE @@AgentBase@@ SET collectorTitleCache = '" + collectorTitleCache + "' WHERE id = " + id; |
|
82 |
datasource.executeUpdate(caseType.replaceTableNames(sql)); |
|
74 | 83 |
} |
75 | 84 |
}else if ("Person".equalsIgnoreCase(dtype)){ |
76 | 85 |
//for each person in gathering event |
77 |
handlePerson(rs, datasource, caseType, result);
|
|
86 |
handlePerson(rs, datasource, caseType); |
|
78 | 87 |
} |
79 | 88 |
} |
80 | 89 |
} |
81 | 90 |
|
82 |
private void handlePerson(ResultSet rs, ICdmDataSource datasource, CaseType caseType, SchemaUpdateResult result) throws SQLException {
|
|
83 |
//set collectorTitle = titleCache
|
|
91 |
private Person handlePerson(ResultSet rs, ICdmDataSource datasource, CaseType caseType) throws SQLException {
|
|
92 |
//set collectorTitle |
|
84 | 93 |
int id = rs.getInt("id"); |
85 |
String sql = "UPDATE @@AgentBase@@ SET collectorTitle = titleCache WHERE id = " + id; |
|
94 |
String familyName = rs.getString("familyName"); |
|
95 |
String initials = rs.getString("initials"); |
|
96 |
String givenName = rs.getString("givenName"); |
|
97 |
String titleCache = rs.getString("titleCache"); |
|
98 |
String nomenclaturalTitle = rs.getString("nomenclaturalTitle"); |
|
99 |
boolean protectedTitleCache = rs.getBoolean("protectedTitleCache"); |
|
100 |
|
|
101 |
Person person = Person.NewInstance(nomenclaturalTitle, familyName, initials, givenName); |
|
102 |
person.setTitleCache(titleCache, protectedTitleCache); |
|
103 |
String collectorTitle = PersonDefaultCacheStrategy.INSTANCE().getCollectorTitleCache(person); |
|
104 |
|
|
105 |
String sql = "UPDATE @@AgentBase@@ SET collectorTitleCache = '"+collectorTitle+"', collectorTitle = '"+collectorTitle+"' WHERE id = " + id; |
|
86 | 106 |
datasource.executeUpdate(caseType.replaceTableNames(sql)); |
107 |
return person; |
|
87 | 108 |
} |
88 |
} |
|
109 |
} |
Also available in: Unified diff
ref #4311 improve collectorTitle update script