List of usage examples for javax.sql DataSource DataSource
DataSource
From source file:com.qubole.quark.plugins.jdbc.JdbcDB.java
public Iterator<Object> execute(final Connection conn, final String sql) throws Exception { return ResultSetEnumerable.of(new DataSource() { @Override// w w w . java 2 s. com public Connection getConnection() throws SQLException { return conn; } @Override public Connection getConnection(String s, String s1) throws SQLException { return conn; } @Override public PrintWriter getLogWriter() throws SQLException { return null; } @Override public void setLogWriter(PrintWriter printWriter) throws SQLException { } @Override public void setLoginTimeout(int i) throws SQLException { } @Override public int getLoginTimeout() throws SQLException { return 100; } @Override public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException { return null; } @Override public <T> T unwrap(Class<T> aClass) throws SQLException { return null; } @Override public boolean isWrapperFor(Class<?> aClass) throws SQLException { return false; } }, sql).iterator(); }
From source file:org.photovault.common.Test_NewSchemaMigration.java
/** Add the tables from previous schema and populate with data from testfiles/migration_test_data_0.5.0.xml. *///from w w w . j av a2s. co m @BeforeClass public void setUpTestCase() throws DdlUtilsException, SQLException, IOException { PVDatabase db = PhotovaultSettings.getSettings().getCurrentDatabase(); int oldVersion = db.getSchemaVersion(); // Find needed information fr DdlUtils Session session = HibernateUtil.getSessionFactory().openSession(); Platform platform = null; if (db.getDbDescriptor() instanceof DerbyDescriptor) { platform = PlatformFactory.createNewPlatformInstance("derby"); } else if (db.getDbDescriptor() instanceof MysqlDescriptor) { platform = PlatformFactory.createNewPlatformInstance("mysql"); } platform.getPlatformInfo().setDelimiterToken(""); // Get the database schema XML file InputStream schemaIS = getClass().getClassLoader().getResourceAsStream("db_schema_0.5.0.xml"); DatabaseIO dbio = new DatabaseIO(); dbio.setValidateXml(false); Database dbModel = dbio.read(new InputStreamReader(schemaIS)); // Alter tables to match corrent schema Transaction tx = session.beginTransaction(); final Connection con = session.connection(); DataSource ds = new DataSource() { public Connection getConnection() throws SQLException { return con; } public Connection getConnection(String arg0, String arg1) throws SQLException { throw new UnsupportedOperationException("Not supported yet."); } public PrintWriter getLogWriter() throws SQLException { throw new UnsupportedOperationException("Not supported yet."); } public void setLogWriter(PrintWriter arg0) throws SQLException { throw new UnsupportedOperationException("Not supported yet."); } public void setLoginTimeout(int arg0) throws SQLException { throw new UnsupportedOperationException("Not supported yet."); } public int getLoginTimeout() throws SQLException { throw new UnsupportedOperationException("Not supported yet."); } public <T> T unwrap(Class<T> arg0) throws SQLException { throw new UnsupportedOperationException("Not supported yet."); } public boolean isWrapperFor(Class<?> arg0) throws SQLException { throw new UnsupportedOperationException("Not supported yet."); } }; platform.createTables(con, dbModel, false, true); DbInfo dbinfo = DbInfo.getDbInfo(); dbinfo.setVersion(11); session.update(dbinfo); session.flush(); tx.commit(); // Load data // Insert the seed data to database platform = PlatformFactory.createNewPlatformInstance("derby"); platform.getPlatformInfo().setDelimiterToken(""); platform.setDataSource(ds); DataToDatabaseSink sink = new DataToDatabaseSink(platform, dbModel); DataReader reader = new DataReader(); reader.setModel(dbModel); reader.setSink(sink); try { sink.start(); reader.parse(new File("testfiles", "migration_test_data_0.5.0.xml")); sink.end(); } catch (SAXException ex) { log.error("SAXException: " + ex.getMessage(), ex); } catch (IOException ex) { log.error("IOException: " + ex.getMessage(), ex); } initTestVolume(db); initTestExtVolume(db); session.close(); }