当前位置: 首页>>代码示例>>Java>>正文


Java PersistenceBroker.commitTransaction方法代码示例

本文整理汇总了Java中org.apache.ojb.broker.PersistenceBroker.commitTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java PersistenceBroker.commitTransaction方法的具体用法?Java PersistenceBroker.commitTransaction怎么用?Java PersistenceBroker.commitTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.ojb.broker.PersistenceBroker的用法示例。


在下文中一共展示了PersistenceBroker.commitTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testObjectCacheDefaultImplTimeout

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
public void testObjectCacheDefaultImplTimeout() throws Exception
{
    TestObjectDefaultCache obj = new TestObjectDefaultCache();
    PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
    try
    {
        broker.beginTransaction();
        broker.store(obj);
        broker.commitTransaction();

        Identity oid = new Identity(obj, broker);
        obj = (TestObjectDefaultCache) broker.serviceObjectCache().lookup(oid);
        assertNotNull(obj);

        Thread.sleep(5000);
        obj = (TestObjectDefaultCache) broker.serviceObjectCache().lookup(oid);
        assertNull(obj);
    }
    finally
    {
        if(broker != null) broker.close();
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:24,代码来源:ObjectCacheTest.java

示例2: insertNewArticlesStress

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
 * A resource cumbering insert-method implementation,
 * this was used to test implementation.
 */
public void insertNewArticlesStress(PerfArticle[] arr) throws Exception
{
    for (int i = 0; i < arr.length; i++)
    {
        PersistenceBroker broker = null;
        try
        {
            broker = PersistenceBrokerFactory.defaultPersistenceBroker();
            broker.beginTransaction();
            broker.store(arr[i]);
            broker.commitTransaction();
        }
        finally
        {
            if (broker != null) broker.close();
        }
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:23,代码来源:OJBPerfTest.java

示例3: insertNewArticles

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
 * A performance optimized insert-method implementation,
 * used to test performance.
 */
public void insertNewArticles(PerfArticle[] arr) throws Exception
{
    PersistenceBroker broker = null;
    try
    {
        broker = PersistenceBrokerFactory.defaultPersistenceBroker();
        broker.serviceConnectionManager().setBatchMode(true);
        broker.beginTransaction();
        for (int i = 0; i < arr.length; i++)
        {
            broker.store(arr[i], ObjectModification.INSERT);
        }
        broker.commitTransaction();
    }
    finally
    {
        if (broker != null) broker.close();
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:24,代码来源:OJBPerfTest.java

示例4: updateArticles

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
public void updateArticles(PerfArticle[] arr) throws Exception
{
    PersistenceBroker broker = null;
    try
    {
        broker = PersistenceBrokerFactory.defaultPersistenceBroker();
        broker.serviceConnectionManager().setBatchMode(true);
        broker.beginTransaction();
        for (int i = 0; i < arr.length; i++)
        {
            broker.store(arr[i], ObjectModification.UPDATE);
            // broker.store(arr[i]);
        }
        broker.commitTransaction();
    }
    finally
    {
        if (broker != null) broker.close();
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:21,代码来源:OJBPerfTest.java

示例5: updateArticlesStress

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
public void updateArticlesStress(PerfArticle[] arr) throws Exception
{
    for (int i = 0; i < arr.length; i++)
    {
        PersistenceBroker broker = null;
        try
        {
            broker = PersistenceBrokerFactory.defaultPersistenceBroker();
            broker.beginTransaction();
            broker.store(arr[i]);
            broker.commitTransaction();
        }
        finally
        {
            if (broker != null) broker.close();
        }
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:19,代码来源:OJBPerfTest.java

示例6: deleteArticlesStress

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
 * A resource cumbering delete-method implementation,
 * used to test implementation
 */
public void deleteArticlesStress(PerfArticle[] arr) throws Exception
{
    for (int i = 0; i < arr.length; i++)
    {
        PersistenceBroker broker = null;
        try
        {
            broker = PersistenceBrokerFactory.defaultPersistenceBroker();
            broker.beginTransaction();
            broker.delete(arr[i]);
            broker.commitTransaction();
        }
        finally
        {
            if (broker != null) broker.close();
        }
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:23,代码来源:OJBPerfTest.java

示例7: deleteArticles

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
 * A performance optimized delete-method implementation,
 * used to test performance
 */
public void deleteArticles(PerfArticle[] arr) throws Exception
{
    PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
    try
    {
        broker.serviceConnectionManager().setBatchMode(true);
        broker.beginTransaction();
        for (int i = 0; i < arr.length; i++)
        {
            broker.delete(arr[i]);
        }
        broker.commitTransaction();
    }
    finally
    {
        if (broker != null) broker.close();
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:23,代码来源:OJBPerfTest.java

示例8: testMultipleAutoincrement

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
     * Test support for classes with multiple autoincrement
     * fields - e.g. see repository for {@link Repository.SMKey}
     */
    public void testMultipleAutoincrement()
    {
        String MESSAGE = "Autoincrement field was not incremented: ";
        String name = "my test key " + System.currentTimeMillis();
        Repository.SMKey key = new Repository.SMKey();
        key.setName(name);
        PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
        broker.beginTransaction();
        broker.store(key);
        broker.commitTransaction();
        assertEquals("Value was not store: " + key, name, key.getName());
        assertNotNull(MESSAGE + key, key.getIntegerKey());
        assertTrue(MESSAGE + key, (key.getIntKey() != 0));
        assertNotNull(MESSAGE + key, key.getLongKey());
        assertNotNull(MESSAGE + key, key.getStringKey());
//        System.out.println("## SMKey: \n"+key);

        Criteria cr = new Criteria();
        cr.addEqualTo("name", name);
        Query query = new QueryByCriteria(Repository.SMKey.class, cr);
        key = (Repository.SMKey) broker.getObjectByQuery(query);

        assertEquals("Value was not store: ", name, key.getName());
        assertNotNull(MESSAGE + key, key.getIntegerKey());
        assertTrue(MESSAGE + key, (key.getIntKey() != 0));
        assertNotNull(MESSAGE + key, key.getLongKey());
        assertNotNull(MESSAGE + key, key.getStringKey());
//        System.out.println("## SMKey: \n"+key);

        broker.close();
    }
 
开发者ID:KualiCo,项目名称:ojb,代码行数:36,代码来源:SequenceManagerTest.java

示例9: testMaxKeySearch2

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
 * Test the max id search used in the standard sequence manager
 * implementations.
 */
public void testMaxKeySearch2()
{
    PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
    // find max from classes using the same table
    broker.beginTransaction();
    broker.store(new ObjectRepository.A());
    broker.store(new ObjectRepository.B());
    broker.store(new ObjectRepository.B1());
    broker.store(new ObjectRepository.C());
    broker.store(new ObjectRepository.D());
    broker.commitTransaction();
    long[] result = new long[5];
    FieldDescriptor field = broker.getClassDescriptor(ObjectRepository.A.class).getAutoIncrementFields()[0];
    result[0] = SequenceManagerHelper.getMaxForExtent(broker, field);
    field = broker.getClassDescriptor(ObjectRepository.B.class).getAutoIncrementFields()[0];
    result[1] = SequenceManagerHelper.getMaxForExtent(broker, field);
    field = broker.getClassDescriptor(ObjectRepository.C.class).getAutoIncrementFields()[0];
    result[2] = SequenceManagerHelper.getMaxForExtent(broker, field);
    field = broker.getClassDescriptor(ObjectRepository.D.class).getAutoIncrementFields()[0];
    result[3] = SequenceManagerHelper.getMaxForExtent(broker, field);
    field = broker.getClassDescriptor(ObjectRepository.B1.class).getAutoIncrementFields()[0];
    result[4] = SequenceManagerHelper.getMaxForExtent(broker, field);
    broker.close();

    for (int i = 0; i < result.length; i++)
    {
        for (int k = 0; k < result.length; k++)
        {
            if (!(result[i] == result[k]))
            {
                fail(DEF_FAIL_MESSAGE);
            }
        }
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:40,代码来源:SequenceManagerTest.java

示例10: testMassStoreOfObjects

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
public void testMassStoreOfObjects()
{
    int outerLoops = 10;
    int innerLoops = 30;
    String name = "Name_" + System.currentTimeMillis();

    Repository.SMKey key = null;
    for (int i = outerLoops - 1; i >= 0; i--)
    {
        PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
        try
        {
            broker.beginTransaction();
            for (int j = innerLoops - 1; j >= 0; j--)
            {
                key = new Repository.SMKey();
                key.setName(name);
                broker.store(key);
            }
            broker.commitTransaction();
        }
        finally
        {
            if(broker != null) broker.close();
        }
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:28,代码来源:SequenceManagerTest.java

示例11: testObjectCacheDefaultImpl

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
public void testObjectCacheDefaultImpl() throws Exception
{
    String name = "testObjectCacheDefaultImpl_"+System.currentTimeMillis();
    TestObjectDefaultCache obj = new TestObjectDefaultCache();
    obj.setName(name);
    PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
    try
    {
        broker.beginTransaction();
        broker.store(obj);
        broker.commitTransaction();

        Identity oid = new Identity(obj, broker);
        obj = (TestObjectDefaultCache) broker.serviceObjectCache().lookup(oid);
        assertNotNull(obj);
        assertEquals(name, obj.getName());

        // modify name
        String new_name = "modified_"+name;
        obj.setName(new_name);
        obj = (TestObjectDefaultCache) broker.getObjectByIdentity(oid);
        assertNotNull(obj);
        assertEquals("current version of cache should return the modified object", new_name, obj.getName());

        broker.removeFromCache(oid);
        obj = (TestObjectDefaultCache) broker.serviceObjectCache().lookup(oid);
        assertNull("Should be removed from cache", obj);
        obj = (TestObjectDefaultCache) broker.getObjectByIdentity(oid);
        assertNotNull(obj);
        assertEquals("Should return the unmodified object", name, obj.getName());
    }
    finally
    {
        if(broker != null) broker.close();
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:37,代码来源:ObjectCacheTest.java

示例12: testPerClassCache

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
 * Test per class ObjectCache declaration. 'TestObjectEmptyCache'
 * class metadata declare an 'empty ObjectCache' implementation
 * as cache, CacheObject use the default ObjectCache implementation.
 * Thus we should found 'CacheObject' instance in cache, but NOT found
 * 'TestObjectEmptyCache' instance.
 */
public void testPerClassCache() throws Exception
{
    PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
    JdbcConnectionDescriptor jcd = broker.serviceConnectionManager().getConnectionDescriptor();
    if(jcd.getObjectCacheDescriptor().getObjectCache().equals(ObjectCacheEmptyImpl.class))
    {
        ojbSkipTestMessage("Doesn't work with " + ObjectCacheEmptyImpl.class + " as default cache.");
        return;
    }
    String name = "testPerClassCache_" + System.currentTimeMillis();

    TestObjectEmptyCache obj = new TestObjectEmptyCache();
    obj.setName(name);
    CacheObject dummy = new CacheObject();
    dummy.setName(name);

    try
    {
        broker.beginTransaction();
        broker.store(obj);
        broker.store(dummy);
        broker.commitTransaction();

        Identity obj_oid = new Identity(obj, broker);
        Identity dummy_oid = new Identity(dummy, broker);
        ObjectCache cache = broker.serviceObjectCache();
        Object ret_obj = cache.lookup(obj_oid);
        Object ret_dummy = cache.lookup(dummy_oid);
        assertNotNull(ret_dummy);
        assertNull(ret_obj);
    }
    finally
    {
        if (broker != null && broker.isInTransaction()) broker.abortTransaction();
        if (broker != null) broker.close();
    }
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:45,代码来源:ObjectCacheTest.java

示例13: YYYtestCacheIsolation

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
     * This test checks if the caches of two different brokers are properly isolated.
     * changes made to an object in tx1 should not be visible in tx2 !
     * TODO: once we work without global cache only (e.g. intern temporary cache), this test should pass!
     */
    public void YYYtestCacheIsolation() throws Exception
    {
        Object[] pk = new Object[]{new Long(42)};
        Identity oid = new Identity(Article.class, InterfaceArticle.class, pk);

        GUID guid = new GUID();

        PersistenceBroker broker1 = PersistenceBrokerFactory.defaultPersistenceBroker();
        broker1.beginTransaction();

        Article a1 = (Article) broker1.getObjectByQuery(new QueryByIdentity(oid));
        String originalName = a1.getArticleName();
        a1.setArticleName(guid.toString());

// start a second transaction
        PersistenceBroker broker2 = PersistenceBrokerFactory.defaultPersistenceBroker();
        broker2.beginTransaction();

        Article a2 = (Article) broker2.getObjectByQuery(new QueryByIdentity(oid));

        assertEquals(guid.toString(), a1.getArticleName());
        assertEquals(originalName, a2.getArticleName());
        assertNotSame(a1, a2);


        broker1.commitTransaction();
        broker1.close();

        broker2.commitTransaction();
        broker2.close();
    }
 
开发者ID:KualiCo,项目名称:ojb,代码行数:37,代码来源:ObjectCacheTest.java

示例14: getSequence

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
protected HighLowSequence getSequence(PersistenceBroker brokerForSequence,
                                    FieldDescriptor field,
                                    String sequenceName)  throws SequenceManagerException
{
    HighLowSequence newSequence = null;
    PersistenceBroker internBroker = null;
    try
    {
        /*
        arminw:
        we use a new internBroker instance, because we run into problems
        when current internBroker was rollback, then we have new sequence
        in memory, but not in database and a concurrent thread will
        get the same sequence.
        Thus we use a new internBroker instance (with new connection) to
        avoid this problem.
        */
        internBroker = PersistenceBrokerFactory.createPersistenceBroker(brokerForSequence.getPBKey());
        internBroker.beginTransaction();

        newSequence = lookupStoreSequence(internBroker, field, sequenceName);

        internBroker.commitTransaction();

        if (log.isDebugEnabled()) log.debug("new sequence was " + newSequence);
    }
    catch(Exception e)
    {
        log.error("Can't lookup new HighLowSequence for field "
                + (field != null ? field.getAttributeName() : null)
                + " using sequence name " + sequenceName, e);
        if(internBroker != null && internBroker.isInTransaction()) internBroker.abortTransaction();
        throw new SequenceManagerException("Can't build new sequence", e);
    }
    finally
    {
        attempts = 0;
        if (internBroker != null) internBroker.close();
    }
    return newSequence;
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:42,代码来源:SequenceManagerHighLowImpl.java

示例15: testObjectsFromAbstractBaseClass2

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
public void testObjectsFromAbstractBaseClass2() throws Exception
    {
        long stamp = System.currentTimeMillis();
        String objectName_One = "testObjectsFromAbstractBaseClass2_objOne_" + stamp;
        String objectName_Two = "testObjectsFromAbstractBaseClass2_objTwo_" + stamp;

        PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();

        Repository.SMSameTableBB dummy1 = new Repository.SMSameTableBB();
        Repository.SMInterfaceExtendA dummy2 = new Repository.SMInterfaceExtendA();

        SMObjectOne smOne_1 = new SMObjectOne(objectName_One);
        SMObjectOne smOne_2 = new SMObjectOne(objectName_One);

        SMObjectTwo smTwo_2 = new SMObjectTwo(objectName_Two);
        SMObjectTwo smTwo_1 = new SMObjectTwo(objectName_Two);
        try
        {
            broker.beginTransaction();

            broker.store(dummy1);
            broker.store(dummy2);

            broker.store(smOne_1);
            broker.store(smOne_2);
// broker.clearCache();
            broker.store(smTwo_2);
            broker.store(smTwo_1);

            broker.commitTransaction();

            // now check if store was successful
            broker.clearCache();

            Criteria cr = new Criteria();
            cr.addEqualTo("name", objectName_One);
            Query query = new QueryByCriteria(SMObjectOne.class, cr);
            Collection result = broker.getCollectionByQuery(query);

            broker.clearCache();

            Criteria cr_2 = new Criteria();
            cr_2.addEqualTo("name", objectName_Two);
            Query query_2 = new QueryByCriteria(SMObjectTwo.class, cr_2);
            Collection result_2 = broker.getCollectionByQuery(query_2);

            assertEquals("We have to found 2 SMObjectOne objects", 2, result.size());
            assertEquals("We have to found 2 SMObjectTwo objects", 2, result_2.size());
        }
        finally
        {
            if (broker != null) broker.close();
        }
    }
 
开发者ID:KualiCo,项目名称:ojb,代码行数:55,代码来源:SequenceManagerTest.java


注:本文中的org.apache.ojb.broker.PersistenceBroker.commitTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。