当前位置: 首页>>代码示例>>Java>>正文


Java JDBCClient类代码示例

本文整理汇总了Java中io.vertx.ext.jdbc.JDBCClient的典型用法代码示例。如果您正苦于以下问题:Java JDBCClient类的具体用法?Java JDBCClient怎么用?Java JDBCClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JDBCClient类属于io.vertx.ext.jdbc包,在下文中一共展示了JDBCClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import io.vertx.ext.jdbc.JDBCClient; //导入依赖的package包/类
@Override
public void start(Future<Void> startFuture) throws Exception {

  HashMap<SqlQuery, String> sqlQueries = loadSqlQueries();

  JDBCClient dbClient = JDBCClient.createShared(vertx, new JsonObject()
    .put("url", config().getString(CONFIG_WIKIDB_JDBC_URL, "jdbc:hsqldb:file:db/wiki"))
    .put("driver_class", config().getString(CONFIG_WIKIDB_JDBC_DRIVER_CLASS, "org.hsqldb.jdbcDriver"))
    .put("max_pool_size", config().getInteger(CONFIG_WIKIDB_JDBC_MAX_POOL_SIZE, 30)));

  WikiDatabaseService.create(dbClient, sqlQueries, ready -> {
    if (ready.succeeded()) {
      ProxyHelper.registerService(WikiDatabaseService.class, vertx, ready.result(), CONFIG_WIKIDB_QUEUE);
      startFuture.complete();
    } else {
      startFuture.fail(ready.cause());
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:20,代码来源:WikiDatabaseVerticle.java

示例2: WikiDatabaseServiceImpl

import io.vertx.ext.jdbc.JDBCClient; //导入依赖的package包/类
WikiDatabaseServiceImpl(JDBCClient dbClient, HashMap<SqlQuery, String> sqlQueries, Handler<AsyncResult<WikiDatabaseService>> readyHandler) {
  this.dbClient = dbClient;
  this.sqlQueries = sqlQueries;

  dbClient.getConnection(ar -> {
    if (ar.failed()) {
      LOGGER.error("Could not open a database connection", ar.cause());
      readyHandler.handle(Future.failedFuture(ar.cause()));
    } else {
      SQLConnection connection = ar.result();
      connection.execute(sqlQueries.get(SqlQuery.CREATE_PAGES_TABLE), create -> {
        connection.close();
        if (create.failed()) {
          LOGGER.error("Database preparation error", create.cause());
          readyHandler.handle(Future.failedFuture(create.cause()));
        } else {
          readyHandler.handle(Future.succeededFuture(this));
        }
      });
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:23,代码来源:WikiDatabaseServiceImpl.java

示例3: start

import io.vertx.ext.jdbc.JDBCClient; //导入依赖的package包/类
@Override
public void start(Future<Void> startFuture) throws Exception {

  HashMap<SqlQuery, String> sqlQueries = loadSqlQueries();

  JDBCClient dbClient = JDBCClient.createShared(vertx, new JsonObject()
    .put("url", config().getString(CONFIG_WIKIDB_JDBC_URL, "jdbc:hsqldb:file:db/wiki"))
    .put("driver_class", config().getString(CONFIG_WIKIDB_JDBC_DRIVER_CLASS, "org.hsqldb.jdbcDriver"))
    .put("max_pool_size", config().getInteger(CONFIG_WIKIDB_JDBC_MAX_POOL_SIZE, 30)));

  WikiDatabaseService.create(dbClient, sqlQueries, ready -> {
    if (ready.succeeded()) {
      ProxyHelper.registerService(WikiDatabaseService.class, vertx, ready.result(), CONFIG_WIKIDB_QUEUE); // <1>
      startFuture.complete();
    } else {
      startFuture.fail(ready.cause());
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:20,代码来源:WikiDatabaseVerticle.java

示例4: createModule

import io.vertx.ext.jdbc.JDBCClient; //导入依赖的package包/类
static ModuleSystem createModule(Vertx vertx, MessageBus messageBus) {
    return TrackerServerExporter.exportTo(
        TrackerServerExporter.ExportToParams.builder()
            .builder(ModuleSystem.builder())
            .jdbcClient(JDBCClient.createShared(vertx, getDbConfig()))
            .messageBus(messageBus)
            .vertx(vertx)
            .authTokenExpireTime(authTokenExpireTime())
            .serverConfig(
                ServerConfig.builder()
                    .uploadDir(config.getString("upload_directory", new File(baseDir(), "/uploads").getAbsolutePath()))
                    .publicDir(config.getString("public_content_directory", new File(baseDir(), "/public").getAbsolutePath()))
                    .build()
            )
            .build()
    ).build();
}
 
开发者ID:codefacts,项目名称:Elastic-Components,代码行数:18,代码来源:TrackerServer.java

示例5: exportBaseSqlDb

import io.vertx.ext.jdbc.JDBCClient; //导入依赖的package包/类
static ModuleSystemBuilder exportBaseSqlDb(ExportToParams config) {
    final ModuleSystemBuilder builder = config.moduleSystemBuilder;
    final JDBCClient jdbcClient = config.jdbcClient;

    builder.export(BaseSqlDB.class, module -> {
        module.export(new BaseSqlDBImpl(
            module.require(SqlExecutor.class),
            module.require(SqlQueryBuilderUtils.class)
        ));
    });

    builder.export(SqlExecutor.class, module -> {
        module.export(new SqlExecutorImpl(
            jdbcClient
        ));
    });

    exportSqlQueryBuilderUtils(builder);

    return builder;
}
 
开发者ID:codefacts,项目名称:Elastic-Components,代码行数:22,代码来源:SqlExporter.java

示例6: main

import io.vertx.ext.jdbc.JDBCClient; //导入依赖的package包/类
static void main(String[] asdfasd) {
    JDBCClient jdbcClient = Test.jdbcClient("jpadb", Vertx.vertx(new VertxOptions()
        .setWorkerPoolSize(1)
        .setEventLoopPoolSize(1)
    ));

    BaseOrm baseOrm = Test.baseOrm();

    final JsonObject employee = new JsonObject(
        "{\"eid\":1201,\"ename\":\"Gopal\",\"salary\":40000.0,\"deg\":\"Technical Manager\",\"department\":{\"id\":98798079087,\"name\":\"ICT\",\"department\":{\"id\":98457984,\"name\":\"RGV\",\"department\":{\"id\":94504975049,\"name\":\"MCE\",\"department\":null,\"employee\":{\"eid\":5258,\"ename\":\"Russel\",\"salary\":52000.0,\"deg\":\"ENG\",\"department\":null,\"department2\":null,\"departments\":[{\"id\":6538921,\"name\":\"TTSK\",\"department\":{\"id\":267935328,\"name\":\"VTVG\",\"department\":null,\"employee\":null},\"employee\":null}]}},\"employee\":{\"eid\":5258,\"ename\":\"Russel\",\"salary\":52000.0,\"deg\":\"ENG\",\"department\":null,\"department2\":null,\"departments\":[{\"id\":6538921,\"name\":\"TTSK\",\"department\":{\"id\":267935328,\"name\":\"VTVG\",\"department\":null,\"employee\":null},\"employee\":null}]}},\"employee\":{\"eid\":5258,\"ename\":\"Russel\",\"salary\":52000.0,\"deg\":\"ENG\",\"department\":null,\"department2\":null,\"departments\":[{\"id\":6538921,\"name\":\"TTSK\",\"department\":{\"id\":267935328,\"name\":\"VTVG\",\"department\":null,\"employee\":null},\"employee\":null}]}},\"department2\":{\"id\":988286326887,\"name\":\"BGGV\",\"department\":{\"id\":8283175518,\"name\":\"MKLC\",\"department\":{\"id\":56165582,\"name\":\"VVKM\",\"department\":null,\"employee\":{\"eid\":2389,\"ename\":\"KOMOL\",\"salary\":8000.0,\"deg\":\"DOC\",\"department\":null,\"department2\":null,\"departments\":[]}},\"employee\":{\"eid\":5258,\"ename\":\"Russel\",\"salary\":52000.0,\"deg\":\"ENG\",\"department\":null,\"department2\":null,\"departments\":[{\"id\":6538921,\"name\":\"TTSK\",\"department\":{\"id\":267935328,\"name\":\"VTVG\",\"department\":null,\"employee\":null},\"employee\":null}]}},\"employee\":{\"eid\":5258,\"ename\":\"Russel\",\"salary\":52000.0,\"deg\":\"ENG\",\"department\":null,\"department2\":null,\"departments\":[{\"id\":6538921,\"name\":\"TTSK\",\"department\":{\"id\":267935328,\"name\":\"VTVG\",\"department\":null,\"employee\":null},\"employee\":null}]}},\"departments\":[{\"id\":98798079087,\"name\":\"ICT\",\"department\":{\"id\":98457984,\"name\":\"RGV\",\"department\":{\"id\":94504975049,\"name\":\"MCE\",\"department\":null,\"employee\":{\"eid\":5258,\"ename\":\"Russel\",\"salary\":52000.0,\"deg\":\"ENG\",\"department\":null,\"department2\":null,\"departments\":[{\"id\":6538921,\"name\":\"TTSK\",\"department\":{\"id\":267935328,\"name\":\"VTVG\",\"department\":null,\"employee\":null},\"employee\":null}]}},\"employee\":{\"eid\":5258,\"ename\":\"Russel\",\"salary\":52000.0,\"deg\":\"ENG\",\"department\":null,\"department2\":null,\"departments\":[{\"id\":6538921,\"name\":\"TTSK\",\"department\":{\"id\":267935328,\"name\":\"VTVG\",\"department\":null,\"employee\":null},\"employee\":null}]}},\"employee\":{\"eid\":5258,\"ename\":\"Russel\",\"salary\":52000.0,\"deg\":\"ENG\",\"department\":null,\"department2\":null,\"departments\":[{\"id\":6538921,\"name\":\"TTSK\",\"department\":{\"id\":267935328,\"name\":\"VTVG\",\"department\":null,\"employee\":null},\"employee\":null}]}}]}"
    );

    merge(employee);

    System.out.println(employee.encodePrettily());

    baseOrm.upsert(
        BaseOrm.UpsertParams.builder()
            .entity("employee")
            .jsonObject(employee)
            .build()
    ).mapP(Test.sqlDB()::update).then(jsonObject -> {
        System.out.println("ppp888888888888888888888888888888888888888888888888888888888888888888888");
    }).err(Throwable::printStackTrace);
}
 
开发者ID:codefacts,项目名称:Elastic-Components,代码行数:26,代码来源:Insert22.java

示例7: start

import io.vertx.ext.jdbc.JDBCClient; //导入依赖的package包/类
@Override
public void start() throws Exception {
    super.start();
    client = JDBCClient.create(vertx, dataSource);


    eventBus.registerDefaultCodec(Book.class, new BookEncoder());
    eventBus.registerDefaultCodec(Recipe.class, new RecipeEncoder());
    eventBus.registerDefaultCodec((Class<ArrayList<Book>>) (Class<?>) ArrayList.class, new ListOfBookEncoder());

    initDb();

    MessageConsumer<Object> read = eventBus.consumer("de.nierbeck.vertx.jdbc.read"); //TODO: move those addresses to a "global" dict.
    MessageConsumer<Object> write = eventBus.consumer("de.nierbeck.vertx.jdbc.write.add");
    MessageConsumer<Object> update = eventBus.consumer("de.nierbeck.vertx.jdbc.write.update");
    MessageConsumer<Object> delete = eventBus.consumer("de.nierbeck.vertx.jdbc.delete");
    read.handler(this::handleRead);
    write.handler(this::handleWrite);
    update.handler(this::handleUpdate);
    delete.handler(this::handleDelete);
}
 
开发者ID:ANierbeck,项目名称:Karaf-Vertx,代码行数:22,代码来源:JdbcServiceVertcl.java

示例8: testStockTradesPersisted

import io.vertx.ext.jdbc.JDBCClient; //导入依赖的package包/类
@Test
public void testStockTradesPersisted(TestContext context) throws ClassNotFoundException {
    Async async = context.async();
    JsonObject jdbcConfig = new JsonObject(config.getObject("jdbc").render(ConfigRenderOptions.concise()));
    JDBCClient jdbc = JDBCClient.createNonShared(vertx, jdbcConfig);
    Class.forName(jdbcConfig.getString("driverclass"));

    jdbc.getConnection(ar -> {
        SQLConnection connection = ar.result();
        if (ar.failed()) {
            context.fail(ar.cause());
        } else {
            connection.query(SELECT_STATEMENT, result -> {
                ResultSet set = result.result();
                List<JsonObject> operations = set.getRows().stream()
                        .map(json -> new JsonObject(json.getString("OPERATION")))
                        .collect(Collectors.toList());
                context.assertTrue(operations.size() >= 3);
                connection.close();
                async.complete();
            });
        }
    });
}
 
开发者ID:docker-production-aws,项目名称:microtrader,代码行数:25,代码来源:AuditVerticleTest.java

示例9: example2

import io.vertx.ext.jdbc.JDBCClient; //导入依赖的package包/类
public void example2(ServiceDiscovery discovery) {
  // Get the record
  discovery.getRecord(
      new JsonObject().put("name", "some-data-source-service"),
      ar -> {
        if (ar.succeeded() && ar.result() != null) {
          // Retrieve the service reference
          ServiceReference reference = discovery.getReferenceWithConfiguration(
              ar.result(), // The record
              new JsonObject().put("username", "clement").put("password", "*****")); // Some additional metadata

          // Retrieve the service object
          JDBCClient client = reference.getAs(JDBCClient.class);

          // ...

          // when done
          reference.release();
        }
      });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:22,代码来源:JDBCDataSourceExamples.java

示例10: example3

import io.vertx.ext.jdbc.JDBCClient; //导入依赖的package包/类
public void example3(ServiceDiscovery discovery) {
  JDBCDataSource.<JsonObject>getJDBCClient(discovery,
      new JsonObject().put("name", "some-data-source-service"),
      new JsonObject().put("username", "clement").put("password", "*****"), // Some additional metadata
      ar -> {
        if (ar.succeeded()) {
          JDBCClient client = ar.result();

          // ...

          // Dont' forget to release the service
          ServiceDiscovery.releaseServiceObject(discovery, client);

        }
      });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:17,代码来源:JDBCDataSourceExamples.java

示例11: testWithSugarWithoutConsumerConf

import io.vertx.ext.jdbc.JDBCClient; //导入依赖的package包/类
@Test
public void testWithSugarWithoutConsumerConf() throws InterruptedException {
  Record record = JDBCDataSource.createRecord("some-hsql-db",
      new JsonObject().put("url", "jdbc:hsqldb:file:target/dumb-db;shutdown=true"),
      new JsonObject().put("database", "some-raw-data").put("driverclass", "org.hsqldb.jdbcDriver"));

  discovery.publish(record, (r) -> {
  });
  await().until(() -> record.getRegistration() != null);


  AtomicBoolean success = new AtomicBoolean();
  JDBCDataSource.getJDBCClient(discovery, new JsonObject().put("name", "some-hsql-db"),
      ar -> {
        JDBCClient client = ar.result();
        client.getConnection(conn -> {
          if (ar.succeeded()) {
            conn.result().close();
          }
          client.close();
          success.set(conn.succeeded());
        });
      });
  await().untilAtomic(success, is(true));
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:26,代码来源:JDBCDataSourceTest.java

示例12: example4

import io.vertx.ext.jdbc.JDBCClient; //导入依赖的package包/类
public void example4(JDBCClient client) {

    // Now do stuff with it:

    client.getConnection(res -> {
      if (res.succeeded()) {

        SQLConnection connection = res.result();

        connection.query("SELECT * FROM some_table", res2 -> {
          if (res2.succeeded()) {

            ResultSet rs = res2.result();
            // Do something with results
          }
        });
      } else {
        // Failed to get connection - deal with it
      }
    });

  }
 
开发者ID:vert-x3,项目名称:vertx-jdbc-client,代码行数:23,代码来源:JDBCExamples.java

示例13: prepareDatabase

import io.vertx.ext.jdbc.JDBCClient; //导入依赖的package包/类
private Future<Void> prepareDatabase() {
  Future<Void> future = Future.future();

  dbClient = JDBCClient.createShared(vertx, new JsonObject()  // <1>
    .put("url", "jdbc:hsqldb:file:db/wiki")   // <2>
    .put("driver_class", "org.hsqldb.jdbcDriver")   // <3>
    .put("max_pool_size", 30));   // <4>

  dbClient.getConnection(ar -> {    // <5>
    if (ar.failed()) {
      LOGGER.error("Could not open a database connection", ar.cause());
      future.fail(ar.cause());    // <6>
    } else {
      SQLConnection connection = ar.result();   // <7>
      connection.execute(SQL_CREATE_PAGES_TABLE, create -> {
        connection.close();   // <8>
        if (create.failed()) {
          LOGGER.error("Database preparation error", create.cause());
          future.fail(create.cause());
        } else {
          future.complete();  // <9>
        }
      });
    }
  });

  return future;
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:29,代码来源:MainVerticle.java

示例14: start

import io.vertx.ext.jdbc.JDBCClient; //导入依赖的package包/类
@Override
public void start(Future<Void> startFuture) throws Exception {

  /*
   * Note: this uses blocking APIs, but data is small...
   */
  loadSqlQueries();  // <1>

  dbClient = JDBCClient.createShared(vertx, new JsonObject()
    .put("url", config().getString(CONFIG_WIKIDB_JDBC_URL, "jdbc:hsqldb:file:db/wiki"))
    .put("driver_class", config().getString(CONFIG_WIKIDB_JDBC_DRIVER_CLASS, "org.hsqldb.jdbcDriver"))
    .put("max_pool_size", config().getInteger(CONFIG_WIKIDB_JDBC_MAX_POOL_SIZE, 30)));

  dbClient.getConnection(ar -> {
    if (ar.failed()) {
      LOGGER.error("Could not open a database connection", ar.cause());
      startFuture.fail(ar.cause());
    } else {
      SQLConnection connection = ar.result();
      connection.execute(sqlQueries.get(SqlQuery.CREATE_PAGES_TABLE), create -> {   // <2>
        connection.close();
        if (create.failed()) {
          LOGGER.error("Database preparation error", create.cause());
          startFuture.fail(create.cause());
        } else {
          vertx.eventBus().consumer(config().getString(CONFIG_WIKIDB_QUEUE, "wikidb.queue"), this::onMessage);  // <3>
          startFuture.complete();
        }
      });
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:33,代码来源:WikiDatabaseVerticle.java

示例15: start

import io.vertx.ext.jdbc.JDBCClient; //导入依赖的package包/类
@Override
public void start(Future<Void> future) throws Exception {
  super.start();
  jdbcClient = JDBCClient.createNonShared(vertx.getDelegate(), config().getJsonObject("jdbc"));
  DatabaseService database = DatabaseService.create(vertx.getDelegate(), config());
  consumer = registerService(DatabaseService.class, vertx.getDelegate(), database, ADDRESS);
  startEBRouter(DatabaseService.ADDRESS, DatabaseService.class, future);
  // TODO: 3.09.2017 setup security for public users (getallusers should not be available for everyone)
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:10,代码来源:DatabaseVerticle.java


注:本文中的io.vertx.ext.jdbc.JDBCClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。