本文整理汇总了Java中org.apache.ojb.broker.query.Query.setEndAtIndex方法的典型用法代码示例。如果您正苦于以下问题:Java Query.setEndAtIndex方法的具体用法?Java Query.setEndAtIndex怎么用?Java Query.setEndAtIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ojb.broker.query.Query
的用法示例。
在下文中一共展示了Query.setEndAtIndex方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCollectionByQuery_2
import org.apache.ojb.broker.query.Query; //导入方法依赖的package包/类
public void testCollectionByQuery_2() throws Exception
{
String dummy = "nothing_to_find";
Criteria criteria = new Criteria();
criteria.addEqualTo("name", dummy);
Query query = QueryFactory.newQuery(TestObject.class, criteria);
// doesn't make sense to use this option here - only for test
query.setStartAtIndex(1);
query.setEndAtIndex(20);
Collection result = broker.getCollectionByQuery(query);
for(Iterator iterator = result.iterator(); iterator.hasNext();)
{
iterator.next();
fail("We don't expect any result objects");
}
}
示例2: limitResultSize
import org.apache.ojb.broker.query.Query; //导入方法依赖的package包/类
/**
* Limit the size of the result set from the given query operation
*
* @param query the given query operation
*/
public static void limitResultSize(Query query) {
int startingIndex = 1;
int endingIndex = getResultLimit().intValue();
query.setStartAtIndex(startingIndex);
query.setEndAtIndex(endingIndex);
}
示例3: runQueryRangeTest
import org.apache.ojb.broker.query.Query; //导入方法依赖的package包/类
/**
* Run a query range test.
*
* @param delta the amount to add to the existing record count when setting
* the start/end index for the query that we'll use.
*/
private void runQueryRangeTest(int delta)
{
// How many records are there in the table?
Query countQuery = QueryFactory.newQuery(ProductGroup.class, null, false);
// Get the existing record count
int recordCount = broker.getCollectionByQuery(countQuery).toArray().length;
// Build a query that will get the range we're looking for.
Query listQuery = QueryFactory.newQuery(ProductGroup.class, null, false);
listQuery.setStartAtIndex(1);
listQuery.setEndAtIndex(recordCount + delta);
// Get the list.
Object[] theObjects = broker.getCollectionByQuery(listQuery).toArray();
// Verify the record count
if(delta <= 0)
{
assertEquals("record count", (recordCount + delta), theObjects.length);
}
else
{
assertEquals("record count", recordCount, theObjects.length);
}
// Verify the query size, fullSize is 0
// assertEquals("Query size", recordCount, listQuery.fullSize());
}
示例4: testIteratorByQuery_2
import org.apache.ojb.broker.query.Query; //导入方法依赖的package包/类
public void testIteratorByQuery_2() throws Exception
{
String dummy = "nothing_to_find";
Criteria criteria = new Criteria();
criteria.addEqualTo("name", dummy);
Query query = QueryFactory.newQuery(TestObject.class, criteria);
query.setStartAtIndex(1);
query.setEndAtIndex(20);
Iterator result = broker.getIteratorByQuery(query);
while(result.hasNext())
{
result.next();
fail("We don't expect any result objects");
}
}
示例5: limitResultSize
import org.apache.ojb.broker.query.Query; //导入方法依赖的package包/类
/**
* Limit the size of the result set from the given query operation
*
* @param query the given query operation
*/
public static void limitResultSize(Query query) {
int startingIndex = 1;
int endingIndex = getResultLimit().intValue();
query.setStartAtIndex(startingIndex);
query.setEndAtIndex(endingIndex);
}
示例6: testGetCollectionByQueryWithStartAndEnd
import org.apache.ojb.broker.query.Query; //导入方法依赖的package包/类
public void testGetCollectionByQueryWithStartAndEnd() throws Exception
{
String name = "testGetCollectionByQueryWithStartAndEnd_" + System.currentTimeMillis();
Criteria criteria = new Criteria();
criteria.addEqualTo("articleName", name);
// criteria.addEqualTo("isSelloutArticle", new Boolean(true));
Query query = QueryFactory.newQuery(Article.class, criteria);
Collection col = broker.getCollectionByQuery(query);
assertEquals("size of collection should be zero", 0, col.size());
//2. insert 5 matching items
broker.beginTransaction();
Article a1 = createArticle(null, name);
broker.store(a1);
Article a2 = createArticle(null, name);
broker.store(a2);
Article a3 = createArticle(null, name);
broker.store(a3);
Article a4 = createArticle(null, name);
broker.store(a4);
Article a5 = createArticle(null, name);
broker.store(a5);
broker.commitTransaction();
broker.clearCache();
// 3. set query start and end
query.setStartAtIndex(2);
query.setEndAtIndex(5);
// 4. check if all items are found
col = broker.getCollectionByQuery(query);
assertEquals("size of collection should be four", 4, col.size());
NumberRange range = new NumberRange(a1.getArticleId(), a5.getArticleId());
Iterator iter = col.iterator();
while (iter.hasNext())
{
InterfaceArticle testIa = (InterfaceArticle) iter.next();
assertEquals("should be same value", name, testIa.getArticleName());
Integer id = testIa.getArticleId();
assertTrue("Id should be a number of the generated articles", range.containsInteger(id));
}
// read one item only
// 1. set query start equals end
query.setStartAtIndex(4);
query.setEndAtIndex(4);
// 2. check if only one item is found
OJBIterator ojbIter = (OJBIterator)broker.getIteratorByQuery(query);
assertEquals("size of iterator should be one", 1, ojbIter.size());
InterfaceArticle test4 = (InterfaceArticle) ojbIter.next();
ojbIter.releaseDbResources();
assertTrue("Id should be a number of the generated articles", range.containsInteger(test4.getArticleId()));
}