Java 5 code style
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,12 +16,11 @@
|
||||
|
||||
package org.springframework.orm.hibernate3;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.engine.FilterDefinition;
|
||||
import org.hibernate.type.Type;
|
||||
import org.hibernate.type.TypeFactory;
|
||||
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
@@ -44,10 +43,10 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
* <bean class="org.springframework.orm.hibernate3.FilterDefinitionFactoryBean">
|
||||
* <property name="filterName" value="myFilter"/>
|
||||
* <property name="parameterTypes">
|
||||
* <props>
|
||||
* <prop key="myParam">string</prop>
|
||||
* <prop key="myOtherParam">long</prop>
|
||||
* </props>
|
||||
* <map>
|
||||
* <entry key="myParam" value="string"/>
|
||||
* <entry key="myOtherParam" value="long"/>
|
||||
* </map>
|
||||
* </property>
|
||||
* </bean>
|
||||
* </list>
|
||||
@@ -63,11 +62,11 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
* @see org.hibernate.engine.FilterDefinition
|
||||
* @see LocalSessionFactoryBean#setFilterDefinitions
|
||||
*/
|
||||
public class FilterDefinitionFactoryBean implements FactoryBean, BeanNameAware, InitializingBean {
|
||||
public class FilterDefinitionFactoryBean implements FactoryBean<FilterDefinition>, BeanNameAware, InitializingBean {
|
||||
|
||||
private String filterName;
|
||||
|
||||
private Map parameterTypeMap = new HashMap();
|
||||
private Map<String, Type> parameterTypeMap = new HashMap<String, Type>();
|
||||
|
||||
private String defaultFilterCondition;
|
||||
|
||||
@@ -86,17 +85,15 @@ public class FilterDefinitionFactoryBean implements FactoryBean, BeanNameAware,
|
||||
* with parameter names as keys and type names as values.
|
||||
* @see org.hibernate.type.TypeFactory#heuristicType(String)
|
||||
*/
|
||||
public void setParameterTypes(Properties parameterTypes) {
|
||||
public void setParameterTypes(Map<String, String> parameterTypes) {
|
||||
if (parameterTypes != null) {
|
||||
this.parameterTypeMap = new HashMap(parameterTypes.size());
|
||||
for (Enumeration names = parameterTypes.propertyNames(); names.hasMoreElements();) {
|
||||
String paramName = (String) names.nextElement();
|
||||
String typeName = parameterTypes.getProperty(paramName);
|
||||
this.parameterTypeMap.put(paramName, TypeFactory.heuristicType(typeName));
|
||||
this.parameterTypeMap = new HashMap<String, Type>(parameterTypes.size());
|
||||
for (Map.Entry<String, String> entry : parameterTypes.entrySet()) {
|
||||
this.parameterTypeMap.put(entry.getKey(), TypeFactory.heuristicType(entry.getValue()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.parameterTypeMap = new HashMap();
|
||||
this.parameterTypeMap = new HashMap<String, Type>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,11 +121,11 @@ public class FilterDefinitionFactoryBean implements FactoryBean, BeanNameAware,
|
||||
}
|
||||
|
||||
|
||||
public Object getObject() {
|
||||
public FilterDefinition getObject() {
|
||||
return this.filterDefinition;
|
||||
}
|
||||
|
||||
public Class getObjectType() {
|
||||
public Class<FilterDefinition> getObjectType() {
|
||||
return FilterDefinition.class;
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ public interface HibernateOperations {
|
||||
* @throws org.springframework.dao.DataAccessException in case of Hibernate errors
|
||||
* @see org.hibernate.Session#get(Class, java.io.Serializable)
|
||||
*/
|
||||
Object get(Class entityClass, Serializable id) throws DataAccessException;
|
||||
<T> T get(Class<T> entityClass, Serializable id) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Return the persistent instance of the given entity class
|
||||
@@ -133,7 +133,7 @@ public interface HibernateOperations {
|
||||
* @throws org.springframework.dao.DataAccessException in case of Hibernate errors
|
||||
* @see org.hibernate.Session#get(Class, java.io.Serializable, org.hibernate.LockMode)
|
||||
*/
|
||||
Object get(Class entityClass, Serializable id, LockMode lockMode)
|
||||
<T> T get(Class<T> entityClass, Serializable id, LockMode lockMode)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -183,7 +183,7 @@ public interface HibernateOperations {
|
||||
* @throws org.springframework.dao.DataAccessException in case of Hibernate errors
|
||||
* @see org.hibernate.Session#load(Class, java.io.Serializable)
|
||||
*/
|
||||
Object load(Class entityClass, Serializable id) throws DataAccessException;
|
||||
<T> T load(Class<T> entityClass, Serializable id) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Return the persistent instance of the given entity class
|
||||
@@ -201,7 +201,7 @@ public interface HibernateOperations {
|
||||
* @throws org.springframework.dao.DataAccessException in case of Hibernate errors
|
||||
* @see org.hibernate.Session#load(Class, java.io.Serializable)
|
||||
*/
|
||||
Object load(Class entityClass, Serializable id, LockMode lockMode)
|
||||
<T> T load(Class<T> entityClass, Serializable id, LockMode lockMode)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -247,7 +247,7 @@ public interface HibernateOperations {
|
||||
* @throws org.springframework.dao.DataAccessException if there is a Hibernate error
|
||||
* @see org.hibernate.Session#createCriteria
|
||||
*/
|
||||
List loadAll(Class entityClass) throws DataAccessException;
|
||||
<T>List<T> loadAll(Class<T> entityClass) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Load the persistent instance with the given identifier
|
||||
@@ -510,7 +510,7 @@ public interface HibernateOperations {
|
||||
* @see #saveOrUpdate
|
||||
* @see org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener
|
||||
*/
|
||||
Object merge(Object entity) throws DataAccessException;
|
||||
<T> T merge(T entity) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Copy the state of the given object onto the persistent object
|
||||
@@ -637,7 +637,7 @@ public interface HibernateOperations {
|
||||
* @throws org.springframework.dao.DataAccessException in case of Hibernate errors
|
||||
* @see org.hibernate.Session#createQuery
|
||||
*/
|
||||
List find(String queryString, Object[] values) throws DataAccessException;
|
||||
List find(String queryString, Object... values) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute an HQL query, binding one value to a ":" named parameter
|
||||
@@ -714,7 +714,7 @@ public interface HibernateOperations {
|
||||
* @throws org.springframework.dao.DataAccessException in case of Hibernate errors
|
||||
* @see org.hibernate.Session#getNamedQuery(String)
|
||||
*/
|
||||
List findByNamedQuery(String queryName, Object[] values) throws DataAccessException;
|
||||
List findByNamedQuery(String queryName, Object... values) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a named query, binding one value to a ":" named parameter
|
||||
@@ -889,7 +889,7 @@ public interface HibernateOperations {
|
||||
* @see org.hibernate.Session#createQuery
|
||||
* @see org.hibernate.Query#iterate
|
||||
*/
|
||||
Iterator iterate(String queryString, Object[] values) throws DataAccessException;
|
||||
Iterator iterate(String queryString, Object... values) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Immediately close an {@link Iterator} created by any of the various
|
||||
@@ -933,6 +933,6 @@ public interface HibernateOperations {
|
||||
* @see org.hibernate.Session#createQuery
|
||||
* @see org.hibernate.Query#executeUpdate
|
||||
*/
|
||||
int bulkUpdate(String queryString, Object[] values) throws DataAccessException;
|
||||
int bulkUpdate(String queryString, Object... values) throws DataAccessException;
|
||||
|
||||
}
|
||||
|
||||
@@ -516,14 +516,15 @@ public class HibernateTemplate extends HibernateAccessor implements HibernateOpe
|
||||
// Convenience methods for loading individual objects
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
public Object get(Class entityClass, Serializable id) throws DataAccessException {
|
||||
public <T> T get(Class<T> entityClass, Serializable id) throws DataAccessException {
|
||||
return get(entityClass, id, null);
|
||||
}
|
||||
|
||||
public Object get(final Class entityClass, final Serializable id, final LockMode lockMode)
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T get(final Class<T> entityClass, final Serializable id, final LockMode lockMode)
|
||||
throws DataAccessException {
|
||||
|
||||
return executeWithNativeSession(new HibernateCallback() {
|
||||
return (T) executeWithNativeSession(new HibernateCallback() {
|
||||
public Object doInHibernate(Session session) throws HibernateException {
|
||||
if (lockMode != null) {
|
||||
return session.get(entityClass, id, lockMode);
|
||||
@@ -554,14 +555,15 @@ public class HibernateTemplate extends HibernateAccessor implements HibernateOpe
|
||||
});
|
||||
}
|
||||
|
||||
public Object load(Class entityClass, Serializable id) throws DataAccessException {
|
||||
public <T> T load(Class<T> entityClass, Serializable id) throws DataAccessException {
|
||||
return load(entityClass, id, null);
|
||||
}
|
||||
|
||||
public Object load(final Class entityClass, final Serializable id, final LockMode lockMode)
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T load(final Class<T> entityClass, final Serializable id, final LockMode lockMode)
|
||||
throws DataAccessException {
|
||||
|
||||
return executeWithNativeSession(new HibernateCallback() {
|
||||
return (T) executeWithNativeSession(new HibernateCallback() {
|
||||
public Object doInHibernate(Session session) throws HibernateException {
|
||||
if (lockMode != null) {
|
||||
return session.load(entityClass, id, lockMode);
|
||||
@@ -592,8 +594,9 @@ public class HibernateTemplate extends HibernateAccessor implements HibernateOpe
|
||||
});
|
||||
}
|
||||
|
||||
public List loadAll(final Class entityClass) throws DataAccessException {
|
||||
return (List) executeWithNativeSession(new HibernateCallback() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> List<T> loadAll(final Class<T> entityClass) throws DataAccessException {
|
||||
return (List<T>) executeWithNativeSession(new HibernateCallback() {
|
||||
public Object doInHibernate(Session session) throws HibernateException {
|
||||
Criteria criteria = session.createCriteria(entityClass);
|
||||
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
|
||||
@@ -631,12 +634,11 @@ public class HibernateTemplate extends HibernateAccessor implements HibernateOpe
|
||||
}
|
||||
|
||||
public boolean contains(final Object entity) throws DataAccessException {
|
||||
Boolean result = (Boolean) executeWithNativeSession(new HibernateCallback() {
|
||||
return (Boolean) executeWithNativeSession(new HibernateCallback() {
|
||||
public Object doInHibernate(Session session) {
|
||||
return (session.contains(entity) ? Boolean.TRUE : Boolean.FALSE);
|
||||
return session.contains(entity);
|
||||
}
|
||||
});
|
||||
return result.booleanValue();
|
||||
}
|
||||
|
||||
public void evict(final Object entity) throws DataAccessException {
|
||||
@@ -769,8 +771,8 @@ public class HibernateTemplate extends HibernateAccessor implements HibernateOpe
|
||||
executeWithNativeSession(new HibernateCallback() {
|
||||
public Object doInHibernate(Session session) throws HibernateException {
|
||||
checkWriteOperationAllowed(session);
|
||||
for (Iterator it = entities.iterator(); it.hasNext();) {
|
||||
session.saveOrUpdate(it.next());
|
||||
for (Object entity : entities) {
|
||||
session.saveOrUpdate(entity);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -879,8 +881,8 @@ public class HibernateTemplate extends HibernateAccessor implements HibernateOpe
|
||||
executeWithNativeSession(new HibernateCallback() {
|
||||
public Object doInHibernate(Session session) throws HibernateException {
|
||||
checkWriteOperationAllowed(session);
|
||||
for (Iterator it = entities.iterator(); it.hasNext();) {
|
||||
session.delete(it.next());
|
||||
for (Object entity : entities) {
|
||||
session.delete(entity);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -918,7 +920,7 @@ public class HibernateTemplate extends HibernateAccessor implements HibernateOpe
|
||||
return find(queryString, new Object[] {value});
|
||||
}
|
||||
|
||||
public List find(final String queryString, final Object[] values) throws DataAccessException {
|
||||
public List find(final String queryString, final Object... values) throws DataAccessException {
|
||||
return (List) executeWithNativeSession(new HibernateCallback() {
|
||||
public Object doInHibernate(Session session) throws HibernateException {
|
||||
Query queryObject = session.createQuery(queryString);
|
||||
@@ -985,7 +987,7 @@ public class HibernateTemplate extends HibernateAccessor implements HibernateOpe
|
||||
return findByNamedQuery(queryName, new Object[] {value});
|
||||
}
|
||||
|
||||
public List findByNamedQuery(final String queryName, final Object[] values) throws DataAccessException {
|
||||
public List findByNamedQuery(final String queryName, final Object... values) throws DataAccessException {
|
||||
return (List) executeWithNativeSession(new HibernateCallback() {
|
||||
public Object doInHibernate(Session session) throws HibernateException {
|
||||
Query queryObject = session.getNamedQuery(queryName);
|
||||
@@ -1115,7 +1117,7 @@ public class HibernateTemplate extends HibernateAccessor implements HibernateOpe
|
||||
return iterate(queryString, new Object[] {value});
|
||||
}
|
||||
|
||||
public Iterator iterate(final String queryString, final Object[] values) throws DataAccessException {
|
||||
public Iterator iterate(final String queryString, final Object... values) throws DataAccessException {
|
||||
return (Iterator) executeWithNativeSession(new HibernateCallback() {
|
||||
public Object doInHibernate(Session session) throws HibernateException {
|
||||
Query queryObject = session.createQuery(queryString);
|
||||
@@ -1147,8 +1149,8 @@ public class HibernateTemplate extends HibernateAccessor implements HibernateOpe
|
||||
return bulkUpdate(queryString, new Object[] {value});
|
||||
}
|
||||
|
||||
public int bulkUpdate(final String queryString, final Object[] values) throws DataAccessException {
|
||||
Integer updateCount = (Integer) executeWithNativeSession(new HibernateCallback() {
|
||||
public int bulkUpdate(final String queryString, final Object... values) throws DataAccessException {
|
||||
return (Integer) executeWithNativeSession(new HibernateCallback() {
|
||||
public Object doInHibernate(Session session) throws HibernateException {
|
||||
Query queryObject = session.createQuery(queryString);
|
||||
prepareQuery(queryObject);
|
||||
@@ -1157,10 +1159,9 @@ public class HibernateTemplate extends HibernateAccessor implements HibernateOpe
|
||||
queryObject.setParameter(i, values[i]);
|
||||
}
|
||||
}
|
||||
return new Integer(queryObject.executeUpdate());
|
||||
return queryObject.executeUpdate();
|
||||
}
|
||||
});
|
||||
return updateCount.intValue();
|
||||
}
|
||||
|
||||
|
||||
@@ -1282,7 +1283,7 @@ public class HibernateTemplate extends HibernateAccessor implements HibernateOpe
|
||||
}
|
||||
else if (method.getName().equals("hashCode")) {
|
||||
// Use hashCode of Session proxy.
|
||||
return new Integer(System.identityHashCode(proxy));
|
||||
return System.identityHashCode(proxy);
|
||||
}
|
||||
else if (method.getName().equals("close")) {
|
||||
// Handle close method: suppress, not valid.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -47,7 +47,7 @@ public class SessionHolder extends ResourceHolderSupport {
|
||||
* This Map needs to be synchronized because there might be multi-threaded
|
||||
* access in the case of JTA with remote transaction propagation.
|
||||
*/
|
||||
private final Map sessionMap = Collections.synchronizedMap(new HashMap(1));
|
||||
private final Map<Object, Session> sessionMap = Collections.synchronizedMap(new HashMap<Object, Session>(1));
|
||||
|
||||
private Transaction transaction;
|
||||
|
||||
@@ -68,7 +68,7 @@ public class SessionHolder extends ResourceHolderSupport {
|
||||
}
|
||||
|
||||
public Session getSession(Object key) {
|
||||
return (Session) this.sessionMap.get(key);
|
||||
return this.sessionMap.get(key);
|
||||
}
|
||||
|
||||
public Session getValidatedSession() {
|
||||
@@ -76,7 +76,7 @@ public class SessionHolder extends ResourceHolderSupport {
|
||||
}
|
||||
|
||||
public Session getValidatedSession(Object key) {
|
||||
Session session = (Session) this.sessionMap.get(key);
|
||||
Session session = this.sessionMap.get(key);
|
||||
// Check for dangling Session that's around but already closed.
|
||||
// Effectively an assertion: that should never happen in practice.
|
||||
// We'll seamlessly remove the Session here, to not let it cause
|
||||
@@ -91,7 +91,7 @@ public class SessionHolder extends ResourceHolderSupport {
|
||||
public Session getAnySession() {
|
||||
synchronized (this.sessionMap) {
|
||||
if (!this.sessionMap.isEmpty()) {
|
||||
return (Session) this.sessionMap.values().iterator().next();
|
||||
return this.sessionMap.values().iterator().next();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -108,7 +108,7 @@ public class SessionHolder extends ResourceHolderSupport {
|
||||
}
|
||||
|
||||
public Session removeSession(Object key) {
|
||||
return (Session) this.sessionMap.remove(key);
|
||||
return this.sessionMap.remove(key);
|
||||
}
|
||||
|
||||
public boolean containsSession(Session session) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -114,7 +114,7 @@ public class LocalPersistenceManagerFactoryBean
|
||||
|
||||
private Resource configLocation;
|
||||
|
||||
private final Map jdoPropertyMap = new HashMap();
|
||||
private final Map<String, Object> jdoPropertyMap = new HashMap<String, Object>();
|
||||
|
||||
private ClassLoader beanClassLoader;
|
||||
|
||||
@@ -165,7 +165,7 @@ public class LocalPersistenceManagerFactoryBean
|
||||
* <p>Can be populated with a "map" or "props" element in XML bean definitions.
|
||||
* @see javax.jdo.JDOHelper#getPersistenceManagerFactory(java.util.Map)
|
||||
*/
|
||||
public void setJdoPropertyMap(Map jdoProperties) {
|
||||
public void setJdoPropertyMap(Map<String, Object> jdoProperties) {
|
||||
if (jdoProperties != null) {
|
||||
this.jdoPropertyMap.putAll(jdoProperties);
|
||||
}
|
||||
@@ -177,7 +177,7 @@ public class LocalPersistenceManagerFactoryBean
|
||||
* <p>Useful for specifying entries directly, for example via
|
||||
* "jdoPropertyMap[myKey]".
|
||||
*/
|
||||
public Map getJdoPropertyMap() {
|
||||
public Map<String, Object> getJdoPropertyMap() {
|
||||
return this.jdoPropertyMap;
|
||||
}
|
||||
/**
|
||||
@@ -218,18 +218,15 @@ public class LocalPersistenceManagerFactoryBean
|
||||
}
|
||||
|
||||
else {
|
||||
Map mergedProps = new HashMap();
|
||||
|
||||
Map<String, Object> mergedProps = new HashMap<String, Object>();
|
||||
if (this.configLocation != null) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Loading JDO config from [" + this.configLocation + "]");
|
||||
}
|
||||
mergedProps.putAll(PropertiesLoaderUtils.loadProperties(this.configLocation));
|
||||
CollectionUtils.mergePropertiesIntoMap(
|
||||
PropertiesLoaderUtils.loadProperties(this.configLocation), mergedProps);
|
||||
}
|
||||
|
||||
mergedProps.putAll(this.jdoPropertyMap);
|
||||
|
||||
// Build PersistenceManagerFactory instance.
|
||||
logger.info("Building new JDO PersistenceManagerFactory");
|
||||
this.persistenceManagerFactory = newPersistenceManagerFactory(mergedProps);
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
|
||||
|
||||
private String persistenceUnitName;
|
||||
|
||||
private final Map<Object, Object> jpaPropertyMap = new HashMap<Object, Object>();
|
||||
private final Map<String, Object> jpaPropertyMap = new HashMap<String, Object>();
|
||||
|
||||
private Class<? extends EntityManagerFactory> entityManagerFactoryInterface;
|
||||
|
||||
@@ -166,7 +166,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
|
||||
* @see javax.persistence.Persistence#createEntityManagerFactory(String, java.util.Map)
|
||||
* @see javax.persistence.spi.PersistenceProvider#createContainerEntityManagerFactory(javax.persistence.spi.PersistenceUnitInfo, java.util.Map)
|
||||
*/
|
||||
public void setJpaPropertyMap(Map<?, ?> jpaProperties) {
|
||||
public void setJpaPropertyMap(Map<String, ?> jpaProperties) {
|
||||
if (jpaProperties != null) {
|
||||
this.jpaPropertyMap.putAll(jpaProperties);
|
||||
}
|
||||
@@ -178,7 +178,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
|
||||
* <p>Useful for specifying entries directly, for example via
|
||||
* "jpaPropertyMap[myKey]".
|
||||
*/
|
||||
public Map getJpaPropertyMap() {
|
||||
public Map<String, Object> getJpaPropertyMap() {
|
||||
return this.jpaPropertyMap;
|
||||
}
|
||||
|
||||
@@ -260,9 +260,9 @@ public abstract class AbstractEntityManagerFactoryBean implements
|
||||
if (this.persistenceProvider == null) {
|
||||
this.persistenceProvider = this.jpaVendorAdapter.getPersistenceProvider();
|
||||
}
|
||||
Map<?, ?> vendorPropertyMap = this.jpaVendorAdapter.getJpaPropertyMap();
|
||||
Map<String, ?> vendorPropertyMap = this.jpaVendorAdapter.getJpaPropertyMap();
|
||||
if (vendorPropertyMap != null) {
|
||||
for (Map.Entry entry : vendorPropertyMap.entrySet()) {
|
||||
for (Map.Entry<String, ?> entry : vendorPropertyMap.entrySet()) {
|
||||
if (!this.jpaPropertyMap.containsKey(entry.getKey())) {
|
||||
this.jpaPropertyMap.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public abstract class EntityManagerFactoryAccessor {
|
||||
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
private final Map jpaPropertyMap = new HashMap();
|
||||
private final Map<String, Object> jpaPropertyMap = new HashMap<String, Object>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -85,7 +85,7 @@ public abstract class EntityManagerFactoryAccessor {
|
||||
* <p>Can be populated with a "map" or "props" element in XML bean definitions.
|
||||
* @see javax.persistence.EntityManagerFactory#createEntityManager(java.util.Map)
|
||||
*/
|
||||
public void setJpaPropertyMap(Map jpaProperties) {
|
||||
public void setJpaPropertyMap(Map<String, Object> jpaProperties) {
|
||||
if (jpaProperties != null) {
|
||||
this.jpaPropertyMap.putAll(jpaProperties);
|
||||
}
|
||||
@@ -96,7 +96,7 @@ public abstract class EntityManagerFactoryAccessor {
|
||||
* provider, with the option to add or override specific entries.
|
||||
* <p>Useful for specifying entries directly, for example via "jpaPropertyMap[myKey]".
|
||||
*/
|
||||
public Map getJpaPropertyMap() {
|
||||
public Map<String, Object> getJpaPropertyMap() {
|
||||
return this.jpaPropertyMap;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public abstract class EntityManagerFactoryAccessor {
|
||||
protected EntityManager createEntityManager() throws IllegalStateException {
|
||||
EntityManagerFactory emf = getEntityManagerFactory();
|
||||
Assert.state(emf != null, "No EntityManagerFactory specified");
|
||||
Map properties = getJpaPropertyMap();
|
||||
Map<String, Object> properties = getJpaPropertyMap();
|
||||
return (!CollectionUtils.isEmpty(properties) ? emf.createEntityManager(properties) : emf.createEntityManager());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -73,12 +73,12 @@ public interface JpaOperations {
|
||||
|
||||
List find(String queryString, Object... values) throws DataAccessException;
|
||||
|
||||
List findByNamedParams(String queryString, Map<String,? extends Object> params) throws DataAccessException;
|
||||
List findByNamedParams(String queryString, Map<String, ?> params) throws DataAccessException;
|
||||
|
||||
List findByNamedQuery(String queryName) throws DataAccessException;
|
||||
|
||||
List findByNamedQuery(String queryName, Object... values) throws DataAccessException;
|
||||
|
||||
List findByNamedQueryAndNamedParams(String queryName, Map<String,? extends Object> params) throws DataAccessException;
|
||||
List findByNamedQueryAndNamedParams(String queryName, Map<String, ?> params) throws DataAccessException;
|
||||
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
|
||||
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
private final Map jpaPropertyMap = new HashMap();
|
||||
private final Map<String, Object> jpaPropertyMap = new HashMap<String, Object>();
|
||||
|
||||
private DataSource dataSource;
|
||||
|
||||
@@ -167,7 +167,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
|
||||
* <p>Can be populated with a "map" or "props" element in XML bean definitions.
|
||||
* @see javax.persistence.EntityManagerFactory#createEntityManager(java.util.Map)
|
||||
*/
|
||||
public void setJpaPropertyMap(Map jpaProperties) {
|
||||
public void setJpaPropertyMap(Map<String, ?> jpaProperties) {
|
||||
if (jpaProperties != null) {
|
||||
this.jpaPropertyMap.putAll(jpaProperties);
|
||||
}
|
||||
@@ -178,7 +178,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
|
||||
* provider, with the option to add or override specific entries.
|
||||
* <p>Useful for specifying entries directly, for example via "jpaPropertyMap[myKey]".
|
||||
*/
|
||||
public Map getJpaPropertyMap() {
|
||||
public Map<String, Object> getJpaPropertyMap() {
|
||||
return this.jpaPropertyMap;
|
||||
}
|
||||
|
||||
@@ -315,8 +315,6 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
|
||||
"on a single DataSource, no matter whether JPA or JDBC access.");
|
||||
}
|
||||
|
||||
EntityManager em = null;
|
||||
|
||||
try {
|
||||
if (txObject.getEntityManagerHolder() == null ||
|
||||
txObject.getEntityManagerHolder().isSynchronizedWithTransaction()) {
|
||||
@@ -327,7 +325,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
|
||||
txObject.setEntityManagerHolder(new EntityManagerHolder(newEm), true);
|
||||
}
|
||||
|
||||
em = txObject.getEntityManagerHolder().getEntityManager();
|
||||
EntityManager em = txObject.getEntityManagerHolder().getEntityManager();
|
||||
|
||||
// Delegate to JpaDialect for actual transaction begin.
|
||||
Object transactionData = getJpaDialect().beginTransaction(em, definition);
|
||||
@@ -391,7 +389,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
|
||||
if (emf instanceof EntityManagerFactoryInfo) {
|
||||
emf = ((EntityManagerFactoryInfo) emf).getNativeEntityManagerFactory();
|
||||
}
|
||||
Map properties = getJpaPropertyMap();
|
||||
Map<String, Object> properties = getJpaPropertyMap();
|
||||
return (!CollectionUtils.isEmpty(properties) ?
|
||||
emf.createEntityManager(properties) : emf.createEntityManager());
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public interface JpaVendorAdapter {
|
||||
* @see javax.persistence.Persistence#createEntityManagerFactory(String, java.util.Map)
|
||||
* @see javax.persistence.spi.PersistenceProvider#createContainerEntityManagerFactory(javax.persistence.spi.PersistenceUnitInfo, java.util.Map)
|
||||
*/
|
||||
Map getJpaPropertyMap();
|
||||
Map<String, ?> getJpaPropertyMap();
|
||||
|
||||
/**
|
||||
* Return the vendor-specific JpaDialect implementation for this
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.orm.jpa.vendor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
|
||||
@@ -115,7 +114,7 @@ public abstract class AbstractJpaVendorAdapter implements JpaVendorAdapter {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Map getJpaPropertyMap() {
|
||||
public Map<String, ?> getJpaPropertyMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,9 @@
|
||||
|
||||
package org.springframework.orm.jpa.vendor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.spi.PersistenceProvider;
|
||||
|
||||
@@ -62,27 +61,27 @@ public class EclipseLinkJpaVendorAdapter extends AbstractJpaVendorAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map getJpaPropertyMap() {
|
||||
Properties jpaProperties = new Properties();
|
||||
public Map<String, Object> getJpaPropertyMap() {
|
||||
Map<String, Object> jpaProperties = new HashMap<String, Object>();
|
||||
|
||||
if (getDatabasePlatform() != null) {
|
||||
jpaProperties.setProperty(PersistenceUnitProperties.TARGET_DATABASE, getDatabasePlatform());
|
||||
jpaProperties.put(PersistenceUnitProperties.TARGET_DATABASE, getDatabasePlatform());
|
||||
}
|
||||
else if (getDatabase() != null) {
|
||||
String targetDatabase = determineTargetDatabaseName(getDatabase());
|
||||
if (targetDatabase != null) {
|
||||
jpaProperties.setProperty(PersistenceUnitProperties.TARGET_DATABASE, targetDatabase);
|
||||
jpaProperties.put(PersistenceUnitProperties.TARGET_DATABASE, targetDatabase);
|
||||
}
|
||||
}
|
||||
|
||||
if (isGenerateDdl()) {
|
||||
jpaProperties.setProperty(PersistenceUnitProperties.DDL_GENERATION,
|
||||
jpaProperties.put(PersistenceUnitProperties.DDL_GENERATION,
|
||||
PersistenceUnitProperties.CREATE_ONLY);
|
||||
jpaProperties.setProperty(PersistenceUnitProperties.DDL_GENERATION_MODE,
|
||||
jpaProperties.put(PersistenceUnitProperties.DDL_GENERATION_MODE,
|
||||
PersistenceUnitProperties.DDL_DATABASE_GENERATION);
|
||||
}
|
||||
if (isShowSql()) {
|
||||
jpaProperties.setProperty(PersistenceUnitProperties.LOGGING_LEVEL, Level.FINE.toString());
|
||||
jpaProperties.put(PersistenceUnitProperties.LOGGING_LEVEL, Level.FINE.toString());
|
||||
}
|
||||
|
||||
return jpaProperties;
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.orm.jpa.vendor;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.HashMap;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.spi.PersistenceProvider;
|
||||
@@ -69,24 +70,24 @@ public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map getJpaPropertyMap() {
|
||||
Properties jpaProperties = new Properties();
|
||||
public Map<String, Object> getJpaPropertyMap() {
|
||||
Map<String, Object> jpaProperties = new HashMap<String, Object>();
|
||||
|
||||
if (getDatabasePlatform() != null) {
|
||||
jpaProperties.setProperty(Environment.DIALECT, getDatabasePlatform());
|
||||
jpaProperties.put(Environment.DIALECT, getDatabasePlatform());
|
||||
}
|
||||
else if (getDatabase() != null) {
|
||||
Class databaseDialectClass = determineDatabaseDialectClass(getDatabase());
|
||||
if (databaseDialectClass != null) {
|
||||
jpaProperties.setProperty(Environment.DIALECT, databaseDialectClass.getName());
|
||||
jpaProperties.put(Environment.DIALECT, databaseDialectClass.getName());
|
||||
}
|
||||
}
|
||||
|
||||
if (isGenerateDdl()) {
|
||||
jpaProperties.setProperty(Environment.HBM2DDL_AUTO, "update");
|
||||
jpaProperties.put(Environment.HBM2DDL_AUTO, "update");
|
||||
}
|
||||
if (isShowSql()) {
|
||||
jpaProperties.setProperty(Environment.SHOW_SQL, "true");
|
||||
jpaProperties.put(Environment.SHOW_SQL, "true");
|
||||
}
|
||||
|
||||
return jpaProperties;
|
||||
|
||||
@@ -16,9 +16,8 @@
|
||||
|
||||
package org.springframework.orm.jpa.vendor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.spi.PersistenceProvider;
|
||||
@@ -59,26 +58,25 @@ public class OpenJpaVendorAdapter extends AbstractJpaVendorAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map getJpaPropertyMap() {
|
||||
Properties jpaProperties = new Properties();
|
||||
public Map<String, Object> getJpaPropertyMap() {
|
||||
Map<String, Object> jpaProperties = new HashMap<String, Object>();
|
||||
|
||||
if (getDatabasePlatform() != null) {
|
||||
jpaProperties.setProperty("openjpa.jdbc.DBDictionary", getDatabasePlatform());
|
||||
jpaProperties.put("openjpa.jdbc.DBDictionary", getDatabasePlatform());
|
||||
}
|
||||
else if (getDatabase() != null) {
|
||||
String databaseDictonary = determineDatabaseDictionary(getDatabase());
|
||||
if (databaseDictonary != null) {
|
||||
jpaProperties.setProperty("openjpa.jdbc.DBDictionary", databaseDictonary);
|
||||
jpaProperties.put("openjpa.jdbc.DBDictionary", databaseDictonary);
|
||||
}
|
||||
}
|
||||
|
||||
if (isGenerateDdl()) {
|
||||
jpaProperties.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
|
||||
jpaProperties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
|
||||
}
|
||||
|
||||
if (isShowSql()) {
|
||||
// Taken from the OpenJPA 0.9.6 docs ("Standard OpenJPA Log Configuration + All SQL Statements")
|
||||
jpaProperties.setProperty("openjpa.Log", "DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE");
|
||||
jpaProperties.put("openjpa.Log", "DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE");
|
||||
}
|
||||
|
||||
return jpaProperties;
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.orm.jpa.vendor;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
@@ -59,27 +60,27 @@ public class TopLinkJpaVendorAdapter extends AbstractJpaVendorAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map getJpaPropertyMap() {
|
||||
Properties jpaProperties = new Properties();
|
||||
public Map<String, Object> getJpaPropertyMap() {
|
||||
Map<String, Object> jpaProperties = new HashMap<String, Object>();
|
||||
|
||||
if (getDatabasePlatform() != null) {
|
||||
jpaProperties.setProperty(TopLinkProperties.TARGET_DATABASE, getDatabasePlatform());
|
||||
jpaProperties.put(TopLinkProperties.TARGET_DATABASE, getDatabasePlatform());
|
||||
}
|
||||
else if (getDatabase() != null) {
|
||||
String targetDatabase = determineTargetDatabaseName(getDatabase());
|
||||
if (targetDatabase != null) {
|
||||
jpaProperties.setProperty(TopLinkProperties.TARGET_DATABASE, targetDatabase);
|
||||
jpaProperties.put(TopLinkProperties.TARGET_DATABASE, targetDatabase);
|
||||
}
|
||||
}
|
||||
|
||||
if (isGenerateDdl()) {
|
||||
jpaProperties.setProperty(EntityManagerFactoryProvider.DDL_GENERATION,
|
||||
jpaProperties.put(EntityManagerFactoryProvider.DDL_GENERATION,
|
||||
EntityManagerFactoryProvider.CREATE_ONLY);
|
||||
jpaProperties.setProperty(EntityManagerFactoryProvider.DDL_GENERATION_MODE,
|
||||
jpaProperties.put(EntityManagerFactoryProvider.DDL_GENERATION_MODE,
|
||||
EntityManagerFactoryProvider.DDL_DATABASE_GENERATION);
|
||||
}
|
||||
if (isShowSql()) {
|
||||
jpaProperties.setProperty(TopLinkProperties.LOGGING_LEVEL, Level.FINE.toString());
|
||||
jpaProperties.put(TopLinkProperties.LOGGING_LEVEL, Level.FINE.toString());
|
||||
}
|
||||
|
||||
return jpaProperties;
|
||||
|
||||
Reference in New Issue
Block a user