/*
* Jalisto - JAva LIght STOrage
* Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
*
* 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.1 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.
*
* Xcalia
* 71, rue Desnouettes
* 75014 Paris - France
* http://www.xcalia.com
*/
package org.objectweb.jalisto.se.test.workbench;
import junit.extensions.jfunc.JFuncTestCase;
import org.objectweb.jalisto.se.api.ClassDescription;
import org.objectweb.jalisto.se.api.Session;
import org.objectweb.jalisto.se.api.Transaction;
import org.objectweb.jalisto.se.api.query.IndexManager;
import org.objectweb.jalisto.se.api.query.QueryManager;
import org.objectweb.jalisto.se.JalistoFactory;
import org.objectweb.jalisto.se.test.data.Book;
import org.objectweb.jalisto.se.test.data.BookWithAuthor;
import java.util.Iterator;
public class JalistoTestCase extends JFuncTestCase {
public JalistoTestCase() {
super();
}
public JalistoTestCase(String name) {
super(name);
}
protected void setTestEngine(JalistoTestEngine testEngine) {
this.testEngine = testEngine;
}
protected void setUpOnce() throws Exception {
System.out.println("=== INIT ===");
super.setUpOnce();
}
protected void tearDownOnce() throws Exception {
super.tearDownOnce();
System.out.println("=== CLOSE ===");
}
protected void tearDown() throws Exception {
super.tearDown();
endTransaction();
}
protected static Object newTestCase(JalistoTestSuite suite,
JalistoTestCase testCase) {
return suite.getTestProxy(testCase);
}
protected String getJalistoPropertiesFilename() {
return testEngine.getDBPropertiesFilename();
}
/**
* ****************************** UTIL **************************************
*/
public void initSession(boolean withErase) {
finishTests();
session = JalistoFactory.getSession(getJalistoPropertiesFilename());
if (withErase && session.getInternalSession().getProperties().allowsSpecialFunctionnalities()) {
session.eraseStorage();
}
session.openSession();
tx = session.currentTransaction();
if(tx == null) {
throw new IllegalStateException("tx == null");
}
queryManager = session.getQueryManager();
if (queryManager != null) {
indexManager = queryManager.getIndexManager();
}
}
public void define(ClassDescription meta) {
session.defineClass(meta);
}
public void cleanUp(Class aClass) {
tx.begin();
Iterator extentIt = session.getExtent(aClass).readFully().iterator();
while (extentIt.hasNext()) {
Object oid = extentIt.next();
session.deleteObjectByOid(oid);
}
tx.commit();
}
public void populate(int nbr) {
tx.begin();
for (int i = 0; i < nbr; i++) {
session.createObject(Book.newBook().toArray(), Book.class);
if ((i != 0) && ((i % 1000) == 0)) {
tx.commit();
tx.begin();
}
}
tx.commit();
}
public void populateBookWithAuthor(int nbr) {
tx.begin();
for (int i = 0; i < nbr; i++) {
session.createObject(BookWithAuthor.newBook().toArray(), BookWithAuthor.class);
if ((i != 0) && ((i % 1000) == 0)) {
tx.commit();
tx.begin();
}
}
tx.commit();
}
public void finishTests() {
endTransaction();
closeSession();
}
public void endTransaction() {
if ((tx != null) && (tx.isActive())) {
tx.rollback();
}
}
public void closeSession() {
endTransaction();
if ((session != null) && (session.isOpen())) {
session.closeSession();
}
}
protected Session session = null;
protected Transaction tx = null;
protected QueryManager queryManager = null;
protected IndexManager indexManager = null;
protected final Object[] oneObjectArray = new Object[1];
private JalistoTestEngine testEngine;
public static final int numberOfQueryExecute = 30;
}
|