1 24 package fr.dyade.aaa.util; 25 26 import java.io.*; 27 28 public class NullTransaction implements Transaction, NullTransactionMBean { 29 private int phase = INIT; 31 32 private final void setPhase(int newPhase) { 33 phase = newPhase; 34 } 35 36 39 public int getPhase() { 40 return phase; 41 } 42 43 public String getPhaseInfo() { 44 return PhaseInfo[phase]; 45 } 46 47 public NullTransaction() {} 48 49 54 public boolean isPersistent() { 55 return false; 56 } 57 58 public void init(String path) throws IOException { 59 phase = INIT; 60 61 62 setPhase(FREE); 63 } 64 65 public File getDir() { 66 return null; 67 } 68 69 74 public String getPersistenceDir() { 75 return null; 76 } 77 78 public synchronized void begin() throws IOException { 79 while (phase != FREE) { 80 try { 81 wait(); 82 } catch (InterruptedException exc) { 83 } 84 } 85 setPhase(RUN); 87 } 88 89 public String [] getList(String prefix) { 90 return new String [0]; 91 } 92 93 public void save(Serializable obj, String name) throws IOException {} 94 95 public void saveByteArray(byte[] buf, String name) throws IOException {} 96 97 public Object load(String name) throws IOException, ClassNotFoundException { 98 return null; 99 } 100 101 public byte[] loadByteArray(String name) throws IOException, ClassNotFoundException { 102 return null; 103 } 104 105 public void delete(String name) {} 106 107 public void save(Serializable obj, String dirName, String name) throws IOException {} 108 109 public void saveByteArray(byte[] buf, String dirName, String name) throws IOException {} 110 111 public Object load(String dirName, String name) throws IOException, ClassNotFoundException { 112 return null; 113 } 114 115 public byte[] loadByteArray(String dirName, String name) throws IOException { 116 return null; 117 } 118 119 public void delete(String dirName, String name) {} 120 121 public void commit() throws IOException { 122 if (phase != RUN) 123 throw new IllegalStateException ("Can not commit."); 124 125 setPhase(COMMIT); 126 } 127 128 public void rollback() throws IOException { 129 if (phase != RUN) 130 throw new IllegalStateException ("Can not rollback."); 131 132 setPhase(ROLLBACK); 133 } 134 135 public synchronized void release() throws IOException { 136 if ((phase != RUN) && (phase != COMMIT) && (phase != ROLLBACK)) 137 throw new IllegalStateException ("Can not release transaction."); 138 139 setPhase(FREE); 141 notify(); 143 } 144 145 public synchronized final void stop() { 146 while (phase != FREE) { 147 try { 149 wait(); 150 } catch (InterruptedException exc) { 151 } 152 } 153 setPhase(FREE); 155 } 156 157 158 public synchronized final void close() { 159 if (phase == INIT) return; 160 161 while (phase != FREE) { 162 try { 164 wait(); 165 } catch (InterruptedException exc) { 166 } 167 } 168 setPhase(INIT); 170 } 171 } 172 | Popular Tags |