public void doTag()

in jelly-tags/sql/src/main/java/org/apache/commons/jelly/tags/sql/TransactionTag.java [81:135]


    public void doTag(XMLOutput output) throws JellyTagException {

        if ((rawDataSource == null) && dataSourceSpecified) {
            throw new JellyTagException(Resources.getMessage("SQL_DATASOURCE_NULL"));
        }

        DataSource dataSource = DataSourceUtil.getDataSource(rawDataSource, context);

        try {
            conn = dataSource.getConnection();
            origIsolation = conn.getTransactionIsolation();
            if (origIsolation == Connection.TRANSACTION_NONE) {
                throw new JellyTagException(Resources.getMessage("TRANSACTION_NO_SUPPORT"));
            }
            if ((isolation != Connection.TRANSACTION_NONE)
                && (isolation != origIsolation)) {
                conn.setTransactionIsolation(isolation);
            }
            conn.setAutoCommit(false);
        }
        catch (SQLException e) {
            throw new JellyTagException(
                Resources.getMessage("ERROR_GET_CONNECTION", e.getMessage()));
        }

        boolean finished = false;
        try {
            invokeBody(output);
            finished = true;
        }
        catch (Exception e) {
            if (conn != null) {
                try {
                    conn.rollback();
                }
                catch (SQLException s) {
                    // Ignore to not hide orignal exception
                }
                doFinally();
            }
            throw new JellyTagException(e);
        }

        // lets commit
        try {
            conn.commit();
        }
        catch (SQLException e) {
            throw new JellyTagException(
                Resources.getMessage("TRANSACTION_COMMIT_ERROR", e.getMessage()));
        }
        finally {
            doFinally();
        }
    }