KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > innig > macker > example > layering > model > Thinger


1 package net.innig.macker.example.layering.model;
2
3 import net.innig.macker.example.layering.persistence.*;
4
5 import java.util.*;
6
7 public class Thinger
8     {
9     private static ThingerPersistence getPersist()
10         throws PersistenceException
11         {
12         if(persist == null)
13             persist = new ThingerPersistence();
14         return persist;
15         }
16     private static ThingerPersistence persist;
17
18     public static Set getAll()
19         throws PersistenceException
20         {
21         Set allNames = getPersist().selectAll();
22         Set allThingers = new HashSet();
23         for(Iterator i = allNames.iterator(); i.hasNext(); )
24             allThingers.add(new Thinger((String JavaDoc) i.next(), true));
25         return allThingers;
26         }
27     
28     public Thinger(String JavaDoc name)
29         { this(name, false); }
30     
31     private Thinger(String JavaDoc name, boolean stored)
32         {
33         this.name = name;
34         this.stored = stored;
35         }
36     
37     public String JavaDoc getName()
38         { return name; }
39     
40     public void store()
41         throws PersistenceException
42         {
43         if(!stored)
44             getPersist().insert(name);
45         stored = true;
46         }
47     
48     public void delete()
49         throws PersistenceException
50         {
51         getPersist().delete(name);
52         stored = false;
53         }
54     
55     public String JavaDoc toString()
56         { return name; }
57     
58     private boolean stored = false;
59     private final String JavaDoc name;
60     }
Popular Tags