Skip to content

Commit 61ec4c5

Browse files
committed
Merge pull request #35 from vert-x3/add-config-options
Add configuration options for charset and timeout
2 parents f3becea + 61a845c commit 61ec4c5

File tree

19 files changed

+337
-76
lines changed

19 files changed

+337
-76
lines changed

src/main/asciidoc/groovy/index.adoc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ application.
1515

1616
To use this client, you need to add the following jar to your `CLASSPATH`:
1717

18-
* vertx-mysql-postgresql-client 3.2.1 (the client)
18+
* vertx-mysql-postgresql-client 3.3.0-SNAPSHOT (the client)
1919
* scala-library 2.11.4
2020
* the postgress-async-2.11 and mysdql-async-2.11 from https://github.com/mauricio/postgresql-async
2121
* joda time
@@ -33,15 +33,15 @@ If you are building a _Fat-jar_ using Maven or Gradle, just add the following de
3333
<dependency>
3434
<groupId>io.vertx</groupId>
3535
<artifactId>vertx-mysql-postgresql-client</artifactId>
36-
<version>3.2.1</version>
36+
<version>3.3.0-SNAPSHOT</version>
3737
</dependency>
3838
----
3939

4040
* Gradle (in your `build.gradle` file):
4141

4242
[source,groovy,subs="+attributes"]
4343
----
44-
compile 'io.vertx:vertx-mysql-postgresql-client:3.2.1'
44+
compile 'io.vertx:vertx-mysql-postgresql-client:3.3.0-SNAPSHOT'
4545
----
4646

4747
=== In an application using a vert.x distributions
@@ -232,7 +232,9 @@ Both the PostgreSql and MySql clients take the same configuration:
232232
"maxPoolSize" : <maximum-number-of-open-connections>,
233233
"username" : <your-username>,
234234
"password" : <your-password>,
235-
"database" : <name-of-your-database>
235+
"database" : <name-of-your-database>,
236+
"charset" : <name-of-the-character-set>,
237+
"queryTimeout" : <timeout-in-milliseconds>
236238
}
237239
----
238240

@@ -241,4 +243,6 @@ Both the PostgreSql and MySql clients take the same configuration:
241243
`maxPoolSize`:: The number of connections that may be kept open. Defaults to `10`.
242244
`username`:: The username to connect to the database. Defaults to `postgres` for PostgreSQL and `root` for MySQL.
243245
`password`:: The password to connect to the database. Default is not set, i.e. it uses no password.
244-
`database`:: The name of the database you want to connect to. Defaults to `test`.
246+
`database`:: The name of the database you want to connect to. Defaults to `test`.
247+
`charset`:: The name of the character set you want to use for the connection. Defaults to `UTF-8`.
248+
`queryTimeout`:: The timeout to wait for a query in milliseconds. Defaults to `10000` (= 10 seconds).

src/main/asciidoc/java/index.adoc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ application.
1515

1616
To use this client, you need to add the following jar to your `CLASSPATH`:
1717

18-
* vertx-mysql-postgresql-client 3.2.1 (the client)
18+
* vertx-mysql-postgresql-client 3.3.0-SNAPSHOT (the client)
1919
* scala-library 2.11.4
2020
* the postgress-async-2.11 and mysdql-async-2.11 from https://github.com/mauricio/postgresql-async
2121
* joda time
@@ -33,15 +33,15 @@ If you are building a _Fat-jar_ using Maven or Gradle, just add the following de
3333
<dependency>
3434
<groupId>io.vertx</groupId>
3535
<artifactId>vertx-mysql-postgresql-client</artifactId>
36-
<version>3.2.1</version>
36+
<version>3.3.0-SNAPSHOT</version>
3737
</dependency>
3838
----
3939

4040
* Gradle (in your `build.gradle` file):
4141

4242
[source,groovy,subs="+attributes"]
4343
----
44-
compile 'io.vertx:vertx-mysql-postgresql-client:3.2.1'
44+
compile 'io.vertx:vertx-mysql-postgresql-client:3.3.0-SNAPSHOT'
4545
----
4646

4747
=== In an application using a vert.x distributions
@@ -194,7 +194,9 @@ Both the PostgreSql and MySql clients take the same configuration:
194194
"maxPoolSize" : <maximum-number-of-open-connections>,
195195
"username" : <your-username>,
196196
"password" : <your-password>,
197-
"database" : <name-of-your-database>
197+
"database" : <name-of-your-database>,
198+
"charset" : <name-of-the-character-set>,
199+
"queryTimeout" : <timeout-in-milliseconds>
198200
}
199201
----
200202

@@ -203,4 +205,6 @@ Both the PostgreSql and MySql clients take the same configuration:
203205
`maxPoolSize`:: The number of connections that may be kept open. Defaults to `10`.
204206
`username`:: The username to connect to the database. Defaults to `postgres` for PostgreSQL and `root` for MySQL.
205207
`password`:: The password to connect to the database. Default is not set, i.e. it uses no password.
206-
`database`:: The name of the database you want to connect to. Defaults to `test`.
208+
`database`:: The name of the database you want to connect to. Defaults to `test`.
209+
`charset`:: The name of the character set you want to use for the connection. Defaults to `UTF-8`.
210+
`queryTimeout`:: The timeout to wait for a query in milliseconds. Defaults to `10000` (= 10 seconds).

src/main/asciidoc/js/index.adoc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ application.
1515

1616
To use this client, you need to add the following jar to your `CLASSPATH`:
1717

18-
* vertx-mysql-postgresql-client 3.2.1 (the client)
18+
* vertx-mysql-postgresql-client 3.3.0-SNAPSHOT (the client)
1919
* scala-library 2.11.4
2020
* the postgress-async-2.11 and mysdql-async-2.11 from https://github.com/mauricio/postgresql-async
2121
* joda time
@@ -33,15 +33,15 @@ If you are building a _Fat-jar_ using Maven or Gradle, just add the following de
3333
<dependency>
3434
<groupId>io.vertx</groupId>
3535
<artifactId>vertx-mysql-postgresql-client</artifactId>
36-
<version>3.2.1</version>
36+
<version>3.3.0-SNAPSHOT</version>
3737
</dependency>
3838
----
3939

4040
* Gradle (in your `build.gradle` file):
4141

4242
[source,groovy,subs="+attributes"]
4343
----
44-
compile 'io.vertx:vertx-mysql-postgresql-client:3.2.1'
44+
compile 'io.vertx:vertx-mysql-postgresql-client:3.3.0-SNAPSHOT'
4545
----
4646

4747
=== In an application using a vert.x distributions
@@ -232,7 +232,9 @@ Both the PostgreSql and MySql clients take the same configuration:
232232
"maxPoolSize" : <maximum-number-of-open-connections>,
233233
"username" : <your-username>,
234234
"password" : <your-password>,
235-
"database" : <name-of-your-database>
235+
"database" : <name-of-your-database>,
236+
"charset" : <name-of-the-character-set>,
237+
"queryTimeout" : <timeout-in-milliseconds>
236238
}
237239
----
238240

@@ -241,4 +243,6 @@ Both the PostgreSql and MySql clients take the same configuration:
241243
`maxPoolSize`:: The number of connections that may be kept open. Defaults to `10`.
242244
`username`:: The username to connect to the database. Defaults to `postgres` for PostgreSQL and `root` for MySQL.
243245
`password`:: The password to connect to the database. Default is not set, i.e. it uses no password.
244-
`database`:: The name of the database you want to connect to. Defaults to `test`.
246+
`database`:: The name of the database you want to connect to. Defaults to `test`.
247+
`charset`:: The name of the character set you want to use for the connection. Defaults to `UTF-8`.
248+
`queryTimeout`:: The timeout to wait for a query in milliseconds. Defaults to `10000` (= 10 seconds).

src/main/asciidoc/ruby/index.adoc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ application.
1515

1616
To use this client, you need to add the following jar to your `CLASSPATH`:
1717

18-
* vertx-mysql-postgresql-client 3.2.1 (the client)
18+
* vertx-mysql-postgresql-client 3.3.0-SNAPSHOT (the client)
1919
* scala-library 2.11.4
2020
* the postgress-async-2.11 and mysdql-async-2.11 from https://github.com/mauricio/postgresql-async
2121
* joda time
@@ -33,15 +33,15 @@ If you are building a _Fat-jar_ using Maven or Gradle, just add the following de
3333
<dependency>
3434
<groupId>io.vertx</groupId>
3535
<artifactId>vertx-mysql-postgresql-client</artifactId>
36-
<version>3.2.1</version>
36+
<version>3.3.0-SNAPSHOT</version>
3737
</dependency>
3838
----
3939

4040
* Gradle (in your `build.gradle` file):
4141

4242
[source,groovy,subs="+attributes"]
4343
----
44-
compile 'io.vertx:vertx-mysql-postgresql-client:3.2.1'
44+
compile 'io.vertx:vertx-mysql-postgresql-client:3.3.0-SNAPSHOT'
4545
----
4646

4747
=== In an application using a vert.x distributions
@@ -232,7 +232,9 @@ Both the PostgreSql and MySql clients take the same configuration:
232232
"maxPoolSize" : <maximum-number-of-open-connections>,
233233
"username" : <your-username>,
234234
"password" : <your-password>,
235-
"database" : <name-of-your-database>
235+
"database" : <name-of-your-database>,
236+
"charset" : <name-of-the-character-set>,
237+
"queryTimeout" : <timeout-in-milliseconds>
236238
}
237239
----
238240

@@ -241,4 +243,6 @@ Both the PostgreSql and MySql clients take the same configuration:
241243
`maxPoolSize`:: The number of connections that may be kept open. Defaults to `10`.
242244
`username`:: The username to connect to the database. Defaults to `postgres` for PostgreSQL and `root` for MySQL.
243245
`password`:: The password to connect to the database. Default is not set, i.e. it uses no password.
244-
`database`:: The name of the database you want to connect to. Defaults to `test`.
246+
`database`:: The name of the database you want to connect to. Defaults to `test`.
247+
`charset`:: The name of the character set you want to use for the connection. Defaults to `UTF-8`.
248+
`queryTimeout`:: The timeout to wait for a query in milliseconds. Defaults to `10000` (= 10 seconds).

src/main/generated/io/vertx/rxjava/ext/asyncsql/PostgreSQLClient.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ public static AsyncSQLClient createNonShared(Vertx vertx, JsonObject config) {
5454
}
5555

5656
/**
57-
* Create a PostgreSQL client which shares its pool with any other MySQL clients created with the same
58-
* pool name.
57+
* Create a PostgreSQL client which shares its pool with any other MySQL clients created with the same pool name.
5958
* @param vertx the Vert.x instance
6059
* @param config the configuration
6160
* @param poolName the pool name

src/main/groovy/io/vertx/groovy/ext/asyncsql/PostgreSQLClient.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ public class PostgreSQLClient extends AsyncSQLClient {
4444
return ret;
4545
}
4646
/**
47-
* Create a PostgreSQL client which shares its pool with any other MySQL clients created with the same
48-
* pool name.
47+
* Create a PostgreSQL client which shares its pool with any other MySQL clients created with the same pool name.
4948
* @param vertx the Vert.x instance
5049
* @param config the configuration
5150
* @param poolName the pool name

src/main/java/io/vertx/ext/asyncsql/MySQLClient.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ public interface MySQLClient extends AsyncSQLClient {
6262
*/
6363
String DEFAULT_PASSWORD = "password";
6464

65+
/**
66+
* The default charset.
67+
*/
68+
String DEFAULT_CHARSET = "UTF-8";
69+
70+
/**
71+
* The default timeout for connect.
72+
*/
73+
long DEFAULT_CONNECT_TIMEOUT = 10000L;
74+
75+
/**
76+
* The default timeout for tests.
77+
*/
78+
long DEFAULT_TEST_TIMEOUT = 10000L;
79+
6580

6681
/**
6782
* Create a MySQL client which maintains its own pool.

src/main/java/io/vertx/ext/asyncsql/PostgreSQLClient.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,37 +62,51 @@ public interface PostgreSQLClient extends AsyncSQLClient {
6262
*/
6363
String DEFAULT_PASSWORD = "password";
6464

65+
/**
66+
* The default charset.
67+
*/
68+
String DEFAULT_CHARSET = "UTF-8";
69+
70+
/**
71+
* The default timeout for connect.
72+
*/
73+
long DEFAULT_CONNECT_TIMEOUT = 10000L;
74+
75+
/**
76+
* The default timeout for tests.
77+
*/
78+
long DEFAULT_TEST_TIMEOUT = 10000L;
79+
6580

6681
/**
6782
* Create a PostgreSQL client which maintains its own pool.
6883
*
69-
* @param vertx the Vert.x instance
70-
* @param config the configuration
84+
* @param vertx the Vert.x instance
85+
* @param config the configuration
7186
* @return the client
7287
*/
7388
static AsyncSQLClient createNonShared(Vertx vertx, JsonObject config) {
7489
return ClientHelper.getOrCreate(vertx, config, UUID.randomUUID().toString(), false);
7590
}
7691

7792
/**
78-
* Create a PostgreSQL client which shares its pool with any other MySQL clients created with the same
79-
* pool name.
93+
* Create a PostgreSQL client which shares its pool with any other MySQL clients created with the same pool name.
8094
*
8195
* @param vertx the Vert.x instance
8296
* @param config the configuration
8397
* @param poolName the pool name
8498
* @return the client
8599
*/
86-
static AsyncSQLClient createShared(Vertx vertx,JsonObject config, String poolName) {
100+
static AsyncSQLClient createShared(Vertx vertx, JsonObject config, String poolName) {
87101
return ClientHelper.getOrCreate(vertx, config, poolName, false);
88102
}
89103

90104

91105
/**
92106
* Like {@link #createShared(io.vertx.core.Vertx, JsonObject, String)} but with the default pool name
93107
*
94-
* @param vertx the Vert.x instance
95-
* @param config the configuration
108+
* @param vertx the Vert.x instance
109+
* @param config the configuration
96110
* @return the client
97111
*/
98112
static AsyncSQLClient createShared(Vertx vertx, JsonObject config) {

src/main/java/io/vertx/ext/asyncsql/impl/BaseSQLClient.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import scala.concurrent.ExecutionContext;
3434
import scala.concurrent.duration.Duration;
3535

36+
import java.nio.charset.Charset;
3637
import java.util.concurrent.TimeUnit;
3738

3839
/**
@@ -57,6 +58,7 @@ public BaseSQLClient(Vertx vertx, JsonObject config) {
5758
}
5859

5960
protected abstract AsyncConnectionPool pool();
61+
6062
protected abstract SQLConnection createFromPool(Connection conn, AsyncConnectionPool pool, ExecutionContext ec);
6163

6264
public void getConnection(Handler<AsyncResult<SQLConnection>> handler) {
@@ -91,17 +93,37 @@ public void close() {
9193
close(null);
9294
}
9395

94-
protected Configuration getConfiguration(String defaultHost, int defaultPort, String defaultDatabase, String defaultUser, String defaultPassword, JsonObject config) {
96+
protected Configuration getConfiguration(
97+
String defaultHost,
98+
int defaultPort,
99+
String defaultDatabase,
100+
String defaultUser,
101+
String defaultPassword,
102+
String defaultCharset,
103+
long defaultConnectTimeout,
104+
long defaultTestTimeout,
105+
JsonObject config) {
106+
95107
String host = config.getString("host", defaultHost);
96108
int port = config.getInteger("port", defaultPort);
97109
String username = config.getString("username", defaultUser);
98110
String password = config.getString("password", defaultPassword);
99111
String database = config.getString("database", defaultDatabase);
112+
Charset charset = Charset.forName(config.getString("charset", defaultCharset));
113+
long connectTimeout = config.getLong("connectTimeout", defaultConnectTimeout);
114+
long testTimeout = config.getLong("testTimeout", defaultTestTimeout);
115+
Long queryTimeout = config.getLong("queryTimeout");
116+
Option<Duration> queryTimeoutOption = (queryTimeout == null) ?
117+
Option.empty() : Option.apply(Duration.apply(queryTimeout, TimeUnit.MILLISECONDS));
100118

101119
log.info("Creating configuration for " + host + ":" + port);
102120
return new Configuration(username, host, port, Option.apply(password), Option.apply(database),
103-
CharsetUtil.UTF_8, 16777216, PooledByteBufAllocator.DEFAULT,
104-
Duration.apply(5, TimeUnit.SECONDS), Duration.apply(5, TimeUnit.SECONDS), Option.empty());
121+
charset,
122+
16777216,
123+
PooledByteBufAllocator.DEFAULT,
124+
Duration.apply(connectTimeout, TimeUnit.MILLISECONDS),
125+
Duration.apply(testTimeout, TimeUnit.MILLISECONDS),
126+
queryTimeoutOption);
105127
}
106128

107129

src/main/java/io/vertx/ext/asyncsql/impl/MYSQLClientImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public MYSQLClientImpl(Vertx vertx,
4343
MySQLClient.DEFAULT_DATABASE,
4444
MySQLClient.DEFAULT_USER,
4545
MySQLClient.DEFAULT_PASSWORD,
46+
MySQLClient.DEFAULT_CHARSET,
47+
MySQLClient.DEFAULT_CONNECT_TIMEOUT,
48+
MySQLClient.DEFAULT_TEST_TIMEOUT,
4649
config));
4750
}
4851

0 commit comments

Comments
 (0)