mirror of https://github.com/apache/openjpa.git
Correctly override any configuration keys using a different prefix for the typed elements in a persistence.xml document.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@596208 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0346483ada
commit
02f0a83dde
|
@ -28,9 +28,11 @@ import java.security.PrivilegedActionException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
import javax.persistence.spi.ClassTransformer;
|
import javax.persistence.spi.ClassTransformer;
|
||||||
import javax.persistence.spi.PersistenceUnitInfo;
|
import javax.persistence.spi.PersistenceUnitInfo;
|
||||||
import javax.persistence.spi.PersistenceUnitTransactionType;
|
import javax.persistence.spi.PersistenceUnitTransactionType;
|
||||||
|
@ -326,52 +328,62 @@ public class PersistenceUnitInfoImpl
|
||||||
*/
|
*/
|
||||||
public static Map toOpenJPAProperties(PersistenceUnitInfo info) {
|
public static Map toOpenJPAProperties(PersistenceUnitInfo info) {
|
||||||
Map map = new HashMap();
|
Map map = new HashMap();
|
||||||
|
Set<String> added = new HashSet<String>();
|
||||||
if (info.getTransactionType() == PersistenceUnitTransactionType.JTA)
|
if (info.getTransactionType() == PersistenceUnitTransactionType.JTA)
|
||||||
map.put("openjpa.TransactionMode", "managed");
|
put(map, added, "TransactionMode", "managed");
|
||||||
|
|
||||||
boolean hasJta = false;
|
boolean hasJta = false;
|
||||||
DataSource ds = info.getJtaDataSource();
|
DataSource ds = info.getJtaDataSource();
|
||||||
if (ds != null) {
|
if (ds != null) {
|
||||||
map.put("openjpa.ConnectionFactory", ds);
|
put(map, added, "ConnectionFactory", ds);
|
||||||
map.put("openjpa.ConnectionFactoryMode", "managed");
|
put(map, added, "ConnectionFactoryMode", "managed");
|
||||||
hasJta = true;
|
hasJta = true;
|
||||||
} else if (info instanceof PersistenceUnitInfoImpl
|
} else if (info instanceof PersistenceUnitInfoImpl
|
||||||
&& ((PersistenceUnitInfoImpl) info).getJtaDataSourceName() != null){
|
&& ((PersistenceUnitInfoImpl) info).getJtaDataSourceName() != null){
|
||||||
map.put("openjpa.ConnectionFactoryName", ((PersistenceUnitInfoImpl)
|
put(map, added, "ConnectionFactoryName", ((PersistenceUnitInfoImpl)
|
||||||
info).getJtaDataSourceName());
|
info).getJtaDataSourceName());
|
||||||
map.put("openjpa.ConnectionFactoryMode", "managed");
|
put(map, added, "ConnectionFactoryMode", "managed");
|
||||||
hasJta = true;
|
hasJta = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ds = info.getNonJtaDataSource();
|
ds = info.getNonJtaDataSource();
|
||||||
if (ds != null) {
|
if (ds != null) {
|
||||||
if (!hasJta)
|
if (!hasJta)
|
||||||
map.put("openjpa.ConnectionFactory", ds);
|
put(map, added, "ConnectionFactory", ds);
|
||||||
else
|
else
|
||||||
map.put("openjpa.ConnectionFactory2", ds);
|
put(map, added, "ConnectionFactory2", ds);
|
||||||
} else if (info instanceof PersistenceUnitInfoImpl
|
} else if (info instanceof PersistenceUnitInfoImpl
|
||||||
&& ((PersistenceUnitInfoImpl) info).getNonJtaDataSourceName()
|
&& ((PersistenceUnitInfoImpl) info).getNonJtaDataSourceName()
|
||||||
!= null) {
|
!= null) {
|
||||||
String nonJtaName = ((PersistenceUnitInfoImpl) info).
|
String nonJtaName = ((PersistenceUnitInfoImpl) info).
|
||||||
getNonJtaDataSourceName();
|
getNonJtaDataSourceName();
|
||||||
if (!hasJta)
|
if (!hasJta)
|
||||||
map.put("openjpa.ConnectionFactoryName", nonJtaName);
|
put(map, added, "ConnectionFactoryName", nonJtaName);
|
||||||
else
|
else
|
||||||
map.put("openjpa.ConnectionFactory2Name", nonJtaName);
|
put(map, added, "ConnectionFactory2Name", nonJtaName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.getClassLoader() != null)
|
if (info.getClassLoader() != null)
|
||||||
map.put("openjpa.ClassResolver", new ClassResolverImpl
|
put(map, added, "ClassResolver", new ClassResolverImpl(
|
||||||
(info.getClassLoader()));
|
info.getClassLoader()));
|
||||||
|
|
||||||
Properties props = info.getProperties();
|
Properties props = info.getProperties();
|
||||||
if (props != null) {
|
if (props != null) {
|
||||||
|
|
||||||
|
// remove any of the things that were set above
|
||||||
|
for (String key : added) {
|
||||||
|
if (Configurations.containsProperty(key, props))
|
||||||
|
Configurations.removeProperty(key, props);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add all the non-conflicting props in the <properties> section
|
||||||
map.putAll(props);
|
map.putAll(props);
|
||||||
|
|
||||||
// this isn't a real config property; remove it
|
// this isn't a real config property; remove it
|
||||||
map.remove(PersistenceProviderImpl.CLASS_TRANSFORMER_OPTIONS);
|
map.remove(PersistenceProviderImpl.CLASS_TRANSFORMER_OPTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!map.containsKey("openjpa.Id"))
|
if (!Configurations.containsProperty("Id", map))
|
||||||
map.put("openjpa.Id", info.getPersistenceUnitName());
|
map.put("openjpa.Id", info.getPersistenceUnitName());
|
||||||
|
|
||||||
Properties metaFactoryProps = new Properties();
|
Properties metaFactoryProps = new Properties();
|
||||||
|
@ -434,6 +446,11 @@ public class PersistenceUnitInfoImpl
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void put(Map map, Set added, String key, Object val) {
|
||||||
|
map.put("openjpa." + key, val);
|
||||||
|
added.add(key);
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
|
|
||||||
public File getSourceFile() {
|
public File getSourceFile() {
|
||||||
|
|
Loading…
Reference in New Issue