/**
* Copyright (C) 2001-2005 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.objectweb.speedo.runtime.query;
import java.util.Collection;
import java.util.Iterator;
import javax.jdo.Extent;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import org.objectweb.speedo.SpeedoTestHelper;
import org.objectweb.speedo.pobjects.basic.BasicA;
import org.objectweb.util.monolog.api.BasicLevel;
/**
*
*
* @author S.Chassande-Barrioz
*/
public class TestBillionQueries extends SpeedoTestHelper {
public TestBillionQueries() {
super("TestBillonQueries");
}
public TestBillionQueries(String n) {
super(n);
}
protected String getLoggerName() {
return SpeedoTestHelper.LOG_NAME + ".TestBillionQueries";
}
public void testLotOfQueryWithClose100_100() {
testLotOfQuery(true, 100, 100);
}
public void testLotOfQueryWithoutClose100_100() {
testLotOfQuery(false, 100, 100);
}
public void testLotOfQueryWithClose10_10() {
testLotOfQuery(true, 10, 10);
}
public void testLotOfQuery(boolean withclose, final int NB_PM, final int NB_QUERY) {
logger.log(BasicLevel.INFO, "testLotOfQuery(" + withclose
+ ", pm:" + NB_PM + ", query: "+ NB_QUERY +") is running ...");
PersistenceManager pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
for(int i=0; i<20; i++) {
BasicA ba = new BasicA();
ba.writeF1("testBillionQuery_" + i);
pm.makePersistent(ba);
}
pm.currentTransaction().commit();
pm.close();
for(int i=0; i<NB_PM; i++) {
logger.log(BasicLevel.DEBUG, "PM: " + i);
pm = pmf.getPersistenceManager();
for(int j=0; j<NB_QUERY; j++) {
Query q = pm.newQuery(BasicA.class);
q.setFilter("f1.startsWith(p1)");
q.declareParameters("String p1");
Collection c = (Collection) q.execute("dep");
for (Iterator it = c.iterator(); it.hasNext();) {
it.next();
}
q.closeAll();
}
pm.close();
}
pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
Extent e = pm.getExtent(BasicA.class);
for(Iterator it = e.iterator(); it.hasNext();) {
pm.deletePersistent(it.next());
}
pm.currentTransaction().commit();
pm.close();
}
}