Skip to content

Commit

Permalink
Use the version of JDBCPool that accepts connect options
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Jul 12, 2024
1 parent c46f661 commit 0661eaf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 25 deletions.
13 changes: 5 additions & 8 deletions kotlin-examples/coroutines/src/main/kotlin/movierating/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,24 @@ package movierating
import coroutineHandler
import io.vertx.ext.web.Router
import io.vertx.ext.web.RoutingContext
import io.vertx.jdbcclient.JDBCConnectOptions
import io.vertx.jdbcclient.JDBCPool
import io.vertx.kotlin.core.json.json
import io.vertx.kotlin.core.json.obj
import io.vertx.kotlin.coroutines.CoroutineVerticle
import io.vertx.kotlin.coroutines.await
import io.vertx.sqlclient.Pool
import io.vertx.sqlclient.PoolOptions
import io.vertx.sqlclient.Tuple


class App : CoroutineVerticle() {

private lateinit var client: JDBCPool
private lateinit var client: Pool

override suspend fun start() {

client = JDBCPool.pool(vertx, json {
obj(
"url" to "jdbc:hsqldb:mem:test?shutdown=true",
"driver_class" to "org.hsqldb.jdbcDriver",
"max_pool_size-loop" to 30
)
})
client = JDBCPool.pool(vertx, JDBCConnectOptions().setJdbcUrl("jdbc:hsqldb:mem:test?shutdown=true"), PoolOptions().setMaxSize(30))

// Populate database
val statements = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
import io.vertx.jdbcclient.JDBCConnectOptions;
import io.vertx.jdbcclient.JDBCPool;
import io.vertx.sqlclient.*;

Expand Down Expand Up @@ -44,11 +45,7 @@ public static void main(String[] args) throws Exception {

@Override
public void start() {
client = JDBCPool.pool(vertx, new JsonObject()
.put("url", "jdbc:hsqldb:mem:test?shutdown=true")
.put("driver_class", "org.hsqldb.jdbcDriver")
.put("max_pool_size-loop", 30)
);
client = JDBCPool.pool(vertx, new JDBCConnectOptions().setJdbcUrl("jdbc:hsqldb:mem:test?shutdown=true"), new PoolOptions().setMaxSize(30));

DB_STATEMENTS.forEach(statement -> {
await(client.query(statement).execute());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Launcher;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.auth.VertxContextPRNG;
import io.vertx.ext.auth.authentication.AuthenticationProvider;
import io.vertx.ext.auth.sqlclient.SqlAuthentication;
import io.vertx.ext.auth.sqlclient.SqlAuthenticationOptions;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.*;
import io.vertx.ext.web.sstore.LocalSessionStore;
import io.vertx.jdbcclient.JDBCConnectOptions;
import io.vertx.jdbcclient.JDBCPool;
import io.vertx.sqlclient.Pool;
import io.vertx.sqlclient.PoolOptions;

import java.sql.Connection;
import java.sql.DriverManager;
Expand All @@ -30,9 +31,7 @@ public static void main(String[] args) {
public void start() throws Exception {

// Create a JDBC client with a test database
JDBCPool client = JDBCPool.pool(vertx, new JsonObject()
.put("url", "jdbc:hsqldb:mem:test?shutdown=true")
.put("driver_class", "org.hsqldb.jdbcDriver"));
Pool client = JDBCPool.pool(vertx, new JDBCConnectOptions().setJdbcUrl("jdbc:hsqldb:mem:test?shutdown=true"), new PoolOptions().setMaxSize(10));

// Simple auth service which uses a JDBC data source
SqlAuthentication authProvider = SqlAuthentication.create(client, new SqlAuthenticationOptions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.handler.BodyHandler;
import io.vertx.jdbcclient.JDBCConnectOptions;
import io.vertx.jdbcclient.JDBCPool;
import io.vertx.sqlclient.Row;
import io.vertx.sqlclient.RowSet;
import io.vertx.sqlclient.SqlResult;
import io.vertx.sqlclient.*;
import io.vertx.sqlclient.templates.SqlTemplate;
import io.vertx.sqlclient.templates.TupleMapper;

Expand All @@ -46,17 +45,15 @@ public static void main(String[] args) {
Launcher.executeCommand("run", Server.class.getName());
}

private JDBCPool client;
private Pool client;
private SqlTemplate<Map<String, Object>, RowSet<JsonObject>> getProductTmpl;
private SqlTemplate<JsonObject, SqlResult<Void>> addProductTmpl;

@Override
public void start(Promise<Void> startPromise) throws Exception {

// Create a JDBC client with a test database
client = JDBCPool.pool(vertx, new JsonObject()
.put("url", "jdbc:hsqldb:mem:test?shutdown=true")
.put("driver_class", "org.hsqldb.jdbcDriver"));
client = JDBCPool.pool(vertx, new JDBCConnectOptions().setJdbcUrl("jdbc:hsqldb:mem:test?shutdown=true"), new PoolOptions().setMaxSize(10));
getProductTmpl = SqlTemplate
.forQuery(client, "SELECT id, name, price, weight FROM products where id = #{id}")
.mapTo(Row::toJson);
Expand Down

0 comments on commit 0661eaf

Please sign in to comment.