Search in sources :

Example 1 with CopyWriter

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);
    }
}
Also used : PGConnection(org.postgresql.PGConnection) PGCopyOutputStream(org.postgresql.copy.PGCopyOutputStream) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PGConnection(org.postgresql.PGConnection) RepositoryException(com.baremaps.osm.repository.RepositoryException) IOException(java.io.IOException) Way(com.baremaps.osm.domain.Way) CopyWriter(com.baremaps.postgres.jdbc.CopyWriter)

Example 2 with CopyWriter

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);
    }
}
Also used : PGConnection(org.postgresql.PGConnection) PGCopyOutputStream(org.postgresql.copy.PGCopyOutputStream) SQLException(java.sql.SQLException) Node(com.baremaps.osm.domain.Node) Connection(java.sql.Connection) PGConnection(org.postgresql.PGConnection) RepositoryException(com.baremaps.osm.repository.RepositoryException) IOException(java.io.IOException) CopyWriter(com.baremaps.postgres.jdbc.CopyWriter)

Example 3 with CopyWriter

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);
    }
}
Also used : PGConnection(org.postgresql.PGConnection) PGCopyOutputStream(org.postgresql.copy.PGCopyOutputStream) Relation(com.baremaps.osm.domain.Relation) MemberType(com.baremaps.osm.domain.Member.MemberType) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PGConnection(org.postgresql.PGConnection) RepositoryException(com.baremaps.osm.repository.RepositoryException) IOException(java.io.IOException) Member(com.baremaps.osm.domain.Member) CopyWriter(com.baremaps.postgres.jdbc.CopyWriter)

Example 4 with CopyWriter

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);
    }
}
Also used : PGConnection(org.postgresql.PGConnection) PGCopyOutputStream(org.postgresql.copy.PGCopyOutputStream) Header(com.baremaps.osm.domain.Header) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PGConnection(org.postgresql.PGConnection) RepositoryException(com.baremaps.osm.repository.RepositoryException) IOException(java.io.IOException) CopyWriter(com.baremaps.postgres.jdbc.CopyWriter)

Aggregations

RepositoryException (com.baremaps.osm.repository.RepositoryException)4 CopyWriter (com.baremaps.postgres.jdbc.CopyWriter)4 IOException (java.io.IOException)4 Connection (java.sql.Connection)4 SQLException (java.sql.SQLException)4 PGConnection (org.postgresql.PGConnection)4 PGCopyOutputStream (org.postgresql.copy.PGCopyOutputStream)4 Header (com.baremaps.osm.domain.Header)1 Member (com.baremaps.osm.domain.Member)1 MemberType (com.baremaps.osm.domain.Member.MemberType)1 Node (com.baremaps.osm.domain.Node)1 Relation (com.baremaps.osm.domain.Relation)1 Way (com.baremaps.osm.domain.Way)1