use of com.baremaps.postgres.jdbc.CopyWriter 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.postgres.jdbc.CopyWriter 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.postgres.jdbc.CopyWriter in project baremaps by baremaps.
the class PostgresRelationRepository method copy.
/**
* {@inheritDoc}
*/
@Override
public void copy(List<Relation> 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 (Relation value : values) {
writer.startRow(10);
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.getMembers().stream().map(Member::getRef).collect(Collectors.toList()));
writer.writeIntegerList(value.getMembers().stream().map(Member::getType).map(MemberType::ordinal).collect(Collectors.toList()));
writer.writeStringList(value.getMembers().stream().map(Member::getRole).collect(Collectors.toList()));
writer.writeGeometry(value.getGeometry());
}
}
} catch (IOException | SQLException ex) {
throw new RepositoryException(ex);
}
}
use of com.baremaps.postgres.jdbc.CopyWriter in project baremaps by baremaps.
the class PostgresHeaderRepository method copy.
/**
* {@inheritDoc}
*/
@Override
public void copy(List<Header> 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 (Header value : values) {
writer.startRow(5);
writer.writeLong(value.getReplicationSequenceNumber());
writer.writeLocalDateTime(value.getReplicationTimestamp());
writer.writeString(value.getReplicationUrl());
writer.writeString(value.getSource());
writer.writeString(value.getWritingProgram());
}
}
} catch (IOException | SQLException e) {
throw new RepositoryException(e);
}
}
Aggregations