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:io.dockstore.client.cli.BasicET.java

/**
 * Tests the case where a manually registered quay container matching an automated build should be treated as a separate auto build (see issue 106)
 *//*from   w ww  .jav a2 s.  c om*/
@Test
public void testManualQuaySameAsAutoQuay() {
    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file.txt"), "tool",
            "manual_publish", "--registry", Registry.QUAY_IO.toString(), "--namespace", "dockstoretestuser",
            "--name", "quayandgithub", "--git-url", "git@github.com:DockstoreTestUser/dockstore-whalesay.git",
            "--git-reference", "master", "--toolname", "regular", "--script" });

    final CommonTestUtilities.TestingPostgres testingPostgres = getTestingPostgres();
    final long count = testingPostgres.runSelectStatement(
            "select count(*) from tool where mode != 'MANUAL_IMAGE_PATH' and path = 'quay.io/dockstoretestuser/quayandgithub' and toolname = 'regular'",
            new ScalarHandler<>());
    Assert.assertTrue("the container should be Auto", count == 1);
}

From source file:com.xeiam.yank.Yank.java

/**
 * Return just one scalar given a an SQL statement
 *
 * @param scalarType The Class of the desired return scalar matching the table
 * @param params The replacement parameters
 * @return The scalar Object/*from  w w w . j a v a 2  s  . c o m*/
 * @throws SQLStatementNotFoundException if an SQL statement could not be found for the given sqlKey String
 */
public static <T> T queryScalar(String sql, Class<T> scalarType, Object[] params) {

    T returnObject = null;

    try {

        ScalarHandler<T> resultSetHandler = new ScalarHandler<T>();

        returnObject = new QueryRunner(YANK_POOL_MANAGER.getDataSource()).query(sql, resultSetHandler, params);

    } catch (SQLException e) {
        handleSQLException(e);
    }

    return returnObject;
}

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

/**
 * Tests altering the cwl and dockerfile paths to invalid locations (quick registered)
 *///  w ww  . jav  a 2s.co  m
@Test
public void testVersionTagWDLCWLAndDockerfilePathsAlteration() {
    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file2.txt"), "tool",
            "version_tag", "update", "--entry", "quay.io/dockstoretestuser2/quayandgithub", "--name", "master",
            "--cwl-path", "/testDir/Dockstore.cwl", "--wdl-path", "/testDir/Dockstore.wdl", "--dockerfile-path",
            "/testDir/Dockerfile", "--script" });

    final CommonTestUtilities.TestingPostgres testingPostgres = getTestingPostgres();
    final long count = testingPostgres.runSelectStatement(
            "select count(*) from tag,tool_tag,tool where tool.path = 'quay.io/dockstoretestuser2/quayandgithub' and tool.toolname = '' and tool.id=tool_tag.toolid and tag.id=tool_tag.tagid and valid = 'f'",
            new ScalarHandler<>());
    Assert.assertTrue("there should now be an invalid tag, found " + count, count == 1);

    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file2.txt"), "tool",
            "version_tag", "update", "--entry", "quay.io/dockstoretestuser2/quayandgithub", "--name", "master",
            "--cwl-path", "/Dockstore.cwl", "--wdl-path", "/Dockstore.wdl", "--dockerfile-path", "/Dockerfile",
            "--script" });

    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file2.txt"), "tool",
            "refresh", "--entry", "quay.io/dockstoretestuser2/quayandgithub", "--script" });

    final long count2 = testingPostgres.runSelectStatement(
            "select count(*) from tag,tool_tag,tool where tool.path = 'quay.io/dockstoretestuser2/quayandgithub' and tool.toolname = '' and tool.id=tool_tag.toolid and tag.id=tool_tag.tagid and valid = 'f'",
            new ScalarHandler<>());
    Assert.assertTrue("the invalid tag should now be valid, found " + count2, count2 == 0);
}

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

@Test
public void manualRegisterABunchOfValidEntries() throws IOException {
    Client.main(new String[] { "--config", getConfigFileLocation(true), "manual_publish", "--registry",
            Registry.QUAY_IO.toString(), "--namespace", "pypi", "--name", "bd2k-python-lib", "--git-url",
            "git@github.com:funky-user/test2.git", "--git-reference", "refs/head/master" });
    Client.main(new String[] { "--config", getConfigFileLocation(true), "manual_publish", "--registry",
            Registry.QUAY_IO.toString(), "--namespace", "pypi", "--name", "bd2k-python-lib", "--git-url",
            "git@github.com:funky-user/test2.git", "--git-reference", "refs/head/master", "--toolname",
            "test1" });
    Client.main(new String[] { "--config", getConfigFileLocation(true), "manual_publish", "--registry",
            Registry.QUAY_IO.toString(), "--namespace", "pypi", "--name", "bd2k-python-lib", "--git-url",
            "git@github.com:funky-user/test2.git", "--git-reference", "refs/head/master", "--toolname",
            "test2" });
    Client.main(new String[] { "--config", getConfigFileLocation(true), "manual_publish", "--registry",
            Registry.DOCKER_HUB.toString(), "--namespace", "pypi", "--name", "bd2k-python-lib", "--git-url",
            "git@github.com:funky-user/test2.git", "--git-reference", "refs/head/master" });
    Client.main(new String[] { "--config", getConfigFileLocation(true), "manual_publish", "--registry",
            Registry.DOCKER_HUB.toString(), "--namespace", "pypi", "--name", "bd2k-python-lib", "--git-url",
            "git@github.com:funky-user/test2.git", "--git-reference", "refs/head/master", "--toolname",
            "test1" });

    // verify DB/* w  w w  .  j ava  2 s. co m*/
    final TestingPostgres testingPostgres = getTestingPostgres();
    final long count = testingPostgres.runSelectStatement(
            "select count(*) from container where name = 'bd2k-python-lib'", new ScalarHandler<>());
    Assert.assertTrue("should see three entries", count == 5);
}

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

/**
 * Tests the case where a manually registered quay container has the same path as an auto build but different git repo
 *///from  w ww . j a v a  2 s.  c  om
@Test
public void testManualQuayToAutoSamePathDifferentGitRepo() {
    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file.txt"), "tool",
            "manual_publish", "--registry", Registry.QUAY_IO.toString(), "--namespace", "dockstoretestuser",
            "--name", "quayandgithub", "--git-url",
            "git@github.com:DockstoreTestUser/dockstore-whalesay-alternate.git", "--git-reference", "master",
            "--toolname", "alternate", "--cwl-path", "/testDir/Dockstore.cwl", "--dockerfile-path",
            "/testDir/Dockerfile", "--script" });

    final CommonTestUtilities.TestingPostgres testingPostgres = getTestingPostgres();
    final long count = testingPostgres.runSelectStatement(
            "select count(*) from tool where mode = 'MANUAL_IMAGE_PATH' and path = 'quay.io/dockstoretestuser/quayandgithub' and toolname = 'alternate'",
            new ScalarHandler<>());
    Assert.assertTrue("the container should be Manual still", count == 1);
}

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

/**
 * This tests attempting to publish a workflow with no valid versions
 */// www  .  ja  v  a  2  s.  c om
@Test
public void testRefreshAndPublishInvalid() {
    // 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
    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file2.txt"), "workflow",
            "refresh", "--entry", "DockstoreTestUser2/dockstore_empty_repo", "--script" });

    // check that no valid versions
    final long count = testingPostgres
            .runSelectStatement("select count(*) from workflowversion where valid='t'", new ScalarHandler<>());
    Assert.assertTrue("there should be 0 valid versions, there are " + count, count == 0);

    // try and publish
    systemExit.expectSystemExitWithStatus(Client.API_ERROR);
    Client.main(new String[] { "--config", ResourceHelpers.resourceFilePath("config_file2.txt"), "workflow",
            "publish", "--entry", "DockstoreTestUser2/dockstore_empty_repo", "--script" });
}

From source file:com.aw.core.dao.DAOSql.java

/**
 * Helper method used to retrieve a COLUMN using standard SQL sintaxis
 * The query must return a single column
 *
 * @param sql        SQL query//from   w  w w .  j  av a  2 s  . c o m
 * @param filterKeys key used to restrict the search
 * @return First Row First column , NULL if no row
 */
public Object findObjectGetColumn(String sql, Object[] filterKeys) {
    try {
        return new QueryRunner().query(getHibernateConnection(), sql, filterKeys, new ScalarHandler());
    } catch (SQLException e) {
        throw AWBusinessException.wrapUnhandledException(logger, e);
    }
}

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

public long getProvisionCount(ProvisionState status) {
    return this.runSelectStatement("select count(*) from provision where status = ?", new ScalarHandler<Long>(),
            status.toString());// w  ww  .  ja  v a 2 s .  c  om
}

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

/**
 * This test checks that a user can successfully refresh their workflows (only stubs)
 * @throws IOException//from www.  j  av a  2 s. com
 * @throws TimeoutException
 * @throws ApiException
 */
@Test
public void testRefreshAllForAUser() throws IOException, TimeoutException, ApiException {
    final CommonTestUtilities.TestingPostgres testingPostgres = getTestingPostgres();
    testingPostgres
            .runUpdateStatement("update enduser set isadmin = 't' where username = 'DockstoreTestUser2';");
    long userId = 1;

    final ApiClient webClient = getWebClient();
    UsersApi usersApi = new UsersApi(webClient);
    final List<Workflow> workflow = usersApi.refreshWorkflows(userId);

    // Check that there are multiple workflows
    final long count = testingPostgres.runSelectStatement("select count(*) from workflow",
            new ScalarHandler<>());
    assertTrue("Workflow entries should exist", count > 0);

    // Check that there are only stubs (no workflow version)
    final long count2 = testingPostgres.runSelectStatement("select count(*) from workflowversion",
            new ScalarHandler<>());
    assertTrue("No entries in workflowversion", count2 == 0);
    final long count3 = testingPostgres.runSelectStatement(
            "select count(*) from workflow where mode = '" + Workflow.ModeEnum.FULL + "'",
            new ScalarHandler<>());
    assertTrue("No workflows are in full mode", count3 == 0);

}

From source file:com.aw.core.dao.DAOSql.java

/**
 * Helper method used to retrieve the select count(*)
 *
 * @param sqlFromWhereClause SQL query without the SELECT section: "FROM x where X=y"
 * @param filterKeys         key used to restrict the search
 * @return number of rows that return the query
 *///ww w.j  ava  2 s.c  o m
public int findCountRows(String sqlFromWhereClause, Object[] filterKeys) {
    String sql = "SELECT count(*) " + sqlFromWhereClause;
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Executing:" + AWQueryRunner.buildSQLLog(sql, filterKeys));
        }
        Number num = (Number) new QueryRunner().query(getHibernateConnection(), sql, filterKeys,
                new ScalarHandler());
        return num.intValue();
    } catch (SQLException e) {
        throw AWBusinessException.wrapUnhandledException(logger, e);
    }
}