Package org.apache.ojb.broker.metadata

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


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

    {
        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

            }
                  
            invoker = new StoreEventInvoker(listeners, this);
            pb = PersistenceBrokerFactory.createPersistenceBroker(pbKey);       
            toBeStored = new HashSet();
            MetadataManager metaManager = MetadataManager.getInstance();
            RepositoryPersistor persistor = new RepositoryPersistor();
            Enumeration descriptors = getClass().getClassLoader().getResources("META-INF/ojb_repository.xml");
            while(descriptors.hasMoreElements())
            {
                URL descriptorUrl = (URL) descriptors.nextElement();
                log.info("Merging OJB respository: "+descriptorUrl);
                DescriptorRepository repo = persistor.readDescriptorRepository(descriptorUrl.openStream());
                metaManager.mergeDescriptorRepository(repo);               
            }
        }
        catch (Throwable e)
        {
            // TODO Auto-generated catch block
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.