Examples of JdbcConnectionDescriptor


Examples of org.apache.ojb.broker.metadata.JdbcConnectionDescriptor

    public void afterPropertiesSet () throws Exception
    {
        // Try to find JCD
        ConnectionRepository cr = MetadataManager.getInstance().connectionRepository();
        JdbcConnectionDescriptor jcd = cr.getDescriptor(new PBKey(jcdAlias));
        if (jcd == null)
        {
            jcd = new JdbcConnectionDescriptor();
            jcd.setJcdAlias(jcdAlias);
            cr.addDescriptor(jcd);
        }
        if (platform != null && platform.length() == 0)
        {
            platform = null;
        }
        DataSource ds = null;
        JdbcMetadataUtils jdbcMetadataUtils = new JdbcMetadataUtils ();
        if (jndiName != null)
        {
            // using "preconfigured" data source
            if (connectionFactoryClass == null)
            {
                connectionFactoryClass = ConnectionFactoryManagedImpl.class.getName ();
            }
            Context initialContext = new InitialContext();
            ds = (DataSource) initialContext.lookup(jndiName);
            externalDs = ds;
      jcd.setDatasourceName(jndiName);
        }
        else
        {
            // have to get data source ourselves
            if (connectionFactoryClass == null)
            {
                connectionFactoryClass = ConnectionFactoryDBCPImpl.class.getName ();
            }
            jcd.setDriver(driverClassName);
            Map conData = jdbcMetadataUtils.parseConnectionUrl(url);
            jcd.setDbms(platform);
            jcd.setProtocol((String)conData.get(JdbcMetadataUtils.PROPERTY_PROTOCOL));
            jcd.setSubProtocol((String)conData.get(JdbcMetadataUtils.PROPERTY_SUBPROTOCOL));
            jcd.setDbAlias((String)conData.get(JdbcMetadataUtils.PROPERTY_DBALIAS));
            jcd.setUserName(username);
            jcd.setPassWord(password);
            // Wrapping the connection factory in a DataSource introduces a bit
            // of redundancy (url is parsed again and platform determined again).
            // But although JdbcMetadataUtils exposes the methods used in
            // fillJCDFromDataSource as public (and these do not require a DataSource)
            // the method itself does more than is made available by the exposed methods.
            // ds = new MinimalDataSource (jcd);
            ds = this;            
        }
        ConnectionPoolDescriptor cpd = jcd.getConnectionPoolDescriptor();
        if (cpd == null)
        {
            cpd = new ConnectionPoolDescriptor();
            jcd.setConnectionPoolDescriptor(cpd);
        }
        Class conFacCls = ClassHelper.getClass(connectionFactoryClass);
        cpd.setConnectionFactory(conFacCls);

        jdbcMetadataUtils.fillJCDFromDataSource(jcd, ds, null, null);
       
        if (platform == null && JdbcMetadataUtils.PLATFORM_ORACLE.equals(jcd.getDbms())) {
            // Postprocess to find Oracle version.
            updateOraclePlatform (jcd, ds);
        }
        // if platform has explicitly been set, the value takes precedence
        if (platform != null) {
            if (!platform.equals(jcd.getDbms())) {
                log.warn ("Automatically derived RDBMS platform \"" + jcd.getDbms()
                          + "\" differs from explicitly set platform \"" + platform + "\"");
            }
            jcd.setDbms(platform);
        } else {
            platform = jcd.getDbms();
        }
       
        // special attributes
        jcd.addAttribute("org.apache.jetspeed.engineScoped",
                         Boolean.toString(jetspeedEngineScoped));
    }
View Full Code Here

Examples of org.apache.ojb.broker.metadata.JdbcConnectionDescriptor

   
    public void init()
    throws Exception
    {
        ConnectionRepository cr = MetadataManager.getInstance().connectionRepository();
        JdbcConnectionDescriptor jcd = cr.getDescriptor(new PBKey(jcdAlias));
        if (jcd == null)
        {
            jcd = new JdbcConnectionDescriptor();
            jcd.setJcdAlias(jcdAlias);
            cr.addDescriptor(jcd);
        }
       
        JdbcMetadataUtils jdbcMetadataUtils = new JdbcMetadataUtils ();
        jdbcMetadataUtils.fillJCDFromDataSource(jcd, ds, null, null);
        String platform = jcd.getDbms();
        if (JdbcMetadataUtils.PLATFORM_ORACLE.equals(platform))
        {
            // Postprocess to find Oracle version.
                platform = updateOraclePlatform (jcd, ds, platform);
        }
        // if platform has explicitly been set, the value takes precedence
        if (platform != null)
        {
            if (!platform.equals(jcd.getDbms()))
            {
                log.warn ("Automatically derived RDBMS platform \"" + jcd.getDbms()
                          + "\" differs from explicitly set platform \"" + platform + "\"");
            }
            jcd.setDbms(platform);
        }
        else
        {
            platform = jcd.getDbms();
        }
        System.out.println("##### platform = " + platform);
    }
View Full Code Here

Examples of org.apache.ojb.broker.metadata.JdbcConnectionDescriptor

     * database).
     *
     */
    protected String getDBCreationUrl()
    {
        JdbcConnectionDescriptor jcd = getConnection();

        // currently I only know about specifics for mysql
        if (TORQUE_PLATFORM_MYSQL.equals(getTargetTorquePlatform()))
        {
            // we have to remove the db name as the jdbc driver would try to connect to
            // a non-existing db
            // the db-alias has this form: [host&port]/[dbname]?[options]
            String dbAliasPrefix = jcd.getDbAlias();
            String dbAliasSuffix = "";
            int    questionPos   = dbAliasPrefix.indexOf('?');

            if (questionPos > 0)
            {
                dbAliasSuffix = dbAliasPrefix.substring(questionPos);
                dbAliasPrefix = dbAliasPrefix.substring(0, questionPos);
            }

            int slashPos = dbAliasPrefix.lastIndexOf('/');

            if (slashPos > 0)
            {
                // it is important that the slash at the end is present
                dbAliasPrefix = dbAliasPrefix.substring(0, slashPos + 1);
            }
            return jcd.getProtocol()+":"+jcd.getSubProtocol()+":"+dbAliasPrefix+dbAliasSuffix;
        }
        else if (TORQUE_PLATFORM_POSTGRESQL.equals(getTargetTorquePlatform()))
        {
            // we have to replace the db name with 'template1'
            // the db-alias has this form: [host&port]/[dbname]?[options]
            String dbAliasPrefix = jcd.getDbAlias();
            String dbAliasSuffix = "";
            int    questionPos   = dbAliasPrefix.indexOf('?');

            if (questionPos > 0)
            {
                dbAliasSuffix = dbAliasPrefix.substring(questionPos);
                dbAliasPrefix = dbAliasPrefix.substring(0, questionPos);
            }

            int slashPos = dbAliasPrefix.lastIndexOf('/');

            if (slashPos > 0)
            {
                // it is important that the slash at the end is present
                dbAliasPrefix = dbAliasPrefix.substring(0, slashPos + 1);
            }
            else
            {
                dbAliasPrefix += "/";
            }
            dbAliasPrefix += "template1";
            if (dbAliasSuffix.length() > 0)
            {
                dbAliasPrefix += "/";
            }
            return jcd.getProtocol()+":"+jcd.getSubProtocol()+":"+dbAliasPrefix+dbAliasSuffix;
           
        }
        else
        {
            return jcd.getProtocol()+":"+jcd.getSubProtocol()+":"+jcd.getDbAlias();
        }
    }
View Full Code Here

Examples of org.apache.ojb.broker.metadata.JdbcConnectionDescriptor

     * to allow for modifying an existing database.
     *
     */
    protected String getDBManipulationUrl()
    {
        JdbcConnectionDescriptor jcd = getConnection();

        return jcd.getProtocol()+":"+jcd.getSubProtocol()+":"+jcd.getDbAlias();
    }
View Full Code Here

Examples of org.apache.ojb.broker.metadata.JdbcConnectionDescriptor

        {
            try
            {
                // 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);
View Full Code Here

Examples of org.apache.ojb.broker.metadata.JdbcConnectionDescriptor

            // we might have to determine the default pb key ourselves
            if (metadataManager.getDefaultPBKey() == null)
            {
                for (Iterator it = metadataManager.connectionRepository().getAllDescriptor().iterator(); it.hasNext();)
                {
                    JdbcConnectionDescriptor descriptor = (JdbcConnectionDescriptor)it.next();

                    if (descriptor.isDefaultConnection())
                    {
                        metadataManager.setDefaultPBKey(new PBKey(descriptor.getJcdAlias(), descriptor.getUserName(), descriptor.getPassWord()));
                        break;
                    }
                }
            }
            return metadataManager;
View Full Code Here

Examples of org.apache.ojb.broker.metadata.JdbcConnectionDescriptor

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

Examples of org.apache.ojb.broker.metadata.JdbcConnectionDescriptor

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

Examples of org.apache.ojb.broker.metadata.JdbcConnectionDescriptor

    protected void setUp() throws Exception
    {
        super.setUp();
        MetadataManager mm = MetadataManager.getInstance();
        JdbcConnectionDescriptor jcd = mm.connectionRepository().getDescriptor(TestHelper.FAR_AWAY_KEY);
        if(jcd == null)
        {
            ConnectionRepository cr = mm.readConnectionRepository(TestHelper.FAR_AWAY_CONNECTION_REPOSITORY);
            mm.connectionRepository().addDescriptor(cr.getDescriptor(TestHelper.FAR_AWAY_KEY));
        }
View Full Code Here

Examples of org.apache.ojb.broker.metadata.JdbcConnectionDescriptor

    }

    protected void tearDown() throws Exception
    {
        MetadataManager mm = MetadataManager.getInstance();
        JdbcConnectionDescriptor jcd = mm.connectionRepository().getDescriptor(TestHelper.FAR_AWAY_KEY);
        mm.connectionRepository().removeDescriptor(jcd);
        super.tearDown();
    }
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.