KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > config > UserConfig


1 /*
2  * Created on Apr 15, 2005
3  * by alex
4  *
5  */

6 package com.nightlabs.ipanema.config;
7
8 import java.io.Serializable JavaDoc;
9 import java.util.Collection JavaDoc;
10
11 import javax.jdo.PersistenceManager;
12 import javax.jdo.Query;
13
14 import com.nightlabs.ipanema.security.User;
15
16 /**
17  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
18  *
19  * @jdo.persistence-capable
20  * identity-type = "application"
21  * detachable = "true"
22  * persitence-cabable-superclass = "com.nightlabs.ipanema.config.Config"
23  *
24  * @jdo.inheritance strategy = "new-table"
25  *
26  * @jdo.query
27  * name="getUserConfigForUser"
28  * query="SELECT
29  * WHERE organisationID == paramUserOrganisationID &&
30  * userConfigID == paramUserUserID &&
31  * implementationClassname == paramClassname
32  * PARAMETERS String paramUserOrganisationID, String paramUserUserID, String paramClassname
33  * IMPORTS import java.lang.String"
34  *
35  * @jdo.query
36  * name="getUserConfigsForGroup"
37  * query="SELECT
38  * WHERE userConfigGroup != null &&
39  * userConfigGroup.organisationID == paramGroupOrganisationID &&
40  * userConfigGroup.userConfigID == paramGroupUserConfigID
41  * implementationClassname == paramClassname
42  * PARAMETERS String paramGroupOrganisationID, String paramGroupUserConfigID, String paramClassname
43  * IMPORTS import java.lang.String"
44  *
45  */

46 public class UserConfig extends Config implements Serializable JavaDoc
47 {
48      public static final String JavaDoc QUERY_GET_USER_CONFIG_FOR_USER = "getUserConfigForUser";
49      public static final String JavaDoc QUERY_GET_USER_CONFIGS_FOR_GROUP = "getUserConfigsForGroup";
50      
51      protected UserConfig() { }
52
53      public UserConfig(UserConfigGroup userConfigGroup, User user) {
54          organisationID = user.getOrganisationID();
55          configID = user.getUserID();
56          this.userConfigGroup = userConfigGroup;
57      this.implementationClassName = this.getClass().getName();
58      }
59     
60      public UserConfig(String JavaDoc organisationID, String JavaDoc userConfigID) {
61          this.organisationID = organisationID;
62          this.configID = userConfigID;
63          this.userConfigGroup = null;
64      this.implementationClassName = this.getClass().getName();
65      }
66
67     /**
68      * @jdo.field persistence-modifier="persistent"
69      */

70     private UserConfigGroup userConfigGroup;
71     
72     public String JavaDoc getOrganisationID()
73   {
74         return organisationID;
75     }
76     
77     /**
78      * The userConfigID of a UserConfig is the userID of the
79      * the User this UserConfig is for. When this UserConfig is a UserConfigGroup
80      * it will be have to be provided by the administrator.
81      *
82      * @return The userConfigID of this UserConfig
83      */

84     public String JavaDoc getUserConfigID()
85   {
86         return configID;
87     }
88
89     /**
90      * The UserConfigGroup this UserConfig is part of
91      * or null if this UserConfig is itsefl a UserConfigGroup.
92      *
93      * @return
94      */

95     public UserConfigGroup getUserConfigGroup()
96   {
97         return userConfigGroup;
98     }
99     
100     /**
101      * Sets the UserConfigGroup this UserConfig should belong to.
102      *
103      * @param userConfigGroup The UserConfigGroup this UserConfig should belong to.
104      */

105     protected void setUserConfigGroup(UserConfigGroup userConfigGroup)
106   {
107         this.userConfigGroup = userConfigGroup;
108     }
109     
110     public static UserConfig getUserConfig(PersistenceManager pm, User user)
111   {
112         return getUserConfig(pm, user.getOrganisationID(), user.getUserID());
113     }
114     
115     /**
116      * Returns an already persistent UserConfig with the given primary key or
117      * newly creates and returns it.
118      *
119      * @param pm PersistenceManager to use
120      * @param organistationID organisationID of the UserConfig
121      * @param userConfigID userConfigID of the UserConfig
122      * @return The defined UserConfig
123      */

124     public static UserConfig getUserConfig(PersistenceManager pm, String JavaDoc organistationID, String JavaDoc userConfigID) {
125         Query q = pm.newNamedQuery(UserConfig.class, QUERY_GET_USER_CONFIG_FOR_USER);
126         Collection JavaDoc uConfigs = (Collection JavaDoc)q.execute(organistationID, userConfigID, UserConfig.class.getName());
127         if (!uConfigs.isEmpty())
128             return (UserConfig)uConfigs.iterator().next();
129         UserConfig userConfig = new UserConfig(organistationID, userConfigID);
130         pm.makePersistent(userConfig);
131         return userConfig;
132     }
133
134     /**
135      * Returns all UserConfigs belonging to the UserConfigGroup defined by the
136      * parameters groupOrganisationID and groupUserConfigID.
137      *
138      * @param pm PersistenceManager to retrieve Query from
139      * @param groupOrganisationID OrganisationID of the UserConfigGroup the UserConfigs should be searched for
140      * @param groupUserConfigID UserConfigID of the UserConfigGroup the UserConfigs should be searched for
141      * @return UserConfigs of the given UserConfigGroup
142      */

143     public static Collection JavaDoc getUserConfigsForGroup(PersistenceManager pm, String JavaDoc groupOrganisationID, String JavaDoc groupUserConfigID) {
144         Query q = pm.newNamedQuery(UserConfig.class, QUERY_GET_USER_CONFIGS_FOR_GROUP);
145         Collection JavaDoc uConfigs = (Collection JavaDoc)q.execute(groupOrganisationID, groupUserConfigID, UserConfig.class.getName());
146         return uConfigs;
147     }
148     
149     
150 }
151
Popular Tags