KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > orm > jpa > persistenceunit > MutablePersistenceUnitInfo


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.orm.jpa.persistenceunit;
18
19 import java.net.URL JavaDoc;
20 import java.util.LinkedList JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Properties JavaDoc;
23
24 import javax.persistence.spi.ClassTransformer;
25 import javax.persistence.spi.PersistenceUnitInfo;
26 import javax.persistence.spi.PersistenceUnitTransactionType;
27 import javax.sql.DataSource JavaDoc;
28
29 import org.springframework.util.ClassUtils;
30
31 /**
32  * Spring's base implementation of the JPA PersistenceUnitInfo interface
33  * used to bootstrap an EntityManagerFactory in a container.
34  *
35  * <p>This implementation is largely a JavaBean, offering mutators
36  * for all standard PersistenceUnitInfo properties.
37  *
38  * @author Rod Johnson
39  * @author Juergen Hoeller
40  * @author Costin Leau
41  * @since 2.0
42  */

43 public class MutablePersistenceUnitInfo implements PersistenceUnitInfo {
44
45     private String JavaDoc persistenceUnitName;
46
47     private String JavaDoc persistenceProviderClassName;
48
49     private PersistenceUnitTransactionType transactionType = PersistenceUnitTransactionType.RESOURCE_LOCAL;
50
51     private DataSource JavaDoc nonJtaDataSource;
52
53     private DataSource JavaDoc jtaDataSource;
54
55     private List JavaDoc<String JavaDoc> mappingFileNames = new LinkedList JavaDoc<String JavaDoc>();
56
57     private List JavaDoc<String JavaDoc> managedClassNames = new LinkedList JavaDoc<String JavaDoc>();
58
59     private List JavaDoc<URL JavaDoc> jarFileUrls = new LinkedList JavaDoc<URL JavaDoc>();
60
61     private boolean excludeUnlistedClasses = false;
62
63     private Properties JavaDoc properties = new Properties JavaDoc();
64
65     private URL JavaDoc persistenceUnitRootUrl;
66
67
68     public void setPersistenceUnitName(String JavaDoc persistenceUnitName) {
69         this.persistenceUnitName = persistenceUnitName;
70     }
71
72     public String JavaDoc getPersistenceUnitName() {
73         return this.persistenceUnitName;
74     }
75
76     public void setPersistenceProviderClassName(String JavaDoc persistenceProviderClassName) {
77         this.persistenceProviderClassName = persistenceProviderClassName;
78     }
79
80     public String JavaDoc getPersistenceProviderClassName() {
81         return this.persistenceProviderClassName;
82     }
83
84     public void setTransactionType(PersistenceUnitTransactionType transactionType) {
85         this.transactionType = transactionType;
86     }
87
88     public PersistenceUnitTransactionType getTransactionType() {
89         return transactionType;
90     }
91
92     public void setJtaDataSource(DataSource JavaDoc jtaDataSource) {
93         this.jtaDataSource = jtaDataSource;
94     }
95
96     public DataSource JavaDoc getJtaDataSource() {
97         return jtaDataSource;
98     }
99
100     public void setNonJtaDataSource(DataSource JavaDoc nonJtaDataSource) {
101         this.nonJtaDataSource = nonJtaDataSource;
102     }
103
104     public DataSource JavaDoc getNonJtaDataSource() {
105         return nonJtaDataSource;
106     }
107
108     public void addMappingFileName(String JavaDoc mappingFileName) {
109         this.mappingFileNames.add(mappingFileName);
110     }
111
112     public List JavaDoc<String JavaDoc> getMappingFileNames() {
113         return mappingFileNames;
114     }
115
116     public void addJarFileUrl(URL JavaDoc jarFileUrl) {
117         this.jarFileUrls.add(jarFileUrl);
118     }
119
120     public List JavaDoc<URL JavaDoc> getJarFileUrls() {
121         return jarFileUrls;
122     }
123
124     public void setPersistenceUnitRootUrl(URL JavaDoc persistenceUnitRootUrl) {
125         this.persistenceUnitRootUrl = persistenceUnitRootUrl;
126     }
127
128     public URL JavaDoc getPersistenceUnitRootUrl() {
129         return persistenceUnitRootUrl;
130     }
131
132     public void addManagedClassName(String JavaDoc managedClassName) {
133         this.managedClassNames.add(managedClassName);
134     }
135
136     public List JavaDoc<String JavaDoc> getManagedClassNames() {
137         return managedClassNames;
138     }
139
140     public void setExcludeUnlistedClasses(boolean excludeUnlistedClasses) {
141         this.excludeUnlistedClasses = excludeUnlistedClasses;
142     }
143
144     public boolean excludeUnlistedClasses() {
145         return excludeUnlistedClasses;
146     }
147
148     public void addProperty(String JavaDoc name, String JavaDoc value) {
149         if (this.properties == null) {
150             this.properties = new Properties JavaDoc();
151         }
152         this.properties.setProperty(name, value);
153     }
154
155     public void setProperties(Properties JavaDoc properties) {
156         this.properties = properties;
157     }
158
159     public Properties JavaDoc getProperties() {
160         return properties;
161     }
162
163
164     public ClassLoader JavaDoc getClassLoader() {
165         return ClassUtils.getDefaultClassLoader();
166     }
167
168     public void addTransformer(ClassTransformer classTransformer) {
169         throw new UnsupportedOperationException JavaDoc("addTransformer not supported");
170     }
171
172     public ClassLoader JavaDoc getNewTempClassLoader() {
173         throw new UnsupportedOperationException JavaDoc("getNewTempClassLoader not supported");
174     }
175
176
177     public String JavaDoc toString() {
178         StringBuilder JavaDoc builder = new StringBuilder JavaDoc();
179         builder.append("SpringPersistenceUnitInfo: unitName='");
180         builder.append(this.persistenceUnitName);
181         builder.append("', unitRootUrl=[");
182         builder.append(this.persistenceUnitRootUrl);
183         builder.append("]");
184         return builder.toString();
185     }
186
187 }
188
Popular Tags