1 24 package org.objectweb.jalisto.se.impl.lock; 25 26 import org.objectweb.jalisto.se.impl.LogicalOid; 27 import org.objectweb.jalisto.se.api.internal.DataWrapper; 28 29 import java.util.Iterator ; 30 31 public class LockManagerPessimistic extends LockManagerDefault { 32 33 public void prepareCreateObject(LogicalOid floid, DataWrapper objectToCreate) { 34 takeLock(floid, WRITE); 35 } 36 37 public void prepareDeleteObjectByOid(LogicalOid floid, short update) { 38 takeLock(floid, WRITE).addTransactionnalValue(sessionId, null, 39 ObjectTransactionnalState.DELETE_ACTION, 40 (short) 0); 41 } 42 43 public void prepareReadObjectByOid(LogicalOid floid) { 44 takeLock(floid, READ); 45 } 46 47 public void prepareUpdateObjectByOid(LogicalOid floid, DataWrapper objectToUpdate) { 48 takeLock(floid, WRITE); 49 } 50 51 52 public void finishCreateObject(LogicalOid floid, DataWrapper objectToCreate) { 53 lockTable.getLock(floid).addTransactionnalValue(sessionId, objectToCreate, 54 ObjectTransactionnalState.CREATE_ACTION, (short) 0); 55 } 56 57 public void finishReadObjectByOid(LogicalOid floid, DataWrapper objectToRead, short update) { 58 lockTable.getLock(floid).addTransactionnalValue(sessionId, objectToRead, 59 ObjectTransactionnalState.READ_ACTION, update); 60 } 61 62 public void finishUpdateObjectByOid(LogicalOid floid, DataWrapper objectToUpdate, short update) { 63 takeLock(floid, WRITE).addTransactionnalValue(sessionId, objectToUpdate, 64 ObjectTransactionnalState.UPDATE_ACTION, update); 65 } 66 67 68 public synchronized void commit() { 69 try { 70 accessController.getAccessControl(AccessController.COMMIT_ROLLBACK_LOCKMANAGER); 71 Iterator floids = lockTable.getKeys(); 72 while (floids.hasNext()) { 73 LogicalOid floid = (LogicalOid) floids.next(); 74 Lock lock = lockTable.getLockOrCreate(floid); 75 if (lock.hasModifiedValueWith(sessionId)) { 76 if (lock.hasWriteLockWith(sessionId)) { 77 if (lock.getCurrentAction(sessionId) == ObjectTransactionnalState.CREATE_ACTION) { 78 session.createObjectCommit(floid); 79 } else if (lock.getCurrentAction(sessionId) == ObjectTransactionnalState.UPDATE_ACTION) { 80 lock.update(sessionId); 81 session.updateObjectCommit(floid); 82 } else if (lock.getCurrentAction(sessionId) == ObjectTransactionnalState.DELETE_ACTION) { 83 session.deleteObjectCommit(floid); 84 } else if (lock.getCurrentAction(sessionId) == ObjectTransactionnalState.NEW_OID_ACTION) { 85 session.makeNewFileOidCommit(floid); 86 } 87 } 88 lock.releaseAllLock(sessionId); 89 lockTable.removeLockByFloid(floid); 90 } 91 } 92 session.getFileAccess().getPhysicalAccess().commit(); 93 } finally { 94 accessController.releaseAccessControl(AccessController.COMMIT_ROLLBACK_LOCKMANAGER); 95 } 96 } 97 98 public synchronized void rollback() { 99 try { 100 accessController.getAccessControl(AccessController.COMMIT_ROLLBACK_LOCKMANAGER); 101 Iterator floids = lockTable.getKeys(); 102 while (floids.hasNext()) { 103 LogicalOid floid = (LogicalOid) floids.next(); 104 Lock lock = lockTable.getLockOrCreate(floid); 105 if (lock.hasModifiedValueWith(sessionId)) { 106 if (lock.hasWriteLockWith(sessionId)) { 107 if (lock.getCurrentAction(sessionId) == ObjectTransactionnalState.CREATE_ACTION) { 108 session.createObjectRollback(floid); 109 } else if (lock.getCurrentAction(sessionId) == ObjectTransactionnalState.UPDATE_ACTION) { 110 session.updateObjectRollback(floid); 111 } else if (lock.getCurrentAction(sessionId) == ObjectTransactionnalState.DELETE_ACTION) { 112 session.deleteObjectRollback(floid); 113 } else if (lock.getCurrentAction(sessionId) == ObjectTransactionnalState.NEW_OID_ACTION) { 114 session.makeNewFileOidRollback(floid); 115 } 116 } 117 lock.releaseAllLock(sessionId); 118 lockTable.removeLockByFloid(floid); 119 } 120 } 121 session.getFileAccess().rollback(sessionId); 122 } finally { 123 accessController.releaseAccessControl(AccessController.COMMIT_ROLLBACK_LOCKMANAGER); 124 } 125 } 126 127 } 128 | Popular Tags |