use of com.baremaps.osm.repository.RepositoryException in project baremaps by baremaps.
the class PostgresRelationRepository method get.
/**
* {@inheritDoc}
*/
@Override
public List<Relation> get(List<Long> keys) throws RepositoryException {
if (keys.isEmpty()) {
return List.of();
}
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(selectIn)) {
statement.setArray(1, connection.createArrayOf("int8", keys.toArray()));
try (ResultSet result = statement.executeQuery()) {
Map<Long, Relation> values = new HashMap<>();
while (result.next()) {
Relation value = getValue(result);
values.put(value.getId(), value);
}
return keys.stream().map(values::get).collect(Collectors.toList());
}
} catch (SQLException | JsonProcessingException e) {
throw new RepositoryException(e);
}
}
use of com.baremaps.osm.repository.RepositoryException in project baremaps by baremaps.
the class PostgresRelationRepository method put.
/**
* {@inheritDoc}
*/
@Override
public void put(List<Relation> values) throws RepositoryException {
if (values.isEmpty()) {
return;
}
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(insert)) {
for (Relation value : values) {
statement.clearParameters();
setValue(statement, value);
statement.addBatch();
}
statement.executeBatch();
} catch (SQLException | JsonProcessingException e) {
throw new RepositoryException(e);
}
}
use of com.baremaps.osm.repository.RepositoryException in project baremaps by baremaps.
the class PostgresRelationRepository method delete.
/**
* {@inheritDoc}
*/
@Override
public void delete(Long key) throws RepositoryException {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(delete)) {
statement.setObject(1, key);
statement.execute();
} catch (SQLException e) {
throw new RepositoryException(e);
}
}
use of com.baremaps.osm.repository.RepositoryException in project baremaps by baremaps.
the class PostgresWayRepository method copy.
/**
* {@inheritDoc}
*/
public void copy(List<Way> values) throws RepositoryException {
if (values.isEmpty()) {
return;
}
try (Connection connection = dataSource.getConnection()) {
PGConnection pgConnection = connection.unwrap(PGConnection.class);
try (CopyWriter writer = new CopyWriter(new PGCopyOutputStream(pgConnection, copy))) {
writer.writeHeader();
for (Way value : values) {
writer.startRow(8);
writer.writeLong(value.getId());
writer.writeInteger(value.getInfo().getVersion());
writer.writeInteger(value.getInfo().getUid());
writer.writeLocalDateTime(value.getInfo().getTimestamp());
writer.writeLong(value.getInfo().getChangeset());
writer.writeJsonb(toJson(value.getTags()));
writer.writeLongList(value.getNodes());
writer.writeGeometry(value.getGeometry());
}
}
} catch (IOException | SQLException e) {
throw new RepositoryException(e);
}
}
use of com.baremaps.osm.repository.RepositoryException in project baremaps by baremaps.
the class PostgresWayRepository method put.
/**
* {@inheritDoc}
*/
@Override
public void put(Way value) throws RepositoryException {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(insert)) {
setValue(statement, value);
statement.execute();
} catch (SQLException | JsonProcessingException e) {
throw new RepositoryException(e);
}
}
Aggregations