details: https://code.openbravo.com/erp/devel/pi/rev/4ece62a0e09c changeset: 29957:4ece62a0e09c user: Gorka Ion Damián <gorkaion.damian <at> openbravo.com> date: Wed Aug 31 11:42:06 2016 +0200 summary: Fixed issue 33750.Add new methods in SessionHandler to manage transactions.
Two new public methods added: - isCurrentTransactionActive() - beginNewTransaction() These methods are needed to be able to modify the database in EventHandlers that are fired when the transaction is completed. diffstat: src-db/database/sourcedata/AD_MESSAGE.xml | 12 ++++++++++++ src/org/openbravo/dal/core/SessionHandler.java | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 0 deletions(-) diffs (60 lines): diff -r 43453b625a06 -r 4ece62a0e09c src-db/database/sourcedata/AD_MESSAGE.xml --- a/src-db/database/sourcedata/AD_MESSAGE.xml Wed Aug 31 11:25:47 2016 +0200 +++ b/src-db/database/sourcedata/AD_MESSAGE.xml Wed Aug 31 11:42:06 2016 +0200 @@ -18271,6 +18271,18 @@ <!--32E491425B01464C9EADC1F4FA0D9F78--> <ISINCLUDEINI18N><![CDATA[Y]]></ISINCLUDEINI18N> <!--32E491425B01464C9EADC1F4FA0D9F78--></AD_MESSAGE> +<!--3324141A8D04401B9ED57CCF3A2B7BE7--><AD_MESSAGE> +<!--3324141A8D04401B9ED57CCF3A2B7BE7--> <AD_MESSAGE_ID><![CDATA[3324141A8D04401B9ED57CCF3A2B7BE7]]></AD_MESSAGE_ID> +<!--3324141A8D04401B9ED57CCF3A2B7BE7--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> +<!--3324141A8D04401B9ED57CCF3A2B7BE7--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID> +<!--3324141A8D04401B9ED57CCF3A2B7BE7--> <ISACTIVE><![CDATA[Y]]></ISACTIVE> +<!--3324141A8D04401B9ED57CCF3A2B7BE7--> <VALUE><![CDATA[NewTrxCreationCheck]]></VALUE> +<!--3324141A8D04401B9ED57CCF3A2B7BE7--> <MSGTEXT><![CDATA[It is not possible to start a new transaction while there is still one active. Please contact your system administrator to solve the issue.]]></MSGTEXT> +<!--3324141A8D04401B9ED57CCF3A2B7BE7--> <MSGTYPE><![CDATA[E]]></MSGTYPE> +<!--3324141A8D04401B9ED57CCF3A2B7BE7--> <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID> +<!--3324141A8D04401B9ED57CCF3A2B7BE7--> <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N> +<!--3324141A8D04401B9ED57CCF3A2B7BE7--></AD_MESSAGE> + <!--3346DD643A854521B2429785B9362D5E--><AD_MESSAGE> <!--3346DD643A854521B2429785B9362D5E--> <AD_MESSAGE_ID><![CDATA[3346DD643A854521B2429785B9362D5E]]></AD_MESSAGE_ID> <!--3346DD643A854521B2429785B9362D5E--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID> diff -r 43453b625a06 -r 4ece62a0e09c src/org/openbravo/dal/core/SessionHandler.java --- a/src/org/openbravo/dal/core/SessionHandler.java Wed Aug 31 11:25:47 2016 +0200 +++ b/src/org/openbravo/dal/core/SessionHandler.java Wed Aug 31 11:42:06 2016 +0200 @@ -40,6 +40,7 @@ import org.openbravo.base.util.Check; import org.openbravo.dal.service.OBDal; import org.openbravo.database.ExternalConnectionPool; +import org.openbravo.erpCommon.utility.OBMessageUtils; import org.openbravo.database.SessionInfo; import org.openbravo.service.db.DbUtility; @@ -165,6 +166,26 @@ } } + /** + * Returns true when the current SessionHandler has a transaction and it is active. + */ + public boolean isCurrentTransactionActive() { + return tx != null && tx.isActive(); + } + + /** + * Begins a new Transaction on the current HibernateSession and assigns it to the SessionHandler. + * + * @throws OBException + * if there is already an available active transaction. + */ + public void beginNewTransaction() throws OBException { + if (isCurrentTransactionActive()) { + throw new OBException(OBMessageUtils.messageBD("NewTrxCreationCheck")); + } + tx = getSession().beginTransaction(); + } + /** Gets a new {@code Connection} from the connection pool. */ public Connection getNewConnection() throws SQLException { Connection newConnection; ------------------------------------------------------------------------------ _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits