You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@baremaps.apache.org by bc...@apache.org on 2023/09/09 11:54:39 UTC

[incubator-baremaps] branch 755-pool-size created (now f98ab9b1)

This is an automated email from the ASF dual-hosted git repository.

bchapuis pushed a change to branch 755-pool-size
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git


      at f98ab9b1 Add a datasource object to the tileset

This branch includes the following new commits:

     new f98ab9b1 Add a datasource object to the tileset

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-baremaps] 01/01: Add a datasource object to the tileset

Posted by bc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bchapuis pushed a commit to branch 755-pool-size
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git

commit f98ab9b15a5b911b2581de5804a99106805cd5df
Author: Bertil Chapuis <bc...@gmail.com>
AuthorDate: Sat Sep 9 13:44:32 2023 +0200

    Add a datasource object to the tileset
---
 .../main/java/org/apache/baremaps/cli/map/Dev.java |   9 +-
 .../java/org/apache/baremaps/cli/map/Serve.java    |  10 +-
 .../org/apache/baremaps/utils/PostgresUtils.java   |  51 +++++++
 .../baremaps/vectortile/tileset/DataSource.java    | 164 +++++++++++++++++++++
 .../baremaps/vectortile/tileset/Tileset.java       |  12 ++
 5 files changed, 244 insertions(+), 2 deletions(-)

diff --git a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java
index 1813823b..f7e24f8d 100644
--- a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java
+++ b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.nio.file.Path;
 import java.util.concurrent.Callable;
 import java.util.function.Supplier;
+import javax.sql.DataSource;
 import org.apache.baremaps.cli.Options;
 import org.apache.baremaps.config.ConfigReader;
 import org.apache.baremaps.server.*;
@@ -69,7 +70,13 @@ public class Dev implements Callable<Integer> {
     var configReader = new ConfigReader();
     var objectMapper = objectMapper();
     var tileset = objectMapper.readValue(configReader.read(this.tilesetPath), Tileset.class);
-    var datasource = PostgresUtils.createDataSource(tileset.getDatabase());
+
+    DataSource datasource;
+    if (tileset.getDataSource() != null) {
+      datasource = PostgresUtils.createDataSource(tileset.getDataSource());
+    } else {
+      datasource = PostgresUtils.createDataSource(tileset.getDatabase());
+    }
 
     var tileStoreType = new TypeLiteral<Supplier<TileStore>>() {};
     var tileStoreSupplier = (Supplier<TileStore>) () -> {
diff --git a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Serve.java b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Serve.java
index f4a47619..3ad0a469 100644
--- a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Serve.java
+++ b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Serve.java
@@ -21,6 +21,7 @@ import io.servicetalk.http.router.jersey.HttpJerseyRouterBuilder;
 import java.nio.file.Path;
 import java.util.concurrent.Callable;
 import java.util.function.Supplier;
+import javax.sql.DataSource;
 import org.apache.baremaps.cli.Options;
 import org.apache.baremaps.config.ConfigReader;
 import org.apache.baremaps.server.*;
@@ -73,7 +74,14 @@ public class Serve implements Callable<Integer> {
     var caffeineSpec = CaffeineSpec.parse(cache);
 
     var tileset = objectMapper.readValue(configReader.read(tilesetPath), Tileset.class);
-    var datasource = PostgresUtils.createDataSource(tileset.getDatabase());
+
+    DataSource datasource;
+    if (tileset.getDataSource() != null) {
+      datasource = PostgresUtils.createDataSource(tileset.getDataSource());
+    } else {
+      datasource = PostgresUtils.createDataSource(tileset.getDatabase());
+    }
+
     var tileStoreSupplierType = new TypeLiteral<Supplier<TileStore>>() {};
     var tileStore = new PostgresTileStore(datasource, tileset);
     var tileCache = new TileCache(tileStore, caffeineSpec);
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/utils/PostgresUtils.java b/baremaps-core/src/main/java/org/apache/baremaps/utils/PostgresUtils.java
index e9679483..be377fd3 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/utils/PostgresUtils.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/utils/PostgresUtils.java
@@ -70,6 +70,57 @@ public final class PostgresUtils {
     return new HikariDataSource(config);
   }
 
+  /**
+   * Creates a data source from an object representation of a data source.
+   *
+   * @param datasource the object representation of a data source
+   * @return the data source
+   */
+  public static DataSource createDataSource(
+      org.apache.baremaps.vectortile.tileset.DataSource datasource) {
+    var config = new HikariConfig();
+    if (datasource.getDataSourceClassName() != null) {
+      config.setDataSourceClassName(datasource.getDataSourceClassName());
+    }
+    if (datasource.getJdbcUrl() != null) {
+      config.setJdbcUrl(datasource.getJdbcUrl());
+    }
+    if (datasource.getUsername() != null) {
+      config.setUsername(datasource.getUsername());
+    }
+    if (datasource.getPassword() != null) {
+      config.setPassword(datasource.getPassword());
+    }
+    if (datasource.getAutoCommit() != null) {
+      config.setAutoCommit(datasource.getAutoCommit());
+    }
+    if (datasource.getConnectionTimeout() != null) {
+      config.setConnectionTimeout(datasource.getConnectionTimeout());
+    }
+    if (datasource.getIdleTimeout() != null) {
+      config.setInitializationFailTimeout(datasource.getIdleTimeout());
+    }
+    if (datasource.getKeepAliveTime() != null) {
+      config.setKeepaliveTime(datasource.getKeepAliveTime());
+    }
+    if (datasource.getMaxLifetime() != null) {
+      config.setMaxLifetime(datasource.getMaxLifetime());
+    }
+    if (datasource.getMinimumIdle() != null) {
+      config.setMinimumIdle(datasource.getMinimumIdle());
+    }
+    if (datasource.getMaximumPoolSize() != null) {
+      config.setMaximumPoolSize(datasource.getMaximumPoolSize());
+    }
+    if (datasource.getPoolName() != null) {
+      config.setPoolName(datasource.getPoolName());
+    }
+    if (datasource.getReadOnly() != null) {
+      config.setReadOnly(datasource.getReadOnly());
+    }
+    return new HikariDataSource(config);
+  }
+
   /**
    * Appends the multi-queries parameter to the given JDBC URL.
    *
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/vectortile/tileset/DataSource.java b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/tileset/DataSource.java
new file mode 100644
index 00000000..ec8e2ba7
--- /dev/null
+++ b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/tileset/DataSource.java
@@ -0,0 +1,164 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.baremaps.vectortile.tileset;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class DataSource {
+
+  @JsonProperty("dataSourceClassName")
+  private String dataSourceClassName;
+
+  @JsonProperty("tilejson")
+  private String jdbcUrl;
+
+  @JsonProperty("username")
+  private String username;
+
+  @JsonProperty("password")
+  private String password;
+
+  @JsonProperty("autoCommit")
+  private Boolean autoCommit;
+
+  @JsonProperty("connectionTimeout")
+  private Integer connectionTimeout;
+
+  @JsonProperty("idleTimeout")
+  private Integer idleTimeout;
+
+  @JsonProperty("keepAliveTime")
+  private Integer keepAliveTime;
+
+  @JsonProperty("maxLifetime")
+  private Integer maxLifetime;
+
+  @JsonProperty("minimumIdle")
+  private Integer minimumIdle;
+
+  @JsonProperty("maximumPoolSize")
+  private Integer maximumPoolSize;
+
+  @JsonProperty("poolName")
+  private String poolName;
+
+  @JsonProperty("readOnly")
+  private Boolean readOnly;
+
+  public DataSource() {}
+
+
+  public String getDataSourceClassName() {
+    return dataSourceClassName;
+  }
+
+  public void setDataSourceClassName(String dataSourceClassName) {
+    this.dataSourceClassName = dataSourceClassName;
+  }
+
+  public String getJdbcUrl() {
+    return jdbcUrl;
+  }
+
+  public void setJdbcUrl(String jdbcUrl) {
+    this.jdbcUrl = jdbcUrl;
+  }
+
+  public String getUsername() {
+    return username;
+  }
+
+  public void setUsername(String username) {
+    this.username = username;
+  }
+
+  public String getPassword() {
+    return password;
+  }
+
+  public void setPassword(String password) {
+    this.password = password;
+  }
+
+  public Boolean getAutoCommit() {
+    return autoCommit;
+  }
+
+  public void setAutoCommit(Boolean autoCommit) {
+    this.autoCommit = autoCommit;
+  }
+
+  public Integer getConnectionTimeout() {
+    return connectionTimeout;
+  }
+
+  public void setConnectionTimeout(Integer connectionTimeout) {
+    this.connectionTimeout = connectionTimeout;
+  }
+
+  public Integer getIdleTimeout() {
+    return idleTimeout;
+  }
+
+  public void setIdleTimeout(Integer idleTimeout) {
+    this.idleTimeout = idleTimeout;
+  }
+
+  public Integer getKeepAliveTime() {
+    return keepAliveTime;
+  }
+
+  public void setKeepAliveTime(Integer keepAliveTime) {
+    this.keepAliveTime = keepAliveTime;
+  }
+
+  public Integer getMaxLifetime() {
+    return maxLifetime;
+  }
+
+  public void setMaxLifetime(Integer maxLifetime) {
+    this.maxLifetime = maxLifetime;
+  }
+
+  public Integer getMinimumIdle() {
+    return minimumIdle;
+  }
+
+  public void setMinimumIdle(Integer minimumIdle) {
+    this.minimumIdle = minimumIdle;
+  }
+
+  public Integer getMaximumPoolSize() {
+    return maximumPoolSize;
+  }
+
+  public void setMaximumPoolSize(Integer maximumPoolSize) {
+    this.maximumPoolSize = maximumPoolSize;
+  }
+
+  public String getPoolName() {
+    return poolName;
+  }
+
+  public void setPoolName(String poolName) {
+    this.poolName = poolName;
+  }
+
+  public Boolean getReadOnly() {
+    return readOnly;
+  }
+
+  public void setReadOnly(Boolean readOnly) {
+    this.readOnly = readOnly;
+  }
+}
diff --git a/baremaps-core/src/main/java/org/apache/baremaps/vectortile/tileset/Tileset.java b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/tileset/Tileset.java
index 7338435c..1b0d47ec 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/vectortile/tileset/Tileset.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/vectortile/tileset/Tileset.java
@@ -72,9 +72,13 @@ public class Tileset {
   @JsonProperty("center")
   private List<Double> center = new ArrayList<>();
 
+  @Deprecated
   @JsonProperty("database")
   private String database;
 
+  @JsonProperty("datasource")
+  private String dataSource;
+
   @JsonProperty("vector_layers")
   private List<TilesetLayer> vectorLayers = new ArrayList<>();
 
@@ -123,6 +127,14 @@ public class Tileset {
     return this;
   }
 
+  public String getDataSource() {
+    return dataSource;
+  }
+
+  public void setDataSource(String dataSource) {
+    this.dataSource = dataSource;
+  }
+
   public String getDescription() {
     return description;
   }