}
}
// Insert the nodes of the new way into the history table.
for (int i = 0; i < nodeReferenceList.size(); i++) {
WayNode nodeReference;
nodeReference = nodeReferenceList.get(i);
try {
prmIndex = 1;
insertWayNodeStatement.setLong(prmIndex++, way.getId());
insertWayNodeStatement.setInt(prmIndex++, way.getVersion());
insertWayNodeStatement.setLong(prmIndex++, nodeReference.getNodeId());
insertWayNodeStatement.setLong(prmIndex++, i + 1);
insertWayNodeStatement.execute();
} catch (SQLException e) {
throw new OsmosisRuntimeException("Unable to insert history way node with way id=" + way.getId()
+ " and node id=" + nodeReference.getNodeId() + ".", e);
}
}
if (populateCurrentTables) {
// Delete the existing way tags from the current table.
try {
deleteWayTagCurrentStatement.setLong(1, way.getId());
deleteWayTagCurrentStatement.execute();
} catch (SQLException e) {
throw new OsmosisRuntimeException("Unable to delete current way tags with id=" + way.getId() + ".", e);
}
// Delete the existing way nodes from the current table.
try {
deleteWayNodeCurrentStatement.setLong(1, way.getId());
deleteWayNodeCurrentStatement.execute();
} catch (SQLException e) {
throw new OsmosisRuntimeException("Unable to delete current way nodes with id=" + way.getId() + ".", e);
}
// Update the node if it already exists in the current table, otherwise insert it.
try {
exists = checkIfEntityExists(selectWayCurrentCountStatement, way.getId());
} catch (SQLException e) {
throw new OsmosisRuntimeException("Unable to check if current way with id=" + way.getId() + " exists.",
e);
}
if (exists) {
// Update the way in the current table.
try {
prmIndex = 1;
updateWayCurrentStatement.setInt(prmIndex++, way.getVersion());
updateWayCurrentStatement.setTimestamp(prmIndex++, new Timestamp(way.getTimestamp().getTime()));
updateWayCurrentStatement.setBoolean(prmIndex++, visible);
updateWayCurrentStatement.setLong(prmIndex++, way.getChangesetId());
updateWayCurrentStatement.setLong(prmIndex++, way.getId());
updateWayCurrentStatement.execute();
} catch (SQLException e) {
throw new OsmosisRuntimeException("Unable to update current way with id=" + way.getId() + ".", e);
}
} else {
// Insert the new way into the current table.
try {
prmIndex = 1;
insertWayCurrentStatement.setLong(prmIndex++, way.getId());
insertWayCurrentStatement.setInt(prmIndex++, way.getVersion());
insertWayCurrentStatement.setTimestamp(prmIndex++, new Timestamp(way.getTimestamp().getTime()));
insertWayCurrentStatement.setBoolean(prmIndex++, visible);
insertWayCurrentStatement.setLong(prmIndex++, way.getChangesetId());
insertWayCurrentStatement.execute();
} catch (SQLException e) {
throw new OsmosisRuntimeException("Unable to insert current way with id=" + way.getId() + ".", e);
}
}
// Insert the tags of the new way into the current table.
for (Tag tag : way.getTags()) {
try {
prmIndex = 1;
insertWayTagCurrentStatement.setLong(prmIndex++, way.getId());
insertWayTagCurrentStatement.setString(prmIndex++, tag.getKey());
insertWayTagCurrentStatement.setString(prmIndex++, tag.getValue());
insertWayTagCurrentStatement.execute();
} catch (SQLException e) {
throw new OsmosisRuntimeException("Unable to insert current way tag with id=" + way.getId()
+ " and key=(" + tag.getKey() + ").", e);
}
}
// Insert the nodes of the new way into the current table.
for (int i = 0; i < nodeReferenceList.size(); i++) {
WayNode nodeReference;
nodeReference = nodeReferenceList.get(i);
try {
prmIndex = 1;
insertWayNodeCurrentStatement.setLong(prmIndex++, way.getId());
insertWayNodeCurrentStatement.setLong(prmIndex++, nodeReference.getNodeId());
insertWayNodeCurrentStatement.setLong(prmIndex++, i);
insertWayNodeCurrentStatement.execute();
} catch (SQLException e) {
throw new OsmosisRuntimeException("Unable to insert current way node with way id=" + way.getId()
+ " and node id=" + nodeReference.getNodeId() + ".", e);
}
}
}
}