View Javadoc

1   /*
2    * PersistanceManager.java
3    *
4    * Created on June 3, 2004, 4:46 PM
5    */
6   
7   package gov.bnl.gums.persistence;
8   
9   import gov.bnl.gums.configuration.Configuration;
10  import gov.bnl.gums.db.AccountPoolMapperDB;
11  import gov.bnl.gums.db.ManualAccountMapperDB;
12  import gov.bnl.gums.db.ManualUserGroupDB;
13  import gov.bnl.gums.db.UserGroupDB;
14  import gov.bnl.gums.db.ConfigurationDB;
15  
16  import java.lang.ref.SoftReference;
17  import java.util.Properties;
18  
19  /** Represent a factory for all the classes that take care of the persistance of
20   * the AccountMappers, the UserGroups or any other components.
21   * <p>
22   * Implementing a new PersistanceManager class allows to complete redefined how
23   * the user, group and accounting information is stored. This will allow to keep
24   * the information integrated in the site accounting system, being it any RDBMS,
25   * LDAP, or even a combination of these.
26   * <p>
27   * It also allow to use different mapping technologies, allowing to use either
28   * entity beans, simple JDBC, Hibernate or any other favorite technology.
29   *
30   * @author Gabriele Carcassi, Jay Packard
31   */
32  public abstract class PersistenceFactory {
33      /**
34       * @return user friendly string representation of the property type called statically 
35       */
36      static public String getTypeStatic() {
37  		return "abstract";
38  	}
39      
40      private String name = "";
41      private boolean storeConfig = false;
42      private String description = "";
43      private Properties properties;
44      private SoftReference configurationRef;
45      
46  	/**
47  	 * Create a persistence factory. This empty constructor is needed by the XML Digestor.
48  	 */
49  	public PersistenceFactory() {
50  	}
51      
52  	/**
53  	 * Create a persistence factory with a configuration.
54  	 * 
55  	 * @param configuration
56  	 */
57  	public PersistenceFactory(Configuration configuration) {
58  		this.configurationRef = new SoftReference(configuration);
59  	}	
60      
61  	/**
62  	 * Create a persistence factory with a configuration and a name.
63  	 * 
64  	 * @param configuration
65  	 * @param name
66  	 */
67  	public PersistenceFactory(Configuration configuration, String name) {
68  		this.name = name;
69  		this.configurationRef = new SoftReference(configuration);
70  	}
71  	
72  	/**
73  	 * Create a clone of itself
74  	 * 
75  	 * @param configuration
76  	 * @return
77  	 */
78  	public abstract PersistenceFactory clone(Configuration configuration);
79  
80  	/**
81       * Getter for property configuration.
82       * 
83       * @return Value of property configuration.
84       */
85  	public Configuration getConfiguration() {
86  		if (configurationRef==null)
87  			return null;
88  		return (Configuration)configurationRef.get();
89  	}
90  	
91      /**
92       * Getter for property description.
93       * 
94       * @return Value of property description.
95       */
96  	public String getDescription() {
97  		return description;
98  	}
99  
100     /**
101      * Getter for property name.
102      * 
103      * @return Value of property name.
104      */
105 	public String getName() {
106 		return name;
107 	}
108 	
109     /**
110      * Getter for the list of properties for the particular technology
111      * deployed by the inhereted classes.
112      * 
113      * @return properties.
114      */
115 	public Properties getProperties() {
116 		return properties;
117 	}
118 
119 	/**
120 	 * @return string representation of type of persistence factory
121 	 */
122 	public String getType() {
123 		return "abstract";
124 	}
125 
126 	public boolean getStoreConfig() {
127 		return storeConfig;
128 	}
129 
130 	public abstract AccountPoolMapperDB retrieveAccountPoolMapperDB(String name);
131 	
132 	public abstract ConfigurationDB retrieveConfigurationDB();
133 	
134 	public abstract ManualAccountMapperDB retrieveManualAccountMapperDB(String name);
135 	
136 	public abstract ManualUserGroupDB retrieveManualUserGroupDB(String name);
137 
138 	public abstract UserGroupDB retrieveUserGroupDB(String name);
139 	
140     /**
141      * Setter for property configuration.
142      * 
143      * @param configuration.
144      */
145 	public void setConfiguration(Configuration configuration) {
146 		this.configurationRef = new SoftReference(configuration);
147 	}
148 	
149     /**
150      * Setter for property description.
151      * 
152      * @param description.
153      */
154     public void setDescription(String description) {
155     	this.description = description;
156     }
157 
158     /**
159      * Setter for property name.
160      * 
161      * @param name.
162      */
163 	public void setName(String name) {
164 		this.name = name;
165 	}
166 	
167     /**
168      * Setter for the list of properties for the particular technology
169      * deployed by the inhereted classes.
170      * 
171      * @param properties.
172      */
173 	public void setProperties(Properties properties) {
174 		if (properties!=null && "net.sf.hibernate.dialect.MySQLDialect".equals(properties.get("mysql.hibernate.dialect")))
175 			properties.setProperty("mysql.hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
176 		if (properties!=null && "net.sf.hibernate.dialect.MySQLDialect".equals(properties.get("hibernate.dialect")))
177 			properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
178 		this.properties = properties;
179 	}
180 
181 	public void setStoreConfig(boolean storeConfig) {
182 		this.storeConfig = storeConfig;
183 	}
184 
185 	/**
186      * Get XML representation of this object for writing to gums.config
187      * 
188      * @return xml as string
189      */
190 	public abstract String toXML();
191 }