props = Collections.EMPTY_MAP;
else if (!props.isEmpty())
props = new HashMap(props);
OpenJPAConfiguration conf = getConfiguration();
Log log = conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
String user = (String) Configurations.removeProperty("ConnectionUserName", props);
if (user == null)
user = conf.getConnectionUserName();
String pass = (String) Configurations.removeProperty("ConnectionPassword", props);
if (pass == null)
pass = conf.getConnectionPassword();
String str = (String) Configurations.removeProperty("TransactionMode", props);
boolean managed;
if (str == null)
managed = conf.isTransactionModeManaged();
else {
Value val = conf.getValue("TransactionMode");
managed = Boolean.parseBoolean(val.unalias(str));
}
Object obj = Configurations.removeProperty("ConnectionRetainMode", props);
int retainMode;
if (obj instanceof Number) {
retainMode = ((Number) obj).intValue();
} else if (obj == null) {
retainMode = conf.getConnectionRetainModeConstant();
} else {
Value val = conf.getValue("ConnectionRetainMode");
try {
retainMode = Integer.parseInt(val.unalias((String) obj));
} catch (Exception e) {
throw new ArgumentException(_loc.get("bad-em-prop", "openjpa.ConnectionRetainMode", obj),
new Throwable[]{ e }, obj, true);
}
}
// javax.persistence.jtaDataSource and openjpa.ConnectionFactory name are equivalent.
// prefer javax.persistence for now.
String cfName = (String) Configurations.removeProperty("jtaDataSource", props);
if(cfName == null) {
cfName = (String) Configurations.removeProperty("ConnectionFactoryName", props);
}
String cf2Name = (String) Configurations.removeProperty("nonJtaDataSource", props);
if(cf2Name == null) {
cf2Name = (String) Configurations.removeProperty("ConnectionFactory2Name", props);
}
if (log != null && log.isTraceEnabled()) {
if(StringUtils.isNotEmpty(cfName)) {
log.trace("Found ConnectionFactoryName from props: " + cfName);
}
if(StringUtils.isNotEmpty(cf2Name)) {
log.trace("Found ConnectionFactory2Name from props: " + cf2Name);
}
}
validateCfNameProps(conf, cfName, cf2Name);
Broker broker = _factory.newBroker(user, pass, managed, retainMode, false, cfName, cf2Name);
// add autodetach for close and rollback conditions to the configuration
broker.setAutoDetach(AutoDetach.DETACH_CLOSE, true);
broker.setAutoDetach(AutoDetach.DETACH_ROLLBACK, true);
broker.setDetachedNew(false);
OpenJPAEntityManagerSPI em = newEntityManagerImpl(broker);
// allow setting of other bean properties of EM
Set<Map.Entry> entrySet = props.entrySet();
for (Map.Entry entry : entrySet) {
em.setProperty(entry.getKey().toString(), entry.getValue());
}
if (log != null && log.isTraceEnabled()) {
log.trace(this + " created EntityManager " + em + ".");
}
return em;
}