1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.waarp.openr66.dao.xml;
22
23 import org.waarp.openr66.dao.BusinessDAO;
24 import org.waarp.openr66.dao.Filter;
25 import org.waarp.openr66.dao.exception.DAOConnectionException;
26 import org.waarp.openr66.dao.exception.DAONoDataException;
27 import org.waarp.openr66.pojo.Business;
28
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.concurrent.ConcurrentHashMap;
32
33 public class XMLBusinessDAO implements BusinessDAO {
34
35
36
37
38 private static final ConcurrentHashMap<String, Business>
39 dbR66BusinessHashMap = new ConcurrentHashMap<String, Business>();
40
41 public XMLBusinessDAO() {
42
43 }
44
45 @Override
46 public void close() {
47
48 }
49
50 @Override
51 public void delete(final Business business) {
52 dbR66BusinessHashMap.remove(business.getHostid());
53 }
54
55 @Override
56 public void deleteAll() {
57 dbR66BusinessHashMap.clear();
58 }
59
60 @Override
61 public List<Business> getAll() throws DAOConnectionException {
62 return new ArrayList<Business>(dbR66BusinessHashMap.values());
63 }
64
65 @Override
66 public boolean exist(final String hostid) throws DAOConnectionException {
67 return dbR66BusinessHashMap.containsKey(hostid);
68 }
69
70 @Override
71 public List<Business> find(final List<Filter> fitlers)
72 throws DAOConnectionException {
73 throw new DAOConnectionException("Operation not supported on XML DAO");
74 }
75
76 @Override
77 public List<Business> find(final List<Filter> filters, final int limit)
78 throws DAOConnectionException {
79 throw new DAOConnectionException("Operation not supported on XML DAO");
80 }
81
82 @Override
83 public List<Business> find(final List<Filter> filters, final String field,
84 final boolean asc) throws DAOConnectionException {
85 throw new DAOConnectionException("Operation not supported on XML DAO");
86 }
87
88 @Override
89 public List<Business> find(final List<Filter> filters, final String field,
90 final boolean asc, final int limit)
91 throws DAOConnectionException {
92 throw new DAOConnectionException("Operation not supported on XML DAO");
93 }
94
95 @Override
96 public List<Business> find(final List<Filter> filters, final String field,
97 final boolean asc, final int limit,
98 final int offset) throws DAOConnectionException {
99 throw new DAOConnectionException("Operation not supported on XML DAO");
100 }
101
102 @Override
103 public void update(final List<Filter> filters, final String toSet)
104 throws DAOConnectionException {
105 throw new DAOConnectionException("Operation not supported on XML DAO");
106 }
107
108
109
110
111
112
113 @Override
114 public long count(final List<Filter> fitlers) throws DAOConnectionException {
115 if (fitlers == null || fitlers.isEmpty()) {
116 return dbR66BusinessHashMap.size();
117 }
118 throw new DAOConnectionException("Operation not supported on XML DAO");
119 }
120
121 @Override
122 public void insert(final Business business) {
123 dbR66BusinessHashMap.put(business.getHostid(), business);
124 }
125
126 @Override
127 public Business select(final String hostid)
128 throws DAOConnectionException, DAONoDataException {
129 final Business business = dbR66BusinessHashMap.get(hostid);
130 if (business != null) {
131 return business;
132 }
133 throw new DAONoDataException("Business not found");
134 }
135
136 @Override
137 public void update(final Business business) {
138 dbR66BusinessHashMap.put(business.getHostid(), business);
139 }
140 }