List of usage examples for org.apache.commons.dbutils.handlers ArrayListHandler ArrayListHandler
public ArrayListHandler()
BasicRowProcessor
for conversions. From source file:net.sourceforge.seqware.pipeline.plugins.MetadataTest.java
@Test public void testCreateWorkflowRunWithFiles() { launchPlugin("--table", "workflow_run", "--create", "--field", "workflow_accession::4", "--field", "status::completed", "--file", "cool_algorithm1::adamantium/gzip::/datastore/adamantium.gz", "--file", "hot_algorithm1::corbomite/gzip::/datastore/corbomite.gz"); String s = getOut();/*from w ww. j a va2s. com*/ String swid = getAndCheckSwid(s, 2); int integer = Integer.valueOf(swid); // check that file records were created correctly and linked in properly, 0.13.13.6.x does not have access to TestDatabaseCreator, so // let's try some workflow run reporter parsing WorkflowRun workflowRun = metadata.getWorkflowRun(integer); String workflowRunReport = ((MetadataWS) metadata).getWorkflowRunReport(integer); Assert.assertTrue("could not find workflowRun", workflowRun != null && workflowRun.getSwAccession() == integer); Assert.assertTrue("could not find files", workflowRunReport.contains("/datastore/adamantium.gz") && workflowRunReport.contains("/datastore/corbomite.gz")); BasicTestDatabaseCreator dbCreator = new BasicTestDatabaseCreator(); List<Object[]> runQuery = dbCreator.runQuery(new ArrayListHandler(), "select f.sw_accession, p.algorithm, p.status from file f, processing p, processing_files pf, workflow_run r " + "WHERE f.file_id=pf.file_id AND pf.processing_id = p.processing_id " + "AND (r.workflow_run_id=p.workflow_run_id OR r.workflow_run_id=p.ancestor_workflow_run_id )" + "AND r.sw_accession =?", integer); Assert.assertTrue("incorrect number of files " + runQuery.size(), runQuery.size() == 2); for (Object[] row : runQuery) { int file_sw_accession = (Integer) row[0]; String processingStatus = (String) row[2]; net.sourceforge.seqware.common.model.File file = metadata.getFile(file_sw_accession); Assert.assertTrue("could not find file", file != null && file.getSwAccession() == file_sw_accession); Assert.assertTrue("processing status incorrect", processingStatus.equals(ProcessingStatus.success.toString())); } }
From source file:org.batoo.jpa.community.test.BaseCoreTest.java
/** * Builds the session factory./*w w w . j av a 2 s . co m*/ * * @throws SQLException * th * * @since 2.0.0 */ @Before public void setup() throws SQLException { if (this.testMode == null) { this.testMode = System.getProperty("testMode"); if (!this.noDatasource) { this.testMode = "hsql"; System.setProperty("testMode", this.testMode); System.setProperty("javax.persistence.jdbc.driver", "org.hsqldb.jdbcDriver"); System.setProperty("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:test"); System.setProperty("javax.persistence.jdbc.user", "sa"); System.setProperty("javax.persistence.jdbc.password", ""); } } if ("mssql".equals(this.testMode)) { final String username = System.getProperty("javax.persistence.jdbc.user"); final String password = System.getProperty("javax.persistence.jdbc.password"); final Connection connection = DriverManager .getConnection(System.getProperty("javax.persistence.jdbc.url"), username, password); try { final QueryRunner qr = new QueryRunner(true, false); qr.update(connection, "use master"); qr.update(connection, "drop database test"); qr.update(connection, "create database test"); } finally { connection.close(); } } if ("oracle".equals(this.testMode)) { final String username = System.getProperty("javax.persistence.jdbc.user"); final String password = System.getProperty("javax.persistence.jdbc.password"); final Connection connection = DriverManager .getConnection(System.getProperty("javax.persistence.jdbc.url"), username, password); try { final QueryRunner qr = new QueryRunner(true, false); final List<Object[]> tables = qr.query(connection, "select TABLE_NAME from user_tables", new ArrayListHandler()); for (final Object[] table : tables) { try { qr.update(connection, "DROP TABLE " + table[0] + " CASCADE CONSTRAINTS"); } catch (final Exception e) { } } } finally { connection.close(); } } if (!this.lazySetup()) { this.emf = this.setupEmf(); } }
From source file:org.batoo.jpa.core.test.BaseCoreTest.java
/** * Builds the session factory.// w ww. j a v a2s .c om * * @throws SQLException * th * * @since 2.0.0 */ @Before public void setup() throws SQLException { if (System.getProperty("testMode") == null) { System.setProperty("testMode", "h2"); System.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver"); System.setProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:test;ALIAS_COLUMN_NAME=TRUE"); System.setProperty("javax.persistence.jdbc.user", "root"); System.setProperty("javax.persistence.jdbc.password", ""); } final String testMode = System.getProperty("testMode"); if ("saw".equals(System.getProperty("testMode"))) { try { Runtime.getRuntime().exec("/bin/sh src/test/resources/saw.sh").waitFor(); } catch (final Exception e) { throw new SQLException(e); } } if ("oracle".equals(testMode)) { final String username = System.getProperty("javax.persistence.jdbc.user"); final String password = System.getProperty("javax.persistence.jdbc.password"); final Connection connection = DriverManager .getConnection(System.getProperty("javax.persistence.jdbc.url"), username, password); try { final QueryRunner qr = new QueryRunner(true, false); final List<Object[]> tables = qr.query(connection, "select TABLE_NAME from user_tables", new ArrayListHandler()); for (final Object[] table : tables) { try { qr.update(connection, "DROP TABLE " + table[0] + " CASCADE CONSTRAINTS"); } catch (final Exception e) { } } } finally { connection.close(); } } if ("mssql".equals(testMode)) { final String username = System.getProperty("javax.persistence.jdbc.user"); final String password = System.getProperty("javax.persistence.jdbc.password"); final Connection connection = DriverManager .getConnection(System.getProperty("javax.persistence.jdbc.url"), username, password); final String dropConstraintSQL = // "SELECT " + // "'ALTER TABLE ' + OBJECT_NAME(parent_object_id) + " + // "' DROP CONSTRAINT ' + name " + // "FROM sys.foreign_keys " + // "WHERE referenced_object_id = object_id('"; try { final QueryRunner qr = new QueryRunner(false, false); final List<Object[]> tables = qr.query(connection, "select * from sys.Tables", new ArrayListHandler()); // first drop all constraints for (final Object[] table : tables) { try { qr.query(connection, dropConstraintSQL + table[0] + "')", new NullResultSetHandler()); } catch (final Exception e) { LOG.debug(e.getMessage()); } } connection.commit(); for (final Object[] table : tables) { try { qr.update(connection, "DROP TABLE " + table[0]); } catch (final Exception e) { LOG.debug(e.getMessage()); } } connection.commit(); } finally { connection.close(); } } if (!this.lazySetup()) { this.emf = this.setupEmf(); } }
From source file:org.jooq.java8.goodies.sql.SQLGoodies.java
public static void main(String[] args) throws Exception { Class.forName("org.h2.Driver"); try (Connection c = getConnection("jdbc:h2:~/test", "sa", "")) { String sql = "select schema_name, is_default from information_schema.schemata order by schema_name"; System.out.println("Fetching data into a with JDBC / Java 7 syntax"); System.out.println("----------------------------------------------"); try (PreparedStatement stmt = c.prepareStatement(sql); ResultSet rs = stmt.executeQuery()) { while (rs.next()) { System.out.println(new Schema(rs.getString("SCHEMA_NAME"), rs.getBoolean("IS_DEFAULT"))); }/*from ww w . j a v a2 s.c o m*/ } System.out.println(); System.out.println("Fetching data into a lambda expression with jOOQ"); System.out.println("------------------------------------------------"); DSL.using(c).fetch(sql) .map(r -> new Schema(r.getValue("SCHEMA_NAME", String.class), r.getValue("IS_DEFAULT", boolean.class))) // could also be written as // .into(Schema.class) .forEach(System.out::println); System.out.println(); System.out.println("Fetching data into a lambda expression with Spring JDBC"); System.out.println("-------------------------------------------------------"); new JdbcTemplate(new SingleConnectionDataSource(c, true)) .query(sql, (rs, rowNum) -> new Schema(rs.getString("SCHEMA_NAME"), rs.getBoolean("IS_DEFAULT"))) .forEach(System.out::println); System.out.println(); System.out.println("Fetching data into a lambda expression with Apache DbUtils"); System.out.println("-------------------------------------------------------"); new QueryRunner().query(c, sql, new ArrayListHandler()).stream() .map(array -> new Schema((String) array[0], (Boolean) array[1])).forEach(System.out::println); } }
From source file:org.mule.tck.util.MuleDerbyTestDatabase.java
/** * Executes a query against the database. * * @param sql SQL query//from www . j a v a 2 s .com * @return * @throws Exception */ public List execSqlQuery(String sql) throws Exception { Connection con = null; try { con = getConnection(); return (List) new QueryRunner().query(con, sql, new ArrayListHandler()); } finally { if (con != null && !con.isClosed()) { con.close(); } } }
From source file:org.mule.test.integration.transaction.AbstractDerbyTestCase.java
protected List execSqlQuery(String sql) throws Exception { Connection con = null;/*from w w w. j a v a2s . c o m*/ try { con = getConnection(); return (List) new QueryRunner().query(con, sql, new ArrayListHandler()); } finally { JdbcUtils.close(con); } }
From source file:org.mule.test.integration.transaction.xa.XATransactionsWithSpringDAO.java
public List execSqlQuery(String sql) throws Exception { Connection con = null;/* w w w. j a v a 2 s. c o m*/ try { con = getConnection(); return (List) new QueryRunner().query(con, sql, new ArrayListHandler()); } finally { JdbcUtils.close(con); } }
From source file:org.mule.transport.jdbc.functional.AbstractJdbcFunctionalTestCase.java
protected List execSqlQuery(String sql) throws Exception { Connection con = null;/*from ww w .j av a2s .c o m*/ try { con = jdbcConnector.getConnection(); return (List) new QueryRunner().query(con, sql, new ArrayListHandler()); } finally { JdbcUtils.close(con); } }
From source file:org.mule.transport.jdbc.functional.JdbcBridgeFunctionalTestCase.java
protected void doTestBridge() throws Exception { QueryRunner queryRunner = jdbcConnector.getQueryRunner(); Connection connection = jdbcConnector.getConnection(); for (int i = 0; i < TEST_ROWS; i++) { queryRunner.update(connection, "INSERT INTO TEST(TYPE, DATA) VALUES (1, 'Test " + i + "')"); }//w ww. j ava 2s . c o m List<?> results = (List<?>) queryRunner.query(connection, "SELECT * FROM TEST WHERE TYPE = 1", new ArrayListHandler()); assertEquals(TEST_ROWS, results.size()); long t0 = System.currentTimeMillis(); while (true) { results = (List<?>) queryRunner.query(connection, "SELECT * FROM TEST_OUT", new ArrayListHandler()); logger.info("Results found: " + results.size()); if (results.size() >= TEST_ROWS) { break; } results = (List<?>) queryRunner.query(connection, "SELECT * FROM TEST WHERE TYPE = 2", new ArrayListHandler()); logger.info("Locked records found: " + results.size()); assertTrue(TEST_ROWS >= results.size()); results = (List<?>) queryRunner.query(connection, "SELECT * FROM TEST WHERE TYPE = 1", new ArrayListHandler()); logger.info("Original records found: " + results.size()); assertTrue(TEST_ROWS >= results.size()); assertTrue(System.currentTimeMillis() - t0 < 20000); Thread.sleep(500); } }
From source file:org.mule.transport.jdbc.functional.JdbcEndpointWithNestedQueriesTestCase.java
@Test public void testDisposeAfterQueryExecution() throws Exception { QueryRunner queryRunner = jdbcConnector.getQueryRunner(); Connection connection = jdbcConnector.getConnection(); // Send a message to trigger nested query on JDBC outbound endpoint to execute. MuleClient client = muleContext.getClient(); client.send("vm://in", "some test data", null); // Assert that query executed correctly. List<?> results = (List<?>) queryRunner.query(connection, "SELECT * FROM TEST", new ArrayListHandler()); assertEquals(1, results.size());//from w w w . ja va 2s.c o m // Try to dispose gracefully. try { muleContext.dispose(); } catch (Exception ex) { fail("Server disposal failed"); } }