1 package org.myoodb.core; 25 26 public final class IdentifierManager extends AbstractManager 27 { 28 public final static String XID = "myoodb.xid"; 29 public final static long BLOCK_SIZE = 100; 30 31 private long m_objectIdentifierBlock; 32 private long m_objectIdentifierBegin; 33 private long m_objectIdentifierEnd; 34 35 private long m_connectionIdentifier; 36 private long m_transactionIdentifier; 37 38 public IdentifierManager() 39 { 40 reset(); 41 } 42 43 private void store() 44 { 45 try 46 { 47 MyOodbManager.getTheManager().getIdentifierProperties().setLongProperty(XID, m_objectIdentifierBlock); 48 MyOodbManager.getTheManager().storeIdentifierProperties(); 49 } 50 catch (Exception e) 51 { 52 MyOodbManager.getTheManager().fatalError(this, "Identifier Manager unable to store identifier: " + e, e); 53 } 54 } 55 56 public void startup() throws Exception 57 { 58 } 59 60 public void shutdown() throws Exception 61 { 62 } 63 64 public void reset() 65 { 66 m_objectIdentifierBlock = -1; 67 m_objectIdentifierBegin = 0; 68 m_objectIdentifierEnd = 0; 69 70 m_connectionIdentifier = 0; 71 m_transactionIdentifier = 0; 72 } 73 74 public synchronized long getNextObjectId() 75 { 76 if (m_objectIdentifierBlock == -1) 77 { 78 m_objectIdentifierBlock = MyOodbManager.getTheManager().getIdentifierProperties().getLongProperty(XID, -1); 79 80 if (m_objectIdentifierBlock == -1) 81 { 82 MyOodbManager.getTheManager().fatalError(this, "Identifier Manager unable to access the " + XID + " property.", null); 83 } 84 else if (m_objectIdentifierBlock != 0) 85 { 86 m_objectIdentifierEnd = m_objectIdentifierBlock; 87 } 88 89 m_objectIdentifierBlock += BLOCK_SIZE; 90 91 store(); 92 } 93 94 if (m_objectIdentifierBegin >= BLOCK_SIZE) 95 { 96 m_objectIdentifierBegin = 0; 97 m_objectIdentifierEnd = m_objectIdentifierBlock; 98 99 m_objectIdentifierBlock += BLOCK_SIZE; 100 101 store(); 102 } 103 104 return ++m_objectIdentifierBegin + m_objectIdentifierEnd; 105 } 106 107 public synchronized long getNextConnectionId() 108 { 109 return ++m_connectionIdentifier; 110 } 111 112 public synchronized long getNextTransactionId() 113 { 114 return ++m_transactionIdentifier; 115 } 116 } 117 | Popular Tags |