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.Filter;
24  import org.waarp.openr66.dao.LimitDAO;
25  import org.waarp.openr66.dao.exception.DAOConnectionException;
26  import org.waarp.openr66.dao.exception.DAONoDataException;
27  import org.waarp.openr66.pojo.Limit;
28  
29  import java.util.ArrayList;
30  import java.util.List;
31  import java.util.concurrent.ConcurrentHashMap;
32  
33  public class XMLLimitDAO implements LimitDAO {
34  
35    
36  
37  
38    private static final ConcurrentHashMap<String, Limit>
39        dbR66ConfigurationHashMap = new ConcurrentHashMap<String, Limit>();
40  
41    public XMLLimitDAO() {
42      
43    }
44  
45    @Override
46    public void close() {
47      
48    }
49  
50    @Override
51    public void delete(final Limit limit) {
52      dbR66ConfigurationHashMap.remove(limit.getHostid());
53    }
54  
55    @Override
56    public void deleteAll() {
57      dbR66ConfigurationHashMap.clear();
58    }
59  
60    @Override
61    public List<Limit> getAll() throws DAOConnectionException {
62      return new ArrayList<Limit>(dbR66ConfigurationHashMap.values());
63    }
64  
65    @Override
66    public boolean exist(final String hostid) throws DAOConnectionException {
67      return dbR66ConfigurationHashMap.containsKey(hostid);
68    }
69  
70    @Override
71    public List<Limit> 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<Limit> 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<Limit> 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<Limit> 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<Limit> find(final List<Filter> filters, final String field,
97                            final boolean asc, final int limit, final int offset)
98        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 dbR66ConfigurationHashMap.size();
117     }
118     throw new DAOConnectionException("Operation not supported on XML DAO");
119   }
120 
121   @Override
122   public void insert(final Limit limit) {
123     dbR66ConfigurationHashMap.put(limit.getHostid(), limit);
124   }
125 
126   @Override
127   public Limit select(final String hostid)
128       throws DAOConnectionException, DAONoDataException {
129     final Limit limit = dbR66ConfigurationHashMap.get(hostid);
130     if (limit != null) {
131       return limit;
132     }
133     throw new DAONoDataException("Limit not found");
134   }
135 
136   @Override
137   public void update(final Limit limit) {
138     dbR66ConfigurationHashMap.put(limit.getHostid(), limit);
139   }
140 }