Examples of jdbcDataSource


Examples of org.h2.jdbcx.JdbcDataSource

            xaConn2.close();
        }
    }

    private XADataSource createXADatasource(boolean useOneDatabase, String url) {
        JdbcDataSource ds = new JdbcDataSource();
        ds.setPassword(getPassword(""));
        ds.setUser("sa");
        if (useOneDatabase) {
            ds.setURL(getURL("xa", true));
        } else {
            ds.setURL(url);
        }
        return ds;
    }
View Full Code Here

Examples of org.h2.jdbcx.JdbcDataSource

        ref.add(new StringRefAddr("url", "jdbc:h2:mem:"));
        ref.add(new StringRefAddr("user", "u"));
        ref.add(new StringRefAddr("password", "p"));
        ref.add(new StringRefAddr("loginTimeout", "1"));
        ref.add(new StringRefAddr("description", "test"));
        JdbcDataSource ds = (JdbcDataSource) factory.getObjectInstance(ref, null, null, null);
        assertEquals(1, ds.getLoginTimeout());
        assertEquals("test", ds.getDescription());
        assertEquals("jdbc:h2:mem:", ds.getURL());
        assertEquals("u", ds.getUser());
        assertEquals("p", ds.getPassword());
        Reference ref2 = ds.getReference();
        assertEquals(ref.size(), ref2.size());
        assertEquals(ref.get("url").getContent().toString(), ref2.get("url").getContent().toString());
        assertEquals(ref.get("user").getContent().toString(), ref2.get("user").getContent().toString());
        assertEquals(ref.get("password").getContent().toString(), ref2.get("password").getContent().toString());
        assertEquals(ref.get("loginTimeout").getContent().toString(), ref2.get("loginTimeout").getContent().toString());
        assertEquals(ref.get("description").getContent().toString(), ref2.get("description").getContent().toString());
        ds.setPasswordChars("abc".toCharArray());
        assertEquals("abc", ds.getPassword());
    }
View Full Code Here

Examples of org.h2.jdbcx.JdbcDataSource

        testXAConnection(true);
    }

    private void testXAConnection(boolean userInDataSource) throws Exception {
        deleteDb("dataSource");
        JdbcDataSource ds = new JdbcDataSource();
        String url = getURL("dataSource", true);
        String user = getUser();
        ds.setURL(url);
        if (userInDataSource) {
            ds.setUser(user);
            ds.setPassword(getPassword());
        }
        if (userInDataSource) {
            assertEquals("ds" + ds.getTraceId() + ": url=" + url + " user=" + user, ds.toString());
        } else {
            assertEquals("ds" + ds.getTraceId() + ": url=" + url + " user=", ds.toString());
        }
        XAConnection xaConn;
        if (userInDataSource) {
            xaConn = ds.getXAConnection();
        } else {
            xaConn = ds.getXAConnection(user, getPassword());
        }

        int traceId = ((JdbcXAConnection) xaConn).getTraceId();
        assertTrue(xaConn.toString().startsWith("xads" + traceId + ": conn"));
View Full Code Here

Examples of org.h2.jdbcx.JdbcDataSource

        xaConn.close();
    }

    private void testDataSource() throws SQLException {
        deleteDb("dataSource");
        JdbcDataSource ds = new JdbcDataSource();
        PrintWriter p = new PrintWriter(new StringWriter());
        ds.setLogWriter(p);
        assertTrue(p == ds.getLogWriter());
        ds.setURL(getURL("dataSource", true));
        ds.setUser(getUser());
        ds.setPassword(getPassword());
        Connection conn;
        conn = ds.getConnection();
        Statement stat;
        stat = conn.createStatement();
        stat.execute("SELECT * FROM DUAL");
        conn.close();
        conn = ds.getConnection(getUser(), getPassword());
        stat = conn.createStatement();
        stat.execute("SELECT * FROM DUAL");
    }
View Full Code Here

Examples of org.h2.jdbcx.JdbcDataSource

        testTwoPhase("xaSimple2b", true, false);
    }

    private void testTwoPhase(String db, boolean shutdown, boolean commit) throws Exception {
        deleteDb(db);
        JdbcDataSource ds = new JdbcDataSource();
        ds.setPassword(getPassword());
        ds.setUser("sa");
        // ds.setURL(getURL("xaSimple", true) + ";trace_level_system_out=3");
        ds.setURL(getURL(db, true));

        XAConnection xa;
        xa = ds.getXAConnection();
        Connection conn;

        conn = xa.getConnection();
        Statement stat = conn.createStatement();
        stat.execute("create table test(id int primary key, name varchar(255))");
        Xid xid = SimpleXid.createRandom();
        xa.getXAResource().start(xid, XAResource.TMNOFLAGS);
        conn.setAutoCommit(false);
        stat.execute("insert into test values(1, 'Hello')");
        xa.getXAResource().end(xid, XAResource.TMSUCCESS);
        xa.getXAResource().prepare(xid);
        if (shutdown) {
            shutdown(ds);
        }

        xa = ds.getXAConnection();
        Xid[] list = xa.getXAResource().recover(XAResource.TMSTARTRSCAN);
        assertEquals(1, list.length);
        assertTrue(xid.equals(list[0]));
        if (commit) {
            xa.getXAResource().commit(list[0], false);
        } else {
            xa.getXAResource().rollback(list[0]);
        }
        if (shutdown) {
            shutdown(ds);
        }

        xa = ds.getXAConnection();
        list = xa.getXAResource().recover(XAResource.TMSTARTRSCAN);
        assertEquals(0, list.length);
        conn = xa.getConnection();
        ResultSet rs;
        rs = conn.createStatement().executeQuery("select * from test");
View Full Code Here

Examples of org.h2.jdbcx.JdbcDataSource

        org.h2.Driver.load();

        // InitialContext context = new InitialContext();
        // context.rebind(USER_TRANSACTION_JNDI_NAME, j.getUserTransaction());

        JdbcDataSource ds1 = new JdbcDataSource();
        ds1.setPassword(getPassword());
        ds1.setUser("sa");
        ds1.setURL(getURL("xaSimple1", true));

        JdbcDataSource ds2 = new JdbcDataSource();
        ds2.setPassword(getPassword());
        ds2.setUser("sa");
        ds2.setURL(getURL("xaSimple2", true));

        // UserTransaction ut = (UserTransaction)
        // context.lookup("UserTransaction");
        // ut.begin();

        XAConnection xa1 = ds1.getXAConnection();
        Connection c1 = xa1.getConnection();
        c1.setAutoCommit(false);
        XAConnection xa2 = ds2.getXAConnection();
        Connection c2 = xa2.getConnection();
        c2.setAutoCommit(false);

        c1.createStatement().executeUpdate("create table test(id int, test varchar(255))");
        c2.createStatement().executeUpdate("create table test(id int, test varchar(255))");
View Full Code Here

Examples of org.h2.jdbcx.JdbcDataSource

        assertEquals(0, man.getActiveConnections());
        man.dispose();
    }

    private JdbcConnectionPool getConnectionPool(int poolSize) {
        JdbcDataSource ds = new JdbcDataSource();
        ds.setURL(getURL("connectionPool", true));
        ds.setUser(getUser());
        ds.setPassword(getPassword());
        JdbcConnectionPool pool = JdbcConnectionPool.create(ds);
        pool.setMaxConnections(poolSize);
        return pool;
    }
View Full Code Here

Examples of org.h2.jdbcx.JdbcDataSource

    private Connection connection;

    @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);
View Full Code Here

Examples of org.h2.jdbcx.JdbcDataSource


    jndiResources = new ArrayList<Resource>();

    // create the real data sources and bind to jndi
    JdbcDataSource realDs1 = new JdbcDataSource();
    realDs1.setUser("sa");
    realDs1.setURL("jdbc:h2:mem:multids1");
    jndiResources.add(new Resource("jdbc/realDs1", realDs1));

    JdbcDataSource realDs2 = new JdbcDataSource();
    realDs2.setUser("sa");
    realDs2.setURL("jdbc:h2:mem:multids2");
    jndiResources.add(new Resource("jdbc/realDs2", realDs2));

    JDBCDataSource realDs3 = new JDBCDataSource();
    realDs3.setUser("sa");
    realDs3.setPassword("");
View Full Code Here

Examples of org.h2.jdbcx.JdbcDataSource

    }

    private static final BasicResponseHandler BASIC_RESPONSE_HANDLER = new BasicResponseHandler();

    private static JdbcDataSource createDataSource(final String url) {
        JdbcDataSource ds = new JdbcDataSource();
        ds.setURL(url);
        return ds;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.