KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > javacoding > jspider > core > storage > memory > SiteDAOImpl


1 package net.javacoding.jspider.core.storage.memory;
2
3 import net.javacoding.jspider.core.storage.spi.SiteDAOSPI;
4 import net.javacoding.jspider.core.storage.spi.StorageSPI;
5 import net.javacoding.jspider.core.model.SiteInternal;
6
7 import java.net.URL JavaDoc;
8 import java.util.HashMap JavaDoc;
9 import java.util.Map JavaDoc;
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 JavaDoc byURL;
18     protected Map JavaDoc byId;
19
20     public SiteDAOImpl ( StorageSPI storage ) {
21         this.storage = storage;
22         this.byURL = new HashMap JavaDoc ( );
23         this.byId = new HashMap JavaDoc ( );
24     }
25
26     public SiteInternal find(int id) {
27         return (SiteInternal)byId.get(new Integer JavaDoc(id));
28     }
29
30     public SiteInternal find(URL JavaDoc 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 JavaDoc(id), site);
37     }
38
39     public void save(int id, SiteInternal site) {
40         URL JavaDoc siteURL = site.getURL();
41         byURL.put(siteURL, site);
42         byId.put(new Integer JavaDoc(id), site);
43     }
44
45     public SiteInternal[] findAll() {
46         return (SiteInternal[]) byURL.values().toArray(new SiteInternal[byURL.size()]);
47     }
48
49 }
50
Popular Tags