KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > ejb > cmp3 > persistence > SEPersistenceUnitInfo


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.ejb.cmp3.persistence;
23
24 import javax.persistence.spi.PersistenceUnitTransactionType;
25 import javax.persistence.spi.ClassTransformer;
26 import javax.sql.DataSource JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Properties JavaDoc;
29 import java.util.Vector JavaDoc;
30 import java.net.URL JavaDoc;
31
32 /**
33  * Internal implementation of the PersistenceUnitInfo detailed in the EJB 3.0 specification
34  * Used by our Java SE implementation so common method calls can be used in setting
35  * of Container and non-Container EntityManagerFactories.
36  */

37 public class SEPersistenceUnitInfo implements javax.persistence.spi.PersistenceUnitInfo {
38
39     protected String JavaDoc persistenceUnitName;
40     protected String JavaDoc persistenceProviderClassName;
41     protected DataSource JavaDoc jtaDataSource;
42     protected DataSource JavaDoc nonJtaDataSource;
43     protected PersistenceUnitTransactionType persistenceUnitTransactionType;
44     protected List JavaDoc mappingFiles;
45     protected List JavaDoc jarFileUrls;
46     protected List JavaDoc managedClassNames;
47     protected URL JavaDoc persistenceUnitRootUrl;
48     protected boolean excludeUnlistedClasses = true;
49     protected Properties JavaDoc properties;
50     protected ClassLoader JavaDoc tempClassLoader;
51     protected ClassLoader JavaDoc realClassLoader;
52
53     public SEPersistenceUnitInfo(){
54         mappingFiles = new Vector JavaDoc();
55         jarFileUrls = new Vector JavaDoc();
56         managedClassNames = new Vector JavaDoc();
57         properties = new Properties JavaDoc();
58         persistenceUnitTransactionType = PersistenceUnitTransactionType.RESOURCE_LOCAL;
59     }
60
61     /**
62     * @return The name of the persistence unit.
63     * Corresponds to the <name> element in the persistence.xml file.
64     */

65     public String JavaDoc getPersistenceUnitName(){
66         return persistenceUnitName;
67     }
68     
69     public void setPersistenceUnitName(String JavaDoc persistenceUnitName){
70         this.persistenceUnitName = persistenceUnitName;
71     }
72
73     /**
74     * @return The fully qualified name of the persistence provider
75     * implementation class.
76     * Corresponds to the <provider> element in the persistence.xml
77     * file.
78     */

79     public String JavaDoc getPersistenceProviderClassName(){
80         return persistenceProviderClassName;
81     }
82     
83     public void setPersistenceProviderClassName(String JavaDoc persistenceProviderClassName){
84         this.persistenceProviderClassName = persistenceProviderClassName;
85     }
86     
87     /**
88     * @return The transaction type of the entity managers created
89     * by the EntityManagerFactory.
90     * The transaction type corresponds to the transaction-type
91     * attribute in the persistence.xml file.
92     */

93     public PersistenceUnitTransactionType getTransactionType(){
94         return persistenceUnitTransactionType;
95     }
96
97     public void setTransactionType(PersistenceUnitTransactionType persistenceUnitTransactionType){
98         this.persistenceUnitTransactionType = persistenceUnitTransactionType;
99     }
100     
101     /**
102     * @return the JTA-enabled data source to be used by the
103     * persistence provider.
104     * The data source corresponds to the <jta-data-source>
105     * element in the persistence.xml file or is provided at
106     * deployment or by the container.
107     */

108     public DataSource JavaDoc getJtaDataSource(){
109         return jtaDataSource;
110     }
111     
112     public void setJtaDataSource(DataSource JavaDoc jtaDataSource){
113         this.jtaDataSource = jtaDataSource;
114     }
115     
116     /**
117     * @return The non-JTA-enabled data source to be used by the
118     * persistence provider for accessing data outside a JTA
119     * transaction.
120     * The data source corresponds to the named <non-jta-data-source>
121     * element in the persistence.xml file or provided at
122     * deployment or by the container.
123     */

124     public DataSource JavaDoc getNonJtaDataSource(){
125         return nonJtaDataSource;
126     }
127
128     public void setNonJtaDataSource(DataSource JavaDoc nonJtaDataSource){
129         this.nonJtaDataSource = nonJtaDataSource;
130     }
131
132     /**
133     * @return The list of mapping file names that the persistence
134     * provider must load to determine the mappings for the entity
135     * classes. The mapping files must be in the standard XML
136     * mapping format, be uniquely named and be resource-loadable
137     * from the application classpath. This list will not include
138     * the orm.xml file if one was specified.
139     * Each mapping file name corresponds to a <mapping-file>
140     * element in the persistence.xml file.
141     */

142     public List JavaDoc<String JavaDoc> getMappingFileNames(){
143         return mappingFiles;
144     }
145     
146     public void setMappingFileNames(List JavaDoc<String JavaDoc> mappingFiles){
147         this.mappingFiles = mappingFiles;
148     }
149     /**
150     * @return The list of JAR file URLs that the persistence
151     * provider must examine for managed classes of the persistence
152     * unit. Each jar file URL corresponds to a named <jar-file>
153     * element in the persistence.xml file.
154     */

155     public List JavaDoc<URL JavaDoc> getJarFileUrls(){
156         return jarFileUrls;
157     }
158     
159     public void setJarFileUrls(List JavaDoc<URL JavaDoc> jarFileUrls){
160         this.jarFileUrls = jarFileUrls;
161     }
162     
163     /**
164     * @return The URL for the jar file that is the root of the
165     * persistence unit. If the persistence unit is rooted in
166     * the WEB-INF/classes directory, this will be the URL of
167     * that directory.
168     */

169     public URL JavaDoc getPersistenceUnitRootUrl(){
170         return persistenceUnitRootUrl;
171     }
172     
173     public void setPersistenceUnitRootUrl(URL JavaDoc persistenceUnitRootUrl){
174         this.persistenceUnitRootUrl = persistenceUnitRootUrl;
175     }
176     
177     /**
178     * @return The list of the names of the classes that the
179     * persistence provider must add it to its set of managed
180     * classes. Each name corresponds to a named <class> element
181     * in the persistence.xml file.
182     */

183     public List JavaDoc<String JavaDoc> getManagedClassNames(){
184         return managedClassNames;
185     }
186
187     public void setManagedClassNames(List JavaDoc<String JavaDoc> managedClassNames){
188         this.managedClassNames = managedClassNames;
189     }
190     /**
191     * @return Whether classes in the root of the persistence
192     * unit that have not been explicitly listed are to be
193     * included in the set of managed classes.
194     * This value corresponds to the <exclude-unlisted-classes>
195     * element in the persistence.xml file.
196     */

197     public boolean excludeUnlistedClasses(){
198         return excludeUnlistedClasses;
199     }
200     
201     public void setExcludeUnlistedClasses(boolean excludeUnlistedClasses){
202         this.excludeUnlistedClasses = excludeUnlistedClasses;
203     }
204     /**
205     * @return Properties object. Each property corresponds
206     * to a <property> element in the persistence.xml file
207     */

208     public Properties JavaDoc getProperties(){
209         return properties;
210     }
211
212     public void setProperties(Properties JavaDoc properties){
213         this.properties = properties;
214     }
215     /**
216     * @return ClassLoader that the provider may use to load any
217     * classes, resources, or open URLs.
218     */

219     public ClassLoader JavaDoc getClassLoader(){
220         return realClassLoader;
221     }
222     /**
223     * Add a transformer supplied by the provider that will be
224     * called for every new class definition or class redefinition
225     * that gets loaded by the loader returned by the
226     * PersistenceUnitInfo.getClassLoader method. The transformer
227     * has no effect on the result returned by the
228     * PersistenceUnitInfo.getNewTempClassLoader method.
229     * Classes are only transformed once within the same classloading
230     * scope, regardless of how many persistence units they may be
231     * a part of.
232     *
233     * @param transformer A provider-supplied transformer that the
234     * Container invokes at class-(re)definition time
235     */

236     public void addTransformer(ClassTransformer transformer){
237         // not required for our Java SE implementation
238
}
239
240     /**
241     * Return a ClassLoader that the provider may use to temporarily
242     * load any classes, resources, or open URLs. The scope and
243     * classpath of this loader is exactly the same as that of the
244     * loader returned by PersistenceUnitInfo.getClassLoader. None of the
245     * classes loaded by this class loader will be visible to
246     * application components.
247     *
248     * @return Temporary ClassLoader with same visibility as current
249     * loader
250     */

251     public ClassLoader JavaDoc getNewTempClassLoader(){
252         return tempClassLoader;
253     }
254     
255     public void setNewTempClassLoader(ClassLoader JavaDoc loader){
256         this.tempClassLoader = loader;
257     }
258     
259     public void setClassLoader(ClassLoader JavaDoc loader) {
260         this.realClassLoader = loader;
261     }
262 }
Popular Tags