Package org.apache.ojb.broker.accesslayer

Examples of org.apache.ojb.broker.accesslayer.ConnectionFactory


                // Use OJB API to obtain JDBC Connection. All settings are read from
                // the repository.xml file.
                JdbcConnectionDescriptor jcd =
                        MetadataManager.getInstance().connectionRepository().getDescriptor(
                                TestHelper.DEF_KEY);
                ConnectionFactory cf =
                        ConnectionFactoryFactory.getInstance().createConnectionFactory();
                conn = cf.lookupConnection(jcd);
                System.out.println("] Waited for connection " + (System.currentTimeMillis() - startToWait) + "msecs");
                break;
            }
            catch (Throwable t)
            {
View Full Code Here


        try
        {
            fac = ConnectionFactoryFactory.getInstance();
            oldFac = fac.getClassToServe();
            fac.setClassToServe(factory);
            ConnectionFactory conFac = (ConnectionFactory) fac.createNewInstance();

            MetadataManager mm = MetadataManager.getInstance();
            JdbcConnectionDescriptor jcd = (JdbcConnectionDescriptor) SerializationUtils.clone(
                    broker.serviceConnectionManager().getConnectionDescriptor());
            jcd.setJcdAlias(factory.getName() + "_test_checkFactory_a");
            jcd.setUseAutoCommit(2);
            // use this attribute to allow OJB changing initial state of connections
            jcd.addAttribute("initializationCheck", "true");

            mm.connectionRepository().addDescriptor(jcd);
            Connection con = conFac.lookupConnection(jcd);
            Connection con2 = conFac.lookupConnection(jcd);
            Connection con3 = conFac.lookupConnection(jcd);
            assertFalse("Expect autocommit state false", con.getAutoCommit());
            con.close();
            con2.close();
            con3.close();


            conFac = (ConnectionFactory) fac.createNewInstance();

            jcd = (JdbcConnectionDescriptor) SerializationUtils.clone(
                    broker.serviceConnectionManager().getConnectionDescriptor());
            jcd.setJcdAlias(factory.getName() + "_test_checkFactory_b");
            jcd.setUseAutoCommit(1);

            mm.connectionRepository().addDescriptor(jcd);
            con = conFac.lookupConnection(jcd);
            assertTrue("Expect autocommit state true", con.getAutoCommit());
        }
        finally
        {
            if (oldFac != null) fac.setClassToServe(oldFac);
View Full Code Here

        try
        {
            fac = ConnectionFactoryFactory.getInstance();
            oldFac = fac.getClassToServe();
            fac.setClassToServe(factory);
            ConnectionFactory conFac = (ConnectionFactory) fac.createNewInstance();

            MetadataManager mm = MetadataManager.getInstance();
            JdbcConnectionDescriptor jcd = (JdbcConnectionDescriptor) SerializationUtils.clone(
                    broker.serviceConnectionManager().getConnectionDescriptor());
            jcd.setJcdAlias(factory.getName() + "_test_checkFactoryPoolExhausted_1");
            jcd.setUseAutoCommit(1);
            jcd.getConnectionPoolDescriptor().setMaxActive(2);
            jcd.getConnectionPoolDescriptor().setConnectionFactory(factory);
            mm.connectionRepository().addDescriptor(jcd);

            Connection con = null;
            Connection con2 = null;
            Connection con3 = null;
            try
            {
                con = conFac.lookupConnection(jcd);
                con2 = conFac.lookupConnection(jcd);
                try
                {
                    con3 = conFac.lookupConnection(jcd);
                    fail("We expect an exception indicating that the pool is exhausted");
                }
                catch (LookupException e)
                {
                    // we expected that
View Full Code Here

        // Use OJB API to obtain JDBC Connection. All settings are read from
        // the repository.xml file.
        ClassDescriptor cld = broker.getClassDescriptor(PerformanceArticle.class);
        JdbcConnectionDescriptor jcd = MetadataManager.getInstance().connectionRepository()
                .getDescriptor(TestHelper.DEF_KEY);
        ConnectionFactory cf = ConnectionFactoryFactory.getInstance().createConnectionFactory();
        Connection conn = cf.lookupConnection(jcd);
        return conn;
    }
View Full Code Here

        // Use OJB API to obtain JDBC Connection. All settings are read from
        // the repository.xml file.
        ClassDescriptor cld = broker.getClassDescriptor(PerformanceArticle.class);
        JdbcConnectionDescriptor jcd = MetadataManager.getInstance().connectionRepository()
                .getDescriptor(TestHelper.DEF_KEY);
        ConnectionFactory cf = ConnectionFactoryFactory.getInstance().createConnectionFactory();
    cf.releaseConnection(jcd, conn);
    }
View Full Code Here

                // the repository.xml file.
                ClassDescriptor cld = broker.getClassDescriptor(PerformanceArticle.class);
                JdbcConnectionDescriptor jcd =
                        MetadataManager.getInstance().connectionRepository().getDescriptor(
                                TestHelper.DEF_KEY);
                ConnectionFactory cf =
                        ConnectionFactoryFactory.getInstance().createConnectionFactory();
                conn = cf.lookupConnection(jcd);
                System.out.println("] Waited for connection " + (System.currentTimeMillis() - startToWait) + "msecs");
                break;
            }
            catch (Throwable t)
            {
View Full Code Here

        try
        {
            fac = ConnectionFactoryFactory.getInstance();
            oldFac = fac.getClassToServe();
            fac.setClassToServe(factory);
            ConnectionFactory conFac = (ConnectionFactory) fac.createNewInstance();

            MetadataManager mm = MetadataManager.getInstance();
            JdbcConnectionDescriptor jcd = (JdbcConnectionDescriptor) SerializationUtils.clone(
                    broker.serviceConnectionManager().getConnectionDescriptor());
            jcd.setJcdAlias(factory.getName() + "_test_checkFactory_a");
            jcd.setUseAutoCommit(2);

            mm.connectionRepository().addDescriptor(jcd);
            Connection con = conFac.lookupConnection(jcd);
            Connection con2 = conFac.lookupConnection(jcd);
            Connection con3 = conFac.lookupConnection(jcd);
            assertFalse("Expect autocommit state false", con.getAutoCommit());
            con.close();
            con2.close();
            con3.close();


            conFac = (ConnectionFactory) fac.createNewInstance();

            jcd = (JdbcConnectionDescriptor) SerializationUtils.clone(
                    broker.serviceConnectionManager().getConnectionDescriptor());
            jcd.setJcdAlias(factory.getName() + "_test_checkFactory_b");
            jcd.setUseAutoCommit(1);

            mm.connectionRepository().addDescriptor(jcd);
            con = conFac.lookupConnection(jcd);
            assertTrue("Expect autocommit state true", con.getAutoCommit());
        }
        finally
        {
            if (oldFac != null) fac.setClassToServe(oldFac);
View Full Code Here

        try
        {
            fac = ConnectionFactoryFactory.getInstance();
            oldFac = fac.getClassToServe();
            fac.setClassToServe(factory);
            ConnectionFactory conFac = (ConnectionFactory) fac.createNewInstance();

            MetadataManager mm = MetadataManager.getInstance();
            JdbcConnectionDescriptor jcd = (JdbcConnectionDescriptor) SerializationUtils.clone(
                    broker.serviceConnectionManager().getConnectionDescriptor());
            jcd.setJcdAlias(factory.getName() + "_test_checkFactoryPoolExhausted_1");
            jcd.setUseAutoCommit(1);
            jcd.getConnectionPoolDescriptor().setMaxActive(2);
            jcd.getConnectionPoolDescriptor().setConnectionFactory(factory);
            mm.connectionRepository().addDescriptor(jcd);

            Connection con = null;
            Connection con2 = null;
            Connection con3 = null;
            try
            {
                con = conFac.lookupConnection(jcd);
                con2 = conFac.lookupConnection(jcd);
                try
                {
                    con3 = conFac.lookupConnection(jcd);
                    fail("We expect an exception indicating that the pool is exhausted");
                }
                catch (LookupException e)
                {
                    // we expected that
View Full Code Here

     * @param jcd JDBC connection descriptor
     * @return
     */
    private static ConnectionFactory setupConnectionFactory(JdbcConnectionDescriptor jcd)
    {
        ConnectionFactory cf = null;
        ConnectionPoolDescriptor cpd = jcd.getConnectionPoolDescriptor();       
        if (cpd != null && cpd.getConnectionFactory() != null)
        {
            cf = (ConnectionFactory)connectionFactories.get(cpd.getConnectionFactory());
            if ( cf == null )
View Full Code Here

TOP

Related Classes of org.apache.ojb.broker.accesslayer.ConnectionFactory

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.