本文整理汇总了Java中org.apache.derby.jdbc.EmbeddedDataSource类的典型用法代码示例。如果您正苦于以下问题:Java EmbeddedDataSource类的具体用法?Java EmbeddedDataSource怎么用?Java EmbeddedDataSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EmbeddedDataSource类属于org.apache.derby.jdbc包,在下文中一共展示了EmbeddedDataSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupInitialContext
import org.apache.derby.jdbc.EmbeddedDataSource; //导入依赖的package包/类
protected static void setupInitialContext() throws Exception {
if (System.getProperty(Context.INITIAL_CONTEXT_FACTORY) == null) {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, javaURLContextFactory.class.getName());
System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
InitialContext ic = new InitialContext();
ic.createSubcontext("java:");
ic.createSubcontext("java:comp");
ic.createSubcontext("java:comp/env");
ic.createSubcontext("java:comp/env/jdbc");
EmbeddedDataSource ds = new EmbeddedDataSource();
ds.setDatabaseName("memory:testDB");
ds.setCreateDatabase("create");
ic.bind("java:comp/env/jdbc/testDS", ds);
}
}
示例2: configs
import org.apache.derby.jdbc.EmbeddedDataSource; //导入依赖的package包/类
@Parameterized.Parameters
public static Collection<Object[]> configs() {
EmbeddedDataSource derbyDs = new EmbeddedDataSource();
derbyDs.setDatabaseName("test");
derbyDs.setCreateDatabase("create");
JdbcDataSource h2Ds = new JdbcDataSource();
h2Ds.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;MODE=PostgreSQL");
// Tests on postgres disabled
// PGPoolingDataSource postgresDs = new PGPoolingDataSource();
// postgresDs.setServerName("localhost");
// postgresDs.setDatabaseName("syndesis");
// postgresDs.setUser("postgres");
// postgresDs.setPassword("password");
return Arrays.asList(new Object[][]{
{derbyDs},
// {postgresDs},
{h2Ds}
});
}
示例3: testDerbyDataSource
import org.apache.derby.jdbc.EmbeddedDataSource; //导入依赖的package包/类
@Test
public void testDerbyDataSource() throws SQLException {
BQRuntime runtime = testFactory.app("-c", "classpath:HikariCPDerbyIT.yml")
.autoLoadModules()
.createRuntime();
DataSource ds4 = runtime.getInstance(DataSourceFactory.class).forName("derby4");
assertNotNull(ds4);
assertTrue(ds4 instanceof HikariDataSource);
HikariDataSource hikariDS = (HikariDataSource) ds4;
assertEquals("org.apache.derby.jdbc.EmbeddedDataSource", hikariDS.getDataSourceClassName());
HikariPool pool = (HikariPool) hikariDS.getHikariPoolMXBean();
assertTrue(pool.getUnwrappedDataSource().getClass().isAssignableFrom(EmbeddedDataSource.class));
try (Connection c = hikariDS.getConnection()) {
assertEquals("jdbc:derby:target/derby4", c.getMetaData().getURL());
}
}
示例4: createDataSource
import org.apache.derby.jdbc.EmbeddedDataSource; //导入依赖的package包/类
public static DataSource createDataSource(String homeDir) throws IOException {
// Setup the Derby datasource.
System.setProperty("derby.system.home", homeDir);
System.setProperty("derby.storage.fileSyncTransactionLog", "true");
System.setProperty("derby.storage.pageCacheSize", "100");
final EmbeddedDataSource ds = new EmbeddedDataSource();
ds.setDatabaseName("derbydb");
ds.setCreateDatabase("create");
return ds;
}
示例5: messageSent
import org.apache.derby.jdbc.EmbeddedDataSource; //导入依赖的package包/类
@Override
protected void messageSent() throws Exception {
verifyExpectedBroker(inflightMessageCount);
if (++inflightMessageCount == failureCount) {
LOG.info("STOPPING [email protected]!!!!");
final EmbeddedDataSource ds = ((SyncCreateDataSource) getExistingDataSource()).getDelegate();
ds.setShutdownDatabase("shutdown");
LOG.info("DB [email protected]!!!!");
Thread dbRestartThread = new Thread("db-re-start-thread") {
@Override
public void run() {
delayTillRestartRequired();
ds.setShutdownDatabase("false");
LOG.info("DB RE[email protected]!!!!");
}
};
dbRestartThread.start();
}
verifyExpectedBroker(inflightMessageCount);
}
示例6: createPersistenceAdapter
import org.apache.derby.jdbc.EmbeddedDataSource; //导入依赖的package包/类
@Override
protected PersistenceAdapter createPersistenceAdapter() throws IOException {
JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
EmbeddedDataSource dataSource = new EmbeddedDataSource();
dataSource.setDatabaseName("derbyDb");
dataSource.setCreateDatabase("create");
jdbc.setDataSource(dataSource);
jdbc.setCleanupPeriod(1000); // set up small cleanup period
return jdbc;
}
示例7: initDB
import org.apache.derby.jdbc.EmbeddedDataSource; //导入依赖的package包/类
private void initDB() {
try {
logger.debug("Initializing DB...");
Database db = new DatabaseIO().read(new InputStreamReader(JvmMonitorLoader.class.getResourceAsStream("/dbSchema.xml"), "UTF-8"));
Platform platform = PlatformFactory.createNewPlatformInstance(DerbyPlatform.DATABASENAME);
EmbeddedDataSource dataSource = new EmbeddedDataSource();
dataSource.setDatabaseName(databasePath + DB_NAME);
dataSource.setCreateDatabase("create");
platform.setDataSource(dataSource);
if (platform.readModelFromDatabase(DB_NAME).getTableCount() == 0) { //TODO is that needed?
platform.createTables(db, false, false);
} else {
platform.alterTables(db, false);
}
} catch (DdlUtilsException | UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}
示例8: before
import org.apache.derby.jdbc.EmbeddedDataSource; //导入依赖的package包/类
@BeforeClass
public void before() {
storage = new StorageServiceImpl();
EmbeddedDataSource dataSource = new EmbeddedConnectionPoolDataSource();
dataSource.setDatabaseName(System.getProperty("java.io.tmpdir") +
File.separator + "chii2" +
File.separator + "mqtt" +
File.separator + "server");
dataSource.setCreateDatabase("create");
storage.setDataSource(dataSource);
storage.start();
storage.clearTable("MESSAGE_ID");
storage.clearTable("RETAIN");
storage.clearTable("INFLIGHT");
storage.clearTable("QOS2");
storage.clearTable("SUBSCRIPTION");
}
示例9: createEntityManagerFactory
import org.apache.derby.jdbc.EmbeddedDataSource; //导入依赖的package包/类
private EntityManagerFactory createEntityManagerFactory() {
try {
Properties connectionProperties = new Properties();
connectionProperties.load(ClassLoader.getSystemResourceAsStream("at/arz/ngs/connection.properties"));
EmbeddedDataSource dataSource = new EmbeddedDataSource();
dataSource.setDatabaseName("memory:ngs-service-db");
dataSource.setCreateDatabase("create");
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(JPA_UNIT_NAME,
connectionProperties);
return entityManagerFactory;
}
catch (IOException e) {
throw new RuntimeException("could not load create entity manager factory", e);
}
}
示例10: setUp
import org.apache.derby.jdbc.EmbeddedDataSource; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
dataSource = new EmbeddedDataSource();
dataSource.setDatabaseName(dbName);
dataSource.setCreateDatabase("create");
conn = dataSource.getConnection();
TestDb.dropTables(conn);
TestDb.buildCoffeeTable(conn);
}
示例11: stopDerby
import org.apache.derby.jdbc.EmbeddedDataSource; //导入依赖的package包/类
private void stopDerby() {
LOG.info("STOPPING [email protected]!!!!");
final EmbeddedDataSource ds = dataSource;
try {
ds.setShutdownDatabase("shutdown");
ds.getConnection();
} catch (Exception ignored) {
}
}
示例12: setUp
import org.apache.derby.jdbc.EmbeddedDataSource; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
setAutoFail(true);
topic = false;
verbose = true;
// startup db
sharedDs = (EmbeddedDataSource) DataSourceServiceSupport.createDataSource(IOHelper.getDefaultDataDirectory());
broker = new BrokerService();
DefaultIOExceptionHandler handler = new DefaultIOExceptionHandler();
handler.setIgnoreSQLExceptions(false);
handler.setStopStartConnectors(true);
broker.setIoExceptionHandler(handler);
broker.addConnector("tcp://localhost:0");
broker.setUseJmx(false);
broker.setPersistent(true);
broker.setDeleteAllMessagesOnStartup(true);
JDBCPersistenceAdapter persistenceAdapter = new JDBCPersistenceAdapter();
persistenceAdapter.setDataSource(sharedDs);
persistenceAdapter.setUseLock(false);
persistenceAdapter.setLockKeepAlivePeriod(500);
persistenceAdapter.getLocker().setLockAcquireSleepInterval(500);
broker.setPersistenceAdapter(persistenceAdapter);
broker.start();
super.setUp();
}
示例13: messageSent
import org.apache.derby.jdbc.EmbeddedDataSource; //导入依赖的package包/类
@Override
protected void messageSent() throws Exception {
if (++inflightMessageCount == failureCount) {
LOG.info("STOPPING [email protected]!!!!");
final EmbeddedDataSource ds = sharedDs;
ds.setShutdownDatabase("shutdown");
try {
ds.getConnection();
} catch (Exception ignored) {
}
LOG.info("DB [email protected]!!!!");
Thread dbRestartThread = new Thread("db-re-start-thread") {
@Override
public void run() {
LOG.info("Sleeping for 10 seconds before allowing db restart");
try {
restartDBLatch.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
ds.setShutdownDatabase("false");
LOG.info("DB [email protected]!!!!");
}
};
dbRestartThread.start();
}
}
示例14: testJdbcConfig
import org.apache.derby.jdbc.EmbeddedDataSource; //导入依赖的package包/类
@Test
public void testJdbcConfig() throws Exception {
File journalFile = new File(JOURNAL_ROOT + "testJDBCConfig/journal");
recursiveDelete(journalFile);
File derbyFile = new File(DERBY_ROOT + "testJDBCConfig/derbydb"); // Default
recursiveDelete(derbyFile);
BrokerService broker;
broker = createBroker(new FileSystemResource(CONF_ROOT + "jdbc-example.xml"));
try {
assertEquals("Broker Config Error (brokerName)", "brokerJdbcConfigTest", broker.getBrokerName());
PersistenceAdapter adapter = broker.getPersistenceAdapter();
assertTrue("Should have created a jdbc persistence adapter", adapter instanceof JDBCPersistenceAdapter);
assertEquals("JDBC Adapter Config Error (cleanupPeriod)", 60000, ((JDBCPersistenceAdapter) adapter).getCleanupPeriod());
assertTrue("Should have created an EmbeddedDataSource", ((JDBCPersistenceAdapter) adapter).getDataSource() instanceof EmbeddedDataSource);
assertTrue("Should have created a DefaultWireFormat", ((JDBCPersistenceAdapter) adapter).getWireFormat() instanceof ObjectStreamWireFormat);
LOG.info("Success");
} finally {
if (broker != null) {
broker.stop();
}
}
}
示例15: createTablesOnInitialize
import org.apache.derby.jdbc.EmbeddedDataSource; //导入依赖的package包/类
private static boolean createTablesOnInitialize(DataSource dataSource) {
// If the classes are not in the classpath a 'instanceof' would throw ClassNotFoundError
if (StringUtils.equals(dataSource.getClass().getName(), "org.apache.derby.jdbc.EmbeddedDataSource")) {
return "create".equals(((EmbeddedDataSource) dataSource).getCreateDatabase());
} else if (StringUtils.equals(dataSource.getClass().getName(), "org.h2.jdbcx.JdbcDataSource")) {
String url = ((JdbcDataSource) dataSource).getUrl();
if (url.startsWith("jdbc:h2:mem")) {
return true;
}
String databaseFile = url.substring("jdbc:h2:".length());
return !new File(databaseFile).exists();
}
return false;
}