Java Code Examples for io.vertx.ext.jdbc.JDBCClient#createShared()
The following examples show how to use
io.vertx.ext.jdbc.JDBCClient#createShared() .
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: SettingsConfiguration.java From prebid-server-java with Apache License 2.0 | 6 votes |
@Bean JDBCClient vertxJdbcClient(Vertx vertx, StoredRequestsDatabaseProperties storedRequestsDatabaseProperties) { final String jdbcUrl = String.format("%s//%s:%d/%s?%s", storedRequestsDatabaseProperties.getType().jdbcUrlPrefix, storedRequestsDatabaseProperties.getHost(), storedRequestsDatabaseProperties.getPort(), storedRequestsDatabaseProperties.getDbname(), storedRequestsDatabaseProperties.getType().jdbcUrlSuffix); return JDBCClient.createShared(vertx, new JsonObject() .put("url", jdbcUrl) .put("user", storedRequestsDatabaseProperties.getUser()) .put("password", storedRequestsDatabaseProperties.getPassword()) .put("driver_class", storedRequestsDatabaseProperties.getType().jdbcDriver) .put("initial_pool_size", storedRequestsDatabaseProperties.getPoolSize()) .put("min_pool_size", storedRequestsDatabaseProperties.getPoolSize()) .put("max_pool_size", storedRequestsDatabaseProperties.getPoolSize())); }
Example 2
Source File: JdbcApplicationSettingsTest.java From prebid-server-java with Apache License 2.0 | 5 votes |
private JdbcClient jdbcClient() { return new BasicJdbcClient(vertx, JDBCClient.createShared(vertx, new JsonObject() .put("url", JDBC_URL) .put("driver_class", "org.h2.Driver") .put("max_pool_size", 10)), metrics, clock ); }
Example 3
Source File: DATAVerticle.java From VX-API-Gateway with MIT License | 5 votes |
@Override public void start(Future<Void> fut) throws Exception { LOG.info("start DATA Verticle ..."); thisVertxName = System.getProperty("thisVertxName", "VX-API"); initShorthand();// 初始化简写后的常量数据 JsonObject dbConfig = config(); String url = dbConfig.getString("url"); if (dbConfig.getString("url").contains("jdbc:sqlite:")) { String temp = url.replace("jdbc:sqlite:", ""); if (temp.indexOf("/") < 0) { dbConfig.put("url", "jdbc:sqlite:" + PathUtil.getPathString(temp)); } } jdbcClient = JDBCClient.createShared(vertx, dbConfig, VxApiGatewayAttribute.NAME); // application operation address vertx.eventBus().consumer(thisVertxName + VxApiEventBusAddressConstant.FIND_APP, this::findApplication); vertx.eventBus().consumer(thisVertxName + VxApiEventBusAddressConstant.GET_APP, this::getApplication); vertx.eventBus().consumer(thisVertxName + VxApiEventBusAddressConstant.ADD_APP, this::addApplication); vertx.eventBus().consumer(thisVertxName + VxApiEventBusAddressConstant.DEL_APP, this::delApplication); vertx.eventBus().consumer(thisVertxName + VxApiEventBusAddressConstant.UPDT_APP, this::updtApplication); // api operation address vertx.eventBus().consumer(thisVertxName + VxApiEventBusAddressConstant.FIND_API_ALL, this::findAPI); vertx.eventBus().consumer(thisVertxName + VxApiEventBusAddressConstant.FIND_API_BY_PAGE, this::findAPIByPage); vertx.eventBus().consumer(thisVertxName + VxApiEventBusAddressConstant.GET_API, this::getAPI); vertx.eventBus().consumer(thisVertxName + VxApiEventBusAddressConstant.ADD_API, this::addAPI); vertx.eventBus().consumer(thisVertxName + VxApiEventBusAddressConstant.DEL_API, this::delAPI); vertx.eventBus().consumer(thisVertxName + VxApiEventBusAddressConstant.UPDT_API, this::updtAPI); // blacklist vertx.eventBus().consumer(thisVertxName + VxApiEventBusAddressConstant.FIND_BLACKLIST, this::findBlacklist); vertx.eventBus().consumer(thisVertxName + VxApiEventBusAddressConstant.REPLACE_BLACKLIST, this::replaceBlacklist); LOG.info("start DATA Verticle successful"); fut.complete(); }
Example 4
Source File: RecommendationPersistenceVerticle.java From istio-tutorial with Apache License 2.0 | 5 votes |
private void initJdbc(Vertx vertx) { populateData(); jdbcClient = JDBCClient.createShared(vertx, new JsonObject() .put("url", URL) .put("driver_class", "org.postgresql.Driver") .put("user", USER) .put("password", PASSWORD) .put("max_pool_size", 30)); }
Example 5
Source File: JDBCDataSourceImpl.java From vertx-service-discovery with Apache License 2.0 | 5 votes |
@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 6
Source File: JdbcProperties.java From enmasse with Apache License 2.0 | 5 votes |
public static SQLClient dataSource(final Vertx vertx, final JdbcProperties dataSourceProperties) { /* * In the following lines we explicitly set the "provider_class" and **must not** use * the existing constant for that. * * The reason for this is, that the downstream version changes the value of the constant to * use Agroal as the connection pool. As C3P0 is the upstream default for Vert.x and Agroal * isn't even mentioned upstream, we explicitly set C3P0 here. Without using the (not so) constant. */ final JsonObject config = new JsonObject() // set default explicitly: see comment above .put("provider_class", "io.vertx.ext.jdbc.spi.impl.C3P0DataSourceProvider") .put("url", dataSourceProperties.getUrl()) .put("user", dataSourceProperties.getUsername()) .put("password", dataSourceProperties.getPassword()); if (dataSourceProperties.getDriverClass() != null) { config.put("driver_class", dataSourceProperties.getDriverClass()); } if (dataSourceProperties.getMaximumPoolSize() != null) { config.put("max_pool_size", dataSourceProperties.getMaximumPoolSize()); } log.info("Creating new SQL client: {} - table: {}", config, dataSourceProperties.getTableName()); return JDBCClient.createShared(vertx, config); }
Example 7
Source File: JDBCShellAuth.java From vertx-shell with Apache License 2.0 | 5 votes |
@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 8
Source File: Config.java From nubes with Apache License 2.0 | 5 votes |
private void createAuthHandlers() { String auth = json.getString("auth-type"); JsonObject authProperties = json.getJsonObject("auth-properties"); // TODO : discuss it. I'm really not convinced about all the boilerplate needed in config (dbName only for JDBC, etc.) if (authProperties != null) { // For now, only JWT,Shiro and JDBC supported (same as for Vert.x web) switch (auth) { case "JWT":// For now only allow properties realm this.authProvider = JWTAuth.create(vertx, authProperties); break; case "Shiro": ShiroAuth.create(vertx, new ShiroAuthOptions(authProperties)); break; case "JDBC": String dbName = json.getString("db-name"); Objects.requireNonNull(dbName); JDBCClient client = JDBCClient.createShared(vertx, authProperties, dbName); this.authProvider = JDBCAuth.create(vertx, client); break; default: LOG.warn("Unknown type of auth : " + auth + " . Ignoring."); } } else if (auth != null) { LOG.warn("You have defined " + auth + " as auth type, but didn't provide any configuration, can't create authProvider"); } }
Example 9
Source File: AuthJDBCExamples.java From vertx-auth with Apache License 2.0 | 5 votes |
public void example5(Vertx vertx, JsonObject jdbcClientConfig) { JDBCClient jdbcClient = JDBCClient.createShared(vertx, jdbcClientConfig); JDBCAuthenticationOptions options = new JDBCAuthenticationOptions(); JDBCAuthentication authenticationProvider = JDBCAuthentication.create(jdbcClient, options); }
Example 10
Source File: JDBCAuthOptions.java From vertx-auth with Apache License 2.0 | 5 votes |
@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 11
Source File: VertxJdbcClientImpl.java From apiman with Apache License 2.0 | 4 votes |
public VertxJdbcClientImpl(Vertx vertx, String dsName, JdbcOptionsBean config) { jdbcClient = JDBCClient.createShared(vertx, parseConfig(config), dsName); }
Example 12
Source File: JdbcProperties.java From hono with Eclipse Public License 2.0 | 3 votes |
/** * Create a {@link SQLClient} from the configuration properties. * @param vertx The vertx instance to use. * @param dataSourceProperties The properties. * @return The new SQL client. */ public static SQLClient dataSource(final Vertx vertx, final JdbcProperties dataSourceProperties) { final JsonObject config = new JsonObject() .put("url", dataSourceProperties.getUrl()) .put("user", dataSourceProperties.getUsername()); // password is added later, after logging if (dataSourceProperties.getDriverClass() != null) { config.put("driver_class", dataSourceProperties.getDriverClass()); } if (dataSourceProperties.getMaximumPoolSize() != null) { config.put("max_pool_size", dataSourceProperties.getMaximumPoolSize()); } log.info("Creating new SQL client: {} - table: {}", config, dataSourceProperties.getTableName()); // put password after logging config .put("password", dataSourceProperties.getPassword()); // create new client return JDBCClient.createShared(vertx, config); }
Example 13
Source File: JDBCExamples.java From vertx-jdbc-client with Apache License 2.0 | 3 votes |
public void example5(Vertx vertx) { JsonObject config = new JsonObject() .put("url", "jdbc:hsqldb:mem:test?shutdown=true") .put("driver_class", "org.hsqldb.jdbcDriver") .put("max_pool_size", 30); SQLClient client = JDBCClient.createShared(vertx, config); }
Example 14
Source File: JDBCExamples.java From vertx-jdbc-client with Apache License 2.0 | 2 votes |
public void exampleCreateDefault(Vertx vertx, JsonObject config) { SQLClient client = JDBCClient.createShared(vertx, config); }
Example 15
Source File: JDBCExamples.java From vertx-jdbc-client with Apache License 2.0 | 2 votes |
public void exampleCreateDataSourceName(Vertx vertx, JsonObject config) { SQLClient client = JDBCClient.createShared(vertx, config, "MyDataSource"); }