1 package org.myoodb.core; 25 26 import org.myoodb.exception.*; 27 28 public final class Lock implements AbstractLock 29 { 30 private long m_lockId; 31 private int m_level = ACCESS_NONE; 32 33 public Lock() 34 { 35 reset(); 36 } 37 38 public int tryAcquire(AbstractTransaction tx, int level) 39 { 40 synchronized (this) 41 { 42 int prevLevel = getLockLevel(tx); 43 44 if ((m_lockId == -1) || (isAcquiredBy(tx) == true)) 45 { 46 m_lockId = tx.getTransactionIdentifier(); 47 m_level = level > m_level ? level : m_level; 48 return prevLevel; 49 } 50 else 51 { 52 return NOT_ACQUIRED; 53 } 54 } 55 } 56 57 public void release(AbstractTransaction tx) 58 { 59 65 66 reset(); 67 } 68 69 public boolean isAcquiredBy(AbstractTransaction tx) 70 { 71 return (m_lockId != -1) ? (m_lockId == tx.getTransactionIdentifier()) : false; 72 } 73 74 public long getLockIdentifier() 75 { 76 return m_lockId; 77 } 78 79 public int getLockLevel(AbstractTransaction tx) 80 { 81 if (tx != null) 82 { 83 return isAcquiredBy(tx) ? m_level : ACCESS_NONE; 84 } 85 else 86 { 87 return m_level; 88 } 89 } 90 91 public int getLockLevel() 92 { 93 return m_level; 94 } 95 96 public void reset() 97 { 98 synchronized (this) 99 { 100 m_lockId = -1; 101 m_level = ACCESS_NONE; 102 } 103 } 104 } 105 | Popular Tags |