99import io .github .thunderz99 .cosmos .CosmosException ;
1010import io .github .thunderz99 .cosmos .dto .CosmosContainerResponse ;
1111import io .github .thunderz99 .cosmos .dto .UniqueKeyPolicy ;
12+ import io .github .thunderz99 .cosmos .impl .postgres .dto .PostgresHikariOptions ;
1213import io .github .thunderz99 .cosmos .impl .postgres .util .PGSortUtil ;
1314import io .github .thunderz99 .cosmos .impl .postgres .util .TableUtil ;
1415import io .github .thunderz99 .cosmos .util .Checker ;
@@ -61,8 +62,22 @@ public PostgresImpl(String connectionString) {
6162 }
6263
6364 public PostgresImpl (String connectionString , boolean expireAtEnabled , boolean etagEnabled , String collate ) {
65+ this (connectionString , expireAtEnabled , etagEnabled , collate , null );
66+ }
67+
68+ /**
69+ * Build postgres cosmos client with custom hikari settings.
70+ *
71+ * @param connectionString postgres connection string
72+ * @param expireAtEnabled whether enable expireAt feature
73+ * @param etagEnabled whether enable etag feature
74+ * @param collate collation used for postgres sorting
75+ * @param hikariOptions optional custom hikari options
76+ */
77+ public PostgresImpl (String connectionString , boolean expireAtEnabled , boolean etagEnabled ,
78+ String collate , PostgresHikariOptions hikariOptions ) {
6479
65- var pair = parseToHikariConfig (connectionString );
80+ var pair = parseToHikariConfig (connectionString , hikariOptions );
6681 var config = pair .getLeft ();
6782 this .account = pair .getRight ();
6883
@@ -84,9 +99,21 @@ public PostgresImpl(String connectionString, boolean expireAtEnabled, boolean et
8499 * @return pair of HikariConfig and account(hostName)
85100 */
86101 public static Pair <HikariConfig , String > parseToHikariConfig (String connectionString ) {
102+ return parseToHikariConfig (connectionString , null );
103+ }
104+
105+ /**
106+ * parse connectionString("postgres://user:pass@localhost:5432/database1") to HikariConfig,
107+ * then apply optional custom hikari settings.
108+ *
109+ * @param connectionString postgres connectionString
110+ * @param hikariOptions optional custom hikari options
111+ * @return pair of HikariConfig and account(hostName)
112+ */
113+ public static Pair <HikariConfig , String > parseToHikariConfig (String connectionString ,
114+ PostgresHikariOptions hikariOptions ) {
87115
88116 Checker .checkNotBlank (connectionString , "connectionString" );
89- var config = new HikariConfig ();
90117 URI uri ;
91118 try {
92119 // use URI to parse connectionString
@@ -100,6 +127,8 @@ public static Pair<HikariConfig, String> parseToHikariConfig(String connectionSt
100127 throw new IllegalArgumentException ("connectionString not valid for postgres: " + connectionString , e );
101128 }
102129
130+ var config = hikariOptions == null ? new HikariConfig () : new HikariConfig (hikariOptions .getHikariProperties ());
131+
103132 String jdbcUrl = String .format ("jdbc:postgresql://%s:%d%s" ,
104133 uri .getHost (), uri .getPort (), uri .getRawPath ());
105134
@@ -128,6 +157,10 @@ public static Pair<HikariConfig, String> parseToHikariConfig(String connectionSt
128157 }
129158 config .setDriverClassName ("org.postgresql.Driver" );
130159
160+ if (hikariOptions != null ) {
161+ hikariOptions .applyTo (config );
162+ }
163+
131164 var account = uri .getHost ();
132165
133166 return Pair .of (config , account );
@@ -309,4 +342,4 @@ public void closeClient() {
309342 this .getDataSource ().close ();
310343 }
311344
312- }
345+ }
0 commit comments