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


Java Database类代码示例

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


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

示例1: main

import com.github.davidmoten.rx.jdbc.Database; //导入依赖的package包/类
public static void main(String[] args) {
    Database db = Database.from("jdbc:mysql://127.0.0.1:3306/alarm_user", "root", "");

    //After running this code you have no guarantee that the update person set score=1 ran before the update person set score=2.
    Database adb = db.asynchronous();
    Observable
            .just(1, 2, 3)
            .lift(adb.update("update person set score = ?")
                    .parameterOperator());

    // To run those queries synchronously either use a transaction:
    Observable
            .just(1, 2, 3)
            .lift(adb.update("update person set score = ?")
                    .dependsOn(db.beginTransaction())
                    .parameterOperator())
            .lift(adb.commitOnCompleteOperator());
}
 
开发者ID:edgar615,项目名称:javase-study,代码行数:19,代码来源:AsynchronousExample.java

示例2: main

import com.github.davidmoten.rx.jdbc.Database; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(1);
        Database db = Database.from("jdbc:mysql://127.0.0.1:3306/alarm_user", "root", "");
        db.select("select alarm_user_id, alarm_user_name from alarm_user where alarm_user_id = ?")
                .parameter("001205151325580000420758933716")
                .get(rs -> {
                    System.out.println(Thread.currentThread().getId());
                    return rs.getString(1) + "-" + rs.getString(2);
                })
                .singleOrDefault("no record")
                .subscribe(rs -> {
                    latch.countDown();
                    System.out.println(Thread.currentThread().getId());
                    System.out.println("subscribe");
                    System.out.println(rs);
                });
//        .get(rs -> rs.getString(1) + "-" + rs.getString(2))

        latch.await();

    }
 
开发者ID:edgar615,项目名称:javase-study,代码行数:22,代码来源:GetNoRecordExample.java

示例3: main

import com.github.davidmoten.rx.jdbc.Database; //导入依赖的package包/类
public static void main(String[] args) {
        Database db = Database.from("jdbc:mysql://127.0.0.1:3306/alarm_user", "root", "");
        List<String> names = db.select("select alarm_user_name from alarm_user where  alarm_user_id = :alarmUserId")
                .parameter("alarmUserId", "001205151324410000020758933716").getAs(String.class).toList().toBlocking().single();
        System.out.println(names);

        Map<String, String> map = new HashMap<String, String>();
        map.put("alarmUserId", "001205151324410000020758933716");
        names = db.select("select alarm_user_name from alarm_user where  alarm_user_id = :alarmUserId")
                .parameters(map).getAs(String.class).toList().toBlocking().single();
        System.out.println(names);

//        Observable<String> names = db
//                .select("select name from person where score >= :min and score <=:max")
//                .parameters(Observable.just(map1, map2))
//                .getAs(String.class);
    }
 
开发者ID:edgar615,项目名称:javase-study,代码行数:18,代码来源:NamedParameterExample.java

示例4: main

import com.github.davidmoten.rx.jdbc.Database; //导入依赖的package包/类
public static void main(String[] args) {
        Database db = Database.from("jdbc:mysql://127.0.0.1:3306/alarm_user", "root", "");

        // use composition to find the first person alphabetically with
// a score less than the person with the last name alphabetically
// whose name is not XAVIER. Two threads and connections will be used.
        Observable<String> ids = db.select("select alarm_user_id from alarm_user  order by alarm_user_id limit ?")
                .parameter(1).getAs(String.class).last();
        String names = db.select("select alarm_user_name from alarm_user where alarm_user_id = ?")
                .parameters(ids).getAs(String.class).first().toBlocking().single();
        System.out.println(names);

        // alternatively using the Observable.lift() method to chain everything in one command:
        names = db.select("select alarm_user_id from alarm_user  order by alarm_user_id limit ?")
                .parameter(1).getAs(String.class).last().lift(db.select("select alarm_user_name from alarm_user where alarm_user_id = ?")
                .parameterOperator().getAs(String.class)).first().toBlocking().single();
        System.out.println(names);
    }
 
开发者ID:edgar615,项目名称:javase-study,代码行数:19,代码来源:ComposeExample.java

示例5: ExtractorClient

import com.github.davidmoten.rx.jdbc.Database; //导入依赖的package包/类
public ExtractorClient(Config config) {
    this.dataSource = DatasourceBuilder.from(config.getConfig("db"));
    this.databaseName = new DatabaseName(config.getString("database.name"));
    ParseTableConfig parseTableConfig = new ParseTableConfig(dataSource);
    this.sqlFlavour = detectSqlFlavour(config.getConfig("db"));
    this.tableConfigs = parseTableConfig.parse(config);
    this.callbackName = optionalString(config, "strategy.callbackName");
    this.redisson = createRedisso(config);
    this.timeZone = TimeZoneConfig.timeZone(config);
    this.database = new Database(new DataSourceConnectionProvider(dataSource), () -> Schedulers.io());
}
 
开发者ID:jamescross91,项目名称:shyft-extractor,代码行数:12,代码来源:ExtractorClient.java

示例6: main

import com.github.davidmoten.rx.jdbc.Database; //导入依赖的package包/类
/**
 * create table person(
 id bigint auto_increment primary key,
 score int
 )
 * @param args
 */
public static void main(String[] args) {
    Database db = Database.from("jdbc:mysql://127.0.0.1:3306/alarm_user", "root", "");

    List<Integer> mins = Observable
            // do 3 times
            .just(11, 12, 13)
                    // begin transaction for each item
            .lift(db.beginTransactionOnNextOperator())
                    // update all scores to the item
            .lift(db.update("update person set score=?").parameterOperator())
                    // to empty parameter list
            .map(toEmpty())
                    // increase score
            .lift(db.update("update person set score=score + 5").parameterListOperator())
                    //only expect one result so can flatten
            .lift(RxUtil.<Integer>flatten())
                    // commit transaction
            .lift(db.commitOnNextOperator())
                    // to empty lists
            .map(toEmpty())
                    // return count
            .lift(db.select("select min(score) from person").parameterListOperator()
                    .getAs(Integer.class))
                    // list the results
            .toList()
                    // block and get
            .toBlocking().single();

    System.out.println(mins);
}
 
开发者ID:edgar615,项目名称:javase-study,代码行数:38,代码来源:OnNextTransactionEaxmple.java

示例7: main

import com.github.davidmoten.rx.jdbc.Database; //导入依赖的package包/类
public static void main(String[] args) {
    Database db = Database.from("jdbc:mysql://127.0.0.1:3306/alarm_user", "root", "");

    long count = db
            .select("select count(*) from note")
                    // return as Long
            .getAs(Long.class)
                    // get answer
            .toBlocking().single();
    System.out.println(count);

    Observable<Boolean> begin = db.beginTransaction();
    Observable<Integer> updateCount = db
            // set everyones score to 99
            .update("insert into note(text) values(?)")
                    // is within transaction
            .dependsOn(begin)
                    // new score
            .parameter("hello")
                    // execute
            .count();
    Observable<Boolean> commit = db.commit(updateCount);
    count = db
            .select("select count(*) from note")
                    // depends on
            .dependsOn(commit)
                    // return as Long
            .getAs(Long.class)
                    // log
            .doOnEach(RxUtil.log())
                    // get answer
            .toBlocking().single();
    System.out.println(count);
}
 
开发者ID:edgar615,项目名称:javase-study,代码行数:35,代码来源:TransactionEaxmple.java

示例8: main

import com.github.davidmoten.rx.jdbc.Database; //导入依赖的package包/类
public static void main(String[] args) {
    Database db = Database.from("jdbc:mysql://127.0.0.1:3306/alarm_user", "root", "123456");
    List<String> names = db.select("select alarm_user_id, alarm_user_name from alarm_user")
            .get(rs -> rs.getString(1) + "-" + rs.getString(2)).toList().toBlocking().single();
    System.out.println(names);

}
 
开发者ID:edgar615,项目名称:javase-study,代码行数:8,代码来源:GetExample.java

示例9: main

import com.github.davidmoten.rx.jdbc.Database; //导入依赖的package包/类
public static void main(String[] args) {
    Database db = Database.from("jdbc:mysql://127.0.0.1:3306/alarm_user", "root", "");
    Observable<Integer> keys =
            db.update("insert into note(text) values(?)")
                    .parameter("hello", "there")
                    .returnGeneratedKeys()
                    .getAs(Integer.class);
}
 
开发者ID:edgar615,项目名称:javase-study,代码行数:9,代码来源:KeyExample.java

示例10: main

import com.github.davidmoten.rx.jdbc.Database; //导入依赖的package包/类
public static void main(String[] args) {
        Database db = Database.from("jdbc:mysql://127.0.0.1:3306/alarm_user", "root", "");

        Observable<Integer> score = Observable
                // parameters for coming update
                .just(4, "FRED")
                        // update Fred's score to 4
                .lift(db.update("update person set score=? where name=?")
                        //parameters are pushed
                        .parameterOperator())
                        // update everyone with score of 4 to 14
                .lift(db.update("update person set score=? where score=?")
                        .parameters(14, 4)
                                //wait for completion of previous observable
                        .dependsOnOperator())
                        // get Fred's score
                .lift(db.select("select score from person where name=?")
                        .parameters("FRED")
                                //wait for completion of previous observable
                        .dependsOnOperator()
                        .getAs(Integer.class));

        //If the query does not require parameters you can push it an empty list and use the parameterListOperator() to force execution.
//        Observable<Integer> rowsAffected = Observable
//                //generate two integers
//                .range(1,2)
//                        //replace the integers with empty observables
//                .map(toEmpty())
//                        //execute the update twice with an empty list
//                .lift(db.update("update person set score = score + 1")
//                        .parameterListOperator())
//                        // flatten
//                .lift(RxUtil.<Integer> flatten())
//                        // total the affected records
//                .lift(SUM_INTEGER);
    }
 
开发者ID:edgar615,项目名称:javase-study,代码行数:37,代码来源:LiftExample.java

示例11: main

import com.github.davidmoten.rx.jdbc.Database; //导入依赖的package包/类
public static void main(String[] args) {
    Database db = Database.from("jdbc:mysql://127.0.0.1:3306/alarm_user", "root", "");

    //Insert a Clob
    String document = null;
    Observable<Integer> count = db
            .update("insert into person_clob(name,document) values(?,?)")
            .parameter("FRED")
            .parameter(Database.toSentinelIfNull(document)).count();

    //or
    Reader reader = null;
     count = db
            .update("insert into person_clob(name,document) values(?,?)")
            .parameter("FRED")
            .parameter(reader).count();

    //Insert a Null Clob
    count = db
            .update("insert into person_clob(name,document) values(?,?)")
            .parameter("FRED")
            .parameterClob(null).count();
    //or
    count = db
            .update("insert into person_clob(name,document) values(?,?)")
            .parameter("FRED")
            .parameter(Database.NULL_CLOB).count();

    //Read a Clob
    Observable<String> document2 = db.select("select document from person_clob")
            .getAs(String.class);

    //or
    Observable<Reader> document3 = db.select("select document from person_clob")
            .getAs(Reader.class);
}
 
开发者ID:edgar615,项目名称:javase-study,代码行数:37,代码来源:ClobExample.java

示例12: main

import com.github.davidmoten.rx.jdbc.Database; //导入依赖的package包/类
public static void main(String[] args) {
    Database db = Database.from("jdbc:mysql://127.0.0.1:3306/alarm_user", "root", "");
    List<AlarmUser> names = db.select("select alarm_user_id, alarm_user_name from alarm_user")
           .autoMap(AlarmUser.class).toList().toBlocking().single();
    System.out.println(names);

    List<AlarmUser2> alarmUser2 = db.select("select alarm_user_id, alarm_user_name from alarm_user")
            .autoMap(AlarmUser2.class).toList().toBlocking().single();
    System.out.println(alarmUser2);
}
 
开发者ID:edgar615,项目名称:javase-study,代码行数:11,代码来源:AutoMapExample.java

示例13: main

import com.github.davidmoten.rx.jdbc.Database; //导入依赖的package包/类
public static void main(String[] args) {
    Database db = Database.from("jdbc:mysql://127.0.0.1:3306/alarm_user", "root", "");

    //Insert a Blob
    byte[] bytes = new byte[0];
    Observable<Integer> count = db
            .update("insert into person_blob(name,document) values(?,?)")
            .parameter("FRED")
            .parameter(Database.toSentinelIfNull(bytes)).count();


    //Insert a Null Blob
    count = db
            .update("insert into person_blob(name,document) values(?,?)")
            .parameter("FRED")
            .parameterBlob(null).count();
    //or
    count = db
            .update("insert into person_clob(name,document) values(?,?)")
            .parameter("FRED")
            .parameter(Database.NULL_BLOB).count();

    //Read a Blob
    Observable<byte[]> document = db.select("select document from person_clob")
            .getAs(byte[].class);

    //or
    Observable<InputStream> document2 = db.select("select document from person_clob")
            .getAs(InputStream.class);
}
 
开发者ID:edgar615,项目名称:javase-study,代码行数:31,代码来源:BlobExample.java

示例14: test

import com.github.davidmoten.rx.jdbc.Database; //导入依赖的package包/类
@Test
public void test() {
    TestSubscriber<Object> ts = new TestSubscriber<Object>();
    Database db = DatabaseCreator.db();
    db.select("select name from Person").autoMap(Thing.class).count().subscribe(ts);
    ts.assertError(SQLRuntimeException.class);
    assertTrue(ts.getOnErrorEvents().get(0).getMessage()
            .startsWith("query column names do not include 'bingo'"));
}
 
开发者ID:davidmoten,项目名称:rxjava-jdbc,代码行数:10,代码来源:ColumnNotFoundTest.java

示例15: configure

import com.github.davidmoten.rx.jdbc.Database; //导入依赖的package包/类
@Override
public void configure(final Env env, final Config config, final Binder binder) {
  Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
  DataSource ds = env.get(dskey)
      .orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));
  Database db = Database.fromDataSource(ds);

  env.serviceKey().generate(Database.class, name, k -> binder.bind(k).toInstance(db));

  // close on shutdown
  env.onStop(db::close);
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:13,代码来源:RxJdbc.java


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