Package org.apache.ojb.broker.metadata

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


    {
        PersistenceBrokerFactory.releaseAllInstances();
        String old = null;
        try
        {
            MetadataManager mm = MetadataManager.getInstance();
            JdbcConnectionDescriptor jcd = mm.connectionRepository().getDescriptor(mm.getDefaultPBKey());
            if(jcd.getObjectCacheDescriptor().getObjectCache().equals(ObjectCacheEmptyImpl.class))
            {
                ojbSkipTestMessage("Doesn't work with " + ObjectCacheEmptyImpl.class + " as default cache.");
                return;
            }
View Full Code Here


    public void testAutoNaming() throws Exception
    {
        String jcdAlias = "testAutoNaming";
        PBKey tempKey = new PBKey(jcdAlias, TestHelper.DEF_KEY.getUser(), TestHelper.DEF_KEY.getPassword());
        MetadataManager mm = MetadataManager.getInstance();
        PersistenceBroker broker = null;
        try
        {
            JdbcConnectionDescriptor jcd = mm.connectionRepository().getDescriptor(TestHelper.DEF_KEY);
            jcd = (JdbcConnectionDescriptor) SerializationUtils.clone(jcd);
            // modify jcd copy
            jcd.setJcdAlias(jcdAlias);
            SequenceDescriptor sd = jcd.getSequenceDescriptor();
            assertNotNull("Can not find sequence-descriptor - check test", sd);
            // don't use autoNaming
            sd.addAttribute("autoNaming", "false");
            // add new connection descriptor to global base
            mm.connectionRepository().addDescriptor(jcd);

            // allow per thread changes of persistent object data
            mm.setEnablePerThreadChanges(true);
            DescriptorRepository dr = mm.copyOfGlobalRepository();
            ClassDescriptor cld = dr.getDescriptorFor(SMAutoNaming.class);
            FieldDescriptor field = cld.getAutoIncrementFields()[0];

            // set sequence name for persistent object to null
            field.setSequenceName(null);
            mm.setDescriptor(dr);

            broker = PersistenceBrokerFactory.createPersistenceBroker(tempKey);
            try
            {
                /*
                persistent object descriptor doesn't has a sequence name
                and autoNaming is false --> expect an exception
                */
                SMAutoNaming obj = new SMAutoNaming("testAutoNaming_1");
                sd = broker.serviceConnectionManager().getConnectionDescriptor().getSequenceDescriptor();
                assertTrue("false".equals(sd.getAttribute("autoNaming")));

                broker.beginTransaction();
                broker.store(obj);
                broker.commitTransaction();
                fail("If sequence manager implementation supports 'autoNaming' feature,"
                        +" this test should cause an exception (else ignore this failure).");
            }
            catch (PersistenceBrokerException e)
            {
                assertTrue(true);
                broker.abortTransaction();
            }

            try
            {
                /* attribute 'auto-naming' is still false,
                but now we set a sequence name for autoincrement field
                --> should pass
                */
                field.setSequenceName("AA_testAutoNaming_user_set");
                SMAutoNaming obj = new SMAutoNaming("testAutoNaming_2");
                broker.beginTransaction();
                broker.store(obj);
                broker.commitTransaction();
            }
            catch (PersistenceBrokerException e)
            {
                e.printStackTrace();
                broker.close();
                throw e;
            }

            try
            {
                // let OJB re-initialize sequence-manager
                broker.close();
                PersistenceBrokerFactory.releaseAllInstances();
                /*
                remove sequence name of autoincrement field
                but enable automatic sequence name generation
                --> should pass
                */
                field.setSequenceName(null);
                sd.addAttribute("autoNaming", "true");
                broker = PersistenceBrokerFactory.createPersistenceBroker(tempKey);
                SMAutoNaming obj = new SMAutoNaming("testAutoNaming_3");
                broker.beginTransaction();
                broker.store(obj);
                broker.commitTransaction();
            }
            catch (PersistenceBrokerException e)
            {
                e.printStackTrace();
                fail("Sequence key generation failed");
            }

        }
        finally
        {
            // cleanup
            if (broker != null) broker.close();
            mm.setEnablePerThreadChanges(false);
        }
    }
View Full Code Here

    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));
        }

        odmg_1 = OJB.getInstance();
        db_1 = odmg_1.newDatabase();
        db_1.open(TestHelper.DEF_DATABASE_NAME, Database.OPEN_READ_WRITE);
View Full Code Here

        db_2.open(TestHelper.FAR_AWAY_DATABASE_NAME, Database.OPEN_READ_WRITE);
    }

    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)
            {
                odmg_1.currentTransaction().abort();
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

    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));
        }

        odmg_1 = OJB.getInstance();
        db_1 = odmg_1.newDatabase();
        db_1.open(TestHelper.DEF_DATABASE_NAME, Database.OPEN_READ_WRITE);
View Full Code Here

        db_2.open(TestHelper.FAR_AWAY_DATABASE_NAME, Database.OPEN_READ_WRITE);
    }

    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)
            {
                odmg_1.currentTransaction().abort();
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

     * @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

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.