}
}
// Insert the members of the new relation into the history table.
for (int i = 0; i < relationMemberList.size(); i++) {
RelationMember relationMember;
relationMember = relationMemberList.get(i);
try {
prmIndex = 1;
insertRelationMemberStatement.setLong(prmIndex++, relation.getId());
insertRelationMemberStatement.setInt(prmIndex++, relation.getVersion());
insertRelationMemberStatement.setString(prmIndex++, memberTypeRenderer.render(relationMember
.getMemberType()));
insertRelationMemberStatement.setLong(prmIndex++, relationMember.getMemberId());
insertRelationMemberStatement.setString(prmIndex++, relationMember.getMemberRole());
insertRelationMemberStatement.setInt(prmIndex++, i + 1);
insertRelationMemberStatement.execute();
} catch (SQLException e) {
throw new OsmosisRuntimeException("Unable to insert history relation member with relation id="
+ relation.getId() + ", member type=" + relationMember.getMemberId() + " and member id="
+ relationMember.getMemberId() + ".", e);
}
}
if (populateCurrentTables) {
// Delete the existing relation tags from the current table.
try {
deleteRelationTagCurrentStatement.setLong(1, relation.getId());
deleteRelationTagCurrentStatement.execute();
} catch (SQLException e) {
throw new OsmosisRuntimeException("Unable to delete current relation tags with id=" + relation.getId()
+ ".", e);
}
// Delete the existing relation members from the current table.
try {
deleteRelationMemberCurrentStatement.setLong(1, relation.getId());
deleteRelationMemberCurrentStatement.execute();
} catch (SQLException e) {
throw new OsmosisRuntimeException("Unable to delete current relation members with id="
+ relation.getId() + ".", e);
}
// Update the relation if it already exists in the current table, otherwise insert it.
try {
exists = checkIfEntityExists(selectRelationCurrentCountStatement, relation.getId());
} catch (SQLException e) {
throw new OsmosisRuntimeException("Unable to check if current relation with id=" + relation.getId()
+ " exists.", e);
}
if (exists) {
// Update the relation in the current table.
try {
prmIndex = 1;
updateRelationCurrentStatement.setInt(prmIndex++, relation.getVersion());
updateRelationCurrentStatement.setTimestamp(prmIndex++, new Timestamp(relation.getTimestamp()
.getTime()));
updateRelationCurrentStatement.setBoolean(prmIndex++, visible);
updateRelationCurrentStatement.setLong(prmIndex++, relation.getChangesetId());
updateRelationCurrentStatement.setLong(prmIndex++, relation.getId());
updateRelationCurrentStatement.execute();
} catch (SQLException e) {
throw new OsmosisRuntimeException("Unable to update current relation with id=" + relation.getId()
+ ".", e);
}
} else {
// Insert the new node into the current table.
try {
prmIndex = 1;
insertRelationCurrentStatement.setLong(prmIndex++, relation.getId());
insertRelationCurrentStatement.setInt(prmIndex++, relation.getVersion());
insertRelationCurrentStatement.setTimestamp(prmIndex++, new Timestamp(relation.getTimestamp()
.getTime()));
insertRelationCurrentStatement.setBoolean(prmIndex++, visible);
insertRelationCurrentStatement.setLong(prmIndex++, relation.getChangesetId());
insertRelationCurrentStatement.execute();
} catch (SQLException e) {
throw new OsmosisRuntimeException("Unable to insert current relation with id=" + relation.getId()
+ ".", e);
}
}
// Insert the tags of the new relation into the current table.
for (Tag tag : relation.getTags()) {
try {
prmIndex = 1;
insertRelationTagCurrentStatement.setLong(prmIndex++, relation.getId());
insertRelationTagCurrentStatement.setString(prmIndex++, tag.getKey());
insertRelationTagCurrentStatement.setString(prmIndex++, tag.getValue());
insertRelationTagCurrentStatement.execute();
} catch (SQLException e) {
throw new OsmosisRuntimeException("Unable to insert current relation tag with id="
+ relation.getId() + " and key=(" + tag.getKey() + ").", e);
}
}
// Insert the members of the new relation into the current table.
for (int i = 0; i < relationMemberList.size(); i++) {
RelationMember relationMember;
relationMember = relationMemberList.get(i);
try {
prmIndex = 1;
insertRelationMemberCurrentStatement.setLong(prmIndex++, relation.getId());
insertRelationMemberCurrentStatement.setString(prmIndex++, memberTypeRenderer.render(relationMember
.getMemberType()));
insertRelationMemberCurrentStatement.setLong(prmIndex++, relationMember.getMemberId());
insertRelationMemberCurrentStatement.setString(prmIndex++, relationMember.getMemberRole());
insertRelationMemberCurrentStatement.setInt(prmIndex++, i + 1);
insertRelationMemberCurrentStatement.execute();
} catch (SQLException e) {
throw new OsmosisRuntimeException("Unable to insert current relation member with relation id="
+ relation.getId() + ", member type=" + relationMember.getMemberId() + " and member id="
+ relationMember.getMemberId() + ".", e);
}
}
}
}