use of org.h2.jdbcx.JdbcDataSource in project che by eclipse.
the class H2DBTestServer method start.
@Override
public void start() {
final JdbcDataSource dataSource = new JdbcDataSource();
dataSource.setUrl(getUrl() + ";DB_CLOSE_DELAY=-1");
try (Connection conn = dataSource.getConnection()) {
RunScript.execute(conn, new StringReader("SELECT 1"));
} catch (SQLException x) {
throw new RuntimeException(x);
}
}
use of org.h2.jdbcx.JdbcDataSource in project ratpack by ratpack.
the class Example method main.
public static void main(String[] args) throws Exception {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:transactionExamples;DB_CLOSE_DELAY=-1");
txDs = Transaction.dataSource(ds);
tx = Transaction.create(ds::getConnection);
try (Connection connection = txDs.getConnection()) {
try (Statement statement = connection.createStatement()) {
statement.executeUpdate("CREATE TABLE tbl (value VARCHAR(50)) ");
}
}
List<Block> examples = Arrays.asList(Example::singleTransactionExample, Example::singleTransactionRollbackExample, Example::nestedTransactionExample, Example::nestedTransactionRollbackExample, () -> manualTransactionExample(true), () -> manualTransactionExample(false));
try (ExecHarness harness = ExecHarness.harness()) {
for (Block example : examples) {
harness.execute(Operation.of(example));
reset();
}
}
}
use of org.h2.jdbcx.JdbcDataSource in project felix by apache.
the class H2Activator method start.
@Override
public void start(BundleContext context) throws Exception {
ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
Dictionary<String, String> props = new Hashtable<String, String>();
props.put("dataSourceName", "test");
context.registerService(DataSource.class.getName(), ds, props);
loadData(ds);
// Register the H2 console servlet
Dictionary<String, String> servletProps = new Hashtable<String, String>();
servletProps.put("alias", "/h2");
servletProps.put("init.webAllowOthers", "true");
context.registerService(Servlet.class.getName(), new WebServlet(), servletProps);
}
use of org.h2.jdbcx.JdbcDataSource in project microservice_framework by CJSCommonPlatform.
the class TestDataSourceFactory method createDataSource.
public JdbcDataSource createDataSource() throws LiquibaseException, SQLException {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
dataSource = new JdbcDataSource();
dataSource.setURL("jdbc:h2:mem:test;MV_STORE=FALSE;MVCC=FALSE;DB_CLOSE_ON_EXIT=TRUE");
dataSource.setUser("sa");
dataSource.setPassword("sa");
initDatabase();
return dataSource;
}
use of org.h2.jdbcx.JdbcDataSource in project h2database by h2database.
the class OsgiDataSourceFactory method createXADataSource.
/**
* Creates a pooled XA data source.
*
* @param properties the properties for the data source.
* @throws SQLException if unsupported properties are supplied, or if data
* source can not be created.
* @return a new data source.
*/
@Override
public XADataSource createXADataSource(Properties properties) throws SQLException {
// Make copy of properties
Properties propertiesCopy = new Properties();
if (properties != null) {
propertiesCopy.putAll(properties);
}
// Verify that no unsupported standard options are used
rejectUnsupportedOptions(propertiesCopy);
// The integrated connection pool is H2 is not configurable
rejectPoolingOptions(propertiesCopy);
JdbcDataSource dataSource = new JdbcDataSource();
setupH2DataSource(dataSource, propertiesCopy);
return dataSource;
}
Aggregations