01: package simpleorm.data.dynabeanadaptor;
02:
03: import org.apache.commons.beanutils.DynaBean;
04:
05: import java.util.LinkedHashMap;
06: import java.util.List;
07: import java.util.Collection;
08:
09: import simpleorm.data.DException;
10:
11: /**
12: * Simple hash map implementation of a dyna database
13: */
14: public class DDynaDatabase {
15: LinkedHashMap<String, DynaBean> records = new LinkedHashMap(10);
16:
17: public synchronized DynaBean search(String key) {
18: return records.get(key);
19: }
20:
21: public synchronized DynaBean find(String key) {
22: DynaBean bean = records.get(key);
23: if (bean == null)
24: throw new DException("Bean not found " + key);
25: return bean;
26: }
27:
28: public synchronized void insert(String key, DynaBean bean) {
29: if (records.get(key) != null)
30: throw new DException("Inserted record already exists "
31: + key);
32: records.put(key, bean);
33: }
34:
35: public synchronized void update(String key, DynaBean bean) {
36: if (records.get(key) == null)
37: throw new DException("Updated record not found " + key);
38: records.put(key, bean);
39: }
40:
41: public synchronized Collection<DynaBean> values() {
42: return records.values();
43: }
44: }
|