Examples of JdbcConnectionDescriptor


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

    public 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);
        try
        {
            if(odmg_1.currentTransaction() != null)
            {
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.
                ClassDescriptor cld = broker.getClassDescriptor(PerformanceArticle.class);
                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

            log.debug("Initializing OJB");
        }

        // This line effectively loads OJB.properties & repository.xml
        ConnectionRepository     connRep = MetadataManager.getInstance().connectionRepository();
        JdbcConnectionDescriptor jcd     = connRep.addDescriptor("default", dataSource, username, password);
        SequenceDescriptor       seqDesc = new SequenceDescriptor(jcd);

        seqDesc.setSequenceManagerClass(SequenceManagerHighLowImpl.class);
        jcd.setSequenceDescriptor(seqDesc);
    }
View Full Code Here

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);
            jcd.setDatasourceName(jndiName);
        } else {
            // have to get data source ourselves
            if (connectionFactoryClass == null) {
                connectionFactoryClass = ConnectionFactoryDBCPImpl.class.getName ();
            }
            jcd.setDriver(driverClassName);
            HashMap 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);
        }
        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

  /**
   * fail ifF the specified PersistenceBroker does not use P6Spy.
   */
  protected final void checkP6spyEnabled(PBKey pbKey)
  {
    JdbcConnectionDescriptor conDesc
            = MetadataManager.getInstance().connectionRepository().getDescriptor(pbKey);
    if (!P6SpyDriver.class.getName().equals(conDesc.getDriver()))
    {
      fail("this test works only with p6spy.\n" +
           "Please set 'driver=" + P6SpyDriver.class.getName() + "' in file repository_database.xml" +
           " or use ant build property '-DuseP6Spy=true'");
    }
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);

            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
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.