/* * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Florent Guillaume, jcarsique */ package org.nuxeo.ecm.core.storage.sql; import org.nuxeo.common.Environment; import org.nuxeo.ecm.core.storage.sql.ra.PoolingRepositoryFactory; import org.nuxeo.runtime.datasource.ConnectionHelper; import org.nuxeo.runtime.transaction.TransactionHelper; /** * Transactional SQL Repository TestCase. * <p> * The tests are run with a session that is open in a transaction. */ public abstract class TXSQLRepositoryTestCase extends SQLRepositoryTestCase { @Override public void setUp() throws Exception { super.setUp(); // calls deployRepositoryConfig() Environment.getDefault().setHostApplicationName( Environment.NXSERVER_HOST); fireFrameworkStarted(); TransactionHelper.startTransaction(); openSession(); } /** Can be subclassed to instantiate specific pool config. */ protected void setUpContainer() throws Exception { } /** * Overridden to use a pooling configuration. */ @Override protected void deployRepositoryContrib() throws Exception { DatabaseHelper.setRepositoryFactory(PoolingRepositoryFactory.class); super.deployRepositoryContrib(); deployBundle("org.nuxeo.runtime.jtajca"); } protected boolean hasPoolingConfig() { return database instanceof DatabaseH2 || database instanceof DatabasePostgreSQL; } protected boolean useSingleConnectionMode() { return ConnectionHelper.useSingleConnection(ConnectionHelper.getPseudoDataSourceNameForRepository(database.repositoryName)); } @Override public void tearDown() throws Exception { try { if (session != null) { session.cancel(); closeSession(); } if (TransactionHelper.isTransactionActiveOrMarkedRollback()) { TransactionHelper.setTransactionRollbackOnly(); TransactionHelper.commitOrRollbackTransaction(); } } finally { super.tearDown(); } } }