1 18 package org.objectweb.perseus.persistence.lib; 19 20 import org.objectweb.perseus.persistence.api.ConnectionHolder; 21 import org.objectweb.perseus.persistence.api.TransactionalWorkingSet; 22 import org.objectweb.perseus.persistence.api.State; 23 import org.objectweb.perseus.persistence.api.PersistenceException; 24 import org.objectweb.util.monolog.api.Logger; 25 import org.objectweb.util.monolog.api.BasicLevel; 26 import org.objectweb.fractal.api.control.BindingController; 27 28 import java.util.Set ; 29 import java.util.HashSet ; 30 import java.util.LinkedHashMap ; 31 32 37 public class BasicWorkingSet 38 implements TransactionalWorkingSet, BindingController { 39 40 protected Logger logger = null; 41 protected LinkedHashMap oid2state; 42 protected byte status; 43 protected Object userObject; 44 protected ConnectionHolder connectionHolder; 45 protected boolean retainValues = true; 46 protected boolean restoreValues = false; 47 protected boolean rollBackOnly = false; 48 49 public BasicWorkingSet() { 50 status = CTX_ACTIVE; 51 oid2state = new LinkedHashMap (); 52 userObject = null; 53 connectionHolder = null; 54 } 55 56 59 public String [] listFc() { 60 return new String [] { }; 61 } 62 63 public Object lookupFc(String c) { 64 return null; 65 } 66 67 public void bindFc(String c, Object s) { 68 if ("logger".equals(c)) { 69 logger = (Logger) s; 70 } 71 } 72 73 public void unbindFc(String c) { 74 } 75 76 79 public byte getStatus() { 80 return status; 81 } 82 83 public void setStatus(byte status) throws PersistenceException { 84 this.status = status; 85 } 86 87 90 public State lookup(Object oid) { 91 return (State) oid2state.get(oid); 92 } 93 94 100 public State bind(State state, Object oid, byte mode) { 101 Object old; 102 synchronized(oid2state) { 103 old = oid2state.put(oid, state); 104 } 105 if (logger.isLoggable(BasicLevel.DEBUG)) { 106 if (old == null) { 107 logger.log(BasicLevel.DEBUG, 108 "Bind (" + oid + ", " + state + ") to the context"); 109 } else { 110 logger.log(BasicLevel.DEBUG, 111 "Change the state in the context" 112 + "\n-oid=" + oid 113 + "\n-old state=" + old 114 + "\n- new state=" + state); 115 } 116 } 117 return (State)old; 118 } 119 120 124 public boolean unbind(Object oid) { 125 if (logger.isLoggable(BasicLevel.DEBUG)) 126 logger.log(BasicLevel.DEBUG, "UnBind " + oid + " from the context"); 127 synchronized(oid2state) { 128 return (oid2state.remove(oid) == null); 129 } 130 } 131 132 135 public void clear() { 136 synchronized(oid2state) { 137 oid2state.clear(); 138 } 139 } 140 141 144 public Set entries() { 145 synchronized(oid2state) { 146 return new HashSet (oid2state.values()); 147 } 148 } 149 150 public Set oids() { 151 return oid2state.keySet(); 152 } 153 154 public Object getUserObject() { 155 return userObject; 156 } 157 158 public ConnectionHolder getConnectionHolder() { 159 return connectionHolder; 160 } 161 162 public boolean getWSRetainValues() { 163 return retainValues; 164 } 165 166 public void setWSRetainValues(boolean val) { 167 retainValues = val; 168 } 169 170 public boolean getWSRestoreValues() { 171 return restoreValues; 172 } 173 174 public void setWSRestoreValues(boolean val) { 175 restoreValues = val; 176 } 177 178 public boolean getWSRollBackOnly() { 179 return rollBackOnly; 180 } 181 public void setWSRollBackOnly(boolean val) { 182 rollBackOnly = val; 183 } 184 } 185 | Popular Tags |