Package org.apache.ojb.broker.metadata

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


     * @see org.springframework.orm.ojb.support.PersistenceBrokerDaoSupport
     * @throws Exception
     */
    public void init() throws Exception
    {
        MetadataManager metaManager = MetadataManager.getInstance();
        RepositoryPersistor persistor = new RepositoryPersistor();
        URL descriptorUrl = getClass().getClassLoader().getResource(repositoryPath);

        logger.info("Merging OJB respository "+descriptorUrl+" for DAO class "+getClass().getName());
        DescriptorRepository repo = persistor.readDescriptorRepository(descriptorUrl.openStream());
        metaManager.mergeDescriptorRepository(repo);
    }
View Full Code Here


     * @see org.springframework.orm.ojb.support.PersistenceBrokerDaoSupport
     * @throws Exception
     */
    public void init() throws Exception
    {
        MetadataManager metaManager = MetadataManager.getInstance();
        RepositoryPersistor persistor = new RepositoryPersistor();
        URL descriptorUrl = getClass().getClassLoader().getResource(repositoryPath);

        logger.info("Merging OJB respository "+descriptorUrl+" for DAO class "+getClass().getName());
        DescriptorRepository repo = persistor.readDescriptorRepository(descriptorUrl.openStream());
        metaManager.mergeDescriptorRepository(repo);
    }
View Full Code Here

                }
                log("Using properties file "+_ojbPropertiesFile.getAbsolutePath(), Project.MSG_INFO);
                System.setProperty("OJB.properties", _ojbPropertiesFile.getAbsolutePath());
            }

            MetadataManager     metadataManager = MetadataManager.getInstance();
            RepositoryPersistor persistor       = new RepositoryPersistor();

            if (_repositoryFile != null)
            {
                if (!_repositoryFile.exists())
                {
                    throw new BuildException("Could not load the specified repository file "+_repositoryFile);
                }
                log("Loading repository file "+_repositoryFile.getAbsolutePath(), Project.MSG_INFO);

                // this will load the info from the specified repository file
                // and merge it with the existing info (if it has been loaded)
                metadataManager.mergeConnectionRepository(persistor.readConnectionRepository(_repositoryFile.getAbsolutePath()));
                metadataManager.mergeDescriptorRepository(persistor.readDescriptorRepository(_repositoryFile.getAbsolutePath()));
            }
            else if (metadataManager.connectionRepository().getAllDescriptor().isEmpty() &&
                     metadataManager.getGlobalRepository().getDescriptorTable().isEmpty())
            {
                // Seems nothing was loaded, probably because we're not starting in the directory
                // that the properties file is in, and the repository file path is relative
                // So lets try to resolve this path and load the repository info manually
                Properties props = new Properties();

                props.load(new FileInputStream(_ojbPropertiesFile));
   
                String repositoryPath = props.getProperty("repositoryFile", "repository.xml");
                File   repositoryFile = new File(repositoryPath);
   
                if (!repositoryFile.exists())
                {
                    repositoryFile = new File(_ojbPropertiesFile.getParentFile(), repositoryPath);
                }
                metadataManager.mergeConnectionRepository(persistor.readConnectionRepository(repositoryFile.getAbsolutePath()));
                metadataManager.mergeDescriptorRepository(persistor.readDescriptorRepository(repositoryFile.getAbsolutePath()));
            }
            // 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

        // from the classpath used to load this task's class
        Thread.currentThread().setContextClassLoader(newClassLoader);
       
        try
        {
            MetadataManager      manager  = initOJB();
            Database             dbModel  = readModel();
            DescriptorRepository objModel = manager.getGlobalRepository();

            if (dbModel == null)
            {
                throw new BuildException("No database model specified");
            }
View Full Code Here

     * @param collClass The collection type
     * @param query     The defining query
     */
    public CollectionProxyDefaultImpl(PBKey brokerKey, Class collClass, Query query)
    {
        MetadataManager mm = MetadataManager.getInstance();
        _perThreadDescriptorsEnabled = mm.isEnablePerThreadChanges();
        if (_perThreadDescriptorsEnabled)
        {
            // mkalen:  To minimize memory footprint we remember only the OJB profile key
            //          (instead of all active class-mappings).
            final Object key = mm.getCurrentProfileKey();
            if (key == null)
            {
                // mkalen:  Unsupported: using proxies with per-thread metadata changes without profile keys.
                throw new MetadataException("Trying to create a Collection proxy with per-thread metadata changes enabled, but no profile key.");
            }
View Full Code Here

    protected void loadProfileIfNeeded()
    {
        final Object key = getProfileKey();
        if (key != null)
        {
            final MetadataManager mm = MetadataManager.getInstance();
            if (!key.equals(mm.getCurrentProfileKey()))
            {
                mm.loadProfile(key);
            }
        }
    }
View Full Code Here

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

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

    }

    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

        }
    }

    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

Related Classes of org.apache.ojb.broker.metadata.MetadataManager

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.