The existing EclipseLinkJpaVendorAdapter allows you to set some basic functions. Most of the parameters are not configurable over the existing one.
Here’s my extended version:
package de.mischur.utils;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter;
public class ExtendedEclipseLinkJpaVendorAdapter extends EclipseLinkJpaVendorAdapter {
public static final Logger log = LoggerFactory.getLogger(ExtendedEclipseLinkJpaVendorAdapter.class);
private String targetServer = null;
private String logger = null;
private String profiler = null;
private String cacheCoordinationNamingService = null;
private String cacheCoordinationProtocol = null;
private String jndiUser = null;
private String jndiPwd = null;
private String propagateAsynchronously = null;
private String removeConnectionOnError = null;
private String rmiUrl = null;
private String rmiAnnouncementDelay = null;
private String rmiMulticastGroup = null;
private String rmiMulticastGroupPort = null;
private String packetTime2Live = null;
private String jmsTopic = null;
private String jmsFactory = null;
private String jmsHost = null;
private String jmsReusePublisher = null;
@Override
public Map getJpaPropertyMap() {
Map jpaProperties = super.getJpaPropertyMap();
if (StringUtils.isNotEmpty(targetServer)) {
jpaProperties.put(PersistenceUnitProperties.TARGET_SERVER, targetServer);
}
if (StringUtils.isNotEmpty(logger)) {
jpaProperties.put(PersistenceUnitProperties.LOGGING_LOGGER, logger);
}
if (StringUtils.isNotEmpty(profiler)) {
jpaProperties.put(PersistenceUnitProperties.PROFILER, profiler);
}
if (StringUtils.isNotEmpty(cacheCoordinationProtocol)) {
jpaProperties.put(PersistenceUnitProperties.COORDINATION_PROTOCOL, cacheCoordinationProtocol);
if (StringUtils.isNotEmpty(cacheCoordinationNamingService)) {
jpaProperties.put(PersistenceUnitProperties.COORDINATION_NAMING_SERVICE, cacheCoordinationNamingService);
}
if (StringUtils.isNotEmpty(jndiUser)) {
jpaProperties.put(PersistenceUnitProperties.COORDINATION_JNDI_USER, jndiUser);
}
if (StringUtils.isNotEmpty(jndiPwd)) {
jpaProperties.put(PersistenceUnitProperties.COORDINATION_JNDI_PASSWORD, jndiPwd);
}
if (StringUtils.isNotEmpty(propagateAsynchronously)) {
jpaProperties.put(PersistenceUnitProperties.COORDINATION_ASYNCH, propagateAsynchronously);
}
if (StringUtils.equalsIgnoreCase("rmi", cacheCoordinationProtocol)) {
if (StringUtils.isNotEmpty(rmiUrl)) {
jpaProperties.put(PersistenceUnitProperties.COORDINATION_RMI_URL, rmiUrl);
}
if (StringUtils.isNotEmpty(packetTime2Live)) {
jpaProperties.put(PersistenceUnitProperties.COORDINATION_RMI_PACKET_TIME_TO_LIVE, packetTime2Live);
}
if (StringUtils.isNotEmpty(rmiMulticastGroup)) {
jpaProperties.put(PersistenceUnitProperties.COORDINATION_RMI_MULTICAST_GROUP, rmiMulticastGroup);
}
if (StringUtils.isNotEmpty(rmiMulticastGroupPort)) {
jpaProperties.put(PersistenceUnitProperties.COORDINATION_RMI_MULTICAST_GROUP_PORT, rmiMulticastGroupPort);
}
if (StringUtils.isNotEmpty(rmiAnnouncementDelay)) {
jpaProperties.put(PersistenceUnitProperties.COORDINATION_RMI_ANNOUNCEMENT_DELAY, rmiAnnouncementDelay);
}
if (StringUtils.isNotEmpty(removeConnectionOnError)) {
jpaProperties.put(PersistenceUnitProperties.COORDINATION_REMOVE_CONNECTION, removeConnectionOnError);
}
}
if (StringUtils.equalsIgnoreCase("jms", cacheCoordinationProtocol)) {
if (StringUtils.isNotEmpty(jmsTopic)) {
jpaProperties.put(PersistenceUnitProperties.COORDINATION_JMS_TOPIC, jmsTopic);
}
if (StringUtils.isNotEmpty(jmsFactory)) {
jpaProperties.put(PersistenceUnitProperties.COORDINATION_JMS_FACTORY, jmsFactory);
}
if (StringUtils.isNotEmpty(jmsHost)) {
jpaProperties.put(PersistenceUnitProperties.COORDINATION_JMS_HOST, jmsHost);
}
if (StringUtils.isNotEmpty(jmsReusePublisher)) {
jpaProperties.put(PersistenceUnitProperties.COORDINATION_JMS_REUSE_PUBLISHER, jmsReusePublisher);
}
}
}
if (StringUtils.isNotEmpty(weavingInternal)) {
jpaProperties.put(PersistenceUnitProperties.WEAVING_INTERNAL, Boolean.toString(BooleanUtils.toBoolean(weavingInternal)));
}
if (log.isDebugEnabled()) {
log.debug("After setting own props");
for (String key : jpaProperties.keySet()) {
log.debug(key + "=" + jpaProperties.get(key));
}
}
return jpaProperties;
}
public String getTargetServer() {
return targetServer;
}
/**
* Overrides the property <property>eclipselink.target-server</property>
from persistence.xml
* @see org.eclipse.persistence.config.PersistenceUnitProperties#TARGET_SERVER
*/
public void setTargetServer(String targetServer) {
this.targetServer = targetServer;
}
public String getLogger() {
return logger;
}
/**
* Overrides the property <property>eclipselink.logging.logger</property>
from persistence.xml
* @see org.eclipse.persistence.config.PersistenceUnitProperties#LOGGING_LOGGER
*/
public void setLogger(String logger) {
this.logger = logger;
}
public String getProfiler() {
return profiler;
}
/**
* Overrides the property <property>eclipselink.profiler</property>
from persistence.xml
* @see org.eclipse.persistence.config.PersistenceUnitProperties#PROFILER
*/
public void setProfiler(String profiler) {
this.profiler = profiler;
}
public String getCacheCoordinationNamingService() {
return cacheCoordinationNamingService;
}
public void setCacheCoordinationNamingService(String cacheCoordinationNamingService) {
this.cacheCoordinationNamingService = cacheCoordinationNamingService;
}
public String getRemoveConnectionOnError() {
return removeConnectionOnError;
}
/**
* Overrides the property <property>eclipselink.cache.coordination.remove-connection-on-error</property>
from persistence.xml
* @see org.eclipse.persistence.config.PersistenceUnitProperties#COORDINATION_REMOVE_CONNECTION
*/
public void setRemoveConnectionOnError(String removeConnectionOnError) {
this.removeConnectionOnError = removeConnectionOnError;
}
public String getCacheCoordinationProtocol() {
return cacheCoordinationProtocol;
}
/**
* Overrides the property <property>eclipselink.cache.coordination.protocol</property>
from persistence.xml
* @see org.eclipse.persistence.config.PersistenceUnitProperties#COORDINATION_PROTOCOL
*/
public void setCacheCoordinationProtocol(String cacheCoordinationProtocol) {
this.cacheCoordinationProtocol = cacheCoordinationProtocol;
}
public String getRmiUrl() {
return rmiUrl;
}
/**
* Overrides the property <property>eclipselink.cache.coordination.rmi.url</property>
from persistence.xml
* @see org.eclipse.persistence.config.PersistenceUnitProperties#COORDINATION_RMI_URL
*/
public void setRmiUrl(String rmiUrl) {
this.rmiUrl = rmiUrl;
}
public String getJndiUser() {
return jndiUser;
}
/**
* Overrides the property <property>eclipselink.cache.coordination.jndi.user</property>
from persistence.xml
* @see org.eclipse.persistence.config.PersistenceUnitProperties#COORDINATION_JNDI_USER
*/
public void setJndiUser(String jndiUser) {
this.jndiUser = jndiUser;
}
public String getJndiPwd() {
return jndiPwd;
}
/**
* Overrides the property <property>eclipselink.cache.coordination.jndi.password</property>
from persistence.xml
* @see org.eclipse.persistence.config.PersistenceUnitProperties#COORDINATION_JNDI_PASSWORD
*/
public void setJndiPwd(String jndiPwd) {
this.jndiPwd = jndiPwd;
}
public String getPropagateAsynchronously() {
return propagateAsynchronously;
}
/**
* Overrides the property <property>eclipselink.cache.coordination.propagate-asynchronously</property>
from persistence.xml
* @see org.eclipse.persistence.config.PersistenceUnitProperties#COORDINATION_ASYNCH
*/
public void setPropagateAsynchronously(String propagateAsynchronously) {
this.propagateAsynchronously = propagateAsynchronously;
}
public String getRmiAnnouncementDelay() {
return rmiAnnouncementDelay;
}
/**
* Overrides the property <property>eclipselink.cache.coordination.rmi.announcement-delay</property>
from persistence.xml
* @see org.eclipse.persistence.config.PersistenceUnitProperties#COORDINATION_RMI_ANNOUNCEMENT_DELAY
*/
public void setRmiAnnouncementDelay(String rmiAnnouncementDelay) {
this.rmiAnnouncementDelay = rmiAnnouncementDelay;
}
public String getRmiMulticastGroup() {
return rmiMulticastGroup;
}
/**
* Overrides the property <property>eclipselink.cache.coordination.rmi.multicast-group</property>
from persistence.xml
* @see org.eclipse.persistence.config.PersistenceUnitProperties#COORDINATION_RMI_MULTICAST_GROUP
*/
public void setRmiMulticastGroup(String rmiMulticastGroup) {
this.rmiMulticastGroup = rmiMulticastGroup;
}
public String getRmiMulticastGroupPort() {
return rmiMulticastGroupPort;
}
/**
* Overrides the property <property>eclipselink.cache.coordination.rmi.multicast-group.port</property>
from persistence.xml
* @see org.eclipse.persistence.config.PersistenceUnitProperties#COORDINATION_RMI_MULTICAST_GROUP_PORT
*/
public void setRmiMulticastGroupPort(String rmiMulticastGroupPort) {
this.rmiMulticastGroupPort = rmiMulticastGroupPort;
}
public String getPacketTime2Live() {
return packetTime2Live;
}
/**
* Overrides the property <property>eclipselink.cache.coordination.rmi.packet-time-to-live</property>
from persistence.xml
* @see org.eclipse.persistence.config.PersistenceUnitProperties#COORDINATION_RMI_PACKET_TIME_TO_LIVE
*/
public void setPacketTime2Live(String packetTime2Live) {
this.packetTime2Live = packetTime2Live;
}
public String getJmsTopic() {
return jmsTopic;
}
/**
* Overrides the property <property>eclipselink.cache.coordination.jms.topic</property>
from persistence.xml
* @see org.eclipse.persistence.config.PersistenceUnitProperties#COORDINATION_JMS_TOPIC
*/
public void setJmsTopic(String jmsTopic) {
this.jmsTopic = jmsTopic;
}
public String getJmsFactory() {
return jmsFactory;
}
/**
* Overrides the property <property>eclipselink.cache.coordination.jms.factory</property>
from persistence.xml
* @see org.eclipse.persistence.config.PersistenceUnitProperties#COORDINATION_JMS_FACTORY
*/
public void setJmsFactory(String jmsFactory) {
this.jmsFactory = jmsFactory;
}
public String getJmsHost() {
return jmsHost;
}
/**
* Overrides the property <property>eclipselink.cache.coordination.jms.host</property>
from persistence.xml
* @see org.eclipse.persistence.config.PersistenceUnitProperties#COORDINATION_JMS_HOST
*/
public void setJmsHost(String jmsHost) {
this.jmsHost = jmsHost;
}
public String getJmsReusePublisher() {
return jmsReusePublisher;
}
/**
* Overrides the property <eclipselink.cache.coordination.jms.reuse-topic-publisher</property>
from persistence.xml
* @see org.eclipse.persistence.config.PersistenceUnitProperties#COORDINATION_JMS_REUSE_PUBLISHER
*/
public void setJmsReusePublisher(String jmsReusePublisher) {
this.jmsReusePublisher = jmsReusePublisher;
}
public String getWeavingInternal() {
return weavingInternal;
}
/**
* Overrides the property <eclipselink.weaving.internal</property>
from persistence.xml
* @see org.eclipse.persistence.config.PersistenceUnitProperties#WEAVING_INTERNAL
*/
public void setWeavingInternal(String weavingInternal) {
this.weavingInternal = weavingInternal;
}
}
And the related xml declaration:
Config for EclipseLink
Keine Kommentare:
Kommentar veröffentlichen