r486 - in trunk: echobase-entities/src/main/java/fr/ifremer/echobase echobase-entities/src/main/resources echobase-ui/src/main/java/fr/ifremer/echobase/ui echobase-ui/src/main/resources
Author: tchemit Date: 2012-04-04 13:05:41 +0200 (Wed, 04 Apr 2012) New Revision: 486 Url: http://forge.codelutin.com/repositories/revision/echobase/486 Log: fixes #1084: Apr?\195?\168s un import en erreur, impossible d'en recommencer un Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaConnectionProvider.java Modified: trunk/echobase-entities/src/main/resources/topia-h2.properties trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseTopiaTransactionFilter.java trunk/echobase-ui/src/main/resources/echobase.properties Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaConnectionProvider.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaConnectionProvider.java (rev 0) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaConnectionProvider.java 2012-04-04 11:05:41 UTC (rev 486) @@ -0,0 +1,87 @@ +/* + * #%L + * EchoBase :: Entities + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.framework.TopiaConnectionProvider; + +import java.sql.Connection; +import java.sql.SQLException; + +/** + * To fix roolback errors. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.6 + */ +public class EchoBaseTopiaConnectionProvider extends TopiaConnectionProvider { + + /** Logger. */ + private static final Log log = LogFactory.getLog(EchoBaseTopiaConnectionProvider.class); + + @Override + public void closeConnection(Connection conn) throws SQLException { + + // if connection is already closed, nothing has to be done + // we can't keep this connection (and can not be push in pool) + + if (conn.isClosed()) { + + if (log.isDebugEnabled()) { + log.debug("Connection [" + conn + + "] alreay closed!, will not use it any longer "); + } + return; + } + + + // connection was not closed, can push it in the pool (if pool is not + // full) + + synchronized (getPool()) { + int currentSize = getPool().size(); + if (currentSize < getPoolSize()) { + if (log.isTraceEnabled()) { + log.trace("returning connection to pool, pool size: " + + (currentSize + 1)); + } + + // make sure connection is always rollback before keep it + conn.rollback(); + + getPool().add(conn); + return; + } + } + + // pool was full, must release the connection which will be loose + + if (log.isDebugEnabled()) { + log.debug("closing JDBC connection"); + } + + conn.close(); + } +} Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaConnectionProvider.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/echobase-entities/src/main/resources/topia-h2.properties =================================================================== --- trunk/echobase-entities/src/main/resources/topia-h2.properties 2012-04-03 15:04:16 UTC (rev 485) +++ trunk/echobase-entities/src/main/resources/topia-h2.properties 2012-04-04 11:05:41 UTC (rev 486) @@ -28,4 +28,5 @@ hibernate.connection.driver_class=org.h2.Driver hibernate.connection.username=sa hibernate.connection.password=sa -hibernate.connection.provider_class=org.nuiton.topia.framework.TopiaConnectionProvider +hibernate.connection.provider_class=fr.ifremer.echobase.EchoBaseTopiaConnectionProvider +#hibernate.connection.provider_class=org.nuiton.topia.framework.TopiaConnectionProvider Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseTopiaTransactionFilter.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseTopiaTransactionFilter.java 2012-04-03 15:04:16 UTC (rev 485) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseTopiaTransactionFilter.java 2012-04-04 11:05:41 UTC (rev 486) @@ -61,4 +61,34 @@ throw new TopiaRuntimeException("Could not start transaction", eee); } } + + /** + * Hook method to close the topia transaction of the request at the end of + * the request when all filter has been consumed. + * + * @param transaction the transaction to close (can be null if transaction + * was not required while the current request) + * @since 1.9.1 + */ + protected void onCloseTransaction(TopiaContext transaction) { + if (transaction == null) { + if (log.isTraceEnabled()) { + log.trace("no transaction to close"); + } + } else if (transaction.isClosed()) { + if (log.isTraceEnabled()) { + log.trace("transaction " + transaction + " is already closed"); + } + } else { + if (log.isDebugEnabled()) { + log.debug("closing transaction " + transaction); + } + + try { + transaction.closeContext(); + } catch (TopiaException e) { + throw new TopiaRuntimeException(e); + } + } + } } Modified: trunk/echobase-ui/src/main/resources/echobase.properties =================================================================== --- trunk/echobase-ui/src/main/resources/echobase.properties 2012-04-03 15:04:16 UTC (rev 485) +++ trunk/echobase-ui/src/main/resources/echobase.properties 2012-04-04 11:05:41 UTC (rev 486) @@ -28,7 +28,8 @@ hibernate.hbm2ddl.auto=none hibernate.show_sql=false hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.connection.provider_class=org.nuiton.topia.framework.TopiaConnectionProvider +hibernate.connection.provider_class=fr.ifremer.echobase.EchoBaseTopiaConnectionProvider +#hibernate.connection.provider_class=org.nuiton.topia.framework.TopiaConnectionProvider hibernate.connection.driver_class=org.h2.Driver hibernate.connection.url=jdbc:h2:file:${data.directory}/db/echobase
participants (1)
-
tchemit@users.forge.codelutin.com