use of com.baremaps.osm.repository.RepositoryException in project baremaps by baremaps.
the class PostgresHeaderRepository method delete.
/**
* {@inheritDoc}
*/
@Override
public void delete(List<Long> keys) throws RepositoryException {
if (keys.isEmpty()) {
return;
}
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(delete)) {
for (Long key : keys) {
statement.clearParameters();
statement.setObject(1, key);
statement.addBatch();
}
statement.executeBatch();
} catch (SQLException e) {
throw new RepositoryException(e);
}
}
use of com.baremaps.osm.repository.RepositoryException in project baremaps by baremaps.
the class PostgresNodeRepository method delete.
/**
* {@inheritDoc}
*/
@Override
public void delete(List<Long> keys) throws RepositoryException {
if (keys.isEmpty()) {
return;
}
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(delete)) {
for (Long key : keys) {
statement.clearParameters();
statement.setObject(1, key);
statement.addBatch();
}
statement.executeBatch();
} catch (SQLException e) {
throw new RepositoryException(e);
}
}
use of com.baremaps.osm.repository.RepositoryException in project baremaps by baremaps.
the class PostgresNodeRepository method get.
/**
* {@inheritDoc}
*/
@Override
public List<Node> 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, Node> values = new HashMap<>();
while (result.next()) {
Node 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 PostgresNodeRepository method copy.
/**
* {@inheritDoc}
*/
@Override
public void copy(List<Node> 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 (Node value : values) {
writer.startRow(9);
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.writeDouble(value.getLon());
writer.writeDouble(value.getLat());
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 PostgresRelationRepository method delete.
/**
* {@inheritDoc}
*/
@Override
public void delete(List<Long> keys) throws RepositoryException {
if (keys.isEmpty()) {
return;
}
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(delete)) {
for (Long key : keys) {
statement.clearParameters();
statement.setObject(1, key);
statement.addBatch();
}
statement.executeBatch();
} catch (SQLException e) {
throw new RepositoryException(e);
}
}
Aggregations