OPENJPA-2057: Change classloading scheme

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1194953 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Pinaki Poddar 2011-10-29 17:55:26 +00:00
parent 2bee63d702
commit 31e00f7d76
5 changed files with 14 additions and 65 deletions

View File

@ -21,6 +21,7 @@ package org.apache.openjpa.abstractstore;
import java.util.Map; import java.util.Map;
import org.apache.openjpa.conf.OpenJPAConfiguration; import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
import org.apache.openjpa.kernel.AbstractBrokerFactory; import org.apache.openjpa.kernel.AbstractBrokerFactory;
import org.apache.openjpa.kernel.Bootstrap; import org.apache.openjpa.kernel.Bootstrap;
import org.apache.openjpa.kernel.BrokerFactory; import org.apache.openjpa.kernel.BrokerFactory;
@ -48,6 +49,7 @@ import org.apache.openjpa.util.UserException;
* and bootstrapping from a {@link Map} object (the strategy used by * and bootstrapping from a {@link Map} object (the strategy used by
* {@link Bootstrap} to create a factory in a vendor-neutral manner). * {@link Bootstrap} to create a factory in a vendor-neutral manner).
*/ */
@SuppressWarnings("serial")
public class AbstractStoreBrokerFactory public class AbstractStoreBrokerFactory
extends AbstractBrokerFactory { extends AbstractBrokerFactory {
@ -55,11 +57,9 @@ public class AbstractStoreBrokerFactory
* The property name under which to name the concrete store manager * The property name under which to name the concrete store manager
* class for this runtime. * class for this runtime.
*/ */
private static final String PROP_ABSTRACT_STORE = private static final String PROP_ABSTRACT_STORE = "abstractstore.AbstractStoreManager";
"abstractstore.AbstractStoreManager";
private static final Localizer s_loc = Localizer.forPackage private static final Localizer s_loc = Localizer.forPackage(AbstractStoreBrokerFactory.class);
(AbstractStoreBrokerFactory.class);
private String _storeCls = null; private String _storeCls = null;
private String _storeProps = null; private String _storeProps = null;
@ -71,8 +71,7 @@ public class AbstractStoreBrokerFactory
*/ */
public static AbstractStoreBrokerFactory getInstance(ConfigurationProvider cp) { public static AbstractStoreBrokerFactory getInstance(ConfigurationProvider cp) {
Object key = toPoolKey(cp.getProperties()); Object key = toPoolKey(cp.getProperties());
AbstractStoreBrokerFactory factory = (AbstractStoreBrokerFactory) AbstractStoreBrokerFactory factory = (AbstractStoreBrokerFactory)getPooledFactoryForKey(key);
getPooledFactoryForKey(key);
if (factory != null) if (factory != null)
return factory; return factory;
@ -89,11 +88,12 @@ public class AbstractStoreBrokerFactory
// use a tmp store manager to get metadata about the capabilities of // use a tmp store manager to get metadata about the capabilities of
// this runtime // this runtime
Map map = cp.getProperties(); Map map = cp.getProperties();
String storePlugin = (String) map.get(ProductDerivations OpenJPAConfiguration tmp = new OpenJPAConfigurationImpl();
.getConfigurationKey(PROP_ABSTRACT_STORE, map)); cp.setInto(tmp);
String storePlugin = (String) map.get(ProductDerivations.getConfigurationKey(PROP_ABSTRACT_STORE, map));
String storeCls = Configurations.getClassName(storePlugin); String storeCls = Configurations.getClassName(storePlugin);
String storeProps = Configurations.getProperties(storePlugin); String storeProps = Configurations.getProperties(storePlugin);
AbstractStoreManager store = createStoreManager(storeCls, storeProps); AbstractStoreManager store = createStoreManager(storeCls, tmp, storeProps);
// populate configuration // populate configuration
OpenJPAConfiguration conf = store.newConfiguration(); OpenJPAConfiguration conf = store.newConfiguration();
@ -101,8 +101,7 @@ public class AbstractStoreBrokerFactory
conf.supportedOptions().removeAll(store.getUnsupportedOptions()); conf.supportedOptions().removeAll(store.getUnsupportedOptions());
// create and pool a new factory // create and pool a new factory
return new AbstractStoreBrokerFactory(conf, storeCls, storeProps, return new AbstractStoreBrokerFactory(conf, storeCls, storeProps, store.getPlatform());
store.getPlatform());
} }
/** /**
@ -123,12 +122,12 @@ public class AbstractStoreBrokerFactory
} }
protected StoreManager newStoreManager() { protected StoreManager newStoreManager() {
return createStoreManager(_storeCls, _storeProps); return createStoreManager(_storeCls, new OpenJPAConfigurationImpl(), _storeProps);
} }
private static AbstractStoreManager createStoreManager(String cls, String props) { private static AbstractStoreManager createStoreManager(String cls, OpenJPAConfiguration conf, String props) {
AbstractStoreManager store = AbstractStoreManager store =
(AbstractStoreManager) Configurations.newInstance(cls, (Configuration)null, props); (AbstractStoreManager) Configurations.newInstance(cls, conf, props);
Configurations.configureInstance(store, null, props, PROP_ABSTRACT_STORE); Configurations.configureInstance(store, null, props, PROP_ABSTRACT_STORE);
if (store == null) if (store == null)
throw new UserException(s_loc.get("no-store-manager", throw new UserException(s_loc.get("no-store-manager",

View File

@ -93,7 +93,7 @@ public class ManagedClassSubclasser {
if (!PersistenceCapable.class.isAssignableFrom(cls)) if (!PersistenceCapable.class.isAssignableFrom(cls))
unenhanced.add(cls); unenhanced.add(cls);
if (unenhanced.size() > 0) { if (unenhanced.size() > 0) {
if (PCEnhancerAgent.getLoadSuccessful() == true) { if (PCEnhancerAgent.getLoadSuccessful()) {
// This means that the enhancer has been ran but we // This means that the enhancer has been ran but we
// have some unenhanced classes. This can happen if an // have some unenhanced classes. This can happen if an
// entity is loaded by the JVM before the EntityManger // entity is loaded by the JVM before the EntityManger

View File

@ -19,7 +19,6 @@
package org.apache.openjpa.kernel; package org.apache.openjpa.kernel;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.security.AccessController;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -40,7 +39,6 @@ import javax.transaction.TransactionManager;
import org.apache.commons.collections.set.MapBackedSet; import org.apache.commons.collections.set.MapBackedSet;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.openjpa.kernel.AuditManager;
import org.apache.openjpa.audit.Auditor; import org.apache.openjpa.audit.Auditor;
import org.apache.openjpa.conf.BrokerValue; import org.apache.openjpa.conf.BrokerValue;
import org.apache.openjpa.conf.OpenJPAConfiguration; import org.apache.openjpa.conf.OpenJPAConfiguration;

View File

@ -43,7 +43,6 @@ import org.apache.openjpa.kernel.ConnectionRetainModes;
import org.apache.openjpa.lib.conf.Configuration; import org.apache.openjpa.lib.conf.Configuration;
import org.apache.openjpa.lib.conf.ConfigurationProvider; import org.apache.openjpa.lib.conf.ConfigurationProvider;
import org.apache.openjpa.lib.conf.Configurations; import org.apache.openjpa.lib.conf.Configurations;
import org.apache.openjpa.lib.conf.ProductDerivation;
import org.apache.openjpa.lib.conf.ProductDerivations; import org.apache.openjpa.lib.conf.ProductDerivations;
import org.apache.openjpa.lib.log.Log; import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.Localizer;
@ -51,9 +50,7 @@ import org.apache.openjpa.meta.AbstractCFMetaDataFactory;
import org.apache.openjpa.meta.MetaDataModes; import org.apache.openjpa.meta.MetaDataModes;
import org.apache.openjpa.meta.MetaDataRepository; import org.apache.openjpa.meta.MetaDataRepository;
import org.apache.openjpa.persistence.osgi.BundleUtils; import org.apache.openjpa.persistence.osgi.BundleUtils;
import org.apache.openjpa.persistence.osgi.OSGiDerivation;
import org.apache.openjpa.persistence.validation.ValidationUtils; import org.apache.openjpa.persistence.validation.ValidationUtils;
import org.apache.openjpa.util.ClassResolver;
/** /**

View File

@ -1,45 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.openjpa.persistence.osgi;
import org.apache.openjpa.lib.conf.ConfigurationProvider;
import org.apache.openjpa.persistence.PersistenceProductDerivation;
/**
* Derives for OSGi environment. Adds bundle class loader in class loading scheme.
*
* @author Pinaki Poddar
*
*/
public class OSGiDerivation extends PersistenceProductDerivation {
@Override
public void validate() throws Exception {
if (!BundleUtils.runningUnderOSGi()) {
throw new RuntimeException("Not running in OSGi environment");
}
}
@Override
public boolean beforeConfigurationConstruct(ConfigurationProvider cp) {
cp.getClassLoader().addClassLoader(BundleUtils.getBundleClassLoader());
super.beforeConfigurationConstruct(cp);
return true;
}
}