Package org.apache.derby.jdbc

Examples of org.apache.derby.jdbc.EmbeddedDataSource


    BrokerService brokerService;
    EmbeddedDataSource dataSource;

    @Before
    public void setUpStore() throws Exception {
        dataSource = new EmbeddedDataSource();
        dataSource.setDatabaseName("derbyDb");
        dataSource.setCreateDatabase("create");
        jdbc = new JDBCPersistenceAdapter();
        jdbc.setDataSource(dataSource);
        brokerService = new BrokerService();
View Full Code Here


    protected BrokerService createBroker() throws Exception {
        BrokerService broker = new BrokerService();
        broker.setUseJmx(true);
        JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
        EmbeddedDataSource dataSource = new EmbeddedDataSource();
        dataSource.setDatabaseName("derbyDb");
        dataSource.setCreateDatabase("create");
        jdbc.setDataSource(dataSource);
       
        jdbc.deleteAllMessages();
        broker.setPersistenceAdapter(jdbc);
        broker.addConnector("tcp://0.0.0.0:61616");
View Full Code Here

   
    protected BrokerService createRestartedBroker() throws Exception {
        BrokerService broker = new BrokerService();
        broker.setUseJmx(true);
        JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
        EmbeddedDataSource dataSource = new EmbeddedDataSource();
        dataSource.setDatabaseName("derbyDb");
        dataSource.setCreateDatabase("create");
        jdbc.setDataSource(dataSource);
        broker.setPersistenceAdapter(jdbc);
        broker.addConnector("tcp://0.0.0.0:61616");
        return broker;
    }
View Full Code Here

    EmbeddedDataSource dataSource;
   
    protected void configureBroker(BrokerService answer) throws Exception {
        super.configureBroker(answer);
        JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
        dataSource = new EmbeddedDataSource();
        dataSource.setDatabaseName("derbyDb");
        dataSource.setCreateDatabase("create");
        jdbc.setDataSource(dataSource);    
        answer.setPersistenceAdapter(jdbc);
    }
View Full Code Here

   
    protected void messageSent() throws Exception {
        verifyExpectedBroker(inflightMessageCount);
        if (++inflightMessageCount == failureCount) {
            LOG.info("STOPPING DB!@!!!!");
            final EmbeddedDataSource ds = ((SyncDataSource)getExistingDataSource()).getDelegate();
            ds.setShutdownDatabase("shutdown");
            LOG.info("DB STOPPED!@!!!!");
           
            Thread dbRestartThread = new Thread("db-re-start-thread") {
                public void run() {
                    delayTillRestartRequired();
                    ds.setShutdownDatabase("false");
                    LOG.info("DB RESTARTED!@!!!!");
                }
            };
            dbRestartThread.start();
        }
View Full Code Here

    @Override
    protected void messageSent() throws Exception {   
        if (++inflightMessageCount == failureCount) {
            LOG.info("STOPPING DB!@!!!!");
            final EmbeddedDataSource ds = sharedDs;
            ds.setShutdownDatabase("shutdown");
            try {
                ds.getConnection();
            } catch (Exception ignored) {
            }
            LOG.info("DB STOPPED!@!!!!");
           
            Thread dbRestartThread = new Thread("db-re-start-thread") {
                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 RESTARTED!@!!!!");
                }
            };
            dbRestartThread.start();
        }
View Full Code Here

*/
public class JDBCPersistenceAdapterTest extends PersistenceAdapterTestSupport {
   
    protected PersistenceAdapter createPersistenceAdapter(boolean delete) throws IOException {
        JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
        EmbeddedDataSource dataSource = new EmbeddedDataSource();
        dataSource.setDatabaseName("derbyDb");
        dataSource.setCreateDatabase("create");
        jdbc.setDataSource(dataSource);
        if( delete ) {
            jdbc.deleteAllMessages();
        }
        return jdbc;
View Full Code Here

        throw exc;
      }
    });

    /* Create database */
    EmbeddedDataSource database = new EmbeddedDataSource();
    database.setCreateDatabase("create");
    database.setDatabaseName("SampleDB");
    /* Do action on DB */
    // Get Connection
    try (Connection dbConnection = database.getConnection()) {
      dbConnection.setAutoCommit(true);
      // Get DB Statement
      // If an SQLException occurs here it will catched by parent catch block...
      try (Statement stmt = dbConnection.createStatement()) {
        stmt.execute("CREATE TABLE DerbyTax(userName varchar(20), returnName varchar(20))");
      }
      System.out.printf("Database Product Name    = %s\n", dbConnection.getMetaData().getDatabaseProductName());
      System.out.printf("Database Product Version = %s\n", dbConnection.getMetaData().getDatabaseProductVersion());
    }
    catch (SQLException e) {
      e.printStackTrace();
    }
    // Shutdown DB
    database.setShutdownDatabase("shutdown");
  }
View Full Code Here

    s.close();
  }

  private static void testDSRequestAuthentication() throws SQLException {

    EmbeddedDataSource ds = new EmbeddedDataSource();

    System.out.println("DataSource - EMPTY");
    dsConnectionRequests(ds);

    System.out.println("DataSource - connectionAttributes=databaseName=wombat");
    ds.setConnectionAttributes("databaseName=wombat");
    dsConnectionRequests(ds);
    ds.setConnectionAttributes(null);

    System.out.println("DataSource - attributesAsPassword=true");
    ds.setAttributesAsPassword(true);
    dsConnectionRequests(ds);
    ds.setAttributesAsPassword(false);

    System.out.println("DataSource - attributesAsPassword=true, connectionAttributes=databaseName=kangaroo");
    ds.setAttributesAsPassword(true);
    ds.setConnectionAttributes("databaseName=kangaroo");
    dsConnectionRequests(ds);
    ds.setAttributesAsPassword(false);
    ds.setConnectionAttributes(null);

    System.out.println("Enable Authentication");
    ds.setDatabaseName("wombat");
    Connection cadmin = ds.getConnection();
    CallableStatement cs = cadmin.prepareCall("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(?, ?)");
    cs.setString(1, "derby.user.fred");
    cs.setString(2, "wilma");
    cs.execute();

    cs.setString(1, "derby.authentication.provider");
    cs.setString(2, "BUILTIN");
    cs.execute();

    cs.setString(1, "derby.connection.requireAuthentication");
    cs.setString(2, "true");
    cs.execute();

    cs.close();

    cadmin.close();

    ds.setShutdownDatabase("shutdown");
    try {
      ds.getConnection();
    } catch (SQLException sqle) {
      System.out.println(sqle.getSQLState() + ":" + sqle.getMessage() );
    }

    ds.setDatabaseName(null);
    ds.setShutdownDatabase(null);

    System.out.println("AUTHENTICATION NOW ENABLED");

    System.out.println("DataSource - attributesAsPassword=true");
    ds.setAttributesAsPassword(true);
    dsConnectionRequests(ds);
    ds.setAttributesAsPassword(false);

    // ensure the DS property password is not treated as a set of attributes.
    System.out.println("DataSource - attributesAsPassword=true, user=fred, password=databaseName=wombat;password=wilma");
    ds.setAttributesAsPassword(true);
    ds.setUser("fred");
    ds.setPassword("databaseName=wombat;password=wilma");
    dsConnectionRequests(ds);
    ds.setAttributesAsPassword(false);
    ds.setUser(null);
    ds.setPassword(null);
    ds = null;

    // now with ConnectionPoolDataSource
    EmbeddedConnectionPoolDataSource cpds = new EmbeddedConnectionPoolDataSource();
    System.out.println("ConnectionPoolDataSource - EMPTY");
View Full Code Here

  }

  public void testJira95ds(Connection conn, String dbName) throws SQLException
  {
    System.out.print("\ntesting jira 95 for DataSource");
    EmbeddedDataSource ds = new EmbeddedDataSource();
    ds.setDatabaseName( dbName);
    Connection conn1 = ds.getConnection();
    conn1.close();
  }
View Full Code Here

TOP

Related Classes of org.apache.derby.jdbc.EmbeddedDataSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.