Java Code Examples for io.vertx.sqlclient.Pool#getConnection()

The following examples show how to use io.vertx.sqlclient.Pool#getConnection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlClientExamples.java    From vertx-sql-client with Apache License 2.0 6 votes vote down vote up
public void usingConnections01(Vertx vertx, Pool pool) {

    pool.getConnection(ar1 -> {
      if (ar1.succeeded()) {
        SqlConnection connection = ar1.result();

        connection
          .query("SELECT * FROM users WHERE id='julien'")
          .execute(ar2 -> {
          if (ar1.succeeded()) {
            connection
              .query("SELECT * FROM users WHERE id='paulo'")
              .execute(ar3 -> {
              // Do something with rows and return the connection to the pool
              connection.close();
            });
          } else {
            // Return the connection to the pool
            connection.close();
          }
        });
      }
    });
  }
 
Example 2
Source File: SqlClientExamples.java    From vertx-sql-client with Apache License 2.0 6 votes vote down vote up
public void usingConnections01(Vertx vertx, Pool pool) {

    pool.getConnection(ar1 -> {
      if (ar1.succeeded()) {
        SqlConnection connection = ar1.result();

        connection
          .query("SELECT * FROM users WHERE id='andy'")
          .execute(ar2 -> {
          if (ar1.succeeded()) {
            connection
              .query("SELECT * FROM users WHERE id='julien'")
              .execute(ar3 -> {
              // Do something with rows and return the connection to the pool
              connection.close();
            });
          } else {
            // Return the connection to the pool
            connection.close();
          }
        });
      }
    });
  }
 
Example 3
Source File: SqlClientExamples.java    From vertx-sql-client with Apache License 2.0 6 votes vote down vote up
public void usingConnections01(Vertx vertx, Pool pool) {

    pool.getConnection(ar1 -> {
      if (ar1.succeeded()) {
        SqlConnection connection = ar1.result();

        connection
          .query("SELECT * FROM users WHERE id='julien'")
          .execute(ar2 -> {
          if (ar1.succeeded()) {
            connection
              .query("SELECT * FROM users WHERE id='paulo'")
              .execute(ar3 -> {
              // Do something with rows and return the connection to the pool
              connection.close();
            });
          } else {
            // Return the connection to the pool
            connection.close();
          }
        });
      }
    });
  }
 
Example 4
Source File: TransactionTestBase.java    From vertx-sql-client with Apache License 2.0 6 votes vote down vote up
protected void initConnector() {
  connector = handler -> {
    Pool pool = getPool();
    pool.getConnection(ar1 -> {
      if (ar1.succeeded()) {
        SqlConnection conn = ar1.result();
        conn.begin(ar2 -> {
          if (ar2.succeeded()) {
            Transaction tx = ar2.result();
            tx.completion().onComplete(ar3 -> {
              conn.close();
            });
            handler.handle(Future.succeededFuture(new Result(conn, tx)));
          } else {
            conn.close();
          }
        });
      } else {
        handler.handle(ar1.mapEmpty());
      }
    });
  };
}
 
Example 5
Source File: SqlClientExamples.java    From vertx-sql-client with Apache License 2.0 6 votes vote down vote up
public void usingConnections01(Vertx vertx, Pool pool) {

    pool.getConnection(ar1 -> {
      if (ar1.succeeded()) {
        SqlConnection connection = ar1.result();

        connection
          .query("SELECT * FROM users WHERE id='julien'")
          .execute(ar2 -> {
          if (ar1.succeeded()) {
            connection
              .query("SELECT * FROM users WHERE id='paulo'")
              .execute(ar3 -> {
              // Do something with rows and return the connection to the pool
              connection.close();
            });
          } else {
            // Return the connection to the pool
            connection.close();
          }
        });
      }
    });
  }
 
Example 6
Source File: DriverTestBase.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreatePoolFromDriver01(TestContext ctx) {
  Pool p = getDriver().createPool(defaultOptions());
  p.getConnection(ctx.asyncAssertSuccess(ar -> {
    ar.close();
  }));
}
 
Example 7
Source File: DriverTestBase.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreatePoolFromDriver02(TestContext ctx) {
  SqlConnectOptions genericOptions = new SqlConnectOptions(defaultOptions());
  Pool p = getDriver().createPool(genericOptions);
  p.getConnection(ctx.asyncAssertSuccess(ar -> {
    ar.close();
  }));
}
 
Example 8
Source File: DriverTestBase.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreatePoolFromDriver03(TestContext ctx) {
  Pool p = getDriver().createPool(defaultOptions(), new PoolOptions().setMaxSize(1));
  p.getConnection(ctx.asyncAssertSuccess(ar -> {
    ar.close();
  }));
}
 
Example 9
Source File: DriverTestBase.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreatePoolFromDriver04(TestContext ctx) {
  Pool p = getDriver().createPool(Vertx.vertx(), defaultOptions(), new PoolOptions().setMaxSize(1));
  p.getConnection(ctx.asyncAssertSuccess(ar -> {
    ar.close();
  }));
}
 
Example 10
Source File: SqlClientExamples.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
public void transaction01(Pool pool) {
  pool.getConnection(res -> {
    if (res.succeeded()) {

      // Transaction must use a connection
      SqlConnection conn = res.result();

      // Begin the transaction
      conn.begin(ar0 -> {
        if (ar0.succeeded()) {
          Transaction tx = ar0.result();

          // Various statements
          conn
            .query("INSERT INTO Users (first_name,last_name) VALUES ('Julien','Viet')")
            .execute(ar1 -> {
              if (ar1.succeeded()) {
                conn
                  .query("INSERT INTO Users (first_name,last_name) VALUES ('Emad','Alblueshi')")
                  .execute(ar2 -> {
                    if (ar2.succeeded()) {
                      // Commit the transaction
                      tx.commit(ar3 -> {
                        if (ar3.succeeded()) {
                          System.out.println("Transaction succeeded");
                        } else {
                          System.out.println("Transaction failed " + ar3.cause().getMessage());
                        }
                        // Return the connection to the pool
                        conn.close();
                      });
                    } else {
                      // Return the connection to the pool
                      conn.close();
                    }
                  });
              } else {
                // Return the connection to the pool
                conn.close();
              }
            });
        } else {
          // Return the connection to the pool
          conn.close();
        }
      });
    }
  });
}
 
Example 11
Source File: SqlClientExamples.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
public void transaction01(Pool pool) {
  pool.getConnection(res -> {
    if (res.succeeded()) {

      // Transaction must use a connection
      SqlConnection conn = res.result();

      // Begin the transaction
      conn.begin(ar0 -> {
        if (ar0.succeeded()) {
          Transaction tx = ar0.result();
          // Various statements
          conn
            .query("INSERT INTO Users (first_name,last_name) VALUES ('Julien','Viet')")
            .execute(ar1 -> {
              if (ar1.succeeded()) {
                conn
                  .query("INSERT INTO Users (first_name,last_name) VALUES ('Emad','Alblueshi')")
                  .execute(ar2 -> {
                    if (ar2.succeeded()) {
                      // Commit the transaction
                      tx.commit(ar3 -> {
                        if (ar3.succeeded()) {
                          System.out.println("Transaction succeeded");
                        } else {
                          System.out.println("Transaction failed " + ar3.cause().getMessage());
                        }
                        // Return the connection to the pool
                        conn.close();
                      });
                    } else {
                      // Return the connection to the pool
                      conn.close();
                    }
                  });
              } else {
                // Return the connection to the pool
                conn.close();
              }
            });
        } else {
          // Return the connection to the pool
          conn.close();
        }
      });
    }
  });
}
 
Example 12
Source File: SqlClientExamples.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
public void transaction01(Pool pool) {
  pool.getConnection(res -> {
    if (res.succeeded()) {

      // Transaction must use a connection
      SqlConnection conn = res.result();

      // Begin the transaction
      conn.begin(ar0 -> {
        if (ar0.succeeded()) {
          Transaction tx = ar0.result();

          // Various statements
          conn
            .query("INSERT INTO Users (first_name,last_name) VALUES ('Julien','Viet')")
            .execute(ar1 -> {
              if (ar1.succeeded()) {
                conn
                  .query("INSERT INTO Users (first_name,last_name) VALUES ('Emad','Alblueshi')")
                  .execute(ar2 -> {
                    if (ar2.succeeded()) {
                      // Commit the transaction
                      tx.commit(ar3 -> {
                        if (ar3.succeeded()) {
                          System.out.println("Transaction succeeded");
                        } else {
                          System.out.println("Transaction failed " + ar3.cause().getMessage());
                        }
                        // Return the connection to the pool
                        conn.close();
                      });
                    } else {
                      // Return the connection to the pool
                      conn.close();
                    }
                  });
              } else {
                // Return the connection to the pool
                conn.close();
              }
            });
        } else {
          // Return the connection to the pool
          conn.close();
        }
      });
    }
  });
}
 
Example 13
Source File: SqlClientExamples.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
public void transaction01(Pool pool) {
  pool.getConnection(res -> {
    if (res.succeeded()) {

      // Transaction must use a connection
      SqlConnection conn = res.result();

      // Begin the transaction
      conn.begin(ar0 -> {
        if (ar0.succeeded()) {
          Transaction tx = ar0.result();
          // Various statements
          conn
            .query("INSERT INTO Users (first_name,last_name) VALUES ('Julien','Viet')")
            .execute(ar1 -> {
              if (ar1.succeeded()) {
                conn
                  .query("INSERT INTO Users (first_name,last_name) VALUES ('Emad','Alblueshi')")
                  .execute(ar2 -> {
                    if (ar2.succeeded()) {
                      // Commit the transaction
                      tx.commit(ar3 -> {
                        if (ar3.succeeded()) {
                          System.out.println("Transaction succeeded");
                        } else {
                          System.out.println("Transaction failed " + ar3.cause().getMessage());
                        }
                        // Return the connection to the pool
                        conn.close();
                      });
                    } else {
                      // Return the connection to the pool
                      conn.close();
                    }
                  });
              } else {
                // Return the connection to the pool
                conn.close();
              }
            });
        } else {
          // Return the connection to the pool
          conn.close();
        }
      });
    }
  });
}