use of org.openstreetmap.osmosis.pgsimple.common.NoSuchRecordException in project osmosis by openstreetmap.
the class ChangeWriter method writeUser.
/**
* Writes the specified user to the database.
*
* @param user
* The user to write.
*/
private void writeUser(OsmUser user) {
// Entities without a user assigned should not be written.
if (!OsmUser.NONE.equals(user)) {
// run.
if (!userSet.contains(user.getId())) {
int userId;
OsmUser existingUser;
userId = user.getId();
try {
existingUser = userDao.getUser(userId);
if (!user.equals(existingUser)) {
userDao.updateUser(user);
}
} catch (NoSuchRecordException e) {
userDao.addUser(user);
}
userSet.add(user.getId());
}
}
}
use of org.openstreetmap.osmosis.pgsimple.common.NoSuchRecordException in project osmosis by openstreetmap.
the class PostgreSqlEntityManager method writeUser.
/**
* Writes the specified user to the database.
*
* @param user
* The user to write.
*/
private void writeUser(OsmUser user) {
// Entities without a user assigned should not be written.
if (!OsmUser.NONE.equals(user)) {
// run.
if (!userSet.contains(user.getId())) {
int userId;
OsmUser existingUser;
userId = user.getId();
try {
existingUser = userDao.getUser(userId);
if (!user.equals(existingUser)) {
userDao.updateUser(user);
}
} catch (NoSuchRecordException e) {
userDao.addUser(user);
}
userSet.add(user.getId());
}
}
}
use of org.openstreetmap.osmosis.pgsimple.common.NoSuchRecordException in project osmosis by openstreetmap.
the class EntityDao method getEntity.
/**
* Loads the specified entity from the database.
*
* @param entityId
* The unique identifier of the entity.
* @return The loaded entity.
*/
public T getEntity(long entityId) {
T entity;
if (getStatement == null) {
getStatement = prepareStatement(entityMapper.getSqlSelect(true, true));
}
try {
getStatement.setLong(1, entityId);
try (ResultSet resultSet = getStatement.executeQuery()) {
if (!resultSet.next()) {
throw new NoSuchRecordException(entityMapper.getEntityName() + " " + entityId + " doesn't exist.");
}
entity = entityMapper.parseRecord(resultSet);
}
for (DbFeature<Tag> dbTag : tagDao.getAll(entityId)) {
entity.getTags().add(dbTag.getFeature());
}
// Add the type specific features.
loadFeatures(entityId, entity);
return entity;
} catch (SQLException e) {
throw new OsmosisRuntimeException("Query failed for " + entityMapper.getEntityName() + " " + entityId + ".", e);
}
}
use of org.openstreetmap.osmosis.pgsimple.common.NoSuchRecordException in project osmosis by openstreetmap.
the class UserDao method getUser.
/**
* Loads the specified way from the database.
*
* @param userId
* The unique identifier of the user.
* @return The loaded user.
*/
public OsmUser getUser(long userId) {
ResultSet resultSet = null;
OsmUser user;
if (selectUserStatement == null) {
selectUserStatement = prepareStatement(SELECT_USER);
}
try {
selectUserStatement.setLong(1, userId);
resultSet = selectUserStatement.executeQuery();
if (!resultSet.next()) {
throw new NoSuchRecordException("User " + userId + " doesn't exist.");
}
user = buildUser(resultSet);
resultSet.close();
resultSet = null;
return user;
} catch (SQLException e) {
throw new OsmosisRuntimeException("Query failed for user " + userId + ".");
} finally {
if (resultSet != null) {
try {
resultSet.close();
} catch (SQLException e) {
// We are already in an error condition so log and continue.
LOG.log(Level.WARNING, "Unable to close the result set.", e);
}
}
}
}
Aggregations