/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2009 Oracle. All rights reserved.
*
*/
using System;
using System.Collections.Generic;
using System.Text;
using BerkeleyDB.Internal;
namespace BerkeleyDB {
///
/// The ActiveTransaction class describes a currently active transaction.
///
public class ActiveTransaction {
private DB_TXN_ACTIVE txn;
private LSN _lsn;
private LSN _read_lsn;
private byte[] gid;
private string txnname;
internal ActiveTransaction(DB_TXN_ACTIVE active, byte[] GlobalID, string Name) {
txn = active;
_lsn = new LSN(txn.lsn.file, txn.lsn.offset);
_read_lsn = new LSN(txn.read_lsn.file, txn.read_lsn.offset);
gid = GlobalID;
txnname = Name;
}
///
/// The status of an active transaction.
///
public enum TransactionStatus {
///
/// The transaction has been aborted
///
ABORTED = DB_TXN_ACTIVE_STATUS.TXN_ABORTED,
///
/// The transaction has been committed
///
COMMITTED = DB_TXN_ACTIVE_STATUS.TXN_COMMITTED,
///
/// The transaction has been prepared
///
PREPARED = DB_TXN_ACTIVE_STATUS.TXN_PREPARED,
///
/// The transaction is running
///
RUNNING = DB_TXN_ACTIVE_STATUS.TXN_RUNNING
}
///
/// The transaction ID of the transaction.
///
public uint ID { get { return txn.txnid; } }
///
/// The transaction ID of the parent transaction (or 0, if no parent).
///
public uint ParentID { get { return txn.parentid; } }
///
/// The process ID of the originator of the transaction.
///
public int ProcessID { get { return txn.pid; } }
///
/// The thread of control ID of the originator of the transaction.
///
public uint ThreadID { get { return txn.tid; } }
///
/// The current log sequence number when the transaction was begun.
///
public LSN Begun { get { return _lsn; } }
///
/// The log sequence number of reads for snapshot transactions.
///
public LSN SnapshotReads { get { return _read_lsn; } }
///
/// The number of MVCC buffer copies created by this transaction that
/// remain in cache.
///
public uint BufferCopiesInCache { get { return txn.mvcc_ref; } }
///
/// Status of the transaction.
///
public TransactionStatus Status {
get { return (TransactionStatus)txn.status; }
}
///
/// If the transaction is a prepare transaction, the transaction's
/// Global ID. Otherwise, the GlobalID contents are undefined.
///
public byte[] GlobalID { get { return gid; } }
///
/// If a name was specified for the transaction, up to the first 50
/// bytes of that name.
///
public string Name { get { return txnname; } }
}
}