Package org.apache.derby.jdbc

Examples of org.apache.derby.jdbc.EmbeddedDataSource


            running = true;
            System.setProperty("derby.system.home", "build/db");
            File db = new File("build/db");
            db.mkdirs();

            dataSource = new EmbeddedDataSource();
            dataSource.setCreateDatabase("create");
            dataSource.setDatabaseName("testing");

            final Connection conn = dataSource.getConnection();
            conn.close();
View Full Code Here


        System.setProperty("derby.storage.fileSyncTransactionLog", "true");

        // load the Embedded driver to initialize the home
        new org.apache.derby.jdbc.EmbeddedDriver();

        EmbeddedDataSource datasource = new EmbeddedDataSource();
        datasource.setDatabaseName("SystemDatabase");
        datasource.setCreateDatabase("create");
        try {
            Connection c = datasource.getConnection();
            c.close();
        } catch (SQLException e) {
            while (e.getNextException() != null) {
                e.printStackTrace();
                e = e.getNextException();
View Full Code Here

    @Test
    public void testWriteRead() throws Exception {
        NamingManager.setInitialContextFactoryBuilder(new MyInitialcontextFactoryBuilder());
        InitialContext ic = new InitialContext();
        EmbeddedDataSource ds = new EmbeddedDataSource();
        ds.setDatabaseName("target/test");
        ds.setCreateDatabase("create");
        ic.bind("osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/derbyds)", ds);
        PersonServiceImpl personService = new PersonServiceImpl();
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("personTest", System.getProperties());
        EntityManager em = emf.createEntityManager();
        personService.setEntityManager(em);
View Full Code Here

    @Ignore
    @Test
    public void testWriteRead() throws Exception {
        NamingManager.setInitialContextFactoryBuilder(new MyInitialcontextFactoryBuilder());
        InitialContext ic = new InitialContext();
        EmbeddedDataSource ds = new EmbeddedDataSource();
        ds.setDatabaseName("target/test");
        ds.setCreateDatabase("create");
        ic.bind("osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/derbyds)", ds);
        PersonServiceImpl personService = new PersonServiceImpl();
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("personTest", System.getProperties());
        EntityManager em = emf.createEntityManager();
        personService.setEntityManager(em);
View Full Code Here

public class DbExampleTest {

    @Test
    public void test() throws Exception {
        EmbeddedDataSource ds = new EmbeddedDataSource();
        ds.setDatabaseName("./target/test");
        ds.setCreateDatabase("create");
        DbExample example = new DbExample();
        example.setDataSource(ds);
        example.test();
    }
View Full Code Here

    return s;

  }
  public javax.sql.DataSource getDS(String database, String user, String password) {
   
    EmbeddedDataSource ds = new EmbeddedDataSource();
    ds.setDatabaseName(database);
    if (user != null) {
      ds.setUser(user);
      ds.setPassword(password);
    }

    return ds;
  }
View Full Code Here

        System.setProperty("derby.storage.fileSyncTransactionLog", "true");

        // load the Embedded driver to initialize the home
        new org.apache.derby.jdbc.EmbeddedDriver();

        EmbeddedDataSource datasource = new EmbeddedDataSource();
        datasource.setDatabaseName("SystemDatabase");
        datasource.setCreateDatabase("create");
        try {
            Connection c = datasource.getConnection();
            c.close();
        } catch (SQLException e) {
            while (e.getNextException() != null) {
                e.printStackTrace();
                e = e.getNextException();
View Full Code Here

 
 
  private static class DerbyDataSourceFactory implements DataSourceFactory {

    public DataSource createDataSource(Properties props) throws SQLException {
      EmbeddedDataSource ds = new EmbeddedDataSource();
      ds.setDatabaseName("memory:TEST");
      ds.setCreateDatabase("create");
      return ds;
    }
View Full Code Here

    {
        String tmpDir = System.getProperty("java.io.tmpdir")+System.getProperty("file.separator");
        System.setProperty("derby.system.home", tmpDir);
        String dbname = "derby-"+(int)(random.nextDouble()*10000);
       
        EmbeddedDataSource eds = new EmbeddedDataSource();
       
        Context comp = null;
        Context env = null;
        try
        {
            //make the java:comp/env
            InitialContext ic = new InitialContext();
            comp = (Context)ic.lookup("java:comp");
            env = comp.createSubcontext ("env");
           
            //make a DataSource   
            eds.setDatabaseName(dbname);         
            eds.setCreateDatabase("create");
           
                       
            env.createSubcontext("jdbc");
            env.bind("ds", eds);
           
           
            Connection connection = eds.getConnection();
         
           
            //create tables
            String sql = "create table myusers (myuser varchar(32) PRIMARY KEY, mypassword varchar(32))";
            Statement createStatement = connection.createStatement();
            createStatement.executeUpdate (sql);
           
            sql = " create table myuserroles (myuser varchar(32), myrole varchar(32))";
            createStatement.executeUpdate (sql);
            createStatement.close();
           
            //insert test users and roles
            sql = "insert into myusers (myuser, mypassword) values (?, ?)";
           
            PreparedStatement statement = connection.prepareStatement(sql);
            statement.setString (1, "me");
            statement.setString (2, "me");
           
            statement.executeUpdate();
            sql = "insert into myuserroles (myuser, myrole) values ( ? , ? )";
            statement = connection.prepareStatement (sql);
            statement.setString (1, "me");
            statement.setString (2, "roleA");
            statement.executeUpdate();
           
            statement.setString(1, "me");
            statement.setString(2, "roleB");
            statement.executeUpdate();
           
            statement.close();
            connection.close();
           
           
            //create a JAASUserRealm
            JAASUserRealm realm = new JAASUserRealm ("testRealm");
           
            realm.setLoginModuleName ("ds");
           
           
            JAASUserPrincipal userPrincipal = (JAASUserPrincipal)realm.authenticate ("me", "blah",(Request)null);
            assertNull (userPrincipal);
           
            userPrincipal = (JAASUserPrincipal)realm.authenticate ("me", "me", (Request)null);
           
            assertNotNull (userPrincipal);
            assertNotNull (userPrincipal.getName());
            assertTrue (userPrincipal.getName().equals("me"));
           
            assertTrue (userPrincipal.isUserInRole("roleA"));
            assertTrue (userPrincipal.isUserInRole("roleB"));
            assertTrue (!userPrincipal.isUserInRole("roleC"));
           
            realm.pushRole (userPrincipal, "roleC");
            assertTrue (userPrincipal.isUserInRole("roleC"));
            assertTrue (!userPrincipal.isUserInRole("roleA"));
            assertTrue (!userPrincipal.isUserInRole("roleB"));
           
            realm.pushRole (userPrincipal, "roleD");
            assertTrue (userPrincipal.isUserInRole("roleD"));
            assertTrue (!userPrincipal.isUserInRole("roleC"));
            assertTrue (!userPrincipal.isUserInRole("roleA"));
            assertTrue (!userPrincipal.isUserInRole("roleB"));
           
            realm.popRole(userPrincipal);
            assertTrue (userPrincipal.isUserInRole("roleC"));
            assertTrue (!userPrincipal.isUserInRole("roleA"));
            assertTrue (!userPrincipal.isUserInRole("roleB"));
           
            realm.popRole(userPrincipal);
            assertTrue (!userPrincipal.isUserInRole("roleC"));
            assertTrue (userPrincipal.isUserInRole("roleA"));
           
            realm.disassociate(userPrincipal);
        }
        finally
        {
            comp.destroySubcontext("env");
            try
            {
                Connection c = eds.getConnection();
                Statement s = c.createStatement();
                s.executeUpdate("drop table myusers");
                s.executeUpdate("drop table myuserroles");
                s.close();
                c.close();
View Full Code Here

    private static final Log LOG = LogFactory.getLog(JDBCMessagePriorityTest.class);
   
    @Override
    protected PersistenceAdapter createPersistenceAdapter(boolean delete) throws Exception {
        JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
        EmbeddedDataSource dataSource = new EmbeddedDataSource();
        dataSource.setDatabaseName("derbyDb");
        dataSource.setCreateDatabase("create");
        dataSource.setShutdownDatabase("false");
        jdbc.setDataSource(dataSource);
        jdbc.deleteAllMessages();
        jdbc.setCleanupPeriod(2000);
        return jdbc;
    }
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.