Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/main/asciidoc/groovy/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ application.

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

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

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

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

=== In an application using a vert.x distributions
Expand Down Expand Up @@ -232,7 +232,9 @@ Both the PostgreSql and MySql clients take the same configuration:
"maxPoolSize" : <maximum-number-of-open-connections>,
"username" : <your-username>,
"password" : <your-password>,
"database" : <name-of-your-database>
"database" : <name-of-your-database>,
"charset" : <name-of-the-character-set>,
"queryTimeout" : <timeout-in-milliseconds>
}
----

Expand All @@ -241,4 +243,6 @@ Both the PostgreSql and MySql clients take the same configuration:
`maxPoolSize`:: The number of connections that may be kept open. Defaults to `10`.
`username`:: The username to connect to the database. Defaults to `postgres` for PostgreSQL and `root` for MySQL.
`password`:: The password to connect to the database. Default is not set, i.e. it uses no password.
`database`:: The name of the database you want to connect to. Defaults to `test`.
`database`:: The name of the database you want to connect to. Defaults to `test`.
`charset`:: The name of the character set you want to use for the connection. Defaults to `UTF-8`.
`queryTimeout`:: The timeout to wait for a query in milliseconds. Defaults to `10000` (= 10 seconds).
14 changes: 9 additions & 5 deletions src/main/asciidoc/java/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ application.

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

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

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

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

=== In an application using a vert.x distributions
Expand Down Expand Up @@ -194,7 +194,9 @@ Both the PostgreSql and MySql clients take the same configuration:
"maxPoolSize" : <maximum-number-of-open-connections>,
"username" : <your-username>,
"password" : <your-password>,
"database" : <name-of-your-database>
"database" : <name-of-your-database>,
"charset" : <name-of-the-character-set>,
"queryTimeout" : <timeout-in-milliseconds>
}
----

Expand All @@ -203,4 +205,6 @@ Both the PostgreSql and MySql clients take the same configuration:
`maxPoolSize`:: The number of connections that may be kept open. Defaults to `10`.
`username`:: The username to connect to the database. Defaults to `postgres` for PostgreSQL and `root` for MySQL.
`password`:: The password to connect to the database. Default is not set, i.e. it uses no password.
`database`:: The name of the database you want to connect to. Defaults to `test`.
`database`:: The name of the database you want to connect to. Defaults to `test`.
`charset`:: The name of the character set you want to use for the connection. Defaults to `UTF-8`.
`queryTimeout`:: The timeout to wait for a query in milliseconds. Defaults to `10000` (= 10 seconds).
14 changes: 9 additions & 5 deletions src/main/asciidoc/js/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ application.

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

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

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

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

=== In an application using a vert.x distributions
Expand Down Expand Up @@ -232,7 +232,9 @@ Both the PostgreSql and MySql clients take the same configuration:
"maxPoolSize" : <maximum-number-of-open-connections>,
"username" : <your-username>,
"password" : <your-password>,
"database" : <name-of-your-database>
"database" : <name-of-your-database>,
"charset" : <name-of-the-character-set>,
"queryTimeout" : <timeout-in-milliseconds>
}
----

Expand All @@ -241,4 +243,6 @@ Both the PostgreSql and MySql clients take the same configuration:
`maxPoolSize`:: The number of connections that may be kept open. Defaults to `10`.
`username`:: The username to connect to the database. Defaults to `postgres` for PostgreSQL and `root` for MySQL.
`password`:: The password to connect to the database. Default is not set, i.e. it uses no password.
`database`:: The name of the database you want to connect to. Defaults to `test`.
`database`:: The name of the database you want to connect to. Defaults to `test`.
`charset`:: The name of the character set you want to use for the connection. Defaults to `UTF-8`.
`queryTimeout`:: The timeout to wait for a query in milliseconds. Defaults to `10000` (= 10 seconds).
14 changes: 9 additions & 5 deletions src/main/asciidoc/ruby/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ application.

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

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

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

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

=== In an application using a vert.x distributions
Expand Down Expand Up @@ -232,7 +232,9 @@ Both the PostgreSql and MySql clients take the same configuration:
"maxPoolSize" : <maximum-number-of-open-connections>,
"username" : <your-username>,
"password" : <your-password>,
"database" : <name-of-your-database>
"database" : <name-of-your-database>,
"charset" : <name-of-the-character-set>,
"queryTimeout" : <timeout-in-milliseconds>
}
----

Expand All @@ -241,4 +243,6 @@ Both the PostgreSql and MySql clients take the same configuration:
`maxPoolSize`:: The number of connections that may be kept open. Defaults to `10`.
`username`:: The username to connect to the database. Defaults to `postgres` for PostgreSQL and `root` for MySQL.
`password`:: The password to connect to the database. Default is not set, i.e. it uses no password.
`database`:: The name of the database you want to connect to. Defaults to `test`.
`database`:: The name of the database you want to connect to. Defaults to `test`.
`charset`:: The name of the character set you want to use for the connection. Defaults to `UTF-8`.
`queryTimeout`:: The timeout to wait for a query in milliseconds. Defaults to `10000` (= 10 seconds).
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public static AsyncSQLClient createNonShared(Vertx vertx, JsonObject config) {
}

/**
* Create a PostgreSQL client which shares its pool with any other MySQL clients created with the same
* pool name.
* Create a PostgreSQL client which shares its pool with any other MySQL clients created with the same pool name.
* @param vertx the Vert.x instance
* @param config the configuration
* @param poolName the pool name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public class PostgreSQLClient extends AsyncSQLClient {
return ret;
}
/**
* Create a PostgreSQL client which shares its pool with any other MySQL clients created with the same
* pool name.
* Create a PostgreSQL client which shares its pool with any other MySQL clients created with the same pool name.
* @param vertx the Vert.x instance
* @param config the configuration
* @param poolName the pool name
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/io/vertx/ext/asyncsql/MySQLClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ public interface MySQLClient extends AsyncSQLClient {
*/
String DEFAULT_PASSWORD = "password";

/**
* The default charset.
*/
String DEFAULT_CHARSET = "UTF-8";

/**
* The default timeout for connect.
*/
long DEFAULT_CONNECT_TIMEOUT = 10000L;

/**
* The default timeout for tests.
*/
long DEFAULT_TEST_TIMEOUT = 10000L;


/**
* Create a MySQL client which maintains its own pool.
Expand Down
28 changes: 21 additions & 7 deletions src/main/java/io/vertx/ext/asyncsql/PostgreSQLClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,51 @@ public interface PostgreSQLClient extends AsyncSQLClient {
*/
String DEFAULT_PASSWORD = "password";

/**
* The default charset.
*/
String DEFAULT_CHARSET = "UTF-8";

/**
* The default timeout for connect.
*/
long DEFAULT_CONNECT_TIMEOUT = 10000L;

/**
* The default timeout for tests.
*/
long DEFAULT_TEST_TIMEOUT = 10000L;


/**
* Create a PostgreSQL client which maintains its own pool.
*
* @param vertx the Vert.x instance
* @param config the configuration
* @param vertx the Vert.x instance
* @param config the configuration
* @return the client
*/
static AsyncSQLClient createNonShared(Vertx vertx, JsonObject config) {
return ClientHelper.getOrCreate(vertx, config, UUID.randomUUID().toString(), false);
}

/**
* Create a PostgreSQL client which shares its pool with any other MySQL clients created with the same
* pool name.
* Create a PostgreSQL client which shares its pool with any other MySQL clients created with the same pool name.
*
* @param vertx the Vert.x instance
* @param config the configuration
* @param poolName the pool name
* @return the client
*/
static AsyncSQLClient createShared(Vertx vertx,JsonObject config, String poolName) {
static AsyncSQLClient createShared(Vertx vertx, JsonObject config, String poolName) {
return ClientHelper.getOrCreate(vertx, config, poolName, false);
}


/**
* Like {@link #createShared(io.vertx.core.Vertx, JsonObject, String)} but with the default pool name
*
* @param vertx the Vert.x instance
* @param config the configuration
* @param vertx the Vert.x instance
* @param config the configuration
* @return the client
*/
static AsyncSQLClient createShared(Vertx vertx, JsonObject config) {
Expand Down
28 changes: 25 additions & 3 deletions src/main/java/io/vertx/ext/asyncsql/impl/BaseSQLClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import scala.concurrent.ExecutionContext;
import scala.concurrent.duration.Duration;

import java.nio.charset.Charset;
import java.util.concurrent.TimeUnit;

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

protected abstract AsyncConnectionPool pool();

protected abstract SQLConnection createFromPool(Connection conn, AsyncConnectionPool pool, ExecutionContext ec);

public void getConnection(Handler<AsyncResult<SQLConnection>> handler) {
Expand Down Expand Up @@ -91,17 +93,37 @@ public void close() {
close(null);
}

protected Configuration getConfiguration(String defaultHost, int defaultPort, String defaultDatabase, String defaultUser, String defaultPassword, JsonObject config) {
protected Configuration getConfiguration(
String defaultHost,
int defaultPort,
String defaultDatabase,
String defaultUser,
String defaultPassword,
String defaultCharset,
long defaultConnectTimeout,
long defaultTestTimeout,
JsonObject config) {

String host = config.getString("host", defaultHost);
int port = config.getInteger("port", defaultPort);
String username = config.getString("username", defaultUser);
String password = config.getString("password", defaultPassword);
String database = config.getString("database", defaultDatabase);
Charset charset = Charset.forName(config.getString("charset", defaultCharset));
long connectTimeout = config.getLong("connectTimeout", defaultConnectTimeout);
long testTimeout = config.getLong("testTimeout", defaultTestTimeout);
Long queryTimeout = config.getLong("queryTimeout");
Option<Duration> queryTimeoutOption = (queryTimeout == null) ?
Option.empty() : Option.apply(Duration.apply(queryTimeout, TimeUnit.MILLISECONDS));

log.info("Creating configuration for " + host + ":" + port);
return new Configuration(username, host, port, Option.apply(password), Option.apply(database),
CharsetUtil.UTF_8, 16777216, PooledByteBufAllocator.DEFAULT,
Duration.apply(5, TimeUnit.SECONDS), Duration.apply(5, TimeUnit.SECONDS), Option.empty());
charset,
16777216,
PooledByteBufAllocator.DEFAULT,
Duration.apply(connectTimeout, TimeUnit.MILLISECONDS),
Duration.apply(testTimeout, TimeUnit.MILLISECONDS),
queryTimeoutOption);
}


Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/vertx/ext/asyncsql/impl/MYSQLClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public MYSQLClientImpl(Vertx vertx,
MySQLClient.DEFAULT_DATABASE,
MySQLClient.DEFAULT_USER,
MySQLClient.DEFAULT_PASSWORD,
MySQLClient.DEFAULT_CHARSET,
MySQLClient.DEFAULT_CONNECT_TIMEOUT,
MySQLClient.DEFAULT_TEST_TIMEOUT,
config));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public PostgreSQLClientImpl(Vertx vertx, JsonObject config) {
PostgreSQLClient.DEFAULT_DATABASE,
PostgreSQLClient.DEFAULT_USER,
PostgreSQLClient.DEFAULT_PASSWORD,
PostgreSQLClient.DEFAULT_CHARSET,
PostgreSQLClient.DEFAULT_CONNECT_TIMEOUT,
PostgreSQLClient.DEFAULT_TEST_TIMEOUT,
config));
}

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/io/vertx/ext/asyncsql/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@
* "maxPoolSize" : <maximum-number-of-open-connections>,
* "username" : <your-username>,
* "password" : <your-password>,
* "database" : <name-of-your-database>
* "database" : <name-of-your-database>,
* "charset" : <name-of-the-character-set>,
* "queryTimeout" : <timeout-in-milliseconds>
* }
* ----
*
Expand All @@ -193,6 +195,8 @@
* `username`:: The username to connect to the database. Defaults to `postgres` for PostgreSQL and `root` for MySQL.
* `password`:: The password to connect to the database. Default is not set, i.e. it uses no password.
* `database`:: The name of the database you want to connect to. Defaults to `test`.
* `charset`:: The name of the character set you want to use for the connection. Defaults to `UTF-8`.
* `queryTimeout`:: The timeout to wait for a query in milliseconds. Defaults to `10000` (= 10 seconds).
*/
@Document(fileName = "index.adoc")
@ModuleGen(name = "vertx-mysql-postgresql", groupPackage = "io.vertx") package io.vertx.ext.asyncsql;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ PostgreSQLClient.createNonShared = function(vertx, config) {
};

/**
Create a PostgreSQL client which shares its pool with any other MySQL clients created with the same
pool name.
Create a PostgreSQL client which shares its pool with any other MySQL clients created with the same pool name.

@memberof module:vertx-mysql-postgresql-js/postgre_sql_client
@param vertx {Vertx} the Vert.x instance
Expand Down
Loading