Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Keith2011-06-10 21:23:53 +0000
committerMike Keith2011-06-10 21:23:53 +0000
commitd3c63a9245ad0bd540906b4039e81e42b65e8239 (patch)
tree673c7a58782d5f139f0805c9975dfb34354500cc
parent72ffa5c704a9691e436d299b9db145a2985ed04a (diff)
downloadorg.eclipse.gemini.jpa-d3c63a9245ad0bd540906b4039e81e42b65e8239.tar.gz
org.eclipse.gemini.jpa-d3c63a9245ad0bd540906b4039e81e42b65e8239.tar.xz
org.eclipse.gemini.jpa-d3c63a9245ad0bd540906b4039e81e42b65e8239.zip
git-svn-id: file:///svnroot/rt/org.eclipse.gemini.jpa/trunk@109 738bc060-e27f-0410-be59-ab60bd4d2b7a
-rw-r--r--org.eclipse.gemini.jpa/META-INF/MANIFEST.MF10
-rw-r--r--org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/GeminiServicesUtil.java58
-rw-r--r--org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/GeminiUtil.java8
-rw-r--r--org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/PUnitInfo.java1
-rw-r--r--org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/PersistenceBundleExtender.java100
-rw-r--r--org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/PersistenceUnitBundleUtil.java205
-rw-r--r--org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/provider/EclipseLinkOSGiProvider.java79
-rw-r--r--org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/provider/OSGiJpaProvider.java7
8 files changed, 115 insertions, 353 deletions
diff --git a/org.eclipse.gemini.jpa/META-INF/MANIFEST.MF b/org.eclipse.gemini.jpa/META-INF/MANIFEST.MF
index 12ea4dd..c69d98a 100644
--- a/org.eclipse.gemini.jpa/META-INF/MANIFEST.MF
+++ b/org.eclipse.gemini.jpa/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Gemini JPA
Bundle-SymbolicName: org.eclipse.gemini.jpa
-Bundle-Version: 1.0.0.RC1
+Bundle-Version: 1.0.0.RC2
Bundle-Activator: org.eclipse.gemini.jpa.provider.EclipseLinkOSGiProvider
Bundle-Vendor: Oracle Corporation
Bundle-RequiredExecutionEnvironment: J2SE-1.5
@@ -22,8 +22,8 @@ Import-Package: javax.naming,
org.xml.sax,
org.xml.sax.helpers
Bundle-ClassPath: .
-Require-Bundle: org.eclipse.persistence.asm;bundle-version="2.2",
- org.eclipse.persistence.antlr;bundle-version="2.2",
- org.eclipse.persistence.core;bundle-version="2.2",
- org.eclipse.persistence.jpa;bundle-version="2.2"
+Require-Bundle: org.eclipse.persistence.asm;bundle-version="2.3",
+ org.eclipse.persistence.antlr;bundle-version="2.3",
+ org.eclipse.persistence.core;bundle-version="2.3",
+ org.eclipse.persistence.jpa;bundle-version="2.3"
Export-Package: org.eclipse.gemini.jpa.provider
diff --git a/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/GeminiServicesUtil.java b/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/GeminiServicesUtil.java
index 0031b34..290f081 100644
--- a/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/GeminiServicesUtil.java
+++ b/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/GeminiServicesUtil.java
@@ -17,14 +17,12 @@ package org.eclipse.gemini.jpa;
import static org.eclipse.gemini.jpa.GeminiUtil.bundleVersion;
import static org.eclipse.gemini.jpa.GeminiUtil.debug;
import static org.eclipse.gemini.jpa.GeminiUtil.fatalError;
-import static org.eclipse.gemini.jpa.GeminiUtil.formattedPackageString;
import static org.eclipse.gemini.jpa.GeminiUtil.warning;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Dictionary;
-import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
@@ -54,13 +52,17 @@ public class GeminiServicesUtil {
// Keep this for logging convenience
String providerClassName;
+ // The anchor util to use to get anchor class info from
+ AnchorClassUtil anchorUtil;
+
// PersistenceProvider service
ServiceRegistration providerService;
- public GeminiServicesUtil(OSGiJpaProvider provider) {
+ public GeminiServicesUtil(OSGiJpaProvider provider, AnchorClassUtil anchorUtil) {
this.osgiJpaProvider = provider;
this.providerClassName = provider.getProviderClassName();
+ this.anchorUtil= anchorUtil;
}
/*==================*/
@@ -108,14 +110,13 @@ public class GeminiServicesUtil {
*/
public void registerEMFServices(PUnitInfo pUnitInfo) {
+ debug("GeminiServicesUtil registerEMFServices for ", pUnitInfo.getUnitName());
+
// Map of generated anchor classes keyed by class name
Map<String, Class<?>> anchorClasses;
- debug("GeminiServicesUtil registerEMFServices for ", pUnitInfo.getUnitName());
- Bundle pUnitBundle = pUnitInfo.getBundle();
-
// Will be empty if anchor classes not generated
- anchorClasses = loadAnchorClasses(pUnitInfo);
+ anchorClasses = anchorUtil.loadAnchorClasses(pUnitInfo);
// Create the properties used for both services
Dictionary<String,String> props = buildServiceProperties(pUnitInfo);
@@ -205,43 +206,7 @@ public class GeminiServicesUtil {
/*================*/
/* Helper methods */
/*================*/
-
- /*
- * Some environments (PDE!) do not support dynamically installing bundles, hence
- * anchor classes cannot be generated.
- * Return whether anchor classes are currently being generated.
- */
- boolean canGenerateAnchorClasses() {
- // TODO Make this properly configurable
- return false;
- }
-
- /*
- * Load and return the anchor classes that were generated.
- * Return an empty collection if anchor classes were not generated.
- */
- Map<String, Class<?>> loadAnchorClasses(PUnitInfo pUnitInfo) {
-
- Map<String, Class<?>> result = new HashMap<String, Class<?>>();
-
- if (!canGenerateAnchorClasses())
- return result;
-
- for (String packageName : pUnitInfo.getUniquePackageNames()) {
- String className = formattedPackageString(packageName, '/', '.') +
- osgiJpaProvider.getAnchorClassName();
- try {
- debug("GeminiServicesUtil loading anchor class ", className);
- Class<?> cls = pUnitInfo.getBundle().loadClass(className);
- debug("GeminiServicesUtil loaded anchor class ", cls);
- result.put(className, cls);
- } catch (ClassNotFoundException cnfEx) {
- fatalError("Could not load anchor class ", cnfEx);
- }
- }
- return result;
- }
-
+
/**
* Get or create a loader to load classes from the punit.
* A sequence of conditions provides a pattern for obtaining it.
@@ -464,8 +429,8 @@ public class GeminiServicesUtil {
// Add EMF class and anchor classes to the proxied class collection for EMF proxy
proxiedClasses.addAll(anchorClasses.values());
proxiedClasses.add(emfBuilderClass);
+ debug("GeminiServicesUtil EMFBuilder proxied classes: ", proxiedClasses);
Class<?>[] classArray = proxiedClasses.toArray(new Class[0]);
- debug("GeminiServicesUtil EMFBuilder proxy class array: ", classArray);
// Get a loader to load the proxy classes
ClassLoader loader = proxyLoader(pUnitInfo, anchorClasses, emfBuilderClass);
@@ -482,6 +447,7 @@ public class GeminiServicesUtil {
ServiceRegistration emfBuilderService = null;
try {
// TODO Should be registered by p-unit context, not provider context
+ // emfBuilderService = pUnitInfo.getBundle().getBundleContext()
emfBuilderService = osgiJpaProvider.getBundleContext()
.registerService(classNameArray, emfBuilderServiceProxy, props);
} catch (Exception e) {
@@ -519,7 +485,7 @@ public class GeminiServicesUtil {
if (dsfRefs == null)
return false;
- // We found at least one -- track the first ranked one (assuming it will be used)
+ // We found at least one -- track the first one (assuming it will be used)
// TODO Race condition where service could disappear before being tracked
debug("GeminiServicesUtil starting tracker for DataSourceFactory ",
pUnitInfo.getDriverClassName());
diff --git a/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/GeminiUtil.java b/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/GeminiUtil.java
index 5580858..c0ffff9 100644
--- a/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/GeminiUtil.java
+++ b/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/GeminiUtil.java
@@ -111,21 +111,21 @@ public class GeminiUtil {
// Function to print out debug strings for XML parsing purposes
public static void debugXml(String... msgs) {
- if (System.getProperty("GEMINI_DEBUG_XML") != null) {
+ if (GeminiProperties.debugXml()) {
debug(msgs);
}
}
// Function to print out debug strings for classloading purposes
public static void debugClassLoader(String... msgs) {
- if (System.getProperty("GEMINI_DEBUG_CLASSLOADER") != null) {
+ if (GeminiProperties.debugClassloader()) {
debug(msgs);
}
}
// Function to print out series of debug strings
public static void debug(String... msgs) {
- if (System.getProperty("GEMINI_DEBUG") != null) {
+ if (GeminiProperties.debug()) {
StringBuilder sb = new StringBuilder();
for (String msg : msgs) sb.append(msg);
System.out.println(sb.toString());
@@ -135,7 +135,7 @@ public class GeminiUtil {
// Function to print out a string and an object.
// Handles some objects specially and prints out more info
public static void debug(String msg, Object obj) {
- if (System.getProperty("GEMINI_DEBUG") != null) {
+ if (GeminiProperties.debug()) {
if (obj == null) {
System.out.println(msg + String.valueOf(obj));
} else if (ClassLoader.class.isAssignableFrom(obj.getClass())) {
diff --git a/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/PUnitInfo.java b/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/PUnitInfo.java
index d2e96e9..0b17719 100644
--- a/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/PUnitInfo.java
+++ b/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/PUnitInfo.java
@@ -14,7 +14,6 @@
******************************************************************************/
package org.eclipse.gemini.jpa;
-import java.net.URL;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
diff --git a/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/PersistenceBundleExtender.java b/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/PersistenceBundleExtender.java
index 7aaa6c9..785dfc7 100644
--- a/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/PersistenceBundleExtender.java
+++ b/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/PersistenceBundleExtender.java
@@ -15,15 +15,12 @@
package org.eclipse.gemini.jpa;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.jar.Manifest;
-
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
@@ -35,10 +32,9 @@ import org.eclipse.gemini.jpa.provider.OSGiJpaProvider;
import static org.eclipse.gemini.jpa.GeminiUtil.*;
-
/**
- * This extender can be used by a provider to listen for persistence unit
- * bundles and assign them to this provider if the unit is able to be assigned.
+ * This extender is used by the provider to listen for persistence unit
+ * bundles and assign them to the provider if the unit is able to be assigned.
*/
public class PersistenceBundleExtender implements SynchronousBundleListener {
@@ -49,8 +45,8 @@ public class PersistenceBundleExtender implements SynchronousBundleListener {
// The provider associated with this extender
OSGiJpaProvider osgiJpaProvider;
- // Utility class
- PersistenceUnitBundleUtil util;
+ // Utility classes
+ PersistenceUnitBundleUtil bundleUtil;
// Persistence units by bundle
Map<Bundle, List<PUnitInfo>> unitsByBundle =
@@ -67,7 +63,8 @@ public class PersistenceBundleExtender implements SynchronousBundleListener {
public PersistenceBundleExtender() {}
public PersistenceBundleExtender(OSGiJpaProvider provider) {
this.osgiJpaProvider = provider;
- this.util = new PersistenceUnitBundleUtil();
+ this.bundleUtil = new PersistenceUnitBundleUtil();
+
}
/*================================*/
@@ -97,48 +94,34 @@ public class PersistenceBundleExtender implements SynchronousBundleListener {
public void lookForExistingBundles() {
// Look at the bundles that are already installed
- Bundle[] activeBundles = osgiJpaProvider.getBundleContext().getBundles();
- debug("GeminiExtender looking at existing bundles: ", activeBundles);
+ Bundle[] installedBundles = osgiJpaProvider.getBundleContext().getBundles();
+ debug("GeminiExtender looking at existing bundles: ", installedBundles);
// Check if any are p-unit bundles
- for (Bundle b : activeBundles) {
+ for (Bundle b : installedBundles) {
if (isPersistenceUnitBundle(b)) {
// We found a persistence unit bundle.
- // Refresh it so it will go through the resolving state again and client
- // bundles that are waiting for the EMF service will get one
- if ((b.getState() != Bundle.INSTALLED) && (b.getState() != Bundle.UNINSTALLED)) {
- addToRefreshingBundles(b);
- PackageAdmin admin = getPackageAdmin(osgiJpaProvider.getBundleContext());
- debug("GeminiExtender refreshing packages of bundle ", b);
- admin.refreshPackages(new Bundle[] { b });
+ if (GeminiProperties.refreshPersistenceBundles()) {
+ // Refresh it so it will go through resolving again and we can assign it a provider, etc.
+ if ((b.getState() != Bundle.INSTALLED) && (b.getState() != Bundle.UNINSTALLED)) {
+ refreshBundle(b);
+ }
+ } else {
+ // Refreshing is disabled - go through assigning and registering process w/o events
+ if (b.getState() != Bundle.UNINSTALLED) {
+ // Assign the p-unit
+ // NOTE: With no refresh, assigning may be happening after the bundle has been resolved
+ tryAssigningPersistenceUnitsInBundle(b);
+ // Now if bundle is starting or active then register the p-units in it
+ if ((b.getState() == Bundle.STARTING) || (b.getState() == Bundle.ACTIVE)) {
+ registerPersistenceUnitsInBundle(b);
+ } // Otherwise just let future events take their course
+ }
}
}
}
}
- /**
- * Generate a set of anchor interfaces for the packages in the p-units.
- * Create a fragment for them and install the fragment, attaching it to the
- * persistence unit bundle.
- *
- * @param b the persistence unit bundle
- * @param infos the collection of metadata for all of the persistence units
- *
- * @return The bundle object of the installed fragment
- */
- public Bundle generateAndInstallFragment(Bundle b, Collection<PUnitInfo> infos) {
-
- debug("GeminiExtender generating fragment");
- List<String> packageNames = util.uniquePackages(infos);
- List<byte[]> generatedClasses = util.generateAnchorInterfaces(packageNames, osgiJpaProvider.getAnchorClassName());
- Manifest manifest = util.generateFragmentManifest(b);
- byte[] fragment = util.createFragment(manifest, packageNames, osgiJpaProvider.getAnchorClassName(), generatedClasses);
- debug("GeminiExtender finished generating fragment");
- Bundle installedFragment = util.installFragment(b, osgiJpaProvider.getBundle(), fragment);
- debug("GeminiExtender installed fragment bundle: ", installedFragment);
- return installedFragment;
- }
-
public Map<Bundle, List<PUnitInfo>> clearAllPUnitInfos() {
Map<Bundle, List<PUnitInfo>> pUnitInfos = unitsByBundle;
unitsByBundle = null;
@@ -167,10 +150,10 @@ public class PersistenceBundleExtender implements SynchronousBundleListener {
}
// Look for all of the persistence descriptor files in the bundle
- List<PersistenceDescriptorInfo> descriptorInfos = util.persistenceDescriptorInfos(b);
+ List<PersistenceDescriptorInfo> descriptorInfos = bundleUtil.persistenceDescriptorInfos(b);
// Do a partial parse of the descriptors
- Set<PUnitInfo> pUnitInfos = util.persistenceUnitInfoFromXmlFiles(descriptorInfos);
+ Set<PUnitInfo> pUnitInfos = bundleUtil.persistenceUnitInfoFromXmlFiles(descriptorInfos);
// Cycle through each p-unit info and see if a provider was specified
for (PUnitInfo info : pUnitInfos) {
@@ -231,8 +214,8 @@ public class PersistenceBundleExtender implements SynchronousBundleListener {
"bundles so that both the persistence unit bundle and the provider resolve " +
"to the same javax.persistence package.");
unassignPersistenceUnitsInBundle(b);
- // No point in updating/refreshing.
- // (It would likely just re-resolve to the same JPA interface package.)
+ // No point in updating or refreshing.
+ // It would likely just re-resolve to the same JPA interface package.
}
}
@@ -251,6 +234,21 @@ public class PersistenceBundleExtender implements SynchronousBundleListener {
osgiJpaProvider.unregisterPersistenceUnits(unitsByBundle.get(b));
}
+ /**
+ * Refresh the persistence bundle.
+ *
+ * @param b the bundle the p-units are in
+ */
+ public void refreshBundle(Bundle b) {
+ // Add the list of currently refreshing bundles.
+ // (It will be removed when the UNRESOLVED event is fired on it)
+ addToRefreshingBundles(b);
+ // Call refresh on all of the packages
+ PackageAdmin admin = getPackageAdmin(osgiJpaProvider.getBundleContext());
+ debug("GeminiExtender refreshing packages of bundle ", b);
+ admin.refreshPackages(new Bundle[] { b });
+ }
+
/*========================*/
/* BundleListener methods */
/*========================*/
@@ -338,9 +336,13 @@ public class PersistenceBundleExtender implements SynchronousBundleListener {
protected void addToBundleUnits(Map<Bundle,List<PUnitInfo>> map,
Bundle b,
PUnitInfo info) {
- if (!map.containsKey(b))
- map.put(b, new ArrayList<PUnitInfo>());
- map.get(b).add(info);
+ synchronized (map) {
+ if (!map.containsKey(b))
+ map.put(b, new ArrayList<PUnitInfo>());
+ List<PUnitInfo> infos = map.get(b);
+ if (!infos.contains(info))
+ infos.add(info);
+ }
}
public boolean isPersistenceUnitBundle(Bundle b) {
diff --git a/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/PersistenceUnitBundleUtil.java b/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/PersistenceUnitBundleUtil.java
index ba1ff7c..dd3a64e 100644
--- a/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/PersistenceUnitBundleUtil.java
+++ b/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/PersistenceUnitBundleUtil.java
@@ -14,33 +14,16 @@
******************************************************************************/
package org.eclipse.gemini.jpa;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import java.util.jar.Attributes;
-import java.util.jar.JarEntry;
-import java.util.jar.JarInputStream;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
-
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-
-import org.eclipse.persistence.internal.libraries.asm.ClassWriter;
-import org.eclipse.persistence.internal.libraries.asm.Constants;
-
import org.eclipse.gemini.jpa.xml.PersistenceDescriptorHandler;
import static org.eclipse.gemini.jpa.GeminiUtil.*;
@@ -178,192 +161,4 @@ public class PersistenceUnitBundleUtil {
debug("Parsed persistence descriptors: ", pUnits);
return pUnits;
}
-
- /**
- * Return a Set of the unique packages in which a JPA managed class exists.
- * The "." characters will be replaced by "/" chars, with a trailing slash.
- *
- * @param pUnits the collection of p-units in the bundle
- *
- * @return a List of unique package names in all p-units in the bundle
- */
- public List<String> uniquePackages(Collection<PUnitInfo> pUnits) {
- Set<String> packageNamesInBundle = new HashSet<String>();
-
- // Iterate through all the p-units in the bundle
- for (PUnitInfo info : pUnits) {
- Set<String> packageNamesInUnit = new HashSet<String>();
-
- // Iterate through each managed class in the p-unit
- for (String classString : info.getClasses()) {
- int idx = classString.lastIndexOf('.');
- String packageName = classString.substring(0,idx);
- String formattedName = formattedPackageString(packageName, '.', '/');
- packageNamesInUnit.add(formattedName);
- packageNamesInBundle.add(formattedName);
- }
- // Convert to a List and set the local p-unit package names in the p-unit info
- List<String> namesInUnit = new ArrayList<String>();
- namesInUnit.addAll(packageNamesInUnit);
- info.setUniquePackageNames(namesInUnit);
- }
- // Convert to a List before returning
- List<String> namesInBundle = new ArrayList<String>();
- namesInBundle.addAll(packageNamesInBundle);
- debug("Unique managed class package names: ", namesInBundle);
- return namesInBundle;
- }
-
- /**
- * Generate an anchor interface for each unique package in which a
- * JPA managed class exists. The anchors will all get generated as the
- * specified class name, but in different packages.
- *
- * @param packageNames the collection of package name strings. They are
- * assumed to be in the format returned by {@link #uniquePackages() uniquePackages}
- * @param className the name of the generated interface
- *
- * @return an ordered List of bytecode arrays, each being a generated anchor
- * interface, in the order that the package names were in
- */
- public List<byte[]> generateAnchorInterfaces(List<String> packageNames, String className) {
- List<byte[]> bytes = new ArrayList<byte[]>();
-
- // Iterate through the packageNames, generating an interface for each one
- for (String packageName : packageNames) {
- ClassWriter writer = new ClassWriter(false);
- String fullClassName = formattedPackageString(packageName, '.', '/') + className;
- final int CLASS_ACCESS = Constants.ACC_PUBLIC + Constants.ACC_ABSTRACT + Constants.ACC_INTERFACE;
- writer.visit(Constants.V1_5, CLASS_ACCESS, fullClassName, "java/lang/Object", null, null);
- writer.visitEnd();
- bytes.add(writer.toByteArray());
- }
- return bytes;
- }
-
- /**
- * Generate a manifest for the fragment. No additional imports or exports have been added.
- *
- * @param pUnitBundle the persistence unit bundle collection of package name strings. They are
- *
- * @return a Manifest with its headers appropriately filled in
- */
- public Manifest generateFragmentManifest(Bundle pUnitBundle){
- Manifest manifest = new Manifest();
- Attributes attrs = manifest.getMainAttributes();
- debug("Creating manifest ");
-
- // Standard manifest versions
- attrs.putValue("Manifest-Version", "1.0");
- attrs.putValue("Bundle-ManifestVersion", "2");
-
- // Informational Entries
- attrs.putValue("Bundle-Name", "JPA Fragment");
- attrs.putValue("Bundle-Description", "Generated JPA Fragment");
-
- // Use a mapping from the p-unit bundle name to the fragment name
- String fragmentName = fragmentSymbolicName(pUnitBundle);
- attrs.putValue("Bundle-SymbolicName", fragmentName);
-
- // Import the org.osgi.service.jpa package to allow access to the EMFBuilder class
- String packageImport = "org.osgi.service.jpa";
- attrs.putValue("Import-Package", packageImport);
-
- // Adopt the version of the persistence unit bundle so it is unique
- String hostVersion = bundleVersion(pUnitBundle);
- attrs.putValue("Bundle-Version", hostVersion);
-
- // Lock this fragment to the symbolic name and version of the persistence unit bundle
- String fragmentHost = pUnitBundle.getSymbolicName() + ";bundle-version=" + hostVersion;
- attrs.putValue("Fragment-Host", fragmentHost);
-
- debug("Created manifest for ", fragmentName);
- return manifest;
- }
-
- // Out of the blue...
- public static final int ESTIMATED_FRAGMENT_SIZE = 2000;
-
- /**
- * Create and return a fragment bundle as a byte array. The manifest and generated classes
- * that were passed in are written to the fragment.
- *
- * @param manifest the manifest to use in the fragment
- * @param packageNames the names of the packages in which interfaces were generated
- * @param className the name of the interfaces that were generated
- * @param generatedClasses the byte arrays of generated interfaces
- *
- * @return a byte array of the fragment bundle data
- */
- public byte[] createFragment(
- Manifest manifest,
- List<String> packageNames,
- String className,
- List<byte[]> generatedClasses) {
-
- debug("Creating fragment ");
- ByteArrayOutputStream baos = new ByteArrayOutputStream(ESTIMATED_FRAGMENT_SIZE);
- BufferedOutputStream bos = new BufferedOutputStream(baos);
- JarOutputStream jos = null;
- try {
- jos = new JarOutputStream(bos, manifest);
- for (String p : packageNames) {
- JarEntry entry = new JarEntry(
- formattedPackageString(p, '.', '/') + className + ".class");
- jos.putNextEntry(entry);
- jos.write(generatedClasses.remove(0));
- }
- debug("Successfully created fragment ");
- jos.close();
- return baos.toByteArray();
- } catch (Exception ex) {
- fatalError("Error creating fragment: ", ex);
- } finally {
- close(jos);
- close(bos);
- close(baos);
- }
- return null;
- }
-
- /**
- * Install the fragment into the framework. Return the installed bundle if the fragment
- * was successfully installed, or null if it could not be installed.
- *
- * @param pUnitBundle the persistence unit bundle
- * @param providerBundle the bundle of the provider
- * @param bundleData the byte array that represents the fragment bundle
- *
- * @return the bundle that was created or null if none was able to be created
- */
- public Bundle installFragment(Bundle pUnitBundle, Bundle providerBundle, byte[] bundleData) {
-
- ByteArrayInputStream bais = new ByteArrayInputStream(bundleData);
- String locationUrl = null;
- Bundle fragmentBundle = null;
- try {
- locationUrl = fragmentLocation(pUnitBundle);
- debug("Installing fragment: ", locationUrl);
- // Use the provider bundle ctx to install the fragment
- BundleContext ctx = providerBundle.getBundleContext();
- fragmentBundle = ctx.installBundle(locationUrl, bais);
- } catch (Exception ex) {
- fatalError("Could not install fragment: " + locationUrl + ": ", ex);
- }
- return fragmentBundle;
- }
-
- /* ============== */
- /* Helper methods */
- /* ============== */
-
- // Function to create a unique fragment location identifier from a p-unit bundle
- public String fragmentLocation(Bundle pUnitBundle) {
- return fragmentSymbolicName(pUnitBundle) + "_" + bundleVersion(pUnitBundle);
- }
-
- // Function to create a symbolic name of the fragment based on the symbolic name of the p-unit bundle
- public String fragmentSymbolicName(Bundle b) {
- return "jpa$fragment." + b.getSymbolicName();
- }
}
diff --git a/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/provider/EclipseLinkOSGiProvider.java b/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/provider/EclipseLinkOSGiProvider.java
index 5ee7437..42c181f 100644
--- a/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/provider/EclipseLinkOSGiProvider.java
+++ b/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/provider/EclipseLinkOSGiProvider.java
@@ -41,6 +41,9 @@ import javax.persistence.spi.PersistenceUnitInfo;
import javax.persistence.spi.ProviderUtil;
import javax.sql.DataSource;
+import org.eclipse.gemini.jpa.AnchorClassUtil;
+import org.eclipse.gemini.jpa.FragmentUtil;
+import org.eclipse.gemini.jpa.GeminiProperties;
import org.eclipse.gemini.jpa.GeminiServicesUtil;
import org.eclipse.gemini.jpa.GeminiUtil;
import org.eclipse.gemini.jpa.PUnitInfo;
@@ -71,7 +74,6 @@ public class EclipseLinkOSGiProvider implements BundleActivator,
/* Static constants */
/*==================*/
public static final String PROVIDER_CLASS_NAME = "org.eclipse.persistence.jpa.PersistenceProvider";
- public static final String ANCHOR_CLASS_NAME = "Jpa$Anchor";
public static final int MAX_EVENT_COLLISION_TRIES = 3;
@@ -88,14 +90,15 @@ public class EclipseLinkOSGiProvider implements BundleActivator,
/** Services utility code */
GeminiServicesUtil servicesUtil;
- /** Other Bundle-level utility code */
- PersistenceUnitBundleUtil puBundleUtil;
-
+ /** Anchor class gen utility */
+ AnchorClassUtil anchorUtil;
+
/** An SPI instance of this provider */
PersistenceProvider eclipseLinkProvider;
/** Map of p-units we have registered */
Map<String, PUnitInfo> pUnitsByName;
+
private FileWriter eclipseLinkLog;
/*=====================*/
@@ -110,8 +113,8 @@ public class EclipseLinkOSGiProvider implements BundleActivator,
ctx = context;
pUnitsByName = Collections.synchronizedMap(new HashMap<String, PUnitInfo>());
extender = new PersistenceBundleExtender(this);
- servicesUtil = new GeminiServicesUtil(this);
- puBundleUtil = new PersistenceUnitBundleUtil();
+ anchorUtil = new AnchorClassUtil(GeminiProperties.generateAnchorClasses());
+ servicesUtil = new GeminiServicesUtil(this, anchorUtil);
openEclipseLinkLoggingFile();
eclipseLinkProvider = new org.eclipse.gemini.jpa.provider.PersistenceProvider();
PersistenceUnitProcessor.setArchiveFactory(new OSGiArchiveFactoryImpl());
@@ -148,28 +151,6 @@ public class EclipseLinkOSGiProvider implements BundleActivator,
debug("EclipseLinkProvider stopped");
}
- public void openEclipseLinkLoggingFile() {
- String loggingFile = System.getProperty(PersistenceUnitProperties.LOGGING_FILE);
- try {
- if (loggingFile != null) {
- eclipseLinkLog = new FileWriter(loggingFile);
- AbstractSessionLog.getLog().setWriter(eclipseLinkLog);
- }
- } catch (IOException e) {
- AbstractSessionLog.getLog().log(SessionLog.WARNING, "cmp_init_default_logging_file_is_invalid",loggingFile,e);
- }
- }
- public void closeEclipseLinkLoggingFile() {
- // Reset to default
- AbstractSessionLog.setLog(new DefaultSessionLog());
- try {
- if (eclipseLinkLog != null) {
- eclipseLinkLog.close();
- }
- } catch (IOException e) {
- }
- }
-
/*==============================*/
/* OSGiJpaProvider impl methods */
/*==============================*/
@@ -182,9 +163,6 @@ public class EclipseLinkOSGiProvider implements BundleActivator,
return this;
}
- // Used when generating the anchor interfaces
- public String getAnchorClassName() { return ANCHOR_CLASS_NAME; }
-
public Bundle getBundle() { return ctx.getBundle(); }
public BundleContext getBundleContext() { return ctx; }
@@ -201,15 +179,20 @@ public class EclipseLinkOSGiProvider implements BundleActivator,
// Run Initializer to process PU and register transformers
BundleContext bundleContext = getBundleContext();
+
+ //TODO Check state of bundle in assign call
+
+ // Generate a fragment for the p-units
+ if (GeminiProperties.generateFragments()) {
+ new FragmentUtil(ctx.getBundle())
+ .generateAndInstallFragment(b, pUnits, anchorUtil);
+ }
+
ClassLoader compositeLoader = compositeLoader(bundleContext,b);
GeminiOSGiInitializer initializer = new GeminiOSGiInitializer(compositeLoader);
initializer.registerBundle(bundleContext, b, compositeLoader, pUnits);
- //TODO Check state of bundle in assign call
-
- // Generate a fragment for the p-units
- Bundle result = extender.generateAndInstallFragment(b, pUnits);
}
/**
@@ -275,7 +258,6 @@ public class EclipseLinkOSGiProvider implements BundleActivator,
}
// Remove from our local pUnit copy
pUnitsByName.remove(info.getUnitName());
-
}
}
@@ -443,4 +425,29 @@ public class EclipseLinkOSGiProvider implements BundleActivator,
debug("EclipseLinkProvider - getJDBCProperties - returning: ", props);
return props;
}
+
+ public void openEclipseLinkLoggingFile() {
+ String loggingFile = System.getProperty(PersistenceUnitProperties.LOGGING_FILE);
+ try {
+ if (loggingFile != null) {
+ eclipseLinkLog = new FileWriter(loggingFile);
+ AbstractSessionLog.getLog().setWriter(eclipseLinkLog);
+ }
+ } catch (IOException e) {
+ AbstractSessionLog.getLog().log(SessionLog.WARNING, "cmp_init_default_logging_file_is_invalid",loggingFile,e);
+ }
+ }
+ public void closeEclipseLinkLoggingFile() {
+ // Reset to default
+ AbstractSessionLog.setLog(new DefaultSessionLog());
+ try {
+ if (eclipseLinkLog != null) {
+ eclipseLinkLog.close();
+ }
+ } catch (IOException e) {
+ }
+ }
+
+
+
} \ No newline at end of file
diff --git a/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/provider/OSGiJpaProvider.java b/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/provider/OSGiJpaProvider.java
index 11bb236..501b4c7 100644
--- a/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/provider/OSGiJpaProvider.java
+++ b/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/provider/OSGiJpaProvider.java
@@ -46,13 +46,6 @@ public interface OSGiJpaProvider {
PersistenceProvider getProviderInstance();
/**
- * The name of the anchor class that is generated by Gemini. There will
- * be a generated class for each unique package in which entity classes exist
- * (and are listed in the persistence descriptor).
- */
- String getAnchorClassName();
-
- /**
* The bundle that contains this provider.
*/
Bundle getBundle();

Back to the top