KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > accounting > TariffRegistry


1 /*
2  * Created on Jan 5, 2005
3  */

4 package com.nightlabs.ipanema.accounting;
5
6 import java.util.Iterator JavaDoc;
7
8 import javax.jdo.PersistenceManager;
9
10 import com.nightlabs.ipanema.organisation.LocalOrganisation;
11
12 /**
13  * @author Marco Schulze - marco at nightlabs dot de
14  *
15  * @jdo.persistence-capable
16  * identity-type = "datastore"
17  * detachable = "true"
18  *
19  * @jdo.inheritance strategy = "new-table"
20  */

21 public class TariffRegistry
22 {
23     /**
24      * This method returns the singleton instance of Accounting. If there is
25      * no instance of Accounting in the datastore, yet, it will be created.
26      *
27      * @param pm
28      * @return
29      */

30     public static TariffRegistry getTariffRegistry(PersistenceManager pm)
31     {
32         Iterator JavaDoc it = pm.getExtent(TariffRegistry.class).iterator();
33         if (it.hasNext())
34             return (TariffRegistry)it.next();
35
36         TariffRegistry categorySetRegistry = new TariffRegistry();
37
38         // initialize the organisationID
39
it = pm.getExtent(LocalOrganisation.class).iterator();
40         if (!it.hasNext())
41             throw new IllegalStateException JavaDoc("LocalOrganisation undefined in datastore!");
42         LocalOrganisation localOrganisation = (LocalOrganisation) it.next();
43         categorySetRegistry.organisationID = localOrganisation.getOrganisation().getOrganisationID();
44
45         pm.makePersistent(categorySetRegistry);
46         return categorySetRegistry;
47     }
48     
49     public TariffRegistry()
50     {
51     }
52     
53     private long nextTariffID = 0;
54     
55     private String JavaDoc organisationID;
56
57     public synchronized long createTariffID()
58     {
59         long res = nextTariffID;
60         nextTariffID = res + 1;
61         return res;
62     }
63     /**
64      * @return Returns the organisationID.
65      */

66     public String JavaDoc getOrganisationID()
67     {
68         return organisationID;
69     }
70 }
71
Popular Tags