1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2009 Oracle. All rights reserved. 5 * 6 */ 7using System; 8using System.Collections.Generic; 9using System.Text; 10using BerkeleyDB.Internal; 11 12namespace BerkeleyDB { 13 /// <summary> 14 /// The ActiveTransaction class describes a currently active transaction. 15 /// </summary> 16 public class ActiveTransaction { 17 private DB_TXN_ACTIVE txn; 18 private LSN _lsn; 19 private LSN _read_lsn; 20 private byte[] gid; 21 private string txnname; 22 23 internal ActiveTransaction(DB_TXN_ACTIVE active, byte[] GlobalID, string Name) { 24 txn = active; 25 _lsn = new LSN(txn.lsn.file, txn.lsn.offset); 26 _read_lsn = new LSN(txn.read_lsn.file, txn.read_lsn.offset); 27 gid = GlobalID; 28 txnname = Name; 29 } 30 31 /// <summary> 32 /// The status of an active transaction. 33 /// </summary> 34 public enum TransactionStatus { 35 /// <summary> 36 /// The transaction has been aborted 37 /// </summary> 38 ABORTED = DB_TXN_ACTIVE_STATUS.TXN_ABORTED, 39 /// <summary> 40 /// The transaction has been committed 41 /// </summary> 42 COMMITTED = DB_TXN_ACTIVE_STATUS.TXN_COMMITTED, 43 /// <summary> 44 /// The transaction has been prepared 45 /// </summary> 46 PREPARED = DB_TXN_ACTIVE_STATUS.TXN_PREPARED, 47 /// <summary> 48 /// The transaction is running 49 /// </summary> 50 RUNNING = DB_TXN_ACTIVE_STATUS.TXN_RUNNING 51 } 52 53 /// <summary> 54 /// The transaction ID of the transaction. 55 /// </summary> 56 public uint ID { get { return txn.txnid; } } 57 /// <summary> 58 /// The transaction ID of the parent transaction (or 0, if no parent). 59 /// </summary> 60 public uint ParentID { get { return txn.parentid; } } 61 /// <summary> 62 /// The process ID of the originator of the transaction. 63 /// </summary> 64 public int ProcessID { get { return txn.pid; } } 65 /// <summary> 66 /// The thread of control ID of the originator of the transaction. 67 /// </summary> 68 public uint ThreadID { get { return txn.tid; } } 69 /// <summary> 70 /// The current log sequence number when the transaction was begun. 71 /// </summary> 72 public LSN Begun { get { return _lsn; } } 73 /// <summary> 74 /// The log sequence number of reads for snapshot transactions. 75 /// </summary> 76 public LSN SnapshotReads { get { return _read_lsn; } } 77 /// <summary> 78 /// The number of MVCC buffer copies created by this transaction that 79 /// remain in cache. 80 /// </summary> 81 public uint BufferCopiesInCache { get { return txn.mvcc_ref; } } 82 /// <summary> 83 /// Status of the transaction. 84 /// </summary> 85 public TransactionStatus Status { 86 get { return (TransactionStatus)txn.status; } 87 } 88 /// <summary> 89 /// If the transaction is a prepare transaction, the transaction's 90 /// Global ID. Otherwise, the GlobalID contents are undefined. 91 /// </summary> 92 public byte[] GlobalID { get { return gid; } } 93 /// <summary> 94 /// If a name was specified for the transaction, up to the first 50 95 /// bytes of that name. 96 /// </summary> 97 public string Name { get { return txnname; } } 98 } 99} 100