本文整理汇总了Java中org.apache.ojb.broker.PersistenceBroker.getCount方法的典型用法代码示例。如果您正苦于以下问题:Java PersistenceBroker.getCount方法的具体用法?Java PersistenceBroker.getCount怎么用?Java PersistenceBroker.getCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ojb.broker.PersistenceBroker
的用法示例。
在下文中一共展示了PersistenceBroker.getCount方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadSize
import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
* Determines the number of elements that the query would return. Override this
* method if the size shall be determined in a specific way.
*
* @return The number of elements
*/
protected synchronized int loadSize() throws PersistenceBrokerException
{
PersistenceBroker broker = getBroker();
try
{
return broker.getCount(getQuery());
}
catch (Exception ex)
{
throw new PersistenceBrokerException(ex);
}
finally
{
releaseBroker(broker);
}
}
示例2: getDBObjectCountWithNewPB
import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
protected int getDBObjectCountWithNewPB(PBKey pbKey, Class target) throws Exception
{
PersistenceBroker broker = PersistenceBrokerFactory.createPersistenceBroker(pbKey);
Criteria c = new Criteria();
Query q = new QueryByCriteria(target, c);
int count = broker.getCount(q);
broker.close();
return count;
}
示例3: checkGeneratedObjects
import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
private void checkGeneratedObjects(int testObjects)
{
PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
int res_1;
int res_2;
try
{
Criteria crit = new Criteria();
crit.addLike("name", goodName+"%");
Criteria crit2 = new Criteria();
crit2.addLike("name", badName+"%");
crit.addOrCriteria(crit2);
Query q_1 = new QueryByCriteria(MTObjectA.class, crit);
Query q_2 = new QueryByCriteria(MTObjectB.class, crit);
res_1 = broker.getCount(q_1);
res_2 = broker.getCount(q_2);
}
finally
{
if(broker != null && !broker.isClosed()) broker.close();
}
assertEquals(testObjects, res_1);
assertEquals(testObjects, res_2);
}
示例4: testLookupPB1
import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
* test to check PB create with PBKey
*/
public void testLookupPB1()
{
PBKey key1 = new PBKey(TestHelper.DEF_JCD_ALIAS);
PBKey key2 = new PBKey(TestHelper.DEF_JCD_ALIAS, TestHelper.DEF_USER, TestHelper.DEF_PASSWORD);
PBKey key3 = new PBKey(TestHelper.FAR_AWAY_JCD_ALIAS);
Query query = QueryFactory.newQuery(TEST_CLASS, new Criteria());
PersistenceBroker broker = PersistenceBrokerFactory.createPersistenceBroker(key1);
broker.getCount(query);
broker.close();
broker = PersistenceBrokerFactory.createPersistenceBroker(key2);
broker.getCount(query);
broker.close();
broker = PersistenceBrokerFactory.createPersistenceBroker(key3);
broker.getCount(query);
broker.close();
}
示例5: testLookupPB2
import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
* test to check PB create with PBKey
*/
public void testLookupPB2()
{
PBKey key1 = new PBKey(TestHelper.DEF_JCD_ALIAS, "!!TestCase: This should fail!!", "nothing");
Query query = QueryFactory.newQuery(TEST_CLASS, new Criteria());
PersistenceBroker broker = PersistenceBrokerFactory.createPersistenceBroker(key1);
// hsql is not very strict in user handling
try
{
broker.getCount(query);
fail("We excect a exception, because we pass a PBKey with user and password that doesn't exist");
}
catch (Exception e)
{
assertTrue(true);
}
broker.close();
}
示例6: articleCount
import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
public int articleCount()
{
Criteria c = new Criteria();
Query q = new QueryByCriteria(PerfArticleImpl.class, c);
int count = 0;
try
{
PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
count = broker.getCount(q);
broker.close();
}
catch (Exception e)
{
e.printStackTrace();
}
return count;
}
示例7: getDBObjectCount
import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
protected int getDBObjectCount(PersistenceBroker broker, Class target) throws Exception
{
Criteria c = new Criteria();
Query q = new QueryByCriteria(target, c);
int count = broker.getCount(q);
return count;
}
示例8: getDBObjectCountWithNewPB
import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
protected int getDBObjectCountWithNewPB(Class target) throws Exception
{
PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
Criteria c = new Criteria();
Query q = new QueryByCriteria(target, c);
int count = broker.getCount(q);
broker.close();
return count;
}
示例9: getCount
import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
protected int getCount(Class target)
{
PersistenceBroker broker = getBroker();
int result = broker.getCount(new QueryByCriteria(target));
broker.close();
return result;
}
示例10: getCount
import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
* Return the count of all objects found
* for given class.
*/
public int getCount(Class target)
{
PersistenceBroker broker = getBroker();
int result;
try
{
result = broker.getCount(new QueryByCriteria(target));
}
finally
{
if (broker != null) broker.close();
}
return result;
}
示例11: getCount
import org.apache.ojb.broker.PersistenceBroker; //导入方法依赖的package包/类
/**
* Return the count of all objects found
* for given class, using the PB-api within
* ODMG - this may change in further versions.
*/
public int getCount(Class target)
{
PersistenceBroker broker = ((HasBroker) odmg.currentTransaction()).getBroker();
int result = broker.getCount(new QueryByCriteria(target));
return result;
}
示例12: 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);
}