1 package org.myoodb; 25 26 public final class MyOodbTransaction 27 { 28 private MyOodbDatabase m_database; 29 private java.util.LinkedList m_transactions; 30 31 private long m_transactionIdentifier; 32 private java.lang.Thread m_transactionThread; 33 private org.myoodb.core.AbstractConnection m_databaseConnection; 34 35 public MyOodbTransaction(MyOodbDatabase database) 36 { 37 m_database = database; 38 m_transactions = new java.util.LinkedList (); 39 40 m_transactionIdentifier = -1; 41 m_transactionThread = null; 42 m_databaseConnection = null; 43 } 44 45 protected void setTransactionThread(java.lang.Thread thread) 46 { 47 m_transactionThread = thread; 48 } 49 50 protected void setTransactionIdentifier(long transactionId) 51 { 52 m_transactionIdentifier = transactionId; 53 } 54 55 protected void setDatabaseConnection(org.myoodb.core.AbstractConnection databaseConnection) 56 { 57 m_databaseConnection = databaseConnection; 58 } 59 60 protected org.myoodb.core.AbstractConnection getDatabaseConnection() 61 { 62 return m_databaseConnection; 63 } 64 65 public MyOodbDatabase getDatabase() 66 { 67 return m_database; 68 } 69 70 public long getTransactionIdentifier() 71 { 72 long transactionId = -1; 73 74 if (m_transactions.size() == 0) 75 { 76 throw new org.myoodb.exception.TransactionException("Transaction has no id"); 77 } 78 else if (m_transactions.size() == 1) 79 { 80 transactionId = m_transactionIdentifier; 81 } 82 else 83 { 84 MyOodbTransaction subTx = (MyOodbTransaction) m_transactions.getLast(); 85 transactionId = subTx.getTransactionIdentifier(); 86 } 87 88 return transactionId; 89 } 90 91 public java.lang.Thread getTransactionThread() 92 { 93 return m_transactionThread; 94 } 95 96 public java.util.ArrayList getTransactions() 97 { 98 return new java.util.ArrayList (m_transactions); 99 } 100 101 public synchronized void begin() throws Exception 102 { 103 if (m_transactions.size() == 0) 104 { 105 m_transactions.add(this); 106 m_database.beginTransaction(this); 107 } 108 else 109 { 110 MyOodbTransaction subTx = m_database.createTransaction(); 111 m_transactions.add(subTx); 112 subTx.begin(); 113 } 114 } 115 116 public synchronized void join() throws Exception 117 { 118 if (m_transactions.size() == 0) 119 { 120 throw new org.myoodb.exception.TransactionException("Transaction has nothing to join"); 121 } 122 else if (m_transactions.size() == 1) 123 { 124 m_database.leaveTransaction(this); 125 m_database.joinTransaction(this); 126 } 127 else 128 { 129 MyOodbTransaction subTx = (MyOodbTransaction) m_transactions.getLast(); 130 subTx.join(); 131 } 132 } 133 134 public synchronized void transfer(Thread thread) throws Exception 135 { 136 if (m_transactions.size() == 0) 137 { 138 throw new org.myoodb.exception.TransactionException("Transaction has nothing to transfer"); 139 } 140 else if (m_transactions.size() == 1) 141 { 142 m_database.transferTransaction(this, thread); 143 } 144 else 145 { 146 MyOodbTransaction subTx = (MyOodbTransaction) m_transactions.getLast(); 147 subTx.transfer(thread); 148 } 149 } 150 151 public synchronized void leave() throws Exception 152 { 153 if (m_transactions.size() == 0) 154 { 155 throw new org.myoodb.exception.TransactionException("Transaction has nothing to leave"); 156 } 157 else if (m_transactions.size() == 1) 158 { 159 m_database.leaveTransaction(this); 160 } 161 else 162 { 163 MyOodbTransaction subTx = (MyOodbTransaction) m_transactions.getLast(); 164 subTx.leave(); 165 } 166 } 167 168 public synchronized void commit() throws Exception 169 { 170 if (m_transactions.size() == 0) 171 { 172 throw new org.myoodb.exception.TransactionException("Transaction has nothing to commit"); 173 } 174 else if (m_transactions.size() == 1) 175 { 176 m_transactions.removeLast(); 177 m_database.commitTransaction(this); 178 } 179 else 180 { 181 MyOodbTransaction subTx = (MyOodbTransaction) m_transactions.removeLast(); 182 subTx.commit(); 183 } 184 } 185 186 public synchronized void rollback() throws Exception 187 { 188 if (m_transactions.size() == 0) 189 { 190 throw new org.myoodb.exception.TransactionException("Transaction has nothing to rollback"); 191 } 192 else if (m_transactions.size() == 1) 193 { 194 m_transactions.removeLast(); 195 m_database.rollbackTransaction(this); 196 } 197 else 198 { 199 MyOodbTransaction subTx = (MyOodbTransaction) m_transactions.removeLast(); 200 subTx.rollback(); 201 } 202 } 203 204 public synchronized int getStatus() throws Exception 205 { 206 if (m_transactions.size() == 0) 207 { 208 throw new org.myoodb.exception.TransactionException("Transaction has no status"); 209 } 210 211 return m_database.getStatusTransaction((MyOodbTransaction) m_transactions.getLast()); 212 } 213 } 214 | Popular Tags |