mirror of
https://github.com/apache/openjpa.git
synced 2025-02-21 17:45:51 +00:00
Changed OpenJPAProductDerivation to have a proper lifecycle callback for BrokerFactoryValue initialization; added supporting infrastructure as needed.
git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@454064 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
43f5348782
commit
28910a7374
@ -21,15 +21,16 @@ import org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory;
|
||||
import org.apache.openjpa.lib.conf.AbstractProductDerivation;
|
||||
import org.apache.openjpa.lib.conf.ConfigurationProvider;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Sets JDBC as default store.
|
||||
*/
|
||||
public class JDBCProductDerivation extends AbstractProductDerivation
|
||||
implements OpenJPAProductDerivation {
|
||||
|
||||
static {
|
||||
BrokerFactoryValue.addDefaultAlias("jdbc",
|
||||
JDBCBrokerFactory.class.getName());
|
||||
public void initializeBrokerFactoryValueAliases(Map m) {
|
||||
m.put("jdbc", JDBCBrokerFactory.class.getName());
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
@ -39,7 +40,7 @@ public class JDBCProductDerivation extends AbstractProductDerivation
|
||||
public boolean beforeConfigurationConstruct(ConfigurationProvider cp) {
|
||||
// default to JDBC when no broker factory set
|
||||
if (BrokerFactoryValue.get(cp) == null) {
|
||||
BrokerFactoryValue.set(cp, JDBCBrokerFactory.class.getName());
|
||||
BrokerFactoryValue.set(cp, "jdbc");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -17,13 +17,17 @@ package org.apache.openjpa.conf;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.openjpa.abstractstore.AbstractStoreBrokerFactory;
|
||||
import org.apache.openjpa.kernel.BrokerFactory;
|
||||
import org.apache.openjpa.lib.conf.ConfigurationProvider;
|
||||
import org.apache.openjpa.lib.conf.PluginValue;
|
||||
import org.apache.openjpa.lib.conf.ProductDerivations;
|
||||
import org.apache.openjpa.lib.conf.ProductDerivation;
|
||||
|
||||
/**
|
||||
* Value type used to represent the {@link BrokerFactory}. This type is
|
||||
@ -40,9 +44,22 @@ public class BrokerFactoryValue
|
||||
|
||||
private static final List _aliases = new ArrayList();
|
||||
private static final List _prefixes = new ArrayList(2);
|
||||
|
||||
static {
|
||||
addDefaultAlias("abstractstore",
|
||||
Map aliases = new HashMap();
|
||||
aliases.put("abstractstore",
|
||||
AbstractStoreBrokerFactory.class.getName());
|
||||
ProductDerivation[] ds = ProductDerivations.getProductDerivations();
|
||||
for (int i = 0; i < ds.length; i++) {
|
||||
if (ds[i] instanceof OpenJPAProductDerivation)
|
||||
((OpenJPAProductDerivation) ds[i])
|
||||
.initializeBrokerFactoryValueAliases(aliases);
|
||||
}
|
||||
|
||||
for (Iterator iter = aliases.entrySet().iterator(); iter.hasNext(); ) {
|
||||
Map.Entry e = (Map.Entry) iter.next();
|
||||
addDefaultAlias((String) e.getKey(), (String) e.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,6 +16,7 @@
|
||||
package org.apache.openjpa.conf;
|
||||
|
||||
import org.apache.openjpa.lib.conf.ProductDerivation;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Adds datastore based extension to ProductDerivation.
|
||||
@ -29,4 +30,11 @@ public interface OpenJPAProductDerivation extends ProductDerivation {
|
||||
public static final int TYPE_STORE = 200;
|
||||
public static final int TYPE_SPEC_STORE = 300;
|
||||
public static final int TYPE_PRODUCT_STORE = 400;
|
||||
|
||||
/**
|
||||
* Load default alias options into the BrokerFactoryValue's static data
|
||||
* structures. In the case of multiple ProductDerivations, this will be
|
||||
* invoked in the order defined by the type of the product derivation.
|
||||
*/
|
||||
public void initializeBrokerFactoryValueAliases(Map aliases);
|
||||
}
|
||||
|
@ -47,14 +47,14 @@ public interface ProductDerivation {
|
||||
|
||||
/**
|
||||
* Load globals into the returned ConfigurationProvider, or return null if
|
||||
* no globals is found.
|
||||
* no globals are found.
|
||||
*/
|
||||
public ConfigurationProvider loadGlobals(ClassLoader loader)
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* Load defaults into the returned ConfigurationProvider, or return null if
|
||||
* no defaults is found.
|
||||
* no defaults are found.
|
||||
*/
|
||||
public ConfigurationProvider loadDefaults(ClassLoader loader)
|
||||
throws Exception;
|
||||
|
@ -75,6 +75,13 @@ public class ProductDerivations {
|
||||
_prefixes[i + 1] = (String) prefixes.get(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the product derivations registered in the current classloader
|
||||
*/
|
||||
public static ProductDerivation[] getProductDerivations() {
|
||||
return _derivations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the recognized prefixes for configuration properties.
|
||||
*/
|
||||
|
@ -24,6 +24,8 @@ import org.apache.openjpa.lib.conf.Configuration;
|
||||
import org.apache.openjpa.persistence.FetchPlan;
|
||||
import org.apache.openjpa.persistence.PersistenceProductDerivation;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Sets JDBC-specific JPA specification defaults.
|
||||
*
|
||||
@ -34,6 +36,9 @@ public class JDBCPersistenceProductDerivation
|
||||
extends AbstractProductDerivation
|
||||
implements OpenJPAProductDerivation {
|
||||
|
||||
public void initializeBrokerFactoryValueAliases(Map m) {
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return TYPE_SPEC_STORE;
|
||||
}
|
||||
|
@ -70,6 +70,9 @@ public class PersistenceProductDerivation
|
||||
private static final Localizer _loc = Localizer.forPackage
|
||||
(PersistenceProductDerivation.class);
|
||||
|
||||
public void initializeBrokerFactoryValueAliases(Map m) {
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return TYPE_SPEC;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user