/** * Creates a new database prepared statement. This statement will be * automatically released when the dao is released. * * @param sql * The statement to be created. * @return The newly created statement. */ protected PreparedStatement prepareStatement(String sql) { return statementContainer.add(dbCtx.prepareStatement(sql)); }
/** * {@inheritDoc} */ @Override public long getLastSequenceId(String sequenceName) { if (selectSequenceIdStatement == null) { selectSequenceIdStatement = statementContainer.add(dbCtx.prepareStatementForStreaming(SQL_SELECT_LAST_SEQUENCE_ID)); } try { selectSequenceIdStatement.setString(1, sequenceName); try (ResultSet lastSequenceQuery = selectSequenceIdStatement.executeQuery()) { lastSequenceQuery.next(); return lastSequenceQuery.getLong("lastSequenceId"); } } catch (SQLException e) { throw new OsmosisRuntimeException("Unable to retrieve the last sequence id.", e); } }
/** * Returns the id of the most recently inserted row on the current * connection. * * @return The newly inserted id. */ public long getLastInsertId() { if (selectInsertIdStatement == null) { selectInsertIdStatement = statementContainer.add(dbCtx .prepareStatementForStreaming(SQL_SELECT_LAST_INSERT_ID)); } try (ResultSet lastInsertQuery = selectInsertIdStatement.executeQuery()) { lastInsertQuery.next(); return lastInsertQuery.getLong("lastInsertId"); } catch (SQLException e) { throw new OsmosisRuntimeException("Unable to retrieve the id of the newly inserted record.", e); } }
private void addChangeset(long changesetId, long userId) { if (insertStatement == null) { insertStatement = statementContainer.add(dbCtx.prepareStatement(SQL_INSERT_CHANGESET)); insertTagStatement = statementContainer.add(dbCtx.prepareStatement(SQL_INSERT_CHANGESET_TAG)); } try { int prmIndex; // Insert the new changeset record. prmIndex = 1; insertStatement.setLong(prmIndex++, changesetId); insertStatement.setLong(prmIndex++, userId); insertStatement.executeUpdate(); // Insert the changeset tags. prmIndex = 1; insertTagStatement.setLong(prmIndex++, changesetId); insertTagStatement.setLong(prmIndex++, changesetId); insertTagStatement.executeUpdate(); // Add the changeset to the cache, and trim the cache if required. knownChangesetIds.add(changesetId); if (knownChangesetIds.size() > MAX_CHANGESET_ID_CACHE_SIZE) { Iterator<Long> i = knownChangesetIds.iterator(); i.next(); i.remove(); } } catch (SQLException e) { throw new OsmosisRuntimeException("Unable to insert a new changeset for user with id " + userId + ".", e); } }
/** * {@inheritDoc} */ @Override public long getLastSequenceId(String sequenceName) { if (selectSequenceIdStatement == null) { selectSequenceIdStatement = statementContainer.add(dbCtx.prepareStatementForStreaming(SQL_SELECT_LAST_SEQUENCE_ID)); } try { selectSequenceIdStatement.setString(1, sequenceName); try (ResultSet lastSequenceQuery = selectSequenceIdStatement.executeQuery()) { lastSequenceQuery.next(); return lastSequenceQuery.getLong("lastSequenceId"); } } catch (SQLException e) { throw new OsmosisRuntimeException("Unable to retrieve the last sequence id.", e); } }
/** * Returns the id of the most recently inserted row on the current * connection. * * @return The newly inserted id. */ public long getLastInsertId() { if (selectInsertIdStatement == null) { selectInsertIdStatement = statementContainer.add(dbCtx .prepareStatementForStreaming(SQL_SELECT_LAST_INSERT_ID)); } try (ResultSet lastInsertQuery = selectInsertIdStatement.executeQuery()) { lastInsertQuery.next(); return lastInsertQuery.getLong("lastInsertId"); } catch (SQLException e) { throw new OsmosisRuntimeException("Unable to retrieve the id of the newly inserted record.", e); } }
/** * Returns the id of the most recently inserted row on the current * connection. * * @return The newly inserted id. */ public long getLastInsertId() { if (selectInsertIdStatement == null) { selectInsertIdStatement = statementContainer.add(dbCtx.prepareStatementForStreaming(SQL_SELECT_LAST_INSERT_ID)); } try (ResultSet lastInsertQuery = selectInsertIdStatement.executeQuery()) { lastInsertQuery.next(); return lastInsertQuery.getLong("lastInsertId"); } catch (SQLException e) { throw new OsmosisRuntimeException( "Unable to retrieve the id of the newly inserted record.", e ); } }
private void addChangeset(long changesetId, long userId) { if (insertStatement == null) { insertStatement = statementContainer.add(dbCtx.prepareStatement(SQL_INSERT_CHANGESET)); insertTagStatement = statementContainer.add(dbCtx.prepareStatement(SQL_INSERT_CHANGESET_TAG)); } try { int prmIndex; // Insert the new changeset record. prmIndex = 1; insertStatement.setLong(prmIndex++, changesetId); insertStatement.setLong(prmIndex++, userId); insertStatement.executeUpdate(); // Insert the changeset tags. prmIndex = 1; insertTagStatement.setLong(prmIndex++, changesetId); insertTagStatement.setLong(prmIndex++, changesetId); insertTagStatement.executeUpdate(); // Add the changeset to the cache, and trim the cache if required. knownChangesetIds.add(changesetId); if (knownChangesetIds.size() > MAX_CHANGESET_ID_CACHE_SIZE) { Iterator<Long> i = knownChangesetIds.iterator(); i.next(); i.remove(); } } catch (SQLException e) { throw new OsmosisRuntimeException("Unable to insert a new changeset for user with id " + userId + ".", e); } }
/** * Returns the id of the most recently inserted row on the current * connection. * * @return The newly inserted id. */ public long getLastInsertId() { if (selectInsertIdStatement == null) { selectInsertIdStatement = statementContainer.add(dbCtx.prepareStatementForStreaming(SQL_SELECT_LAST_INSERT_ID)); } try (ResultSet lastInsertQuery = selectInsertIdStatement.executeQuery()) { lastInsertQuery.next(); return lastInsertQuery.getLong("lastInsertId"); } catch (SQLException e) { throw new OsmosisRuntimeException( "Unable to retrieve the id of the newly inserted record.", e ); } }
private boolean doesChangesetExist(long changesetId) { if (knownChangesetIds.contains(changesetId)) { return true; } if (selectCountStatement == null) { selectCountStatement = statementContainer.add(dbCtx .prepareStatementForStreaming(SQL_SELECT_CHANGESET_COUNT)); } try { int prmIndex; boolean changesetExists; // Check if the changeset exists. prmIndex = 1; selectCountStatement.setLong(prmIndex++, changesetId); changesetExists = readChangesetCount(selectCountStatement.executeQuery()) > 0; return changesetExists; } catch (SQLException e) { throw new OsmosisRuntimeException("Unable to check if a changeset " + changesetId + " exists.", e); } }
private boolean doesChangesetExist(long changesetId) { if (knownChangesetIds.contains(changesetId)) { return true; } if (selectCountStatement == null) { selectCountStatement = statementContainer.add(dbCtx .prepareStatementForStreaming(SQL_SELECT_CHANGESET_COUNT)); } try { int prmIndex; boolean changesetExists; // Check if the changeset exists. prmIndex = 1; selectCountStatement.setLong(prmIndex++, changesetId); changesetExists = readChangesetCount(selectCountStatement.executeQuery()) > 0; return changesetExists; } catch (SQLException e) { throw new OsmosisRuntimeException("Unable to check if a changeset " + changesetId + " exists.", e); } }
/** * Checks if the specified user exists in the database. * * @param user The user to check for. * @return True if the user exists, false otherwise. */ private boolean doesUserExistInDb(OsmUser user) { if (statementExists == null) { statementExists = statementContainer.add(dbCtx.prepareStatementForStreaming(SELECT_SQL_USER_EXISTS)); } try { statementExists.setInt(1, user.getId()); try (ResultSet resultSet = statementExists.executeQuery()) { resultSet.next(); return resultSet.getInt("userCount") != 0; } } catch (SQLException e) { throw new OsmosisRuntimeException("Unable to check if user with id " + user.getId() + " exists in the database.", e); } }
/** * Checks if the specified user exists in the database. * * @param user The user to check for. * @return True if the user exists, false otherwise. */ private boolean doesUserExistInDb(OsmUser user) { if (statementExists == null) { statementExists = statementContainer.add(dbCtx.prepareStatementForStreaming(SELECT_SQL_USER_EXISTS)); } try { statementExists.setInt(1, user.getId()); try (ResultSet resultSet = statementExists.executeQuery()) { resultSet.next(); return resultSet.getInt("userCount") != 0; } } catch (SQLException e) { throw new OsmosisRuntimeException("Unable to check if user with id " + user.getId() + " exists in the database.", e); } }
bulkNodeStatement = statementContainer.add( dbCtx.prepareStatement(nodeBuilder.getSqlInsert(INSERT_BULK_ROW_COUNT_NODE))); singleNodeStatement = statementContainer.add( dbCtx.prepareStatement(nodeBuilder.getSqlInsert(1))); bulkNodeTagStatement = statementContainer.add( dbCtx.prepareStatement(nodeTagBuilder.getSqlInsert(INSERT_BULK_ROW_COUNT_NODE_TAG))); singleNodeTagStatement = statementContainer.add( dbCtx.prepareStatement(nodeTagBuilder.getSqlInsert(1))); bulkWayStatement = statementContainer.add( dbCtx.prepareStatement(wayBuilder.getSqlInsert(INSERT_BULK_ROW_COUNT_WAY))); singleWayStatement = statementContainer.add( dbCtx.prepareStatement(wayBuilder.getSqlInsert(1))); bulkWayTagStatement = statementContainer.add( dbCtx.prepareStatement(wayTagBuilder.getSqlInsert(INSERT_BULK_ROW_COUNT_WAY_TAG))); singleWayTagStatement = statementContainer.add( dbCtx.prepareStatement(wayTagBuilder.getSqlInsert(1))); bulkWayNodeStatement = statementContainer.add( dbCtx.prepareStatement(wayNodeBuilder.getSqlInsert(INSERT_BULK_ROW_COUNT_WAY_NODE))); singleWayNodeStatement = statementContainer.add( dbCtx.prepareStatement(wayNodeBuilder.getSqlInsert(1))); bulkRelationStatement = statementContainer.add( dbCtx.prepareStatement(relationBuilder.getSqlInsert(INSERT_BULK_ROW_COUNT_RELATION))); singleRelationStatement = statementContainer.add( dbCtx.prepareStatement(relationBuilder.getSqlInsert(1))); bulkRelationTagStatement = statementContainer.add( dbCtx.prepareStatement(relationTagBuilder.getSqlInsert(INSERT_BULK_ROW_COUNT_RELATION_TAG))); singleRelationTagStatement = statementContainer.add( dbCtx.prepareStatement(relationTagBuilder.getSqlInsert(1))); bulkRelationMemberStatement = statementContainer.add(
statementInsert = statementContainer.add(dbCtx.prepareStatement(INSERT_SQL_USER));
statementInsert = statementContainer.add(dbCtx.prepareStatement(INSERT_SQL_USER));
/** * Updates the specified user in the database. * * @param user The user to be updated. */ private void updateUser(OsmUser user) { int prmIndex; if (statementUpdate == null) { statementUpdate = statementContainer.add(dbCtx.prepareStatement(UPDATE_SQL_USER)); } try { String userName; if (OsmUser.NONE.equals(user)) { userName = "Osmosis Anonymous"; } else { userName = user.getName(); } prmIndex = 1; statementUpdate.setString(prmIndex++, userName); statementUpdate.setInt(prmIndex++, user.getId()); statementUpdate.executeUpdate(); } catch (SQLException e) { throw new OsmosisRuntimeException("Unable to update user with id " + user.getId() + " in the database.", e); } }
/** * Updates the specified user in the database. * * @param user The user to be updated. */ private void updateUser(OsmUser user) { int prmIndex; if (statementUpdate == null) { statementUpdate = statementContainer.add(dbCtx.prepareStatement(UPDATE_SQL_USER)); } try { String userName; if (OsmUser.NONE.equals(user)) { userName = "Osmosis Anonymous"; } else { userName = user.getName(); } prmIndex = 1; statementUpdate.setString(prmIndex++, userName); statementUpdate.setInt(prmIndex++, user.getId()); statementUpdate.executeUpdate(); } catch (SQLException e) { throw new OsmosisRuntimeException("Unable to update user with id " + user.getId() + " in the database.", e); } }
/** * Performs post-change database updates. */ public void complete() { CallableStatement updateStatement; try (ReleasableStatementContainer statementContainer = new ReleasableStatementContainer()) { updateStatement = statementContainer.add(dbCtx.prepareCall("{call osmosisUpdate()}")); updateStatement.executeUpdate(); } catch (SQLException e) { throw new OsmosisRuntimeException("Unable to invoke the osmosis update stored function.", e); } // Clear all action records. actionDao.truncate(); }
insertNodeStatement = statementContainer.add(dbCtx.prepareStatement(INSERT_SQL_NODE)); updateNodeStatement = statementContainer.add(dbCtx.prepareStatement(UPDATE_SQL_NODE)); selectNodeCountStatement = statementContainer.add(dbCtx.prepareStatement(SELECT_SQL_NODE_COUNT)); insertNodeCurrentStatement = statementContainer.add(dbCtx.prepareStatement(INSERT_SQL_NODE_CURRENT)); updateNodeCurrentStatement = statementContainer.add(dbCtx.prepareStatement(UPDATE_SQL_NODE_CURRENT)); selectNodeCurrentCountStatement = statementContainer.add(dbCtx .prepareStatement(SELECT_SQL_NODE_CURRENT_COUNT)); insertNodeTagStatement = statementContainer.add(dbCtx.prepareStatement(INSERT_SQL_NODE_TAG)); deleteNodeTagStatement = statementContainer.add(dbCtx.prepareStatement(DELETE_SQL_NODE_TAG)); insertNodeTagCurrentStatement = statementContainer.add(dbCtx.prepareStatement(INSERT_SQL_NODE_TAG_CURRENT)); deleteNodeTagCurrentStatement = statementContainer.add(dbCtx.prepareStatement(DELETE_SQL_NODE_TAG_CURRENT));