001: /*
002: * Copyright 2002-2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.orm.jpa.persistenceunit;
018:
019: import java.net.URL;
020: import java.util.LinkedList;
021: import java.util.List;
022: import java.util.Properties;
023:
024: import javax.persistence.spi.ClassTransformer;
025: import javax.persistence.spi.PersistenceUnitInfo;
026: import javax.persistence.spi.PersistenceUnitTransactionType;
027: import javax.sql.DataSource;
028:
029: import org.springframework.util.ClassUtils;
030:
031: /**
032: * Spring's base implementation of the JPA
033: * {@link javax.persistence.spi.PersistenceUnitInfo} interface,
034: * used to bootstrap an EntityManagerFactory in a container.
035: *
036: * <p>This implementation is largely a JavaBean, offering mutators
037: * for all standard PersistenceUnitInfo properties.
038: *
039: * @author Rod Johnson
040: * @author Juergen Hoeller
041: * @author Costin Leau
042: * @since 2.0
043: */
044: public class MutablePersistenceUnitInfo implements PersistenceUnitInfo {
045:
046: private String persistenceUnitName;
047:
048: private String persistenceProviderClassName;
049:
050: private PersistenceUnitTransactionType transactionType;
051:
052: private DataSource nonJtaDataSource;
053:
054: private DataSource jtaDataSource;
055:
056: private List<String> mappingFileNames = new LinkedList<String>();
057:
058: private List<String> managedClassNames = new LinkedList<String>();
059:
060: private List<URL> jarFileUrls = new LinkedList<URL>();
061:
062: private boolean excludeUnlistedClasses = false;
063:
064: private Properties properties = new Properties();
065:
066: private URL persistenceUnitRootUrl;
067:
068: public void setPersistenceUnitName(String persistenceUnitName) {
069: this .persistenceUnitName = persistenceUnitName;
070: }
071:
072: public String getPersistenceUnitName() {
073: return this .persistenceUnitName;
074: }
075:
076: public void setPersistenceProviderClassName(
077: String persistenceProviderClassName) {
078: this .persistenceProviderClassName = persistenceProviderClassName;
079: }
080:
081: public String getPersistenceProviderClassName() {
082: return this .persistenceProviderClassName;
083: }
084:
085: public void setTransactionType(
086: PersistenceUnitTransactionType transactionType) {
087: this .transactionType = transactionType;
088: }
089:
090: public PersistenceUnitTransactionType getTransactionType() {
091: if (this .transactionType != null) {
092: return this .transactionType;
093: } else {
094: return (this .jtaDataSource != null ? PersistenceUnitTransactionType.JTA
095: : PersistenceUnitTransactionType.RESOURCE_LOCAL);
096: }
097: }
098:
099: public void setJtaDataSource(DataSource jtaDataSource) {
100: this .jtaDataSource = jtaDataSource;
101: }
102:
103: public DataSource getJtaDataSource() {
104: return this .jtaDataSource;
105: }
106:
107: public void setNonJtaDataSource(DataSource nonJtaDataSource) {
108: this .nonJtaDataSource = nonJtaDataSource;
109: }
110:
111: public DataSource getNonJtaDataSource() {
112: return this .nonJtaDataSource;
113: }
114:
115: public void addMappingFileName(String mappingFileName) {
116: this .mappingFileNames.add(mappingFileName);
117: }
118:
119: public List<String> getMappingFileNames() {
120: return this .mappingFileNames;
121: }
122:
123: public void addJarFileUrl(URL jarFileUrl) {
124: this .jarFileUrls.add(jarFileUrl);
125: }
126:
127: public List<URL> getJarFileUrls() {
128: return this .jarFileUrls;
129: }
130:
131: public void setPersistenceUnitRootUrl(URL persistenceUnitRootUrl) {
132: this .persistenceUnitRootUrl = persistenceUnitRootUrl;
133: }
134:
135: public URL getPersistenceUnitRootUrl() {
136: return persistenceUnitRootUrl;
137: }
138:
139: public void addManagedClassName(String managedClassName) {
140: this .managedClassNames.add(managedClassName);
141: }
142:
143: public List<String> getManagedClassNames() {
144: return this .managedClassNames;
145: }
146:
147: public void setExcludeUnlistedClasses(boolean excludeUnlistedClasses) {
148: this .excludeUnlistedClasses = excludeUnlistedClasses;
149: }
150:
151: public boolean excludeUnlistedClasses() {
152: return this .excludeUnlistedClasses;
153: }
154:
155: public void addProperty(String name, String value) {
156: if (this .properties == null) {
157: this .properties = new Properties();
158: }
159: this .properties.setProperty(name, value);
160: }
161:
162: public void setProperties(Properties properties) {
163: this .properties = properties;
164: }
165:
166: public Properties getProperties() {
167: return this .properties;
168: }
169:
170: public ClassLoader getClassLoader() {
171: return ClassUtils.getDefaultClassLoader();
172: }
173:
174: public void addTransformer(ClassTransformer classTransformer) {
175: throw new UnsupportedOperationException(
176: "addTransformer not supported");
177: }
178:
179: public ClassLoader getNewTempClassLoader() {
180: throw new UnsupportedOperationException(
181: "getNewTempClassLoader not supported");
182: }
183:
184: public String toString() {
185: StringBuilder builder = new StringBuilder();
186: builder.append("PersistenceUnitInfo: name '");
187: builder.append(this .persistenceUnitName);
188: builder.append("', root URL [");
189: builder.append(this .persistenceUnitRootUrl);
190: builder.append("]");
191: return builder.toString();
192: }
193:
194: }
|