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


Java PersistenceBroker.clearCache方法代码示例

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


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

示例1: testLockLoop

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
public void testLockLoop() throws Exception
{
    int loops = 10;
    Article[] arr = new Article[loops];
    for(int i = 0; i < loops; i++)
    {
        Article a = createArticle("testLockLoop");
        arr[i] = a;
    }

    TransactionImpl tx = (TransactionImpl) odmg1.newTransaction();
    tx.begin();
    for(int i = 0; i < arr.length; i++)
    {
        tx.lock(arr[i], Transaction.WRITE);
    }
    LockManager lm = LockManagerFactory.getLockManager();
    boolean success = lm.writeLock(tx, arr[(loops - 2)]);
    assertTrue("lock should succeed", success);
    tx.commit();

    TransactionImpl tx2 = (TransactionImpl) odmg2.newTransaction();
    tx2.begin();
    success = lm.writeLock(tx2, arr[(loops - 2)]);
    assertTrue("lock should succeed", success);

    OQLQuery query = odmg2.newOQLQuery();
    String sql = "select allArticles from " + Article.class.getName() +
            " where articleName = \"" + PRE + "testLockLoop" + "\"";
    query.create(sql);
    int result = ((List) query.execute()).size();
    tx2.commit();
    assertEquals("Wrong number of objects wrote to DB", loops, result);

    PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
    broker.clearCache();
    Criteria crit = new Criteria();
    crit.addLike("articleName", PRE + "testLockLoop");
    result = broker.getCount(QueryFactory.newQuery(Article.class, crit));
    broker.close();
    assertEquals("Wrong number of objects wrote to DB", loops, result);
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:43,代码来源:LockingTest.java

示例2: testResultsAfterTransactionWithClearedCache

import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
 * Tests object count after a commited transaction
 */
public void testResultsAfterTransactionWithClearedCache() throws Exception
{
    int odmgZoosBefore = getDBObjectCountWithNewPB(ODMGZoo.class);
    int projectsBefore = getDBObjectCountWithNewPB(ODMGGourmet.class);

    Transaction tx = odmg.newTransaction();
    tx.begin();
    //store
    persistentStoreObjects(database, getNewODMGZoos("testResultsAfterTransactionWithClearedCache", 5));
    persistentStoreObjects(database, getNewProjects("testResultsAfterTransactionWithClearedCache", 3));
    //store more
    storeObjects(tx, getNewODMGZoos("testResultsAfterTransactionWithClearedCache", 5));
    storeObjects(tx, getNewProjects("testResultsAfterTransactionWithClearedCache", 2));
    tx.commit();

    //###### hack we clear cache of PB ########
    PersistenceBroker tmp = PersistenceBrokerFactory.defaultPersistenceBroker();
    tmp.clearCache();
    tmp.close();

    int odmgZoosAfter = getDBObjectCountWithNewPB(ODMGZoo.class);
    int projectsAfter = getDBObjectCountWithNewPB(ODMGGourmet.class);
    int odmgZoosAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(odmg, ODMGZoo.class);
    int projectsAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(odmg, ODMGGourmet.class);

    assertEquals("Wrong number of odmgZoos found", (odmgZoosBefore + 10), odmgZoosAfter);
    assertEquals("Wrong number of projects found", (projectsBefore + 5), projectsAfter);
    assertEquals("Wrong number of odmgZoos found", (odmgZoosBefore + 10), odmgZoosAfterOQL);
    assertEquals("Wrong number of projects found", (projectsBefore + 5), projectsAfterOQL);


    //we do twice
    odmgZoosBefore = getDBObjectCountWithNewPB(ODMGZoo.class);
    projectsBefore = getDBObjectCountWithNewPB(ODMGGourmet.class);

    //tx should be reusable
    tx.begin();
    //store
    persistentStoreObjects(database, getNewODMGZoos("testResultsAfterTransactionWithClearedCache", 5));
    persistentStoreObjects(database, getNewProjects("testResultsAfterTransactionWithClearedCache", 3));
    //store more
    storeObjects(tx, getNewODMGZoos("testResultsAfterTransactionWithClearedCache", 5));
    storeObjects(tx, getNewProjects("testResultsAfterTransactionWithClearedCache", 2));
    tx.commit();

    //###### hack we clear cache of PB ########
    tmp = PersistenceBrokerFactory.defaultPersistenceBroker();
    tmp.clearCache();
    tmp.close();

    odmgZoosAfter = getDBObjectCountWithNewPB(ODMGZoo.class);
    projectsAfter = getDBObjectCountWithNewPB(ODMGGourmet.class);
    odmgZoosAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(odmg, ODMGZoo.class);
    projectsAfterOQL = getDBObjectCountViaOqlQueryUseNewTransaction(odmg, ODMGGourmet.class);

    assertEquals("Wrong number of odmgZoos found", (odmgZoosBefore + 10), odmgZoosAfter);
    assertEquals("Wrong number of projects found", (projectsBefore + 5), projectsAfter);
    assertEquals("Wrong number of odmgZoos found", (odmgZoosBefore + 10), odmgZoosAfterOQL);
    assertEquals("Wrong number of projects found", (projectsBefore + 5), projectsAfterOQL);
}
 
开发者ID:KualiCo,项目名称:ojb,代码行数:64,代码来源:ODMGRollbackTest.java

示例3: 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.clearCache方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。