Example usage for org.apache.commons.dbutils.handlers ScalarHandler ScalarHandler

List of usage examples for org.apache.commons.dbutils.handlers ScalarHandler ScalarHandler

Introduction

In this page you can find the example usage for org.apache.commons.dbutils.handlers ScalarHandler ScalarHandler.

Prototype

public ScalarHandler() 

Source Link

Document

Creates a new instance of ScalarHandler.

Usage

From source file:com.demo.db.dao.impl.DriverDaoImpl.java

@Override
public Driver insert(Driver driver) {
    QueryRunner queryRunner = dbHelper.getRunner();
    try {/*w w  w.ja  v  a2s .  com*/
        Long id = queryRunner.insert(dbHelper.getConnection(),
                "insert into demo_driver(cell, password, name, sfz_a, sfz_b, jsz_a, xsz_a, license_plate) values(?, ?, ?, ?, ?, ?, ?, ?)",
                new ScalarHandler<Long>(),
                new Object[] { driver.getCell(), DigestUtils.md5Hex(driver.getPassword()), driver.getName(),
                        driver.getSfzA(), driver.getSfzB(), driver.getJszA(), driver.getXszA(),
                        driver.getLicensePlate() });
        if (id != null && id.longValue() > 0) {
            driver.setId(id);
        }
    } catch (SQLException e) {
        String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
        LOGGER.error("{}??{}", methodName, driver);
        throw new RuntimeException("??", e);
    }
    return driver;
}

From source file:io.dockstore.client.cli.GeneralWorkflowET.java

/**
 * This test checks that refresh all works (with a mix of stub and full) and refresh individual.  It then tries to publish them
 *//*from  w w w.j ava2s .co  m*/
@Test
public void testRefreshAndPublish() {
    // Set up DB
    final CommonTestUtilities.TestingPostgres testingPostgres = getTestingPostgres();

    // refresh all
    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file2.txt"), "workflow",
            "refresh", "--script" });

    // refresh individual that is valid
    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file2.txt"), "workflow",
            "refresh", "--entry", "DockstoreTestUser2/hello-dockstore-workflow", "--script" });

    // refresh all
    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file2.txt"), "workflow",
            "refresh", "--script" });

    // check that valid is valid and full
    final long count = testingPostgres.runSelectStatement("select count(*) from workflow where ispublished='t'",
            new ScalarHandler<>());
    Assert.assertTrue("there should be 0 published entries, there are " + count, count == 0);
    final long count2 = testingPostgres
            .runSelectStatement("select count(*) from workflowversion where valid='t'", new ScalarHandler<>());
    Assert.assertTrue("there should be 2 valid versions, there are " + count2, count2 == 2);

    // attempt to publish it
    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file2.txt"), "workflow",
            "publish", "--entry", "DockstoreTestUser2/hello-dockstore-workflow", "--script" });

    final long count3 = testingPostgres
            .runSelectStatement("select count(*) from workflow where ispublished='t'", new ScalarHandler<>());
    Assert.assertTrue("there should be 1 published entry, there are " + count3, count3 == 1);

    // unpublish
    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file2.txt"), "workflow",
            "publish", "--entry", "DockstoreTestUser2/hello-dockstore-workflow", "--unpub", "--script" });

    final long count4 = testingPostgres
            .runSelectStatement("select count(*) from workflow where ispublished='t'", new ScalarHandler<>());
    Assert.assertTrue("there should be 0 published entries, there are " + count4, count4 == 0);

}

From source file:com.ruihu.easyshop.book.dao.BookDao.java

/**
 * regular search function/* w w w.  j a v  a2  s .  co  m*/
 * @param exprList
 * @param pc
 * @return 
 */
private PageBean<Book> findByCriteria(List<Expression> exprList, int pc) throws SQLException {
    //1 get every record from page ps
    //2 get totol record tr
    //3 get beanList
    //4 get PageBean return
    /**
     * 1 get ps
     */
    int ps = PageConstants.BOOK_PAGE_SIZE;
    /**
     * 2 total record number
     */
    StringBuilder whereSql = new StringBuilder(" where 1=1");
    List<Object> params = new ArrayList<Object>(); //replace ? in the sql query
    for (Expression expr : exprList) {
        whereSql.append(" and ").append(expr.getName()).append(" ").append(expr.getOperator()).append(" ");
        // where 1=1 and bid = 
        if (!expr.getOperator().equals("is null")) {
            // where 1=1 and bid = ?
            whereSql.append("?");
            //parameter
            params.add(expr.getValue());
        }
    }
    String sql = "select count(*) from t_book" + whereSql;
    Number number = (Number) qr.query(sql, new ScalarHandler(), params.toArray());
    int tr = number.intValue();

    /**
     * get beanList means current record
     */
    sql = "select * from t_book" + whereSql + " order by orderBy limit ?,?";
    params.add((pc - 1) * ps); //current page first index
    params.add(ps); //how many record in a page

    List<Book> beanList = qr.query(sql, new BeanListHandler<Book>(Book.class), params.toArray());

    /**
     * create PageBean and set parameter
     */
    PageBean<Book> pb = new PageBean<Book>();
    //withou PageBean url , it can be set by servlet
    pb.setBeanList(beanList);
    pb.setPc(pc);
    pb.setPs(ps);
    pb.setTr(tr);

    return pb;

}

From source file:io.dockstore.client.cli.ClientIT.java

@Test
public void quickRegisterValidEntry() throws IOException {
    Client.main(new String[] { "--config", getConfigFileLocation(true), "publish", "quay.io/test_org/test6" });

    // verify DB/*from  w w  w .j  ava2s.  co  m*/
    final TestingPostgres testingPostgres = getTestingPostgres();
    final long count = testingPostgres.runSelectStatement("select count(*) from container where name = 'test6'",
            new ScalarHandler<>());
    Assert.assertTrue("should see three entries", count == 1);
}

From source file:io.dockstore.client.cli.BasicET.java

/**
 * Tests manually adding, updating, and removing a dockerhub container
 *//*  w w  w  . j  a  va2  s .c om*/
@Test
public void testVersionTagDockerhub() {
    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file.txt"), "tool",
            "manual_publish", "--registry", Registry.DOCKER_HUB.toString(), "--namespace", "dockstoretestuser",
            "--name", "dockerhubandgithub", "--git-url",
            "git@github.com:DockstoreTestUser/dockstore-whalesay.git", "--git-reference", "master",
            "--toolname", "regular", "--script" });

    // Add a tag
    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file.txt"), "tool",
            "version_tag", "add", "--entry",
            "registry.hub.docker.com/dockstoretestuser/dockerhubandgithub/regular", "--name", "masterTest",
            "--image-id", "4728f8f5ce1709ec8b8a5282e274e63de3c67b95f03a519191e6ea675c5d34e8", "--git-reference",
            "master", "--script" });

    final CommonTestUtilities.TestingPostgres testingPostgres = getTestingPostgres();
    final long count = testingPostgres.runSelectStatement("select count(*) from tag where name = 'masterTest'",
            new ScalarHandler<>());
    Assert.assertTrue("there should be one tag", count == 1);

    // Update tag
    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file.txt"), "tool",
            "version_tag", "update", "--entry",
            "registry.hub.docker.com/dockstoretestuser/dockerhubandgithub/regular", "--name", "masterTest",
            "--hidden", "true", "--script" });

    final long count2 = testingPostgres.runSelectStatement(
            "select count(*) from tag where name = 'masterTest' and hidden='t'", new ScalarHandler<>());
    Assert.assertTrue("there should be one tag", count2 == 1);

    // Remove tag
    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file.txt"), "tool",
            "version_tag", "remove", "--entry",
            "registry.hub.docker.com/dockstoretestuser/dockerhubandgithub/regular", "--name", "masterTest",
            "--script" });

    final long count3 = testingPostgres.runSelectStatement("select count(*) from tag where name = 'masterTest'",
            new ScalarHandler<>());
    Assert.assertTrue("there should be no tags", count3 == 0);

}

From source file:com.ruihu.easyshop.order.dao.OrderDao.java

private PageBean<Order> findByCriteria(List<Expression> exprList, int pc) throws SQLException {

    int ps = PageConstants.ORDER_PAGE_SIZE;//get records in a page
    /*/*from  ww w .ja va2 s . c  o m*/
     * 2. where by using exprList
     */
    StringBuilder whereSql = new StringBuilder(" where 1=1");
    List<Object> params = new ArrayList<Object>();
    for (Expression expr : exprList) {
        whereSql.append(" and ").append(expr.getName()).append(" ").append(expr.getOperator()).append(" ");
        // where 1=1 and bid = ?
        if (!expr.getOperator().equals("is null")) {
            whereSql.append("?");
            params.add(expr.getValue());
        }
    }

    /*
     * 3. totally records
     */
    String sql = "select count(*) from t_order" + whereSql;
    Number number = (Number) qr.query(sql, new ScalarHandler(), params.toArray());
    int tr = number.intValue();//get all totally records
    /*
     * 4.get current records through beanlist
     */
    sql = "select * from t_order" + whereSql + " order by ordertime desc limit ?,?";
    params.add((pc - 1) * ps);// index of current page
    params.add(ps);//search how many records in a page

    List<Order> beanList = qr.query(sql, new BeanListHandler<Order>(Order.class), params.toArray());
    // load every items in each order list
    for (Order order : beanList) {
        loadOrderItem(order);
    }

    /*
     * 5. create PageBean
     */
    PageBean<Order> pb = new PageBean<Order>();
    pb.setBeanList(beanList);
    pb.setPc(pc);
    pb.setPs(ps);
    pb.setTr(tr);

    return pb;
}

From source file:io.dockstore.client.cli.ClientIT.java

@Test
public void quickRegisterDuplicateEntry() throws IOException {
    Client.main(new String[] { "--config", getConfigFileLocation(true), "publish", "quay.io/test_org/test6" });
    Client.main(new String[] { "--config", getConfigFileLocation(true), "publish", "quay.io/test_org/test6",
            "view1" });
    Client.main(new String[] { "--config", getConfigFileLocation(true), "publish", "quay.io/test_org/test6",
            "view2" });

    // verify DB/*from w  w  w  .  j  a  va  2s.c  o  m*/
    final TestingPostgres testingPostgres = getTestingPostgres();
    final long count = testingPostgres.runSelectStatement("select count(*) from container where name = 'test6'",
            new ScalarHandler<>());
    Assert.assertTrue("should see three entries", count == 3);
}

From source file:info.pancancer.arch3.persistence.PostgreSQL.java

public long getDesiredNumberOfVMs() {
    return runSelectStatement("select count(*) from provision where status = '" + ProvisionState.PENDING
            + "' or status = '" + ProvisionState.RUNNING + "'", new ScalarHandler<Long>());
}

From source file:info.pancancer.arch3.persistence.PostgreSQL.java

public String getPendingProvisionUUID() {
    return runSelectStatement(
            "select provision_uuid from provision where status = '" + ProvisionState.PENDING + "' limit 1",
            new ScalarHandler<String>());
}

From source file:io.dockstore.client.cli.GeneralET.java

/**
 * Tests adding/editing/deleting container related labels (for search)
 *//*ww  w.j  av a  2  s  .  com*/
@Test
public void testAddEditRemoveLabel() {
    // Test adding/removing labels for different containers
    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file2.txt"), "tool",
            "label", "--entry", "quay.io/dockstoretestuser2/quayandgithub", "--add", "quay", "--add", "github",
            "--remove", "dockerhub", "--script" });
    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file2.txt"), "tool",
            "label", "--entry", "quay.io/dockstoretestuser2/quayandgithub", "--add", "github", "--add",
            "dockerhub", "--remove", "quay", "--script" });

    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file2.txt"), "tool",
            "label", "--entry", "quay.io/dockstoretestuser2/quayandgithubalternate", "--add", "alternate",
            "--add", "github", "--script" });
    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file2.txt"), "tool",
            "label", "--entry", "quay.io/dockstoretestuser2/quayandgithubalternate", "--remove", "github",
            "--script" });

    final CommonTestUtilities.TestingPostgres testingPostgres = getTestingPostgres();
    final long count = testingPostgres
            .runSelectStatement("select count(*) from entry_label where entryid = '2'", new ScalarHandler<>());
    Assert.assertTrue("there should be 2 labels for the given container, there are " + count, count == 2);

    final long count2 = testingPostgres.runSelectStatement(
            "select count(*) from label where value = 'quay' or value = 'github' or value = 'dockerhub' or value = 'alternate'",
            new ScalarHandler<>());
    Assert.assertTrue("there should be 4 labels in the database (No Duplicates), there are " + count2,
            count2 == 4);

}