Java Code Examples for io.vertx.ext.jdbc.JDBCClient#create()

The following examples show how to use io.vertx.ext.jdbc.JDBCClient#create() . 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: JDBCDataSourceImpl.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@Override
public JDBCClient retrieve() {
  JsonObject result = record().getMetadata().copy();
  result.mergeIn(record().getLocation());

  if (config != null) {
    result.mergeIn(config);
  }

  if (result.getBoolean("shared", false)) {
    return JDBCClient.createShared(vertx, result);
  } else {
    return JDBCClient.create(vertx, result);
  }
}
 
Example 2
Source File: JDBCShellAuth.java    From vertx-shell with Apache License 2.0 5 votes vote down vote up
@Override
public AuthProvider create(Vertx vertx, JsonObject config) {
  final JDBCAuthOptions options = new JDBCAuthOptions(config);
  final JDBCClient client;

  if (options.isShared()) {
    String datasourceName = options.getDatasourceName();
    if (datasourceName != null) {
      client = JDBCClient.createShared(vertx, options.getConfig(), datasourceName);
    } else {
      client = JDBCClient.createShared(vertx, options.getConfig());
    }
  } else {
    client = JDBCClient.create(vertx, options.getConfig());
  }

  final JDBCAuth auth = JDBCAuth.create(vertx, client);

  if (options.getAuthenticationQuery() != null) {
    auth.setAuthenticationQuery(options.getAuthenticationQuery());
  }
  if (options.getRolesQuery() != null) {
    auth.setRolesQuery(options.getRolesQuery());
  }
  if (options.getPermissionsQuery() != null) {
    auth.setPermissionsQuery(options.getPermissionsQuery());
  }
  if (options.getRolesPrefix() != null) {
    auth.setRolePrefix(options.getRolesPrefix());
  }
  return auth;
}
 
Example 3
Source File: C3P0DataSourceProviderTest.java    From vertx-jdbc-client with Apache License 2.0 5 votes vote down vote up
@Test
public void continuingConnectionAttempts() {
  client = JDBCClient.create(vertx, config());
  vertx.setTimer(2000, res -> {
    testComplete();
  });
  client.getConnection(ar -> {
    if (ar.succeeded()) {
      fail("Should not succeed");
    }
  });
  await();
}
 
Example 4
Source File: C3P0DataSourceProviderTest.java    From vertx-jdbc-client with Apache License 2.0 5 votes vote down vote up
@Test
public void stopConnectionAttempts() {
  JsonObject config = config().put("acquire_retry_attempts", 1).put("break_after_acquire_failure", true);
  client = JDBCClient.create(vertx, config);
  vertx.setTimer(2000, res -> {
    fail("Should not get invoked");
  });
  client.getConnection(onFailure(t -> {
    assertThat(t, instanceOf(SQLException.class));
    testComplete();
  }));
  await();
}
 
Example 5
Source File: JDBCAuthOptions.java    From vertx-auth with Apache License 2.0 5 votes vote down vote up
@Override
public JDBCAuth createProvider(Vertx vertx) {
  JDBCClient client;
  if (shared) {
    if (datasourceName != null) {
      client = JDBCClient.createShared(vertx, config, datasourceName);
    } else {
      client = JDBCClient.createShared(vertx, config);
    }
  } else {
    client = JDBCClient.create(vertx, config);
  }
  JDBCAuth auth = JDBCAuth.create(vertx, client);
  if (authenticationQuery != null) {
    auth.setAuthenticationQuery(authenticationQuery);
  }
  if (rolesQuery != null) {
    auth.setRolesQuery(rolesQuery);
  }
  if (permissionsQuery != null) {
    auth.setPermissionsQuery(permissionsQuery);
  }
  if (rolesPrefix != null) {
    auth.setRolePrefix(rolesPrefix);
  }
  return auth;
}
 
Example 6
Source File: JDBCEventStore.java    From enode with MIT License 4 votes vote down vote up
@Override
public void start() {
    sqlClient = JDBCClient.create(vertx, dataSource);
}
 
Example 7
Source File: JDBCPublishedVersionStore.java    From enode with MIT License 4 votes vote down vote up
@Override
public void start() {
    sqlClient = JDBCClient.create(vertx, dataSource);
}
 
Example 8
Source File: JDBCAuthTest.java    From vertx-auth with Apache License 2.0 4 votes vote down vote up
protected JDBCAuth createProvider() {
  JDBCClient client = JDBCClient.create(vertx, config());
  return JDBCAuth.create(vertx, client);
}
 
Example 9
Source File: JDBCAuthenticationProviderTest.java    From vertx-auth with Apache License 2.0 4 votes vote down vote up
protected JDBCClient getJDBCCLient() {
  if (jdbcClient == null) {
    jdbcClient = JDBCClient.create(vertx, config());
  }
  return jdbcClient;
}
 
Example 10
Source File: VertxJdbcClientImpl.java    From apiman with Apache License 2.0 4 votes vote down vote up
public VertxJdbcClientImpl(Vertx vertx, DataSource ds) {
    jdbcClient = JDBCClient.create(vertx, ds);
}
 
Example 11
Source File: JDBCExamples.java    From vertx-jdbc-client with Apache License 2.0 2 votes vote down vote up
public void exampleCreateWithDataSource(Vertx vertx, DataSource dataSource) {

    SQLClient client = JDBCClient.create(vertx, dataSource);

  }
 
Example 12
Source File: JDBCExamples.java    From vertx-jdbc-client with Apache License 2.0 2 votes vote down vote up
public void exampleCreateNonShared(Vertx vertx, JsonObject config) {

    SQLClient client = JDBCClient.create(vertx, config);

  }