diff --git a/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresCoordinateMap.java b/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresCoordinateMap.java index 909138d8d..7f27b313e 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresCoordinateMap.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresCoordinateMap.java @@ -31,59 +31,81 @@ */ public class PostgresCoordinateMap extends DataMap { - public static final String SELECT_CONTAINS_KEY = """ - SELECT 1 - FROM osm_nodes - WHERE id = ? LIMIT 1"""; - - public static final String SELECT_CONTAINS_VALUE = """ - SELECT 1 - FROM osm_nodes - WHERE nodes = ? LIMIT 1"""; - - private static final String SELECT_IN = """ - SELECT id, lon, lat - FROM osm_nodes - WHERE id - WHERE id = ANY (?)"""; - - private static final String SELECT_BY_ID = """ - SELECT lon, lat - FROM osm_nodes - WHERE id = ?"""; - - private static final String SELECT_SIZE = """ - SELECT count() - FROM osm_nodes - """; - - private static final String SELECT_KEYS = """ - SELECT id - FROM osm_nodes - """; - - private static final String SELECT_VALUES = """ - SELECT lon, lat - FROM osm_nodes - """; - - private static final String SELECT_ENTRIES = """ - SELECT id, lon, lat - FROM osm_nodes - """; - private final DataSource dataSource; - /** Constructs a {@link PostgresCoordinateMap}. */ + public final String selectContainsKey; + + public final String selectContainsValue; + + private final String selectIn; + + private final String selectById; + + private final String selectSize; + + private final String selectKeys; + + private final String selectValues; + + private final String selectEntries; + + /** + * Constructs a {@link PostgresCoordinateMap}. + */ public PostgresCoordinateMap(DataSource dataSource) { + this(dataSource, "public", "osm_nodes"); + } + + /** + * Constructs a {@link PostgresCoordinateMap}. + */ + public PostgresCoordinateMap(DataSource dataSource, String schema, String table) { this.dataSource = dataSource; + var fullTableName = String.format("%s.%s", schema, table); + this.selectContainsKey = String.format(""" + SELECT 1 + FROM %1$s + WHERE id = ? LIMIT 1 + """, fullTableName); + this.selectContainsValue = String.format(""" + SELECT 1 + FROM %1$s + WHERE nodes = ? LIMIT 1 + """, fullTableName); + this.selectIn = String.format(""" + SELECT id, lon, lat + FROM %1$s + WHERE id = ANY (?) + """, fullTableName); + this.selectById = String.format(""" + SELECT lon, lat + FROM %1$s + WHERE id = ? + """, fullTableName); + this.selectSize = String.format(""" + SELECT count() + FROM %1$s + """, fullTableName); + this.selectKeys = String.format(""" + SELECT id + FROM %1$s + """, fullTableName); + this.selectValues = String.format(""" + SELECT lon, lat + FROM %1$s + """, fullTableName); + this.selectEntries = String.format(""" + SELECT id, lon, lat + FROM %1$s + """, fullTableName); + } /** {@inheritDoc} */ @Override public Coordinate get(Object key) { try (Connection connection = dataSource.getConnection(); - PreparedStatement statement = connection.prepareStatement(SELECT_BY_ID)) { + PreparedStatement statement = connection.prepareStatement(selectById)) { statement.setLong(1, (Long) key); try (ResultSet result = statement.executeQuery()) { if (result.next()) { @@ -103,7 +125,7 @@ public Coordinate get(Object key) { @Override public List getAll(List keys) { try (Connection connection = dataSource.getConnection(); - PreparedStatement statement = connection.prepareStatement(SELECT_IN)) { + PreparedStatement statement = connection.prepareStatement(selectIn)) { statement.setArray(1, connection.createArrayOf("int8", keys.toArray())); try (ResultSet result = statement.executeQuery()) { Map nodes = new HashMap<>(); @@ -123,7 +145,7 @@ public List getAll(List keys) { @Override protected Iterator keyIterator() { try (Connection connection = dataSource.getConnection(); - PreparedStatement statement = connection.prepareStatement(SELECT_KEYS)) { + PreparedStatement statement = connection.prepareStatement(selectKeys)) { ResultSet result = statement.executeQuery(); return new PostgresIterator<>(result, this::key); } catch (SQLException e) { @@ -142,7 +164,7 @@ private Long key(ResultSet resultSet) { @Override protected Iterator valueIterator() { try (Connection connection = dataSource.getConnection(); - PreparedStatement statement = connection.prepareStatement(SELECT_VALUES)) { + PreparedStatement statement = connection.prepareStatement(selectValues)) { ResultSet result = statement.executeQuery(); return new PostgresIterator<>(result, this::value); } catch (SQLException e) { @@ -163,7 +185,7 @@ private Coordinate value(ResultSet resultSet) { @Override protected Iterator> entryIterator() { try (Connection connection = dataSource.getConnection(); - PreparedStatement statement = connection.prepareStatement(SELECT_ENTRIES)) { + PreparedStatement statement = connection.prepareStatement(selectEntries)) { ResultSet result = statement.executeQuery(); return new PostgresIterator<>(result, this::entry); } catch (SQLException e) { @@ -185,7 +207,7 @@ private Entry entry(ResultSet resultSet) { @Override public long sizeAsLong() { try (Connection connection = dataSource.getConnection(); - PreparedStatement statement = connection.prepareStatement(SELECT_SIZE)) { + PreparedStatement statement = connection.prepareStatement(selectSize)) { try (ResultSet result = statement.executeQuery()) { if (result.next()) { return result.getLong(1); @@ -201,7 +223,7 @@ public long sizeAsLong() { @Override public boolean containsKey(Object key) { try (Connection connection = dataSource.getConnection(); - PreparedStatement statement = connection.prepareStatement(SELECT_CONTAINS_KEY)) { + PreparedStatement statement = connection.prepareStatement(selectContainsKey)) { statement.setLong(1, (Long) key); try (ResultSet result = statement.executeQuery()) { return result.next(); @@ -214,7 +236,7 @@ public boolean containsKey(Object key) { @Override public boolean containsValue(Object value) { try (Connection connection = dataSource.getConnection(); - PreparedStatement statement = connection.prepareStatement(SELECT_CONTAINS_VALUE)) { + PreparedStatement statement = connection.prepareStatement(selectContainsValue)) { statement.setArray(1, connection.createArrayOf("int8", (Long[]) value)); try (ResultSet result = statement.executeQuery()) { return result.next(); diff --git a/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresHeaderRepository.java b/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresHeaderRepository.java index 08d076da5..be6a6be5e 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresHeaderRepository.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresHeaderRepository.java @@ -66,7 +66,8 @@ public class PostgresHeaderRepository implements HeaderRepository { * @param dataSource */ public PostgresHeaderRepository(DataSource dataSource) { - this(dataSource, "osm_headers", "replication_sequence_number", "replication_timestamp", + this(dataSource, "public", "osm_headers", "replication_sequence_number", + "replication_timestamp", "replication_url", "source", "writing_program"); } @@ -74,16 +75,18 @@ public PostgresHeaderRepository(DataSource dataSource) { * Constructs a {@code PostgresHeaderRepository} with custom parameters. * * @param dataSource - * @param tableName + * @param schema + * @param table * @param replicationSequenceNumberColumn * @param replicationTimestampColumn * @param replicationUrlColumn * @param sourceColumn * @param writingProgramColumn */ - public PostgresHeaderRepository(DataSource dataSource, String tableName, + public PostgresHeaderRepository(DataSource dataSource, String schema, String table, String replicationSequenceNumberColumn, String replicationTimestampColumn, String replicationUrlColumn, String sourceColumn, String writingProgramColumn) { + var fullTableName = String.format("%1$s.%2$s", schema, table); this.dataSource = dataSource; this.createTable = String.format(""" CREATE TABLE IF NOT EXISTS %1$s ( @@ -92,20 +95,21 @@ public PostgresHeaderRepository(DataSource dataSource, String tableName, %4$s text, %5$s text, %6$s text - )""", tableName, replicationSequenceNumberColumn, replicationTimestampColumn, + )""", fullTableName, replicationSequenceNumberColumn, replicationTimestampColumn, replicationUrlColumn, sourceColumn, writingProgramColumn); - this.dropTable = String.format("DROP TABLE IF EXISTS %1$s CASCADE", tableName); - this.truncateTable = String.format("TRUNCATE TABLE %1$s", tableName); + this.dropTable = String.format("DROP TABLE IF EXISTS %1$s CASCADE", fullTableName); + this.truncateTable = String.format("TRUNCATE TABLE %1$s", fullTableName); this.selectLatest = - String.format("SELECT %2$s, %3$s, %4$s, %5$s, %6$s FROM %1$s ORDER BY %2$s DESC", tableName, + String.format("SELECT %2$s, %3$s, %4$s, %5$s, %6$s FROM %1$s ORDER BY %2$s DESC", + fullTableName, replicationSequenceNumberColumn, replicationTimestampColumn, replicationUrlColumn, sourceColumn, writingProgramColumn); this.select = String.format("SELECT %2$s, %3$s, %4$s, %5$s, %6$s FROM %1$s WHERE %2$s = ?", - tableName, replicationSequenceNumberColumn, replicationTimestampColumn, + fullTableName, replicationSequenceNumberColumn, replicationTimestampColumn, replicationUrlColumn, sourceColumn, writingProgramColumn); this.selectIn = String.format("SELECT %2$s, %3$s, %4$s, %5$s, %6$s FROM %1$s WHERE %2$s = ANY (?)", - tableName, replicationSequenceNumberColumn, replicationTimestampColumn, + fullTableName, replicationSequenceNumberColumn, replicationTimestampColumn, replicationUrlColumn, sourceColumn, writingProgramColumn); this.insert = String.format(""" INSERT INTO %1$s (%2$s, %3$s, %4$s, %5$s, %6$s) @@ -114,12 +118,12 @@ ON CONFLICT (%2$s) DO UPDATE SET %3$s = excluded.%3$s, %4$s = excluded.%4$s, %5$s = excluded.%5$s, - %6$s = excluded.%6$s""", tableName, replicationSequenceNumberColumn, + %6$s = excluded.%6$s""", fullTableName, replicationSequenceNumberColumn, replicationTimestampColumn, replicationUrlColumn, sourceColumn, writingProgramColumn); - this.delete = String.format("DELETE FROM %1$s WHERE %2$s = ?", tableName, + this.delete = String.format("DELETE FROM %1$s WHERE %2$s = ?", fullTableName, replicationSequenceNumberColumn); this.copy = String.format("COPY %1$s (%2$s, %3$s, %4$s, %5$s, %6$s) FROM STDIN BINARY", - tableName, replicationSequenceNumberColumn, replicationTimestampColumn, + fullTableName, replicationSequenceNumberColumn, replicationTimestampColumn, replicationUrlColumn, sourceColumn, writingProgramColumn); } diff --git a/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresNodeRepository.java b/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresNodeRepository.java index e54f22e4a..9478c08d6 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresNodeRepository.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresNodeRepository.java @@ -69,7 +69,8 @@ public class PostgresNodeRepository implements NodeRepository { * @param dataSource */ public PostgresNodeRepository(DataSource dataSource) { - this(dataSource, "osm_nodes", "id", "version", "uid", "timestamp", "changeset", "tags", "lon", + this(dataSource, "public", "osm_nodes", "id", "version", "uid", "timestamp", "changeset", + "tags", "lon", "lat", "geom"); } @@ -77,7 +78,8 @@ public PostgresNodeRepository(DataSource dataSource) { * Constructs a {@code PostgresNodeRepository} with custom parameters. * * @param dataSource - * @param tableName + * @param schema + * @param table * @param idColumn * @param versionColumn * @param uidColumn @@ -88,9 +90,10 @@ public PostgresNodeRepository(DataSource dataSource) { * @param latitudeColumn * @param geometryColumn */ - public PostgresNodeRepository(DataSource dataSource, String tableName, String idColumn, + public PostgresNodeRepository(DataSource dataSource, String schema, String table, String idColumn, String versionColumn, String uidColumn, String timestampColumn, String changesetColumn, String tagsColumn, String longitudeColumn, String latitudeColumn, String geometryColumn) { + var fullTableName = String.format("%1$s.%2$s", schema, table); this.dataSource = dataSource; this.createTable = String.format(""" CREATE TABLE IF NOT EXISTS %1$s @@ -104,17 +107,19 @@ public PostgresNodeRepository(DataSource dataSource, String tableName, String id %8$s float, %9$s float, %10$s geometry(point) - )""", tableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, + )""", fullTableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, tagsColumn, longitudeColumn, latitudeColumn, geometryColumn); - this.dropTable = String.format("DROP TABLE IF EXISTS %1$s CASCADE", tableName); - this.truncateTable = String.format("TRUNCATE TABLE %1$s", tableName); + this.dropTable = String.format("DROP TABLE IF EXISTS %1$s CASCADE", fullTableName); + this.truncateTable = String.format("TRUNCATE TABLE %1$s", fullTableName); this.select = String.format( "SELECT %2$s, %3$s, %4$s, %5$s, %6$s, %7$s, %8$s, %9$s, st_asbinary(%10$s) FROM %1$s WHERE %2$s = ?", - tableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, tagsColumn, + fullTableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, + tagsColumn, longitudeColumn, latitudeColumn, geometryColumn); this.selectIn = String.format( "SELECT %2$s, %3$s, %4$s, %5$s, %6$s, %7$s, %8$s, %9$s, st_asbinary(%10$s) FROM %1$s WHERE %2$s = ANY (?)", - tableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, tagsColumn, + fullTableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, + tagsColumn, longitudeColumn, latitudeColumn, geometryColumn); this.insert = String.format( "INSERT INTO %1$s (%2$s, %3$s, %4$s, %5$s, %6$s, %7$s, %8$s, %9$s, %10$s) " @@ -123,13 +128,15 @@ public PostgresNodeRepository(DataSource dataSource, String tableName, String id + "%4$s = excluded.%4$s, " + "%5$s = excluded.%5$s, " + "%6$s = excluded.%6$s, " + "%7$s = excluded.%7$s, " + "%8$s = excluded.%8$s, " + "%9$s = excluded.%9$s, " + "%10$s = excluded.%10$s", - tableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, tagsColumn, + fullTableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, + tagsColumn, longitudeColumn, latitudeColumn, geometryColumn); - this.delete = String.format("DELETE FROM %1$s WHERE %2$s = ?", tableName, idColumn); - this.deleteIn = String.format("DELETE FROM %1$s WHERE %2$s = ANY (?)", tableName, idColumn); + this.delete = String.format("DELETE FROM %1$s WHERE %2$s = ?", fullTableName, idColumn); + this.deleteIn = String.format("DELETE FROM %1$s WHERE %2$s = ANY (?)", fullTableName, idColumn); this.copy = String.format( "COPY %1$s (%2$s, %3$s, %4$s, %5$s, %6$s, %7$s, %8$s, %9$s, %10$s) FROM STDIN BINARY", - tableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, tagsColumn, + fullTableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, + tagsColumn, longitudeColumn, latitudeColumn, geometryColumn); } diff --git a/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresReferenceMap.java b/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresReferenceMap.java index 87eb0574d..08b86c6b6 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresReferenceMap.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresReferenceMap.java @@ -34,60 +34,79 @@ */ public class PostgresReferenceMap extends DataMap> { - public static final String SELECT_CONTAINS_KEY = """ - SELECT 1 - FROM osm_ways - WHERE id = ? LIMIT 1"""; - - public static final String SELECT_CONTAINS_VALUE = """ - SELECT 1 - FROM osm_ways - WHERE nodes = ? LIMIT 1"""; - - private static final String SELECT_IN = """ - SELECT id, nodes - FROM osm_ways - WHERE id - WHERE id = ANY (?)"""; - - private static final String SELECT_BY_ID = """ - SELECT nodes - FROM osm_ways - WHERE id = ?"""; - - private static final String SELECT_SIZE = """ - SELECT count() - FROM osm_ways - """; - - private static final String SELECT_KEYS = """ - SELECT id - FROM osm_ways - """; - - private static final String SELECT_VALUES = """ - SELECT nodes - FROM osm_ways - """; - - private static final String SELECT_ENTRIES = """ - SELECT id, nodes - FROM osm_ways - """; - private final DataSource dataSource; + public final String selectContainsKey; + + public final String selectContainsValue; + + private final String selectIn; + + private final String selectById; + + private final String selectSize; + + private final String selectKeys; + + private final String selectValues; + + private final String selectEntries; + /** * Constructs a {@code PostgresReferenceMap}. */ public PostgresReferenceMap(DataSource dataSource) { + this(dataSource, "public", "osm_ways"); + } + + /** + * Constructs a {@code PostgresReferenceMap}. + */ + public PostgresReferenceMap(DataSource dataSource, String schema, String table) { this.dataSource = dataSource; + var fullTableName = String.format("%s.%s", schema, table); + this.selectContainsKey = String.format(""" + SELECT 1 + FROM %1$s + WHERE id = ? LIMIT 1 + """, fullTableName); + this.selectContainsValue = String.format(""" + SELECT 1 + FROM %1$s + WHERE nodes = ? LIMIT 1 + """, fullTableName); + this.selectIn = String.format(""" + SELECT id, nodes + FROM %1$s + WHERE id = ANY (?) + """, fullTableName); + this.selectById = String.format(""" + SELECT nodes + FROM %1$s + WHERE id = ? + """, fullTableName); + this.selectSize = String.format(""" + SELECT count() + FROM %1$s + """, fullTableName); + this.selectKeys = String.format(""" + SELECT id + FROM %1$s + """, fullTableName); + this.selectValues = String.format(""" + SELECT nodes + FROM %1$s + """, fullTableName); + this.selectEntries = String.format(""" + SELECT id, nodes + FROM %1$s + """, fullTableName); } @Override public long sizeAsLong() { try (Connection connection = dataSource.getConnection(); - PreparedStatement statement = connection.prepareStatement(SELECT_SIZE)) { + PreparedStatement statement = connection.prepareStatement(selectSize)) { try (ResultSet result = statement.executeQuery()) { if (result.next()) { return result.getLong(1); @@ -103,7 +122,7 @@ public long sizeAsLong() { @Override public boolean containsKey(Object key) { try (Connection connection = dataSource.getConnection(); - PreparedStatement statement = connection.prepareStatement(SELECT_CONTAINS_KEY)) { + PreparedStatement statement = connection.prepareStatement(selectContainsKey)) { statement.setLong(1, (Long) key); try (ResultSet result = statement.executeQuery()) { return result.next(); @@ -116,7 +135,7 @@ public boolean containsKey(Object key) { @Override public boolean containsValue(Object value) { try (Connection connection = dataSource.getConnection(); - PreparedStatement statement = connection.prepareStatement(SELECT_CONTAINS_VALUE)) { + PreparedStatement statement = connection.prepareStatement(selectContainsValue)) { statement.setArray(1, connection.createArrayOf("int8", (Long[]) value)); try (ResultSet result = statement.executeQuery()) { return result.next(); @@ -132,7 +151,7 @@ public boolean containsValue(Object value) { @Override public List get(Object key) { try (Connection connection = dataSource.getConnection(); - PreparedStatement statement = connection.prepareStatement(SELECT_BY_ID)) { + PreparedStatement statement = connection.prepareStatement(selectById)) { statement.setLong(1, (Long) key); try (ResultSet result = statement.executeQuery()) { if (result.next()) { @@ -153,7 +172,7 @@ public List get(Object key) { @Override public List> getAll(List keys) { try (Connection connection = dataSource.getConnection(); - PreparedStatement statement = connection.prepareStatement(SELECT_IN)) { + PreparedStatement statement = connection.prepareStatement(selectIn)) { statement.setArray(1, connection.createArrayOf("int8", keys.toArray())); try (ResultSet result = statement.executeQuery()) { Map> referenceMap = new HashMap<>(); @@ -173,7 +192,7 @@ public List> getAll(List keys) { @Override protected Iterator keyIterator() { try (Connection connection = dataSource.getConnection(); - PreparedStatement statement = connection.prepareStatement(SELECT_KEYS)) { + PreparedStatement statement = connection.prepareStatement(selectKeys)) { ResultSet result = statement.executeQuery(); return new PostgresIterator<>(result, this::key); } catch (SQLException e) { @@ -192,7 +211,7 @@ private Long key(ResultSet resultSet) { @Override protected Iterator> valueIterator() { try (Connection connection = dataSource.getConnection(); - PreparedStatement statement = connection.prepareStatement(SELECT_VALUES)) { + PreparedStatement statement = connection.prepareStatement(selectValues)) { ResultSet result = statement.executeQuery(); return new PostgresIterator<>(result, this::value); } catch (SQLException e) { @@ -212,7 +231,7 @@ private List value(ResultSet resultSet) { @Override protected Iterator>> entryIterator() { try (Connection connection = dataSource.getConnection(); - PreparedStatement statement = connection.prepareStatement(SELECT_ENTRIES)) { + PreparedStatement statement = connection.prepareStatement(selectEntries)) { ResultSet result = statement.executeQuery(); return new PostgresIterator<>(result, this::entry); } catch (SQLException e) { diff --git a/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresRelationRepository.java b/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresRelationRepository.java index 3e48679e2..32f4055e0 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresRelationRepository.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresRelationRepository.java @@ -68,7 +68,8 @@ public class PostgresRelationRepository implements RelationRepository { * @param dataSource */ public PostgresRelationRepository(DataSource dataSource) { - this(dataSource, "osm_relations", "id", "version", "uid", "timestamp", "changeset", "tags", + this(dataSource, "public", "osm_relations", "id", "version", "uid", "timestamp", "changeset", + "tags", "member_refs", "member_types", "member_roles", "geom"); } @@ -76,7 +77,8 @@ public PostgresRelationRepository(DataSource dataSource) { * Constructs a {@code PostgresRelationRepository} with custom parameters. * * @param dataSource - * @param tableName + * @param schema + * @param table * @param idColumn * @param versionColumn * @param uidColumn @@ -88,10 +90,12 @@ public PostgresRelationRepository(DataSource dataSource) { * @param memberRoles * @param geometryColumn */ - public PostgresRelationRepository(DataSource dataSource, String tableName, String idColumn, + public PostgresRelationRepository(DataSource dataSource, String schema, String table, + String idColumn, String versionColumn, String uidColumn, String timestampColumn, String changesetColumn, String tagsColumn, String memberRefs, String memberTypes, String memberRoles, String geometryColumn) { + var fullTableName = String.format("%1$s.%2$s", schema, table); this.dataSource = dataSource; this.createTable = String.format(""" CREATE TABLE IF NOT EXISTS %1$s ( @@ -105,17 +109,19 @@ public PostgresRelationRepository(DataSource dataSource, String tableName, Strin %9$s int[], %10$s text[], %11$s geometry - )""", tableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, + )""", fullTableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, tagsColumn, memberRefs, memberTypes, memberRoles, geometryColumn); - this.dropTable = String.format("DROP TABLE IF EXISTS %1$s CASCADE", tableName); - this.truncateTable = String.format("TRUNCATE TABLE %1$s", tableName); + this.dropTable = String.format("DROP TABLE IF EXISTS %1$s CASCADE", fullTableName); + this.truncateTable = String.format("TRUNCATE TABLE %1$s", fullTableName); this.select = String.format( "SELECT %2$s, %3$s, %4$s, %5$s, %6$s, %7$s, %8$s, %9$s, %10$s, st_asbinary(%11$s) FROM %1$s WHERE %2$s = ?", - tableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, tagsColumn, + fullTableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, + tagsColumn, memberRefs, memberTypes, memberRoles, geometryColumn); this.selectIn = String.format( "SELECT %2$s, %3$s, %4$s, %5$s, %6$s, %7$s, %8$s, %9$s, %10$s, st_asbinary(%11$s) FROM %1$s WHERE %2$s = ANY (?)", - tableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, tagsColumn, + fullTableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, + tagsColumn, memberRefs, memberTypes, memberRoles, geometryColumn); this.insert = String.format(""" INSERT INTO %1$s (%2$s, %3$s, %4$s, %5$s, %6$s, %7$s, %8$s, %9$s, %10$s, %11$s) @@ -129,13 +135,15 @@ ON CONFLICT (%2$s) DO UPDATE SET %8$s = excluded.%8$s, %9$s = excluded.%9$s, %10$s = excluded.%10$s, - %11$s = excluded.%11$s""", tableName, idColumn, versionColumn, uidColumn, timestampColumn, + %11$s = excluded.%11$s""", fullTableName, idColumn, versionColumn, uidColumn, + timestampColumn, changesetColumn, tagsColumn, memberRefs, memberTypes, memberRoles, geometryColumn); - this.delete = String.format("DELETE FROM %1$s WHERE %2$s = ?", tableName, idColumn); - this.deleteIn = String.format("DELETE FROM %1$s WHERE %2$s = ANY (?)", tableName, idColumn); + this.delete = String.format("DELETE FROM %1$s WHERE %2$s = ?", fullTableName, idColumn); + this.deleteIn = String.format("DELETE FROM %1$s WHERE %2$s = ANY (?)", fullTableName, idColumn); this.copy = String.format( "COPY %1$s (%2$s, %3$s, %4$s, %5$s, %6$s, %7$s, %8$s, %9$s, %10$s, %11$s) FROM STDIN BINARY", - tableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, tagsColumn, + fullTableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, + tagsColumn, memberRefs, memberTypes, memberRoles, geometryColumn); } diff --git a/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresWayRepository.java b/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresWayRepository.java index 0e8d6124a..6d3b7ba9a 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresWayRepository.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/openstreetmap/postgres/PostgresWayRepository.java @@ -72,7 +72,8 @@ public class PostgresWayRepository implements WayRepository { * @param dataSource the datasource */ public PostgresWayRepository(DataSource dataSource) { - this(dataSource, "osm_ways", "id", "version", "uid", "timestamp", "changeset", "tags", "nodes", + this(dataSource, "public", "osm_ways", "id", "version", "uid", "timestamp", "changeset", "tags", + "nodes", "geom"); } @@ -80,7 +81,8 @@ public PostgresWayRepository(DataSource dataSource) { * Constructs a {@code PostgresWayRepository} with custom parameters. * * @param dataSource - * @param tableName + * @param schema + * @param table * @param idColumn * @param versionColumn * @param uidColumn @@ -90,9 +92,10 @@ public PostgresWayRepository(DataSource dataSource) { * @param nodesColumn * @param geometryColumn */ - public PostgresWayRepository(DataSource dataSource, String tableName, String idColumn, + public PostgresWayRepository(DataSource dataSource, String schema, String table, String idColumn, String versionColumn, String uidColumn, String timestampColumn, String changesetColumn, String tagsColumn, String nodesColumn, String geometryColumn) { + var fullTableName = String.format("%1$s.%2$s", schema, table); this.dataSource = dataSource; this.createTable = String.format(""" CREATE TABLE IF NOT EXISTS %1$s ( @@ -104,17 +107,19 @@ public PostgresWayRepository(DataSource dataSource, String tableName, String idC %7$s jsonb, %8$s int8[], %9$s geometry - )""", tableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, + )""", fullTableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, tagsColumn, nodesColumn, geometryColumn); - this.dropTable = String.format("DROP TABLE IF EXISTS %1$s CASCADE", tableName); - this.truncateTable = String.format("TRUNCATE TABLE %1$s", tableName); + this.dropTable = String.format("DROP TABLE IF EXISTS %1$s CASCADE", fullTableName); + this.truncateTable = String.format("TRUNCATE TABLE %1$s", fullTableName); this.select = String.format( "SELECT %2$s, %3$s, %4$s, %5$s, %6$s, %7$s, %8$s, st_asbinary(%9$s) FROM %1$s WHERE %2$s = ?", - tableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, tagsColumn, + fullTableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, + tagsColumn, nodesColumn, geometryColumn); this.selectIn = String.format( "SELECT %2$s, %3$s, %4$s, %5$s, %6$s, %7$s, %8$s, st_asbinary(%9$s) FROM %1$s WHERE %2$s = ANY (?)", - tableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, tagsColumn, + fullTableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, + tagsColumn, nodesColumn, geometryColumn); this.insert = String.format(""" INSERT INTO %1$s (%2$s, %3$s, %4$s, %5$s, %6$s, %7$s, %8$s, %9$s) @@ -126,12 +131,13 @@ ON CONFLICT (%2$s) DO UPDATE SET %6$s = excluded.%6$s, %7$s = excluded.%7$s, %8$s = excluded.%8$s, - %9$s = excluded.%9$s""", tableName, idColumn, versionColumn, uidColumn, timestampColumn, + %9$s = excluded.%9$s""", fullTableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, tagsColumn, nodesColumn, geometryColumn); - this.delete = String.format("DELETE FROM %1$s WHERE %2$s = ?", tableName, idColumn); - this.deleteIn = String.format("DELETE FROM %1$s WHERE %2$s = ANY (?)", tableName, idColumn); + this.delete = String.format("DELETE FROM %1$s WHERE %2$s = ?", fullTableName, idColumn); + this.deleteIn = String.format("DELETE FROM %1$s WHERE %2$s = ANY (?)", fullTableName, idColumn); this.copy = String.format( - "COPY %1$s (%2$s, %3$s, %4$s, %5$s, %6$s, %7$s, %8$s, %9$s) FROM STDIN BINARY", tableName, + "COPY %1$s (%2$s, %3$s, %4$s, %5$s, %6$s, %7$s, %8$s, %9$s) FROM STDIN BINARY", + fullTableName, idColumn, versionColumn, uidColumn, timestampColumn, changesetColumn, tagsColumn, nodesColumn, geometryColumn); }