Java Code Examples for org.apache.derby.jdbc.EmbeddedDataSource#setDatabaseName()

The following examples show how to use org.apache.derby.jdbc.EmbeddedDataSource#setDatabaseName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DerbyDataSourceProvider.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@Override
public DataSource get() {
  String jdbcUrl = configuration.getJdbcUrl();
  LOG.info("JDBC Url for Recon : {} ", jdbcUrl);
  try {
    createNewDerbyDatabase(jdbcUrl, RECON_SCHEMA_NAME);
  } catch (Exception e) {
    LOG.error("Error creating Recon Derby DB.", e);
  }
  EmbeddedDataSource dataSource = new EmbeddedDataSource();
  dataSource.setDatabaseName(jdbcUrl.split(":")[2]);
  dataSource.setUser(RECON_SCHEMA_NAME);
  return dataSource;
}
 
Example 2
Source File: JDBCRecordReaderTest.java    From DataVec with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    dataSource = new EmbeddedDataSource();
    dataSource.setDatabaseName(dbName);
    dataSource.setCreateDatabase("create");
    conn = dataSource.getConnection();

    TestDb.dropTables(conn);
    TestDb.buildCoffeeTable(conn);
}
 
Example 3
Source File: JDBCDurableSubscriptionTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 4
Source File: TestJdbcCollector.java    From karaf-decanter with Apache License 2.0 5 votes vote down vote up
@Before
public void prepareBase() throws Exception {
    System.setProperty("derby.stream.error.file", "target/derby.log");
    dataSource = new EmbeddedDataSource();
    dataSource.setDatabaseName("target/testDB");
    dataSource.setCreateDatabase("create");

    try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement();) {
        statement.executeUpdate("create table TEST(id integer not null, name varchar(26))");
        statement.executeUpdate("insert into TEST(id, name) values(1, 'TEST1')");
        statement.executeUpdate("insert into TEST(id, name) values(2, 'TEST2')");
    }
}
 
Example 5
Source File: TestJdbcAppender.java    From karaf-decanter with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws SQLException {
    System.setProperty("derby.stream.error.file", "target/derby.log");
    Marshaller marshaller = new JsonMarshaller();
    EmbeddedDataSource dataSource = new EmbeddedDataSource();
    dataSource.setDatabaseName("target/testDB");
    dataSource.setCreateDatabase("create");
    
    deleteTable(dataSource);
    
    JdbcAppender appender = new JdbcAppender();
    appender.marshaller = marshaller;
    appender.dataSource = dataSource;
    Dictionary<String, Object> config = new Hashtable<>();
    config.put("dialect", "derby");
    appender.open(config);
    
    Map<String, Object> data = new HashMap<>();
    data.put(EventConstants.TIMESTAMP, TIMESTAMP);
    Event event = new Event(TOPIC, data);
    appender.handleEvent(event);

    try (Connection con = dataSource.getConnection(); Statement statement = con.createStatement();) {
        ResultSet res = statement.executeQuery("select timestamp, content from " + TABLE_NAME);
        res.next();
        long dbTimeStamp = res.getLong(1);
        String json = res.getString(2);
        JsonReader reader = Json.createReader(new StringReader(json));
        JsonObject jsonO = reader.readObject();
        Assert.assertEquals("Timestamp db", TIMESTAMP, dbTimeStamp);
        Assert.assertEquals("Timestamp string", "2016-02-02T15:59:40,634Z",jsonO.getString("@timestamp"));
        Assert.assertEquals("timestamp long", TIMESTAMP, jsonO.getJsonNumber(EventConstants.TIMESTAMP).longValue());
        Assert.assertEquals("Topic", TOPIC, jsonO.getString(EventConstants.EVENT_TOPIC.replace('.','_')));
        Assert.assertFalse(res.next());
    }
}
 
Example 6
Source File: JDBCRecordReaderTest.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    File f = testDir.newFolder();
    System.setProperty("derby.system.home", f.getAbsolutePath());

    dataSource = new EmbeddedDataSource();
    dataSource.setDatabaseName(dbName);
    dataSource.setCreateDatabase("create");
    conn = dataSource.getConnection();

    TestDb.dropTables(conn);
    TestDb.buildCoffeeTable(conn);
}