001: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.utils;
007:
008: import java.sql.Connection;
009: import java.sql.SQLException;
010:
011: import org.jasig.portal.RDBMServices;
012: import org.apache.commons.logging.Log;
013: import org.apache.commons.logging.LogFactory;
014:
015: /**
016: * This type is a place to centralize the portal's sql transaction code.
017: * @author Dan Ellentuck
018: * @version $Revision: 36101 $
019: */
020: public class SqlTransaction {
021: private static final Log log = LogFactory
022: .getLog(SqlTransaction.class);
023:
024: /**
025: * SqlTransaction constructor comment.
026: */
027: public SqlTransaction() {
028: super ();
029: }
030:
031: /**
032: * @param conn java.sql.Connection
033: * @exception java.sql.SQLException
034: */
035: public static void begin(Connection conn)
036: throws java.sql.SQLException {
037: /*
038: * Previously this method was invoked in a try-catch SQLException block.
039: * Prior to 2.5.1, RDBMS.setAutoCommit didn't actually throw SQLException, and
040: * as of 2.5.1 its method declaration was corrected to reflect this.
041: */
042: RDBMServices.setAutoCommit(conn, false);
043: }
044:
045: /**
046: * @param conn java.sql.Connection
047: * @exception java.sql.SQLException
048: */
049: public static void commit(Connection conn)
050: throws java.sql.SQLException {
051: /*
052: * Previously this method was invoked in a try-catch SQLException block.
053: * Prior to 2.5.1, RDBMS.commit() and RDBMS.setAutoCommit didn't actually
054: * throw SQLException, and as of 2.5.1 its method declaration was corrected
055: * to reflect this.
056: */
057: RDBMServices.commit(conn);
058: RDBMServices.setAutoCommit(conn, true);
059: }
060:
061: /**
062: *
063: */
064: protected static void logNoTransactionWarning() {
065: String msg = "You are running the portal on a database that does not support transactions. "
066: + "This is not a supported production environment for uPortal. "
067: + "Sooner or later, your database will become corrupt.";
068: log.warn(msg);
069: }
070:
071: /**
072: * @param conn java.sql.Connection
073: * @exception java.sql.SQLException
074: */
075: public static void rollback(Connection conn)
076: throws java.sql.SQLException {
077: try {
078: RDBMServices.rollback(conn);
079: RDBMServices.setAutoCommit(conn, true);
080: } catch (SQLException sqle) {
081: log.error("Error rolling back connection.", sqle);
082: throw sqle;
083: }
084: }
085:
086: /**
087: * @param conn java.sql.Connection
088: * @param newValue boolean
089: * @exception java.sql.SQLException
090: */
091: public static void setAutoCommit(Connection conn, boolean newValue)
092: throws java.sql.SQLException {
093: /*
094: * Previously this method was invoked in a try-catch SQLException block.
095: * Prior to 2.5.1, RDBMS.setAutocommit() didn't actually
096: * throw SQLException, and as of 2.5.1 its method declaration was corrected
097: * to reflect this.
098: */
099: RDBMServices.setAutoCommit(conn, newValue);
100: }
101:
102: }
|