1 16 17 package org.springframework.orm.jpa.persistenceunit; 18 19 import java.net.URL ; 20 import java.util.LinkedList ; 21 import java.util.List ; 22 import java.util.Properties ; 23 24 import javax.persistence.spi.ClassTransformer; 25 import javax.persistence.spi.PersistenceUnitInfo; 26 import javax.persistence.spi.PersistenceUnitTransactionType; 27 import javax.sql.DataSource ; 28 29 import org.springframework.util.ClassUtils; 30 31 43 public class MutablePersistenceUnitInfo implements PersistenceUnitInfo { 44 45 private String persistenceUnitName; 46 47 private String persistenceProviderClassName; 48 49 private PersistenceUnitTransactionType transactionType = PersistenceUnitTransactionType.RESOURCE_LOCAL; 50 51 private DataSource nonJtaDataSource; 52 53 private DataSource jtaDataSource; 54 55 private List <String > mappingFileNames = new LinkedList <String >(); 56 57 private List <String > managedClassNames = new LinkedList <String >(); 58 59 private List <URL > jarFileUrls = new LinkedList <URL >(); 60 61 private boolean excludeUnlistedClasses = false; 62 63 private Properties properties = new Properties (); 64 65 private URL persistenceUnitRootUrl; 66 67 68 public void setPersistenceUnitName(String persistenceUnitName) { 69 this.persistenceUnitName = persistenceUnitName; 70 } 71 72 public String getPersistenceUnitName() { 73 return this.persistenceUnitName; 74 } 75 76 public void setPersistenceProviderClassName(String persistenceProviderClassName) { 77 this.persistenceProviderClassName = persistenceProviderClassName; 78 } 79 80 public String 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 jtaDataSource) { 93 this.jtaDataSource = jtaDataSource; 94 } 95 96 public DataSource getJtaDataSource() { 97 return jtaDataSource; 98 } 99 100 public void setNonJtaDataSource(DataSource nonJtaDataSource) { 101 this.nonJtaDataSource = nonJtaDataSource; 102 } 103 104 public DataSource getNonJtaDataSource() { 105 return nonJtaDataSource; 106 } 107 108 public void addMappingFileName(String mappingFileName) { 109 this.mappingFileNames.add(mappingFileName); 110 } 111 112 public List <String > getMappingFileNames() { 113 return mappingFileNames; 114 } 115 116 public void addJarFileUrl(URL jarFileUrl) { 117 this.jarFileUrls.add(jarFileUrl); 118 } 119 120 public List <URL > getJarFileUrls() { 121 return jarFileUrls; 122 } 123 124 public void setPersistenceUnitRootUrl(URL persistenceUnitRootUrl) { 125 this.persistenceUnitRootUrl = persistenceUnitRootUrl; 126 } 127 128 public URL getPersistenceUnitRootUrl() { 129 return persistenceUnitRootUrl; 130 } 131 132 public void addManagedClassName(String managedClassName) { 133 this.managedClassNames.add(managedClassName); 134 } 135 136 public List <String > 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 name, String value) { 149 if (this.properties == null) { 150 this.properties = new Properties (); 151 } 152 this.properties.setProperty(name, value); 153 } 154 155 public void setProperties(Properties properties) { 156 this.properties = properties; 157 } 158 159 public Properties getProperties() { 160 return properties; 161 } 162 163 164 public ClassLoader getClassLoader() { 165 return ClassUtils.getDefaultClassLoader(); 166 } 167 168 public void addTransformer(ClassTransformer classTransformer) { 169 throw new UnsupportedOperationException ("addTransformer not supported"); 170 } 171 172 public ClassLoader getNewTempClassLoader() { 173 throw new UnsupportedOperationException ("getNewTempClassLoader not supported"); 174 } 175 176 177 public String toString() { 178 StringBuilder builder = new StringBuilder (); 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 |