1
2
3
4
5
6
7
8
9 package bexee.dao;
10
11 import java.util.HashMap;
12 import java.util.Map;
13
14 import bexee.model.process.BPELProcess;
15
16 /***
17 * This class uses memory rather than persistent storage to store and load
18 * <code>BPELProcess</code> objects.
19 *
20 * @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:09 $
21 * @author Patric Fornasier
22 * @author Pawel Kowalski
23 */
24 public class MemoryBPELProcessDAO implements BPELProcessDAO {
25
26 protected static Map map;
27
28 /***
29 * Creates a new <code>MemoryBPELProcessDAO</code> that uses a static
30 * <code>Map</code> to manage the stored <code>BPELProcess</code>
31 * objects.
32 */
33 public MemoryBPELProcessDAO() {
34 if (map == null) {
35 map = new HashMap();
36 }
37 }
38
39 public void delete(String name) {
40 map.remove(name);
41 }
42
43 public void deleteAll() {
44 map.clear();
45 }
46
47 public BPELProcess find(String name) {
48 return (BPELProcess) map.get(name);
49 }
50
51 public String insert(BPELProcess process) {
52
53
54 String name = process.getName();
55
56
57 map.put(name, process);
58 return name;
59 }
60
61 public void update(BPELProcess process) throws DAOException {
62
63
64 String name = process.getName();
65 BPELProcess oldProcess = find(name);
66 if (oldProcess == null) {
67 throw new DAOException("No object with id " + name + " to update");
68 }
69
70
71 map.put(name, process);
72
73 }
74
75 public String replace(BPELProcess process) throws DAOException {
76
77
78 String name = process.getName();
79 BPELProcess oldProcess = find(name);
80
81 if (oldProcess != null) {
82 update(process);
83 } else {
84 name = insert(process);
85 }
86
87 return name;
88 }
89 }