- Moved agent for MySportsProvider into Test project
- Using session customizer to create MOXy context at JPA boot time (Enable's use in JPA-RS with extensions)
- Renamed provider to be MySports specific (and initializer)
diff --git a/Multitenant JPA Provider/.classpath b/Multitenant JPA Provider/.classpath
deleted file mode 100644
index e0cfb85..0000000
--- a/Multitenant JPA Provider/.classpath
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
- <classpathentry combineaccessrules="false" kind="src" path="/MySports"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
diff --git a/Multitenant JPA Provider/.project b/Multitenant JPA Provider/.project
deleted file mode 100644
index 30ad994..0000000
--- a/Multitenant JPA Provider/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>Multitenant JPA Provider</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
diff --git a/Multitenant JPA Provider/.settings/org.eclipse.jdt.core.prefs b/Multitenant JPA Provider/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index 8000cd6..0000000
--- a/Multitenant JPA Provider/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,11 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.6
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.6
diff --git a/Multitenant JPA Provider/eclipselink_mtjpa.jar b/Multitenant JPA Provider/eclipselink_mtjpa.jar
deleted file mode 100644
index 3323c08..0000000
--- a/Multitenant JPA Provider/eclipselink_mtjpa.jar
+++ /dev/null
Binary files differ
diff --git a/MySports Admin/src/META-INF/persistence.xml b/MySports Admin/src/META-INF/persistence.xml
index 1718929..4a5cfcc 100644
--- a/MySports Admin/src/META-INF/persistence.xml
+++ b/MySports Admin/src/META-INF/persistence.xml
@@ -15,7 +15,6 @@
<properties>
<property name="eclipselink.logging.timestamp" value="false" />
<property name="eclipselink.logging.thread" value="false" />
- <property name="eclipselink.logging.session" value="false" />
<property name="eclipselink.logging.exceptions" value="false" />
<property name="eclipselink.logging.connection" value="false" />
<property name="eclipselink.logging.level.ejb_or_metadata" value="WARNING" />
diff --git a/MySports Admin/src/example/mysports/admin/jsf/HostEnvironmentRepositoryBean.java b/MySports Admin/src/example/mysports/admin/jsf/HostEnvironmentRepositoryBean.java
index cbe0f68..d653be8 100644
--- a/MySports Admin/src/example/mysports/admin/jsf/HostEnvironmentRepositoryBean.java
+++ b/MySports Admin/src/example/mysports/admin/jsf/HostEnvironmentRepositoryBean.java
@@ -17,8 +17,6 @@
import javax.faces.bean.ManagedBean;
import javax.inject.Inject;
-import com.sun.xml.registry.uddi.bindings_v2_2.HostingRedirector;
-
import example.mysports.admin.model.HostEnvironment;
import example.mysports.admin.services.HostEnvironmentRepository;
diff --git a/MySports Admin/src/example/mysports/admin/model/HostedLeague.java b/MySports Admin/src/example/mysports/admin/model/HostedLeague.java
index ceb391b..c5d74f1 100644
--- a/MySports Admin/src/example/mysports/admin/model/HostedLeague.java
+++ b/MySports Admin/src/example/mysports/admin/model/HostedLeague.java
@@ -25,6 +25,7 @@
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
+import javax.persistence.Transient;
import javax.persistence.Version;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
@@ -62,6 +63,7 @@
private String logoUrl;
+ @Transient
private String uri;
@Column(name="datasource")
diff --git a/MySports App/src/META-INF/persistence.xml b/MySports App/src/META-INF/persistence.xml
index be2543a..fe7b99c 100644
--- a/MySports App/src/META-INF/persistence.xml
+++ b/MySports App/src/META-INF/persistence.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="mysports" transaction-type="RESOURCE_LOCAL">
- <provider>example.mysports.persistence.MultitenantPersistenceProvider</provider>
+ <provider>example.mysports.persistence.MySportsProvider</provider>
<non-jta-data-source>jdbc/MySports</non-jta-data-source>
<mapping-file>META-INF/local-eclipselink-orm.xml</mapping-file>
@@ -24,9 +24,7 @@
<!-- Tenant specific extension definition access -->
<property name="eclipselink.metadata-source" value="example.mysports.admin.AdminMetadataSource"/>
-
- <!-- EMF per tenant configuration -->
- <property name="eclipselink.template-unit-name" value="mysports"/>
+ <property name="eclipselink.session.customizer" value="example.mysports.persistence.JaxbContextFactory"/>
</properties>
</persistence-unit>
</persistence>
diff --git a/MySports App/src/META-INF/services/javax.persistence.spi.PersistenceProvider b/MySports App/src/META-INF/services/javax.persistence.spi.PersistenceProvider
index 359cc4a..81ec397 100644
--- a/MySports App/src/META-INF/services/javax.persistence.spi.PersistenceProvider
+++ b/MySports App/src/META-INF/services/javax.persistence.spi.PersistenceProvider
@@ -1 +1 @@
-example.mysports.persistence.MultitenantPersistenceProvider
\ No newline at end of file
+example.mysports.persistence.MySportsProvider
\ No newline at end of file
diff --git a/MySports App/src/example/mysports/MySportsConfig.java b/MySports App/src/example/mysports/MySportsConfig.java
index e43fe08..c4d4e4e 100644
--- a/MySports App/src/example/mysports/MySportsConfig.java
+++ b/MySports App/src/example/mysports/MySportsConfig.java
@@ -14,14 +14,17 @@
import java.io.IOException;
import java.io.InputStream;
+import java.util.Map;
import java.util.Properties;
+import javax.persistence.EntityManagerFactory;
+
import org.eclipse.persistence.annotations.Multitenant;
-import org.eclipse.persistence.internal.helper.ConversionManager;
import example.mysports.admin.AdminServerConnector;
import example.mysports.admin.League;
import example.mysports.ejb.LeagueRepository;
+import example.mysports.persistence.MySportsProvider;
/**
* Responsible for managing application context configuration. For now this is
@@ -56,6 +59,11 @@
public static final String ADMIN_CONNECTOR_PROPERTY = "mysports.admin-connector";
/**
+ * Property name to cache MySportsConfig instance in a map.
+ */
+ public static final String CONFIG_PROPERTY = MySportsConfig.class.getName();
+
+ /**
* TODO
*/
private Properties properties;
@@ -87,6 +95,22 @@
}
+ /**
+ * Retrieve the MySportsConfig from the provided map. If one is not present
+ * create one and add it to the map. This is used to lookup and initialize
+ * the cached instance in the {@link EntityManagerFactory}'s properties.
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public static MySportsConfig get(Map properties) {
+ MySportsConfig config = (MySportsConfig) properties.get(CONFIG_PROPERTY);
+
+ if (config == null) {
+ config = new MySportsConfig();
+ properties.put(CONFIG_PROPERTY, config);
+ }
+ return config;
+ }
+
protected String getProperty(String name) {
return (String) this.properties.get(name);
}
@@ -95,15 +119,19 @@
if (this.adminConnector == null) {
Object value = getProperty(ADMIN_CONNECTOR_PROPERTY);
if (value != null && value instanceof String) {
- @SuppressWarnings("unchecked")
- Class<AdminServerConnector> connectorClass = ConversionManager.getDefaultManager().convertClassNameToClass((String) value);
+
try {
+ @SuppressWarnings("unchecked")
+ Class<AdminServerConnector> connectorClass = (Class<AdminServerConnector>) Class.forName((String) value, true, Thread.currentThread().getContextClassLoader());
+
+ if (!AdminServerConnector.class.isAssignableFrom(connectorClass)) {
+ System.err.println("Invalid AdminServerConnector: " + connectorClass);
+ }
+
this.adminConnector = connectorClass.newInstance();
this.adminConnector.setConfig(this);
- } catch (InstantiationException e) {
- throw new RuntimeException("Could not create AdminServerConnector", e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException("Could not create AdminServerConnector", e);
+ } catch (Exception e) {
+ throw new RuntimeException("Could not create AdminServerConnector with value: " + value, e);
}
}
}
@@ -115,7 +143,7 @@
if (leagueId == null || leagueId.isEmpty()) {
throw new IllegalArgumentException("Multitenant instance requires leagueId");
}
- return PU_NAME + "-" + leagueId;
+ return PU_NAME + MySportsProvider.SEPARATOR + leagueId;
}
return null;
}
@@ -123,7 +151,7 @@
public boolean isMultitenant() {
return !this.properties.containsKey(LEAGUE_CONTEXT);
}
-
+
public String getAdminContext() {
return getProperty(ADMIN_SERVER_CONTEXT_PROPERTY);
}
@@ -132,7 +160,7 @@
if (isMultitenant() && leagueId != null) {
getAdminConnector().getLeague(leagueId);
}
-
+
if (this.league == null && this.properties.containsKey(LEAGUE_CONTEXT)) {
this.league = new League();
this.league.setId(getProperty(LEAGUE_CONTEXT));
diff --git a/MySports App/src/example/mysports/admin/AdminMetadataSource.java b/MySports App/src/example/mysports/admin/AdminMetadataSource.java
index d9795c5..7d75922 100644
--- a/MySports App/src/example/mysports/admin/AdminMetadataSource.java
+++ b/MySports App/src/example/mysports/admin/AdminMetadataSource.java
@@ -18,7 +18,6 @@
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.eclipse.persistence.exceptions.ValidationException;
-import org.eclipse.persistence.internal.jpa.deployment.JavaSECMPInitializer;
import org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings;
import org.eclipse.persistence.jpa.metadata.MetadataSource;
import org.eclipse.persistence.jpa.metadata.XMLMetadataSource;
@@ -45,18 +44,9 @@
@Override
public XMLEntityMappings getEntityMappings(Map<String, Object> properties, ClassLoader classLoader, SessionLog log) {
- String sessionName = (String) properties.get(PersistenceUnitProperties.SESSION_NAME);
String leagueId = (String) properties.get(LEAGUE_CONTEXT);
- MySportsConfig config = (MySportsConfig) properties.get(MySportsConfig.class.getName());
+ MySportsConfig config = MySportsConfig.get(properties);
- if (!valid(sessionName) && config != null && valid(leagueId)) {
- properties.put(PersistenceUnitProperties.SESSION_NAME, config.getSessionName(leagueId));
- }
-
-
- if ((leagueId == null || config == null) && !(classLoader instanceof JavaSECMPInitializer.TempEntityLoader)) {
- // throw new RuntimeException("No league specified");
- }
if (config != null) {
properties.put(PersistenceUnitProperties.METADATA_SOURCE_XML_URL, config.getAdminConnector().getOrmURL(leagueId));
}
@@ -72,11 +62,4 @@
return super.getEntityMappings(properties, classLoader, log);
}
- /**
- * Simple test to make sure the property value is both non null and not
- * empty.
- */
- private boolean valid(String value) {
- return value != null && !value.isEmpty();
- }
}
diff --git a/MySports App/src/example/mysports/ejb/LeagueRepository.java b/MySports App/src/example/mysports/ejb/LeagueRepository.java
index 55b4099..a26b1e5 100644
--- a/MySports App/src/example/mysports/ejb/LeagueRepository.java
+++ b/MySports App/src/example/mysports/ejb/LeagueRepository.java
@@ -13,8 +13,6 @@
package example.mysports.ejb;
import static example.mysports.MySportsConfig.LEAGUE_CONTEXT;
-import static example.mysports.MySportsConfig.PU_NAME;
-import static org.eclipse.persistence.config.PersistenceUnitProperties.*;
import java.io.Serializable;
import java.util.ArrayList;
@@ -41,12 +39,10 @@
import javax.persistence.metamodel.ManagedType;
import javax.persistence.metamodel.Metamodel;
import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
import org.eclipse.persistence.annotations.Multitenant;
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.eclipse.persistence.internal.jpa.metamodel.AttributeImpl;
-import org.eclipse.persistence.jaxb.JAXBContextFactory;
import org.eclipse.persistence.jpa.JpaHelper;
import org.eclipse.persistence.logging.SessionLog;
import org.eclipse.persistence.mappings.AttributeAccessor;
@@ -58,11 +54,12 @@
import example.mysports.admin.League;
import example.mysports.model.Division;
import example.mysports.model.Division_;
-import example.mysports.model.Divisions;
import example.mysports.model.Player;
import example.mysports.model.Player_;
import example.mysports.model.Team;
import example.mysports.model.Team_;
+import example.mysports.persistence.JaxbContextFactory;
+import example.mysports.persistence.MySportsProvider;
/**
* MySports Domain Model Repository providing simplified persistence facade for
@@ -433,7 +430,7 @@
}
emfProps.put(LEAGUE_CONTEXT, leagueId);
- emfProps.put(MySportsConfig.class.getName(), getConfig());
+ emfProps.put(MySportsConfig.CONFIG_PROPERTY, getConfig());
this.emf = Persistence.createEntityManagerFactory(getConfig().getSessionName(leagueId), emfProps);
this.leagueId = leagueId;
@@ -445,44 +442,11 @@
session.getSessionLog().log(SessionLog.CONFIG, "LeagueRepository[" + hashCode() + "] initialized with session named: " + session.getName());
}
- /*
- * MOXy (JAXB) API
- */
-
/**
- * Property name for caching the {@link JAXBContext} for the league within
- * its {@link EntityManagerFactory}
- */
- private static final String JAXB_CONTEXT = "jaxb-context";
-
- private static final String MAPPING_FILE = "META-INF/eclipselink-oxm.xml";
-
- /**
- * Create an EclipseLink {@link JAXBContext} which is built from the
- * {@value #MAPPING_FILE} combined with the virtual attribute extended
- * mappings returned from the call to the Admin server.
+ *
*/
public JAXBContext getJAXBContext() {
- JAXBContext context = (JAXBContext) JpaHelper.getServerSession(getEMF()).getProperty(JAXB_CONTEXT);
-
- if (context == null) {
- List<String> xmlBindings = new ArrayList<String>();
- xmlBindings.add(MAPPING_FILE);
- xmlBindings.add(getConfig().getAdminConnector().getOxmURL(getLeagueId()));
-
- Map<String, Object> props = new HashMap<String, Object>();
- props.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, xmlBindings);
-
- try {
- context = JAXBContextFactory.createContext(new Class[] { Divisions.class }, props);
- } catch (JAXBException e) {
- throw new RuntimeException("JAXB Failure to create context. League: " + getLeagueId(), e);
- }
-
- // Cache the JAXB context in the shared session's properties
- JpaHelper.getServerSession(getEMF()).setProperty(JAXB_CONTEXT, context);
- }
- return context;
+ return JaxbContextFactory.getJAXBContext(getEMF().getProperties());
}
}
diff --git a/MySports App/src/example/mysports/ejb/PersistenceWeavingBean.java b/MySports App/src/example/mysports/ejb/PersistenceWeavingBean.java
index 5d99510..fd3b681 100644
--- a/MySports App/src/example/mysports/ejb/PersistenceWeavingBean.java
+++ b/MySports App/src/example/mysports/ejb/PersistenceWeavingBean.java
@@ -15,7 +15,6 @@
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceProperty;
import javax.persistence.PersistenceUnit;
diff --git a/MySports App/src/example/mysports/persistence/JaxbContextFactory.java b/MySports App/src/example/mysports/persistence/JaxbContextFactory.java
new file mode 100644
index 0000000..b95a6a7
--- /dev/null
+++ b/MySports App/src/example/mysports/persistence/JaxbContextFactory.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ * dclarke - EclipseLink 2.4 - MySports Demo Bug 344608
+ ******************************************************************************/
+package example.mysports.persistence;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.EntityManagerFactory;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.eclipse.persistence.config.SessionCustomizer;
+import org.eclipse.persistence.jaxb.JAXBContextFactory;
+import org.eclipse.persistence.sessions.Session;
+
+import example.mysports.MySportsConfig;
+import example.mysports.model.Divisions;
+
+/**
+ * Create an EclipseLink {@link JAXBContext} which is built from the
+ * {@value #MAPPING_FILE} combined with the virtual attribute extended mappings
+ * returned from the call to the Admin server.
+ *
+ * @author dclarke
+ * @since EclipseLink 2.4
+ */
+public class JaxbContextFactory implements SessionCustomizer {
+
+ /**
+ * Property name for caching the {@link JAXBContext} for the league within
+ * its {@link EntityManagerFactory}
+ */
+ private static final String JAXB_CONTEXT = org.eclipse.persistence.jaxb.JAXBContext.class.getName();
+
+ /**
+ * EclipseLink MOXy mapping file to use when creating the context
+ */
+ private static final String MAPPING_FILE = "META-INF/eclipselink-oxm.xml";
+
+ @Override
+ public void customize(Session session) throws Exception {
+ getJAXBContext(session.getProperties());
+ }
+
+ /**
+ * Create an EclipseLink {@link JAXBContext} which is built from the
+ * {@value #MAPPING_FILE} combined with the virtual attribute extended
+ * mappings returned from the call to the Admin server.
+ *
+ * @param properties
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public static JAXBContext getJAXBContext(Map properties) {
+ JAXBContext context = (JAXBContext) properties.get(JAXB_CONTEXT);
+ MySportsConfig config = MySportsConfig.get(properties);
+ String leagueId = (String) properties.get(MySportsConfig.LEAGUE_CONTEXT);
+
+ if (context == null && leagueId != null) {
+ Map<String, Object> props = new HashMap<String, Object>();
+
+ List<String> xmlBindings = new ArrayList<String>();
+ xmlBindings.add(MAPPING_FILE);
+
+ String url = config.getAdminConnector().getOxmURL(leagueId);
+ if (url != null) {
+ xmlBindings.add(url);
+ }
+ props.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, xmlBindings);
+
+ try {
+ context = JAXBContextFactory.createContext(new Class[] { Divisions.class }, props);
+ } catch (JAXBException e) {
+ throw new RuntimeException("JAXB Failure to create context. League: " + leagueId, e);
+ }
+
+ // Cache the JAXB context in the shared session's properties
+ properties.put(JAXB_CONTEXT, context);
+ }
+ return context;
+ }
+
+}
diff --git a/MySports App/src/example/mysports/persistence/MultitenantPersistenceProvider.java b/MySports App/src/example/mysports/persistence/MultitenantPersistenceProvider.java
deleted file mode 100644
index 1119c16..0000000
--- a/MySports App/src/example/mysports/persistence/MultitenantPersistenceProvider.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010-2012 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * dclarke - EclipseLink 2.4 - MySports Demo Bug 344608
- ******************************************************************************/
-package example.mysports.persistence;
-
-import java.util.Map;
-
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.spi.PersistenceUnitInfo;
-
-import org.eclipse.persistence.config.PersistenceUnitProperties;
-import org.eclipse.persistence.internal.jpa.deployment.JPAInitializer;
-import org.eclipse.persistence.jpa.PersistenceProvider;
-
-/**
- * {@link EntityManagerFactory} per tenant provider.
- *
- * @author dclarke
- *
- */
-public class MultitenantPersistenceProvider extends PersistenceProvider {
-
- /**
- * TODO
- */
- public static final String TEMPLATE_PU_NAME = "eclipselink.template-unit-name";
-
- @SuppressWarnings("rawtypes")
- @Override
- public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) {
- return super.createContainerEntityManagerFactory(info, properties);
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- @Override
- public EntityManagerFactory createEntityManagerFactory(String name, Map properties) {
- String puName = name;
-
- if (properties != null && properties.containsKey(TEMPLATE_PU_NAME)) {
- puName = (String) properties.get(TEMPLATE_PU_NAME);
- properties.put(PersistenceUnitProperties.SESSION_NAME, name);
- properties.put(PersistenceUnitProperties.MULTITENANT_SHARED_EMF, Boolean.FALSE.toString());
- }
-
- EntityManagerFactory emf = super.createEntityManagerFactory(puName, properties);
-
- if (emf == null && name.contains("-")) {
- properties.put(TEMPLATE_PU_NAME, name.substring(0, name.indexOf("-")));
- return createEntityManagerFactory(name, properties);
- }
-
- return emf;
- }
-
- @SuppressWarnings("rawtypes")
- @Override
- public JPAInitializer getInitializer(String emName, Map m) {
- ClassLoader classLoader = getClassLoader(emName, m);
- return MultitenantJavaSECMPInitializer.getJavaSECMPInitializer(classLoader);
- }
-
-}
diff --git a/MySports App/src/example/mysports/persistence/MySportsProvider.java b/MySports App/src/example/mysports/persistence/MySportsProvider.java
new file mode 100644
index 0000000..d0cbe19
--- /dev/null
+++ b/MySports App/src/example/mysports/persistence/MySportsProvider.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ * dclarke - EclipseLink 2.4 - MySports Demo Bug 344608
+ ******************************************************************************/
+package example.mysports.persistence;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.spi.PersistenceUnitInfo;
+
+import org.eclipse.persistence.config.PersistenceUnitProperties;
+import org.eclipse.persistence.internal.jpa.deployment.JPAInitializer;
+import org.eclipse.persistence.jpa.PersistenceProvider;
+
+import example.mysports.MySportsConfig;
+
+/**
+ * Custom {@link javax.persistence.spi.PersistenceProvider} to support
+ * EclipseLink JPA usage with an {@link EntityManagerFactory} per tenant. This
+ * implementation is specific to the MySports example
+ *
+ * @author dclarke
+ * @since EclipseLink 2.4
+ */
+@SuppressWarnings({ "rawtypes", "unchecked" })
+public class MySportsProvider extends PersistenceProvider {
+
+ public static final String SEPARATOR = "-";
+
+ @Override
+ public EntityManagerFactory createEntityManagerFactory(String name, Map properties) {
+ String puName = name;
+ Map props = properties == null ? new HashMap() : properties;
+
+ if (name.contains(SEPARATOR)) {
+ int sepIndex = name.indexOf(SEPARATOR);
+ puName = name.substring(0, sepIndex);
+ props.put(PersistenceUnitProperties.SESSION_NAME, name);
+ props.put(PersistenceUnitProperties.MULTITENANT_SHARED_EMF, Boolean.FALSE.toString());
+ props.put(MySportsConfig.LEAGUE_CONTEXT, name.substring(sepIndex + 1));
+ }
+
+ return super.createEntityManagerFactory(puName, props);
+ }
+
+ @Override
+ public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) {
+ // TODO Auto-generated method stub
+ return super.createContainerEntityManagerFactory(info, properties);
+ }
+
+ @Override
+ public JPAInitializer getInitializer(String emName, Map m) {
+ ClassLoader classLoader = getClassLoader(emName, m);
+ return MySportsProviderInitializer.getJavaSECMPInitializer(classLoader);
+ }
+}
diff --git a/MySports App/src/example/mysports/persistence/MultitenantJavaSECMPInitializer.java b/MySports App/src/example/mysports/persistence/MySportsProviderInitializer.java
similarity index 84%
rename from MySports App/src/example/mysports/persistence/MultitenantJavaSECMPInitializer.java
rename to MySports App/src/example/mysports/persistence/MySportsProviderInitializer.java
index cebe9cb..f989ac0 100644
--- a/MySports App/src/example/mysports/persistence/MultitenantJavaSECMPInitializer.java
+++ b/MySports App/src/example/mysports/persistence/MySportsProviderInitializer.java
@@ -20,8 +20,18 @@
import org.eclipse.persistence.logging.AbstractSessionLog;
import org.eclipse.persistence.logging.SessionLog;
+/**
+ * Custom initializer to support {@link MySportsProvider} usage.
+ * This subclass is required to ensure
+ * {@link #isPersistenceProviderSupported(String)} passes when using the custom
+ * provider as well as storing its own singlton instance of this initializer and
+ * avoid conflicting with the default EclipseLink JPA provider's initializer.
+ *
+ * @author dclarke
+ * @since EclipseLink 2.4
+ */
@SuppressWarnings("rawtypes")
-public class MultitenantJavaSECMPInitializer extends JavaSECMPInitializer {
+public class MySportsProviderInitializer extends JavaSECMPInitializer {
// Indicates whether has been initialized - that could be done only once.
protected static boolean isInitialized;
@@ -66,7 +76,7 @@
AbstractSessionLog.getLog().log(SessionLog.FINER, SessionLog.WEAVER, "cmp_init_initialize_from_agent", (Object[]) null);
}
usesAgent = true;
- initializer = new MultitenantJavaSECMPInitializer(classLoader);
+ initializer = new MySportsProviderInitializer(classLoader);
initializer.initialize(m != null ? m : new HashMap(0));
// all the transformers have been added to
// instrumentation, don't need it any more.
@@ -81,7 +91,7 @@
} else {
// when agent is not used initializer does not need to be
// initialized.
- return new MultitenantJavaSECMPInitializer(classLoader);
+ return new MySportsProviderInitializer(classLoader);
}
}
@@ -95,12 +105,12 @@
getJavaSECMPInitializerFromAgent();
}
- protected MultitenantJavaSECMPInitializer(ClassLoader loader) {
+ protected MySportsProviderInitializer(ClassLoader loader) {
super(loader);
}
@Override
public boolean isPersistenceProviderSupported(String providerClassName) {
- return providerClassName != null && providerClassName.equals(MultitenantPersistenceProvider.class.getName());
+ return providerClassName != null && providerClassName.equals("example.mysports.persistence.MySportsProvider");
}
}
diff --git a/MySports Tests/.classpath b/MySports Tests/.classpath
index 59c1568..c114364 100644
--- a/MySports Tests/.classpath
+++ b/MySports Tests/.classpath
@@ -2,6 +2,7 @@
<classpath>
<classpathentry combineaccessrules="false" kind="src" path="/javax.persistence 2.0.0"/>
<classpathentry excluding="**/.svn/**" kind="src" path="src"/>
+ <classpathentry kind="src" path="agent-src"/>
<classpathentry combineaccessrules="false" kind="src" path="/MySports"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
diff --git a/Multitenant JPA Provider/src/META-INF/MANIFEST.MF b/MySports Tests/agent-src/META-INF/MANIFEST.MF
similarity index 81%
rename from Multitenant JPA Provider/src/META-INF/MANIFEST.MF
rename to MySports Tests/agent-src/META-INF/MANIFEST.MF
index daa8b26..b10d0be 100644
--- a/Multitenant JPA Provider/src/META-INF/MANIFEST.MF
+++ b/MySports Tests/agent-src/META-INF/MANIFEST.MF
@@ -6,6 +6,6 @@
Implementation-Vendor: Eclipse.org - EclipseLink Project
Implementation-Version: 2.4
Release-Designation: EclipseLink 2.4
-Premain-Class: example.mysports.persistence.JavaSECMPInitializerAgent
+Premain-Class: example.mysports.persistence.MySportsWeavingAgent
diff --git a/MySports App/src/example/mysports/persistence/JavaSECMPInitializerAgent.java b/MySports Tests/agent-src/example/mysports/persistence/MySportsWeavingAgent.java
similarity index 66%
rename from MySports App/src/example/mysports/persistence/JavaSECMPInitializerAgent.java
rename to MySports Tests/agent-src/example/mysports/persistence/MySportsWeavingAgent.java
index e91a7eb..8e61ad7 100644
--- a/MySports App/src/example/mysports/persistence/JavaSECMPInitializerAgent.java
+++ b/MySports Tests/agent-src/example/mysports/persistence/MySportsWeavingAgent.java
@@ -17,18 +17,16 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-
/**
- * This agent is intended to be run prior to start up on a CMP3 JavaSE application.
- * It gets the globalInstrumentation and makes it available to EclipseLink's initialization code.
- * There are two kinds of initialization. Normally, initialization occurs through reflective
- * creation and invocation of EclipseLink JavaSECMPInitializer.
- * It is possible to run it with the "main" argument to the agent in which case it will simply
- * try to set the globalInstrumentation field on the JavaSECMPInitializer. This type of initialization
- * is useful when debugging, but imposes some restrictions on the user. One such restriction is
- * that no domain classes that use lazy loading may be references in any way other than reflective in the application
+ * Custom agent to support weaving with custom provider: {@link MySportsProvider}.
+ *
+ * @see MySportsProvider
+ * @see MySportsProviderInitializer
+ *
+ * @author dclarke
+ * @since EclipseLink 2.4
*/
-public class JavaSECMPInitializerAgent {
+public class MySportsWeavingAgent {
public static void premain(String agentArgs, Instrumentation instr) throws Throwable {
// Reflection allows:
// JavaSECMPInitializerAgent to be the *ONLY* class is the jar file specified in -javaagent;
@@ -41,7 +39,7 @@
}
public static void initializeFromAgent(Instrumentation instr) throws Throwable {
- Class cls = Class.forName("example.mysports.persistence.MultitenantJavaSECMPInitializer");
+ Class<?> cls = Class.forName("example.mysports.persistence.MySportsProviderInitializer");
Method method = cls.getDeclaredMethod("initializeFromAgent", new Class[] { Instrumentation.class });
try {
method.invoke(null, new Object[] { instr });
@@ -51,7 +49,7 @@
}
public static void initializeFromMain(Instrumentation instr) throws Exception {
- Class cls = Class.forName("example.mysports.persistence.MultitenantJavaSECMPInitializer");
+ Class<?> cls = Class.forName("example.mysports.persistence.MySportsProviderInitializer");
Field field = cls.getField("globalInstrumentation");
field.set(null, instr);
}
diff --git a/MySports Tests/eclipselink_mtjpa.jar b/MySports Tests/eclipselink_mtjpa.jar
deleted file mode 100644
index 3323c08..0000000
--- a/MySports Tests/eclipselink_mtjpa.jar
+++ /dev/null
Binary files differ
diff --git a/MySports Tests/export-agent.jardesc b/MySports Tests/export-agent.jardesc
new file mode 100644
index 0000000..b477d83
--- /dev/null
+++ b/MySports Tests/export-agent.jardesc
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="WINDOWS-1252" standalone="no"?>
+<jardesc>
+ <jar path="MySports Tests/mysports-agent.jar"/>
+ <options buildIfNeeded="true" compress="true" descriptionLocation="/MySports Tests/export-agent.jardesc" exportErrors="false" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
+ <storedRefactorings deprecationInfo="true" structuralOnly="false"/>
+ <selectedProjects/>
+ <manifest generateManifest="false" manifestLocation="/MySports Tests/agent-src/META-INF/MANIFEST.MF" manifestVersion="1.0" reuseManifest="false" saveManifest="false" usesManifest="true">
+ <sealing sealJar="false">
+ <packagesToSeal/>
+ <packagesToUnSeal/>
+ </sealing>
+ </manifest>
+ <selectedElements exportClassFiles="true" exportJavaFiles="true" exportOutputFolder="false">
+ <javaElement handleIdentifier="=MySports Tests/agent-src"/>
+ </selectedElements>
+</jardesc>
diff --git a/MySports Tests/mysports-agent.jar b/MySports Tests/mysports-agent.jar
new file mode 100644
index 0000000..2897f33
--- /dev/null
+++ b/MySports Tests/mysports-agent.jar
Binary files differ
diff --git a/MySports Tests/run-configs/CreateDatabase.launch b/MySports Tests/run-configs/CreateDatabase.launch
index 32e4df4..69a9ad2 100644
--- a/MySports Tests/run-configs/CreateDatabase.launch
+++ b/MySports Tests/run-configs/CreateDatabase.launch
@@ -12,5 +12,5 @@
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="example.mysports.tests.model.CreateDatabase"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="MySports Tests"/>
-<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-javaagent:"${project_loc:/MySports Tests}\eclipselink_mtjpa.jar""/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-javaagent:"${project_loc:/MySports Tests}\mysports-agent.jar""/>
</launchConfiguration>
diff --git a/MySports Tests/run-configs/MySports AllTests.launch b/MySports Tests/run-configs/MySports AllTests.launch
index 36dc1aa..01b8f59 100644
--- a/MySports Tests/run-configs/MySports AllTests.launch
+++ b/MySports Tests/run-configs/MySports AllTests.launch
@@ -16,5 +16,5 @@
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="example.mysports.tests.AllTests"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="MySports Tests"/>
-<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-javaagent:"${project_loc:/MySports Tests}\eclipselink_mtjpa.jar""/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-javaagent:"${project_loc:/MySports Tests}\mysports-agent.jar""/>
</launchConfiguration>
diff --git a/MySports Tests/src/example/mysports/tests/admin/MockAdminMetadataSource.java b/MySports Tests/src/example/mysports/tests/admin/MockAdminMetadataSource.java
index 8187fb4..4308021 100644
--- a/MySports Tests/src/example/mysports/tests/admin/MockAdminMetadataSource.java
+++ b/MySports Tests/src/example/mysports/tests/admin/MockAdminMetadataSource.java
@@ -33,9 +33,6 @@
/**
* {@link MetadataSource} which using REST calls to retrieve the league (tenant)
* specific mappings from the MySports Admin application.
- * <p>
- * If the Admin application can not be reached a warning message is logged and
- * the contained 'local-eclipselink-orm.xml' is returned.
*
* @author dclarke
* @since EclipseLink 2.3.0
@@ -52,11 +49,12 @@
@Override
public XMLEntityMappings getEntityMappings(Map<String, Object> properties, ClassLoader classLoader, SessionLog log) {
String leagueId = (String) properties.get(LEAGUE_CONTEXT);
+
EntityManager em = getAdminEMF().createEntityManager();
try {
String ormxml = MappingsLoader.getORMapping(em, leagueId);
- return readMappings(ormxml, properties,classLoader);
+ return readMappings(ormxml, properties, classLoader);
} finally {
em.close();
}
@@ -69,17 +67,17 @@
}
return this.adminEMF;
}
-
+
private XMLEntityMappings readMappings(String ormxml, Map<String, Object> properties, ClassLoader classLoader) {
Reader reader = new StringReader(ormxml);
try {
return XMLEntityMappingsReader.read(getClass().getName(), reader, classLoader, properties);
} finally {
- if (reader!=null) {
+ if (reader != null) {
try {
reader.close();
} catch (Exception e) {
- //ignore so we rethrow original exception if there was one.
+ // ignore so we rethrow original exception if there was one.
}
}
}
diff --git a/MySports Tests/src/example/mysports/tests/admin/MockAdminServerConnector.java b/MySports Tests/src/example/mysports/tests/admin/MockAdminServerConnector.java
index cd8e0ba..5edfabd 100644
--- a/MySports Tests/src/example/mysports/tests/admin/MockAdminServerConnector.java
+++ b/MySports Tests/src/example/mysports/tests/admin/MockAdminServerConnector.java
@@ -101,7 +101,7 @@
}
public String getOxmURL(String leagueId) {
- return leagueId;
+ return null;
}
public EntityManagerFactory getEMF() {
return ((MockHostedLeagueRepository)this.leaguesBean.getRepository()).getEmf();
diff --git a/MySports Tests/src/example/mysports/tests/model/CreateDatabase.java b/MySports Tests/src/example/mysports/tests/model/CreateDatabase.java
index 884e7d6..d8d650c 100644
--- a/MySports Tests/src/example/mysports/tests/model/CreateDatabase.java
+++ b/MySports Tests/src/example/mysports/tests/model/CreateDatabase.java
@@ -58,7 +58,7 @@
*/
@Test
public void createSharedMySportsSchema() throws Exception {
- Map<String, Object> properties = TestingLeagueRepository.get();
+ Map<String, Object> properties = TestingLeagueRepository.get("ALL");
properties.put(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.DROP_AND_CREATE);
properties.put(PersistenceUnitProperties.DDL_GENERATION_MODE, PersistenceUnitProperties.DDL_DATABASE_GENERATION);
diff --git a/MySports Tests/src/example/mysports/tests/persistence/CreateTenantEMF.java b/MySports Tests/src/example/mysports/tests/persistence/CreateTenantEMF.java
index 4011d6b..14bcf4d 100644
--- a/MySports Tests/src/example/mysports/tests/persistence/CreateTenantEMF.java
+++ b/MySports Tests/src/example/mysports/tests/persistence/CreateTenantEMF.java
@@ -1,8 +1,5 @@
package example.mysports.tests.persistence;
-import java.util.HashMap;
-import java.util.Map;
-
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
@@ -11,16 +8,12 @@
import org.junit.Test;
import example.mysports.MySportsConfig;
-import example.mysports.persistence.MultitenantPersistenceProvider;
public class CreateTenantEMF {
@Test
public void createKFL() throws Exception {
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(MultitenantPersistenceProvider.TEMPLATE_PU_NAME, MySportsConfig.PU_NAME);
-
- EntityManagerFactory emf = Persistence.createEntityManagerFactory(MySportsConfig.PU_NAME + "-KFL", properties);
+ EntityManagerFactory emf = Persistence.createEntityManagerFactory(MySportsConfig.PU_NAME + "-KFL");
Assert.assertNotNull(emf);
}