01: package net.javacoding.jspider.core.storage.memory;
02:
03: import net.javacoding.jspider.core.storage.spi.SiteDAOSPI;
04: import net.javacoding.jspider.core.storage.spi.StorageSPI;
05: import net.javacoding.jspider.core.model.SiteInternal;
06:
07: import java.net.URL;
08: import java.util.HashMap;
09: import java.util.Map;
10:
11: /**
12: * $Id: SiteDAOImpl.java,v 1.6 2003/04/11 16:37:07 vanrogu Exp $
13: */
14: class SiteDAOImpl implements SiteDAOSPI {
15:
16: protected StorageSPI storage;
17: protected Map byURL;
18: protected Map byId;
19:
20: public SiteDAOImpl(StorageSPI storage) {
21: this .storage = storage;
22: this .byURL = new HashMap();
23: this .byId = new HashMap();
24: }
25:
26: public SiteInternal find(int id) {
27: return (SiteInternal) byId.get(new Integer(id));
28: }
29:
30: public SiteInternal find(URL siteURL) {
31: return (SiteInternal) byURL.get(siteURL);
32: }
33:
34: public void create(int id, SiteInternal site) {
35: byURL.put(site.getURL(), site);
36: byId.put(new Integer(id), site);
37: }
38:
39: public void save(int id, SiteInternal site) {
40: URL siteURL = site.getURL();
41: byURL.put(siteURL, site);
42: byId.put(new Integer(id), site);
43: }
44:
45: public SiteInternal[] findAll() {
46: return (SiteInternal[]) byURL.values().toArray(
47: new SiteInternal[byURL.size()]);
48: }
49:
50: }
|