1 package org.myoodb.collectable; 25 26 public class CollectableDbImpl extends org.myoodb.MyOodbObject implements Collectable 27 { 28 private static long m_lastLocalTime = 0; 29 30 protected long m_lastFixUpTime; 31 32 public static synchronized long getSynchronizedLocalTime() 33 { 34 long localtime = new java.util.Date ().getTime(); 35 36 if (m_lastLocalTime >= localtime) 37 { 38 localtime = m_lastLocalTime + 1; 39 } 40 41 m_lastLocalTime = localtime; 42 43 return localtime; 44 } 45 46 public static void fixUpReference(java.util.Collection container, long fixUpTime) 47 { 48 java.util.Iterator iter = container.iterator(); 49 while (iter.hasNext()) 50 { 51 Object object = iter.next(); 52 53 try 54 { 55 if (object instanceof Collectable) 56 { 57 ((Collectable) object).fixUpReference(fixUpTime); 58 } 59 } 60 catch (org.myoodb.exception.ObjectNotFoundException e) 61 { 62 iter.remove(); 63 } 64 } 65 } 66 67 public static void fixUpReference(java.util.Map container, long fixUpTime) 68 { 69 java.util.Iterator iter = container.values().iterator(); 70 while (iter.hasNext()) 71 { 72 Object object = iter.next(); 73 74 try 75 { 76 if (object instanceof Collectable) 77 { 78 ((Collectable) object).fixUpReference(fixUpTime); 79 } 80 } 81 catch (org.myoodb.exception.ObjectNotFoundException e) 82 { 83 iter.remove(); 84 } 85 } 86 } 87 88 public CollectableDbImpl() 89 { 90 m_lastFixUpTime = 0; 91 } 92 93 private org.myoodb.core.AbstractTransaction getCurrentlyAssociatedTransaction() 94 { 95 return org.myoodb.core.MyOodbManager.getTheManager().getTransactionManager().getTransaction(getLockIdentifier()); 96 } 97 98 protected String invokedBy() 99 { 100 String owner = ""; 101 102 java.lang.Thread thread = java.lang.Thread.currentThread(); 103 104 if (thread instanceof org.myoodb.core.command.CommandThread) 105 { 106 owner = ((org.myoodb.core.command.CommandThread) thread).getOwner().getName(); 107 } 108 109 return owner; 110 } 111 112 protected boolean referenceHasBeenFixedUp(long fixUpTime) 113 { 114 return fixUpTime <= m_lastFixUpTime; 115 } 116 117 public long getLocalTime() 118 { 119 return getSynchronizedLocalTime(); 120 } 121 122 public void lock() 123 { 124 } 126 127 public boolean isLocked() 128 { 129 return (getContainer().getLock().getLockLevel() >= org.myoodb.core.AbstractLock.ACCESS_WRITE); 130 } 131 132 public boolean isImplicitLock() 133 { 134 org.myoodb.core.AbstractTransaction tx = getCurrentlyAssociatedTransaction(); 135 return ((tx != null) && (tx.getTransactionType() == org.myoodb.core.AbstractTransaction.IMPLICIT_TRANSACTION)); 136 } 137 138 public boolean isExplicitLock() 139 { 140 org.myoodb.core.AbstractTransaction tx = getCurrentlyAssociatedTransaction(); 141 return ((tx != null) && (tx.getTransactionType() == org.myoodb.core.AbstractTransaction.EXPLICIT_TRANSACTION)); 142 } 143 144 public String isLockedBy() 145 { 146 org.myoodb.core.AbstractTransaction tx = getCurrentlyAssociatedTransaction(); 147 return (tx != null) ? tx.getOwner().getName() : null; 148 } 149 150 public long getLockIdentifier() 151 { 152 return getContainer().getLock().getLockIdentifier(); 153 } 154 155 public void testReference() 156 { 157 } 159 160 public void cleanUpReference() 161 { 162 } 164 165 public void fixUpReference(long fixUpTime) 166 { 167 m_lastFixUpTime = fixUpTime; 168 } 169 170 public String toString() 171 { 172 return super.toString(); 173 } 174 } 175 | Popular Tags |