001/*
002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     matic
016 */
017package org.nuxeo.ecm.core.management.jtajca;
018
019import java.util.Date;
020
021import javax.transaction.SystemException;
022import javax.transaction.Transaction;
023
024/**
025 * @author matic
026 */
027public interface TransactionStatistics {
028
029    enum Status {
030
031        ACTIVE(javax.transaction.Status.STATUS_ACTIVE), COMMITTED(javax.transaction.Status.STATUS_COMMITTED), COMMITTING(
032                javax.transaction.Status.STATUS_COMMITTING), MARKED_ROLLLEDBACK(
033                javax.transaction.Status.STATUS_MARKED_ROLLBACK), NO_TRANSACTION(
034                javax.transaction.Status.STATUS_NO_TRANSACTION), PREPARED(javax.transaction.Status.STATUS_PREPARED), PREPARING(
035                javax.transaction.Status.STATUS_PREPARING), ROLLEDBACK(javax.transaction.Status.STATUS_ROLLEDBACK), ROLLING_BACK(
036                javax.transaction.Status.STATUS_ROLLING_BACK), UNKNOWN(javax.transaction.Status.STATUS_UNKNOWN);
037
038        public final int code;
039
040        Status(int code) {
041            this.code = code;
042        }
043
044        public static Status fromCode(int code) {
045            for (Status e : Status.values()) {
046                if (e.code == code) {
047                    return e;
048                }
049            }
050            return UNKNOWN;
051        }
052
053        public static Status fromTx(Transaction tx) {
054            try {
055                return fromCode(tx.getStatus());
056            } catch (SystemException e) {
057                return UNKNOWN;
058            }
059        }
060    }
061
062    String getId();
063
064    String getThreadName();
065
066    Status getStatus();
067
068    Date getStartDate();
069
070    String getStartCapturedContextMessage();
071
072    Date getEndDate();
073
074    String getEndCapturedContextMessage();
075
076    long getDuration();
077
078    boolean isEnded();
079
080}