You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by kw...@apache.org on 2006/09/06 18:35:07 UTC
svn commit: r440775 [1/5] - in /incubator/openjpa/sandboxes/OPENJPA-24:
openjpa-kernel/src/main/java/org/apache/openjpa/enhance/
openjpa-kernel/src/main/java/org/apache/openjpa/kernel/
openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-kerne...
Author: kwsutter
Date: Wed Sep 6 09:35:03 2006
New Revision: 440775
URL: http://svn.apache.org/viewvc?view=rev&rev=440775
Log:
Merge with changes from HEAD as of 09/06/2006 to get SVN sandbox OPENJPA-24 up-to-date.
Added:
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InterfaceImplGenerator.java
- copied unchanged from r440754, incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InterfaceImplGenerator.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCFetchPlanImpl.java
- copied unchanged from r440755, incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCFetchPlanImpl.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ExtentImpl.java
- copied unchanged from r440755, incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ExtentImpl.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/FetchPlanImpl.java
- copied unchanged from r440755, incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/FetchPlanImpl.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/GeneratorImpl.java
- copied unchanged from r440755, incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/GeneratorImpl.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderExtension.java
- copied unchanged from r440755, incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderExtension.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryResultCacheImpl.java
- copied unchanged from r440755, incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryResultCacheImpl.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/StoreCacheImpl.java
- copied unchanged from r440755, incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/StoreCacheImpl.java
Modified:
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataInheritanceComparator.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/util/ApplicationIds.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreFacadeTypeRegistry.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCFetchPlan.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ConfigurationProviderImpl.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/Extent.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/FetchPlan.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/Generator.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryResultCache.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/StoreCache.java
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/jpa_overview_arch.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/jpa_overview_em.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/jpa_overview_emfactory.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/jpa_overview_mapping.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/jpa_overview_meta.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/jpa_overview_pc.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/jpa_overview_persistence.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/jpa_overview_query.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/jpa_overview_sqlquery.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/jpa_overview_trans.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/jpa_overview_why.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/jpa_tutorials.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/openjpa_intro.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/ref_guide_caching.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/ref_guide_conf.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/ref_guide_deploy.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/ref_guide_integration.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/ref_guide_logging.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/ref_guide_mapping.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/ref_guide_meta.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/ref_guide_optimization.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/ref_guide_pc.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/ref_guide_remote.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/ref_guide_runtime.xml
incubator/openjpa/sandboxes/OPENJPA-24/openjpa-project/src/doc/manual/supported_databases.xml
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java Wed Sep 6 09:35:03 2006
@@ -90,8 +90,9 @@
public static final int ENHANCE_NONE = 0;
public static final int ENHANCE_AWARE = 2 << 0;
- public static final int ENHANCE_PC = 2 << 1;
- public static final int ENHANCE_OID = 2 << 2;
+ public static final int ENHANCE_INTERFACE = 2 << 1;
+ public static final int ENHANCE_PC = 2 << 2;
+ public static final int ENHANCE_OID = 2 << 3;
private static final String PRE = "pc";
private static final Class PCTYPE = PersistenceCapable.class;
@@ -127,7 +128,7 @@
* Constructor. Supply configuration and type to enhance.
*/
public PCEnhancer(OpenJPAConfiguration conf, Class type) {
- this(conf, new Project().loadClass(type), null);
+ this(conf, new Project().loadClass(type), (MetaDataRepository) null);
}
/**
@@ -164,6 +165,17 @@
}
/**
+ * Constructor. Supply configuration, type, and metadata.
+ */
+ public PCEnhancer(OpenJPAConfiguration conf, BCClass type,
+ ClassMetaData meta) {
+ _pc = type;
+ _log = conf.getLog(OpenJPAConfiguration.LOG_ENHANCE);
+ _repos = meta.getRepository();
+ _meta = meta;
+ }
+
+ /**
* Return the bytecode representation of the class being manipulated.
*/
public BCClass getBytecode() {
@@ -266,6 +278,10 @@
_log.trace(_loc.get("enhance-start", _pc.getType()));
try {
+ // if managed interface, skip
+ if (_pc.isInterface())
+ return ENHANCE_INTERFACE;
+
// check if already enhanced
Class[] interfaces = _pc.getDeclaredInterfaceTypes();
for (int i = 0; i < interfaces.length; i++) {
@@ -612,13 +628,13 @@
String prefix = (get) ? PRE + "Get" : PRE + "Set";
methodName = prefix + name;
if (get) {
- mi.setMethod(owner.getDescribedType().getName(),
+ mi.setMethod(getType(owner).getName(),
methodName, typeName, new String[]
- { owner.getDescribedType().getName() });
+ { getType(owner).getName() });
} else {
- mi.setMethod(owner.getDescribedType().getName(),
+ mi.setMethod(getType(owner).getName(),
methodName, "void", new String[]
- { owner.getDescribedType().getName(), typeName });
+ { getType(owner).getName(), typeName });
}
}
}
@@ -659,6 +675,10 @@
if (owner.getName().equals(Object.class.getName()))
return null;
+ // managed interface
+ if (_meta != null && _meta.getDescribedType().isInterface())
+ return _meta;
+
return _repos.getMetaData(owner, null, false);
}
@@ -722,8 +742,9 @@
// super.pcClearFields ()
if (_meta.getPCSuperclass() != null) {
code.aload().setThis();
- code.invokespecial().setMethod(_meta.getPCSuperclass(),
- PRE + "ClearFields", void.class, null);
+ code.invokespecial().setMethod(getType(_meta.
+ getPCSuperclassMetaData()), PRE + "ClearFields", void.class,
+ null);
}
FieldMetaData[] fmds = _meta.getDeclaredFields();
@@ -849,7 +870,8 @@
// return <fields> + <superclass>.pcGetManagedFieldCount ()
code.constant().setValue(_meta.getDeclaredFields().length);
if (_meta.getPCSuperclass() != null) {
- code.invokestatic().setMethod(_meta.getPCSuperclass().getName(),
+ code.invokestatic().setMethod(getType(_meta.
+ getPCSuperclassMetaData()).getName(),
PRE + "GetManagedFieldCount", int.class.getName(), null);
code.iadd();
}
@@ -1039,14 +1061,15 @@
loadManagedInstance(code, false);
String[] args;
if (copy) {
- args = new String[]{ _meta.getPCSuperclass().getName(),
- int.class.getName() };
+ args = new String[]{ getType(_meta.getPCSuperclassMetaData()).
+ getName(), int.class.getName() };
code.aload().setParam(0);
} else
args = new String[]{ int.class.getName() };
code.iload().setParam(fieldNumber);
- code.invokespecial().setMethod(_meta.getPCSuperclass().
- getName(), name, void.class.getName(), args);
+ code.invokespecial().setMethod(getType(_meta.
+ getPCSuperclassMetaData()).getName(), name,
+ void.class.getName(), args);
code.vreturn();
} else
throwException(code, IllegalArgumentException.class);
@@ -1442,7 +1465,8 @@
loadManagedInstance(code, false);
for (int i = 0; i < args.length; i++)
code.aload().setParam(i);
- code.invokespecial().setMethod(_meta.getPCSuperclass().getName(),
+ code.invokespecial().setMethod(getType(_meta.
+ getPCSuperclassMetaData()).getName(),
PRE + "CopyKeyFieldsToObjectId", void.class.getName(), args);
}
@@ -1535,7 +1559,8 @@
loadManagedInstance(code, false);
for (int i = 0; i < args.length; i++)
code.aload().setParam(i);
- code.invokespecial().setMethod(_meta.getPCSuperclass().getName(),
+ code.invokespecial().setMethod(getType(_meta.
+ getPCSuperclassMetaData()).getName(),
PRE + "CopyKeyFieldsFromObjectId", void.class.getName(), args);
}
@@ -1729,14 +1754,14 @@
// new ObjectId (cls, oid)
code.anew().setType(ObjectId.class);
code.dup();
- code.classconstant().setClass(_meta.getDescribedType());
+ code.classconstant().setClass(getType(_meta));
}
// new <oid class> ();
code.anew().setType(oidType);
code.dup();
if (_meta.isOpenJPAIdentity() || (obj && usesClsString == Boolean.TRUE))
- code.classconstant().setClass(_meta.getDescribedType());
+ code.classconstant().setClass(getType(_meta));
if (obj) {
code.aload().setParam(0);
code.checkcast().setType(String.class);
@@ -1926,12 +1951,14 @@
Code code = getOrCreateClassInitCode(true);
if (_meta.getPCSuperclass() != null) {
// pcInheritedFieldCount = <superClass>.pcGetManagedFieldCount()
- code.invokestatic().setMethod(_meta.getPCSuperclass().getName(),
+ code.invokestatic().setMethod(getType(_meta.
+ getPCSuperclassMetaData()).getName(),
PRE + "GetManagedFieldCount", int.class.getName(), null);
code.putstatic().setField(INHERIT, int.class);
// pcPCSuperclass = <superClass>;
- code.classconstant().setClass(_meta.getPCSuperclass());
+ code.classconstant().setClass(getType(_meta.
+ getPCSuperclassMetaData()));
code.putstatic().setField(SUPER, Class.class);
}
@@ -2961,7 +2988,7 @@
// readUnmanaged (in);
loadManagedInstance(code, false);
code.aload().setParam(0);
- code.invokevirtual().setMethod(_meta.getDescribedType(),
+ code.invokevirtual().setMethod(getType(_meta),
PRE + "ReadUnmanaged", void.class, inargs);
if (detachedState) {
@@ -3013,8 +3040,9 @@
if (parentDetachable) {
loadManagedInstance(code, false);
code.aload().setParam(0);
- code.invokespecial().setMethod(_meta.getPCSuperclass(),
- PRE + "ReadUnmanaged", void.class, inargs);
+ code.invokespecial().setMethod(getType(_meta.
+ getPCSuperclassMetaData()), PRE + "ReadUnmanaged", void.class,
+ inargs);
}
// read declared unmanaged serializable fields
@@ -3091,7 +3119,7 @@
Code code = meth.getCode(true);
// super.writeExternal (out);
- Class sup = _meta.getDescribedType().getSuperclass();
+ Class sup = getType(_meta).getSuperclass();
if (!parentDetachable && Externalizable.class.isAssignableFrom(sup)) {
loadManagedInstance(code, false);
code.aload().setParam(0);
@@ -3102,7 +3130,7 @@
// writeUnmanaged (out);
loadManagedInstance(code, false);
code.aload().setParam(0);
- code.invokevirtual().setMethod(_meta.getDescribedType(),
+ code.invokevirtual().setMethod(getType(_meta),
PRE + "WriteUnmanaged", void.class, outargs);
JumpInstruction go2 = null;
@@ -3169,8 +3197,9 @@
if (parentDetachable) {
loadManagedInstance(code, false);
code.aload().setParam(0);
- code.invokespecial().setMethod(_meta.getPCSuperclass(),
- PRE + "WriteUnmanaged", void.class, outargs);
+ code.invokespecial().setMethod(getType(_meta.
+ getPCSuperclassMetaData()), PRE + "WriteUnmanaged", void.class,
+ outargs);
}
// write declared unmanaged serializable fields
@@ -3316,7 +3345,7 @@
// static void pcSet<field> (XXX inst, <fieldtype> value)
BCField field = _pc.getDeclaredField(fmd.getName());
setter = _pc.declareMethod(PRE + "Set" + fmd.getName(), void.class,
- new Class[]{ _meta.getDescribedType(), fmd.getDeclaredType() });
+ new Class[]{ getType(_meta), fmd.getDeclaredType() });
setter.setAccessFlags(field.getAccessFlags()
& ~Constants.ACCESS_TRANSIENT & ~Constants.ACCESS_VOLATILE);
setter.setStatic(true);
@@ -3338,6 +3367,17 @@
}
/**
+ * Return the concrete type for the given class, i.e. impl for managed
+ * interfaces
+ */
+ public Class getType(ClassMetaData meta) {
+ if (meta.getInterfaceImpl() != null)
+ return meta.getInterfaceImpl();
+ return meta.getDescribedType();
+ }
+
+
+ /**
* Move code-related attributes from one method to another.
*/
private static void transferCodeAttributes(BCMethod from, BCMethod to) {
@@ -3479,6 +3519,8 @@
status = enhancer.run();
if (status == ENHANCE_NONE)
log.info(_loc.get("enhance-norun"));
+ else if (status == ENHANCE_INTERFACE)
+ log.info(_loc.get("enhance-interface"));
else if (status == ENHANCE_AWARE) {
log.info(_loc.get("enhance-aware"));
enhancer.record();
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java Wed Sep 6 09:35:03 2006
@@ -2494,6 +2494,9 @@
PersistenceCapable copy;
PCState state;
+ Class type = meta.getDescribedType();
+ if (type.isInterface())
+ type = meta.getInterfaceImpl();
if (obj != null) {
// give copy and the original instance the same state manager
// so that we can copy fields from one to the other
@@ -2512,8 +2515,7 @@
// copy the instance. we do this even if it doesn't already
// have a state manager in case it is later assigned to a
// PC field; at that point it's too late to copy
- copy = PCRegistry.newInstance(meta.getDescribedType(),
- copySM, false);
+ copy = PCRegistry.newInstance(type, copySM, false);
int[] fields = new int[meta.getFields().length];
for (int i = 0; i < fields.length; i++)
fields[i] = i;
@@ -2527,8 +2529,7 @@
pc.pcReplaceStateManager(null);
}
} else {
- copy = PCRegistry.newInstance(meta.getDescribedType(), sm,
- false);
+ copy = PCRegistry.newInstance(type, sm, false);
if ((_flags & FLAG_ACTIVE) != 0 && !_optimistic)
state = PCState.ECLEAN;
else
@@ -3986,8 +3987,11 @@
public Object newInstance(Class cls) {
assertOpen();
- //### JDO2
- if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers()))
+ if (cls.isInterface()) {
+ ClassMetaData meta = _conf.getMetaDataRepositoryInstance().
+ getMetaData(cls, _loader, true);
+ cls = meta.getInterfaceImpl();
+ } else if (Modifier.isAbstract(cls.getModifiers()))
throw new UnsupportedOperationException(_loc.get
("new-abstract", cls).getMessage());
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java Wed Sep 6 09:35:03 2006
@@ -241,6 +241,8 @@
}
_meta = sub;
}
+ if (cls.isInterface())
+ cls = _meta.getInterfaceImpl();
PersistenceCapable inst = PCRegistry.newInstance(cls, this, _oid, true);
if (inst == null) {
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java Wed Sep 6 09:35:03 2006
@@ -41,6 +41,7 @@
private int _access = ClassMetaData.ACCESS_FIELD;
private boolean _ignore = true;
+ private boolean _interface = true;
private boolean _pcRegistry = true;
private int _callback = CALLBACK_RETHROW;
@@ -170,7 +171,8 @@
*/
private void populateFromReflection(ClassMetaData meta) {
Member[] members;
- if (meta.getAccessType() == ClassMetaData.ACCESS_FIELD)
+ boolean iface = meta.getDescribedType().isInterface();
+ if (meta.getAccessType() == ClassMetaData.ACCESS_FIELD && !iface)
members = meta.getDescribedType().getDeclaredFields();
else
members = meta.getDescribedType().getDeclaredMethods();
@@ -263,6 +265,14 @@
protected abstract boolean isDefaultPersistent(ClassMetaData meta,
Member member, String name);
+ public void setDeclaredInterfacePersistent(boolean pers) {
+ _interface = pers;
+ }
+
+ public boolean isDeclaredInterfacePersistent() {
+ return _interface;
+ }
+
public Member getBackingMember(FieldMetaData fmd) {
if (fmd == null)
return null;
@@ -319,6 +329,10 @@
name, clsName, "get" + capName));
throw new UserException(_loc.get("pc-registry-no-boolean-method",
new String[]{ name, clsName, "get" + capName, "is" + capName }));
+ }
+
+ public Class getUnimplementedExceptionType() {
+ return UnsupportedOperationException.class;
}
/**
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java Wed Sep 6 09:35:03 2006
@@ -140,6 +140,8 @@
private Boolean _openjpaId = null;
private Boolean _extent = null;
private Boolean _embedded = null;
+ private Boolean _interface = null;
+ private Class _impl = null;
private int _identity = -1;
private int _idStrategy = ValueStrategies.NONE;
private int _accessType = ACCESS_UNKNOWN;
@@ -215,9 +217,8 @@
* an embedded value changes its declared type.
*/
protected void setDescribedType(Class type) {
- if (type.isInterface())
- throw new MetaDataException(_loc.get("interface", type));
- if ("java.lang.Enum".equals(type.getSuperclass().getName()))
+ if (type.getSuperclass() != null && "java.lang.Enum".equals
+ (type.getSuperclass().getName()))
throw new MetaDataException(_loc.get("enum", type));
_type = type;
}
@@ -670,6 +671,38 @@
}
/**
+ * Whether the type is a managed interface.
+ */
+ public boolean isManagedInterface() {
+ if (!_type.isInterface())
+ return false;
+ return _interface == null ? false : _interface.booleanValue();
+ }
+
+ /**
+ * Whether the type is a managed interface
+ */
+ public void setManagedInterface(boolean managedInterface) {
+ if (!_type.isInterface())
+ throw new MetaDataException(_loc.get("not-interface", _type));
+ _interface = managedInterface ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ /**
+ * Return the managed interface implementor if any.
+ */
+ public Class getInterfaceImpl() {
+ return _impl;
+ }
+
+ /**
+ * Set the managed interface implementor class.
+ */
+ public void setInterfaceImpl(Class impl) {
+ _impl = impl;
+ }
+
+ /**
* Return the number of fields that use impl or intermediate data, in
* order to create a compacted array for storage of said data.
*/
@@ -1481,7 +1514,8 @@
log.trace(_loc.get((embed) ? "resolve-embed-meta" : "resolve-meta",
this + "@" + System.identityHashCode(this)));
- if (runtime && !PersistenceCapable.class.isAssignableFrom(_type))
+ if (runtime && !_type.isInterface() &&
+ !PersistenceCapable.class.isAssignableFrom(_type))
throw new MetaDataException(_loc.get("not-enhanced", _type));
// are we the target of an embedded value?
@@ -1555,6 +1589,16 @@
for (Iterator itr = _fgMap.values().iterator(); itr.hasNext();)
((FetchGroup) itr.next()).resolve();
+ if (!embed && _type.isInterface()) {
+ if (_interface != Boolean.TRUE)
+ throw new MetaDataException(_loc.get("interface", _type));
+
+ if (runtime) {
+ _impl = _repos.getImplGenerator().createImpl(this);
+ _repos.setInterfaceImpl(this, _impl);
+ }
+ }
+
// if this is runtime, create a pc instance and scan it for comparators
if (runtime && !Modifier.isAbstract(_type.getModifiers())) {
ProxySetupStateManager sm = new ProxySetupStateManager();
@@ -2113,6 +2157,8 @@
_objectId = meta.getObjectIdType();
_extent = (meta.getRequiresExtent()) ? Boolean.TRUE : Boolean.FALSE;
_embedded = (meta.isEmbeddedOnly()) ? Boolean.TRUE : Boolean.FALSE;
+ _interface = (meta.isManagedInterface()) ? Boolean.TRUE : Boolean.FALSE;
+ _impl = meta.getInterfaceImpl();
_identity = meta.getIdentityType();
_idStrategy = meta.getIdentityStrategy();
_seqName = meta.getIdentitySequenceName();
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/InheritanceComparator.java Wed Sep 6 09:35:03 2006
@@ -21,8 +21,9 @@
* Comparator that keeps classes in inheritance order.
*
* @author Abe White
+ * @nojavadoc
*/
-class InheritanceComparator
+public class InheritanceComparator
implements Comparator {
private Class _base = Object.class;
@@ -62,8 +63,14 @@
int i1 = levels(c1);
int i2 = levels(c2);
- if (i1 == i2)
+ if (i1 == i2) {
+ // sort simple interfaces as well as simple order test will fail.
+ if (c1.isAssignableFrom(c2))
+ return -1;
+ if (c2.isAssignableFrom(c1))
+ return 1;
return c1.getName().compareTo(c2.getName());
+ }
return i1 - i2;
}
@@ -71,6 +78,8 @@
* Count the levels of inheritance between this class and our base class.
*/
private int levels(Class to) {
+ if (to.isInterface())
+ return to.getInterfaces().length;
for (int i = 0; to != null; i++, to = to.getSuperclass())
if (to == _base)
return i;
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java Wed Sep 6 09:35:03 2006
@@ -51,6 +51,12 @@
public void setIgnoreNonPersistent(boolean ignore);
/**
+ * Whether declared interfaces of a class are treated as persistent
+ * types. Defaults to true.
+ */
+ public boolean isDeclaredInterfacePersistent();
+
+ /**
* Populate the given metadata with default settings.
*
* @param access access type constant from {@link ClassMetaData}
@@ -61,4 +67,10 @@
* Return the backing member for the given field metadata.
*/
public Member getBackingMember(FieldMetaData field);
+
+ /**
+ * Return a runtime exception class to throw for un-implemented
+ * managed interface methods.
+ */
+ public Class getUnimplementedExceptionType();
}
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataInheritanceComparator.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataInheritanceComparator.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataInheritanceComparator.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataInheritanceComparator.java Wed Sep 6 09:35:03 2006
@@ -25,7 +25,8 @@
extends InheritanceComparator {
protected Class toClass(Object elem) {
- return (elem == null) ? null
- : ((ClassMetaData) elem).getDescribedType();
+ if (elem == null)
+ return null;
+ return ((ClassMetaData) elem).getDescribedType();
}
}
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java Wed Sep 6 09:35:03 2006
@@ -105,6 +105,7 @@
private final Map _metas = new HashMap();
private final Map _oids = Collections.synchronizedMap(new HashMap());
private final Map _impls = Collections.synchronizedMap(new HashMap());
+ private final Map _ifaces = Collections.synchronizedMap(new HashMap());
private final Map _queries = new HashMap();
private final Map _seqs = new HashMap();
private final Map _aliases = Collections.synchronizedMap(new HashMap());
@@ -116,6 +117,7 @@
private OpenJPAConfiguration _conf = null;
private Log _log = null;
private MetaDataFactory _factory = null;
+ private InterfaceImplGenerator _implGen = null;
private int _resMode = MODE_META | MODE_MAPPING;
private int _sourceMode = MODE_META | MODE_MAPPING | MODE_QUERY;
private int _validate = VALIDATE_META | VALIDATE_UNENHANCED;
@@ -541,6 +543,18 @@
} else
sup = sup.getSuperclass();
}
+ if (meta.getDescribedType().isInterface()) {
+ Class[] sups = meta.getDescribedType().getInterfaces();
+ for (int i = 0; i < sups.length; i++) {
+ supMeta = getMetaData(sups[i], meta.getEnvClassLoader(),
+ false);
+ if (supMeta != null) {
+ meta.setPCSuperclass(sup);
+ meta.setPCSuperclassMetaData(supMeta);
+ break;
+ }
+ }
+ }
if (_log.isTraceEnabled())
_log.trace(_loc.get("assigned-sup", meta,
meta.getPCSuperclass()));
@@ -845,12 +859,41 @@
if (cls == null)
return false;
if (_metas.remove(cls) != null) {
+ Class impl = (Class) _ifaces.remove(cls);
+ if (impl != null)
+ _metas.remove(impl);
_count--;
return true;
}
return false;
}
+
+ /**
+ * Add the given metadata as declared interface implementation.
+ */
+ public void addDeclaredInterfaceImpl(ClassMetaData meta, Class iface) {
+ synchronized (_impls) {
+ addToCollection(_impls, iface, meta.getDescribedType(), false);
+ }
+ }
+
+ /**
+ * Set the implementation for the given managed interface.
+ */
+ synchronized void setInterfaceImpl(ClassMetaData meta, Class impl) {
+ if (!meta.isManagedInterface())
+ throw new MetaDataException(_loc.get("not-managed-interface",
+ meta, impl));
+ _ifaces.put(meta.getDescribedType(), impl);
+ _metas.put(impl, meta);
+ }
+ synchronized InterfaceImplGenerator getImplGenerator() {
+ if (_implGen == null)
+ _implGen = new InterfaceImplGenerator(this);
+ return _implGen;
+ }
+
/**
* Return the least-derived class metadata for the given application
* identity object.
@@ -1274,6 +1317,8 @@
* Update the list of implementations of base classes and interfaces.
*/
private void updateImpls(Class cls, Class leastDerived, Class check) {
+ if (_factory.getDefaults().isDeclaredInterfacePersistent())
+ return;
// allow users to query on common non-pc superclasses
Class sup = check.getSuperclass();
if (leastDerived == cls && sup != null && sup != Object.class) {
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java Wed Sep 6 09:35:03 2006
@@ -104,10 +104,18 @@
public void setIgnoreNonPersistent(boolean ignore) {
}
+ public boolean isDeclaredInterfacePersistent() {
+ return false;
+ }
+
public void populate(ClassMetaData meta, int access) {
}
public Member getBackingMember(FieldMetaData fmd) {
+ return null;
+ }
+
+ public Class getUnimplementedExceptionType() {
return null;
}
}
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/util/ApplicationIds.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/util/ApplicationIds.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/util/ApplicationIds.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/util/ApplicationIds.java Wed Sep 6 09:35:03 2006
@@ -257,8 +257,11 @@
// to the original oid values, then copy its key fields to a new
// oid instance
if (!Modifier.isAbstract(meta.getDescribedType().getModifiers())) {
- PersistenceCapable pc = PCRegistry.newInstance
- (meta.getDescribedType(), null, oid, false);
+ Class type = meta.getDescribedType();
+ if (meta.getInterfaceImpl() != null)
+ type = meta.getInterfaceImpl();
+ PersistenceCapable pc = PCRegistry.newInstance(type, null, oid,
+ false);
Object copy = pc.pcNewObjectIdInstance();
pc.pcCopyKeyFieldsToObjectId(copy);
return copy;
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreFacadeTypeRegistry.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreFacadeTypeRegistry.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreFacadeTypeRegistry.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreFacadeTypeRegistry.java Wed Sep 6 09:35:03 2006
@@ -49,6 +49,27 @@
}
return (Class) _impls.get(facadeType);
}
+
+ /**
+ * Return the implementation for the given facade and store. If no
+ * registered implementation is found then returns the given default type
+ * provided it the facade type is assignable from the deafult type.
+ *
+ * @param facadeType the facade interface
+ * @param storeType the store's
+ * {@link org.apache.openjpa.kernel.StoreManager} type, or null for generic
+ * @param implType the registered implementor
+ * @param defaultType class if no registered implementation is available.
+ */
+ public Class getImplementation(Class facadeType, Class storeType,
+ Class defaultType) {
+ Class result = getImplementation(facadeType, storeType);
+ if (result == null)
+ result = defaultType;
+ if (facadeType == null || !facadeType.isAssignableFrom(result))
+ throw new InternalException();
+ return result;
+ }
/**
* Lookup key for facade+store hash.
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties Wed Sep 6 09:35:03 2006
@@ -24,6 +24,7 @@
enhance-aware: The class does not have metadata - enhanced as persistence-aware.
enhance-norun: The class is already persistence capable - no enhancement \
performed.
+enhance-interface: The class is a managed interface - no enhancement performed.
enhance-usage: Usage: java org.apache.openjpa.enhance.PCEnhancer\n\
\t[-properties/-p <properties file or resource>]\n\
\t[-<property name> <property value>]*\n\
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties Wed Sep 6 09:35:03 2006
@@ -4,8 +4,8 @@
"{0}".
meta-unknownid: Cannot manipulate identity of type "{0}": it''s identity type \
is unknown.
-new-abstract: Cannot create an instance of "{0}": abstract classes and \
- interfaces are not yet supported.
+new-abstract: Cannot create an instance of "{0}": abstract classes are not \
+ yet supported.
bad-new-query: Attempt to construct a query from an extent or class. You must \
pass a (possibly null) query string or template to the query factory \
method when creating the query.
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties Wed Sep 6 09:35:03 2006
@@ -18,6 +18,8 @@
process-registered: Processing registered persistence-capable class "{0}".
assigned-sup: Set persistence-capable superclass of "{0}" to "{1}".
found-pcs: Found {0} classes with metadata in {1} milliseconds.
+not-managed-interface: Cannot set type "{1}" as interface "{0}" implementor. \
+ "{0}" is not a managed interface.
unmanaged-sup-field: Superclass field "{0}" is mapped in the metadata for \
subclass "{1}", but is not a persistent field.
bad-discover-class: The class "{0}" listed in the openjpa.MetaDataFactory \
@@ -180,7 +182,10 @@
bad-update-strategy-hint: "{0}" declares a read only value of \
"{1}". This is not a recognized strategy, though it closely resembles \
the standard strategy "{2}". Available strategies are: {3}
-interface: Type "{0}" is an interface and therefore cannot be made persistent.
+not-interface: Can't set type "{0}" to be a managed interface as it is not \
+ and interface.
+interface: The type "{0}" is an unmanaged interface and therefore cannot be \
+ made persistent.
enum: Type "{0}" is an enumeration and therefore cannot be made persistent.
bad-drop: The metadata for some of the following classes may not have \
been dropped: {0}
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCFetchPlan.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCFetchPlan.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCFetchPlan.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCFetchPlan.java Wed Sep 6 09:35:03 2006
@@ -28,82 +28,35 @@
/**
* JDBC extensions to the fetch plan.
*
- * @since 0.4.0
+ * @since 0.4.1
* @author Abe White
+ * @author Pinaki Poddar
* @published
*/
-public class JDBCFetchPlan
- extends FetchPlan
- implements EagerFetchModes, LRSSizes, JoinSyntaxes {
-
- private DelegatingJDBCFetchConfiguration _fetch;
-
- /**
- * Constructor; supply delegate.
- */
- public JDBCFetchPlan(FetchConfiguration fetch) {
- super(fetch);
- }
-
- @Override
- protected DelegatingFetchConfiguration newDelegatingFetchConfiguration
- (FetchConfiguration fetch) {
- _fetch = new DelegatingJDBCFetchConfiguration((JDBCFetchConfiguration)
- fetch, PersistenceExceptions.TRANSLATOR);
- return _fetch;
- }
-
- public int getEagerFetchMode() {
- return _fetch.getEagerFetchMode();
- }
-
- public JDBCFetchPlan setEagerFetchMode(int mode) {
- _fetch.setEagerFetchMode(mode);
- return this;
- }
-
- public int getSubclassFetchMode() {
- return _fetch.getSubclassFetchMode();
- }
-
- public JDBCFetchPlan setSubclassFetchMode(int mode) {
- _fetch.setSubclassFetchMode(mode);
- return this;
- }
-
- public int getResultSetType() {
- return _fetch.getResultSetType();
- }
-
- public JDBCFetchPlan setResultSetType(int type) {
- _fetch.setResultSetType(type);
- return this;
- }
-
- public int getFetchDirection() {
- return _fetch.getFetchDirection();
- }
-
- public JDBCFetchPlan setFetchDirection(int direction) {
- _fetch.setFetchDirection(direction);
- return this;
- }
-
- public int getLRSSize() {
- return _fetch.getLRSSize();
- }
-
- public JDBCFetchPlan setLRSSize(int lrsSize) {
- _fetch.setLRSSize(lrsSize);
- return this;
- }
-
- public int getJoinSyntax() {
- return _fetch.getJoinSyntax();
- }
-
- public JDBCFetchPlan setJoinSyntax(int syntax) {
- _fetch.setJoinSyntax(syntax);
- return this;
- }
+public interface JDBCFetchPlan
+ extends FetchPlan, EagerFetchModes, LRSSizes, JoinSyntaxes {
+
+ public int getEagerFetchMode();
+
+ public JDBCFetchPlan setEagerFetchMode(int mode);
+
+ public int getSubclassFetchMode();
+
+ public JDBCFetchPlan setSubclassFetchMode(int mode);
+
+ public int getResultSetType();
+
+ public JDBCFetchPlan setResultSetType(int type);
+
+ public int getFetchDirection();
+
+ public JDBCFetchPlan setFetchDirection(int direction);
+
+ public int getLRSSize();
+
+ public JDBCFetchPlan setLRSSize(int lrsSize);
+
+ public int getJoinSyntax();
+
+ public JDBCFetchPlan setJoinSyntax(int syntax);
}
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java Wed Sep 6 09:35:03 2006
@@ -41,7 +41,7 @@
public void beforeConfigurationLoad(OpenJPAConfiguration c) {
c.getStoreFacadeTypeRegistry().registerImplementation(FetchPlan.class,
- JDBCStoreManager.class, JDBCFetchPlan.class);
+ JDBCStoreManager.class, JDBCFetchPlanImpl.class);
if (!(c instanceof JDBCConfigurationImpl))
return;
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ConfigurationProviderImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ConfigurationProviderImpl.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ConfigurationProviderImpl.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ConfigurationProviderImpl.java Wed Sep 6 09:35:03 2006
@@ -93,9 +93,9 @@
return false;
String providerName = pinfo.getPersistenceProviderClassName();
if (!StringUtils.isEmpty(providerName)
- && !PersistenceProviderImpl.class.getName().equals(providerName))
+ && !getPersistenceProviderName().equals(providerName))
return false;
-
+
addProperties(PersistenceUnitInfoImpl.toOpenJPAProperties(pinfo));
if (m != null)
addProperties(m);
@@ -168,7 +168,7 @@
* @return {@link Boolean#TRUE} if the resource was loaded, null if it
* does not exist, or {@link Boolean#FALSE} if it is not for OpenJPA
*/
- private Boolean load(String rsrc, String name, Map m, ClassLoader loader,
+ protected Boolean load(String rsrc, String name, Map m, ClassLoader loader,
boolean explicit)
throws IOException {
if (loader == null)
@@ -227,7 +227,7 @@
}
if (StringUtils.isEmpty(pinfo.getPersistenceProviderClassName())
- || PersistenceProviderImpl.class.getName().equals(pinfo.
+ || getPersistenceProviderName().equals(pinfo.
getPersistenceProviderClassName())) {
// if no name given and found unnamed unit, return it.
// otherwise record as default unit unless we find a
@@ -276,6 +276,21 @@
log.trace(_loc.get("conf-load", _source, getProperties()));
}
+ /**
+ * Gets the concrete class used as Persistence Provider.
+ * Used to detect whether this receiver should load the configuration.
+ * This receiver will load only if the provider name in the resource
+ * matches the provider name returned by this method.
+ * <B>Note</B>: This is a tentative hook for backward-compatibility work
+ * and would be replaced/removed once ProductDerivation-based extension
+ * framework is available.
+ *
+ * @return
+ */
+ protected String getPersistenceProviderName() {
+ return PersistenceProviderImpl.class.getName();
+ }
+
/**
* SAX handler capable of parsing an JPA persistence.xml file.
* Package-protected for testing.
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java Wed Sep 6 09:35:03 2006
@@ -94,7 +94,7 @@
try {
if (_cache == null) {
OpenJPAConfiguration conf = _factory.getConfiguration();
- _cache = new StoreCache(this,
+ _cache = new StoreCacheImpl(this,
conf.getDataCacheManagerInstance().getSystemDataCache());
}
return _cache;
@@ -104,7 +104,7 @@
}
public StoreCache getStoreCache(String cacheName) {
- return new StoreCache(this, _factory.getConfiguration().
+ return new StoreCacheImpl(this, _factory.getConfiguration().
getDataCacheManagerInstance().getDataCache(cacheName));
}
@@ -112,7 +112,7 @@
_factory.lock();
try {
if (_queryCache == null)
- _queryCache = new QueryResultCache(_factory.getConfiguration().
+ _queryCache = new QueryResultCacheImpl(_factory.getConfiguration().
getDataCacheManagerInstance().getSystemQueryCache());
return _queryCache;
} finally {
@@ -274,9 +274,8 @@
getStoreManager().getInnermostDelegate().getClass();
Class cls = _factory.getConfiguration().
getStoreFacadeTypeRegistry().
- getImplementation(FetchPlan.class, storeType);
- if (cls == null)
- cls = FetchPlan.class;
+ getImplementation(FetchPlan.class, storeType,
+ FetchPlanImpl.class);
_plan = cls.getConstructor(FetchConfiguration.class);
}
return _plan.newInstance(fetch);
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java Wed Sep 6 09:35:03 2006
@@ -614,7 +614,7 @@
getMetaDataRepositoryInstance().getSequenceMetaData(name,
_broker.getClassLoader(), true);
Seq seq = meta.getInstance(_broker.getClassLoader());
- return new Generator(seq, name, _broker, null);
+ return new GeneratorImpl(seq, name, _broker, null);
} catch (RuntimeException re) {
throw PersistenceExceptions.toPersistenceException(re);
}
@@ -626,7 +626,7 @@
getMetaDataRepositoryInstance().getMetaData(forClass,
_broker.getClassLoader(), true);
Seq seq = _broker.getIdentitySequence(meta);
- return (seq == null) ? null : new Generator(seq, null, _broker,
+ return (seq == null) ? null : new GeneratorImpl(seq, null, _broker,
meta);
} catch (Exception e) {
throw PersistenceExceptions.toPersistenceException(e);
@@ -644,7 +644,7 @@
forClass, fieldName), null, null, false);
Seq seq = _broker.getValueSequence(fmd);
- return (seq == null) ? null : new Generator(seq, null, _broker,
+ return (seq == null) ? null : new GeneratorImpl(seq, null, _broker,
meta);
} catch (Exception e) {
throw PersistenceExceptions.toPersistenceException(e);
@@ -652,7 +652,7 @@
}
public <T> Extent<T> createExtent(Class<T> cls, boolean subclasses) {
- return new Extent<T>(this, _broker.newExtent(cls, subclasses));
+ return new ExtentImpl<T>(this, _broker.newExtent(cls, subclasses));
}
public OpenJPAQuery createQuery(String query) {
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/Extent.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/Extent.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/Extent.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/Extent.java Wed Sep 6 09:35:03 2006
@@ -24,113 +24,56 @@
* An extent is a logical view of all instances of a class.
*
* @author Abe White
+ * @author Pinaki Poddar
+ * @since 0.4.0
* @published
*/
-public class Extent<T>
- implements Iterable {
+public interface Extent<T>
+ extends Iterable<T> {
- private final EntityManagerImpl _em;
- private final DelegatingExtent _extent;
- private FetchPlan _fetch = null;
-
- /**
- * Constructor; supply delegate.
- */
- public Extent(EntityManagerImpl em,
- org.apache.openjpa.kernel.Extent extent) {
- _em = em;
- _extent = new DelegatingExtent(extent,
- PersistenceExceptions.getRollbackTranslator(em));
- }
/**
* Delegate.
*/
- public org.apache.openjpa.kernel.Extent getDelegate() {
- return _extent.getDelegate();
- }
+ public org.apache.openjpa.kernel.Extent getDelegate();
/**
* The extent's element type.
*/
- public Class<T> getElementClass() {
- return _extent.getElementType();
- }
+ public Class<T> getElementClass();
/**
* Whether the extent includes subclasses.
*/
- public boolean hasSubclasses() {
- return _extent.hasSubclasses();
- }
+ public boolean hasSubclasses();
/**
* The owning entity manager.
*/
- public OpenJPAEntityManager getEntityManager() {
- return _em;
- }
+ public OpenJPAEntityManager getEntityManager();
/**
* Fetch configuration for controlling how iterated objects are loaded.
*/
- public FetchPlan getFetchPlan() {
- _extent.lock();
- try {
- if (_fetch == null)
- _fetch = ((EntityManagerFactoryImpl) _em.
- getEntityManagerFactory()).toFetchPlan(_extent.getBroker(),
- _extent.getFetchConfiguration());
- return _fetch;
- } finally {
- _extent.unlock();
- }
- }
+ public FetchPlan getFetchPlan();
/**
* Whether the extent sees inserts and deletes in the current transaction.
*/
- public boolean getIgnoreChanges() {
- return _extent.getIgnoreChanges();
- }
+ public boolean getIgnoreChanges();
/**
* Whether the extent sees inserts and deletes in the current transaction.
*/
- public void setIgnoreChanges(boolean ignoreChanges) {
- _extent.setIgnoreChanges(ignoreChanges);
- }
+ public void setIgnoreChanges(boolean ignoreChanges);
/**
* List the extent contents.
*/
- public List<T> list() {
- return _extent.list();
- }
-
- /**
- * Iterator over contents.
- */
- public Iterator<T> iterator() {
- return _extent.iterator();
- }
+ public List<T> list();
/**
* Close all open iterators that are consuming database resources.
*/
- public void closeAll() {
- _extent.closeAll();
- }
-
- public int hashCode() {
- return _extent.hashCode();
- }
-
- public boolean equals(Object other) {
- if (other == this)
- return true;
- if (!(other instanceof Extent))
- return false;
- return _extent.equals(((Extent) other)._extent);
- }
+ public void closeAll();
}
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/FetchPlan.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/FetchPlan.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/FetchPlan.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/FetchPlan.java Wed Sep 6 09:35:03 2006
@@ -30,10 +30,11 @@
* configuration and other aspects of data loading.
*
* @author Abe White
- * @since 0.4.0
+ * @author Pinaki Poddar
+ * @since 0.4.1
* @published
*/
-public class FetchPlan {
+public interface FetchPlan {
/**
* Fetch group representing all fields.
@@ -55,64 +56,35 @@
*/
public static final int DEFAULT = FetchConfiguration.DEFAULT;
- private final DelegatingFetchConfiguration _fetch;
-
- /**
- * Constructor; supply delegate.
- */
- public FetchPlan(FetchConfiguration fetch) {
- _fetch = newDelegatingFetchConfiguration(fetch);
- }
-
- /**
- * Create a new exception-translating delegating fetch configuration.
- */
- protected DelegatingFetchConfiguration newDelegatingFetchConfiguration
- (FetchConfiguration fetch) {
- return new DelegatingFetchConfiguration(fetch,
- PersistenceExceptions.TRANSLATOR);
- }
/**
* Delegate.
*/
- public FetchConfiguration getDelegate() {
- return _fetch.getDelegate();
- }
+ public FetchConfiguration getDelegate();
/**
* The maximum fetch depth when loading an object.
*/
- public int getMaxFetchDepth() {
- return _fetch.getMaxFetchDepth();
- }
+ public int getMaxFetchDepth();
/**
* The maximum fetch depth when loading an object.
*/
- public FetchPlan setMaxFetchDepth(int depth) {
- _fetch.setMaxFetchDepth(depth);
- return this;
- }
+ public FetchPlan setMaxFetchDepth(int depth);
/**
* Return the fetch batch size for large result set support.
* Defaults to the <code>openjpa.FetchBatchSize</code> setting. Note
* that this property will be ignored under some data stores.
*/
- public int getFetchBatchSize() {
- return _fetch.getFetchBatchSize();
- }
+ public int getFetchBatchSize();
/**
* Set the fetch batch size for large result set support.
* Defaults to the <code>openjpa.FetchBatchSize</code> setting. Note
* that this property will be ignored under some data stores.
*/
- public FetchPlan setFetchBatchSize(int fetchBatchSize) {
- _fetch.setFetchBatchSize(fetchBatchSize);
- return this;
- }
+ public FetchPlan setFetchBatchSize(int fetchBatchSize);
/**
* Return whether or not query caching is enabled. If this returns
@@ -121,79 +93,55 @@
* returns <code>false</code>, query caching will not be used
* even if the datacache plugin is installed.
*/
- public boolean getQueryResultCache() {
- return _fetch.getQueryCache();
- }
+ public boolean getQueryResultCache();
/**
* Control whether or not query caching is enabled. This has no effect
* if the datacache plugin is not installed, or if the query cache size
* is set to zero.
*/
- public FetchPlan setQueryResultCache(boolean cache) {
- _fetch.setQueryCache(cache);
- return this;
- }
+ public FetchPlan setQueryResultCache(boolean cache);
/**
* Returns the names of the fetch groups that this component will use
* when loading objects. Defaults to the
* <code>org.apache.openjpa.FetchGroups</code> setting.
*/
- public Collection<String> getFetchGroups() {
- return _fetch.getFetchGroups();
- }
+ public Collection<String> getFetchGroups();
/**
* Adds <code>group</code> to the set of fetch group to
* use when loading objects.
*/
- public FetchPlan addFetchGroup(String group) {
- _fetch.addFetchGroup(group);
- return this;
- }
+ public FetchPlan addFetchGroup(String group);
/**
* Adds <code>groups</code> to the set of fetch group names to
* use when loading objects.
*/
- public FetchPlan addFetchGroups(String... groups) {
- return addFetchGroups(Arrays.asList(groups));
- }
-
+ public FetchPlan addFetchGroups(String... groups);
/**
* Adds <code>groups</code> to the set of fetch group names to
* use when loading objects.
*/
- public FetchPlan addFetchGroups(Collection groups) {
- _fetch.addFetchGroups(groups);
- return this;
- }
+ public FetchPlan addFetchGroups(Collection groups);
/**
* Remove the given fetch group.
*/
- public FetchPlan removeFetchGroup(String group) {
- _fetch.removeFetchGroup(group);
- return this;
- }
+ public FetchPlan removeFetchGroup(String group);
/**
* Removes <code>groups</code> from the set of fetch group names
* to use when loading objects.
*/
- public FetchPlan removeFetchGroups(String... groups) {
- return removeFetchGroups(Arrays.asList(groups));
- }
+ public FetchPlan removeFetchGroups(String... groups);
/**
* Removes <code>groups</code> from the set of fetch group names
* to use when loading objects.
*/
- public FetchPlan removeFetchGroups(Collection groups) {
- _fetch.removeFetchGroups(groups);
- return this;
- }
+ public FetchPlan removeFetchGroups(Collection groups);
/**
* Clears the set of fetch group names to use wen loading
@@ -201,224 +149,135 @@
* the default fetch group (and any requested field) will be
* loaded when loading an object.
*/
- public FetchPlan clearFetchGroups() {
- _fetch.clearFetchGroups();
- return this;
- }
+ public FetchPlan clearFetchGroups();
/**
* Resets the set of fetch groups to the list in the global configuration.
*/
- public FetchPlan resetFetchGroups() {
- _fetch.resetFetchGroups();
- return this;
- }
+ public FetchPlan resetFetchGroups();
/**
* Returns the fully qualified names of the fields that this component
* will use when loading objects. Defaults to the empty set.
*/
- public Collection<String> getFields() {
- return (Collection<String>) _fetch.getFields();
- }
+ public Collection<String> getFields();
/**
* Return true if the given field has been added.
*/
- public boolean hasField(String field) {
- return _fetch.hasField(field);
- }
+ public boolean hasField(String field);
/**
* Return true if the given field has been added.
*/
- public boolean hasField(Class cls, String field) {
- return hasField(toFieldName(cls, field));
- }
+ public boolean hasField(Class cls, String field);
/**
* Adds <code>field</code> to the set of fully-qualified field names to
* use when loading objects.
*/
- public FetchPlan addField(String field) {
- _fetch.addField(field);
- return this;
- }
+ public FetchPlan addField(String field);
/**
* Adds <code>field</code> to the set of field names to
* use when loading objects.
*/
- public FetchPlan addField(Class cls, String field) {
- return addField(toFieldName(cls, field));
- }
+ public FetchPlan addField(Class cls, String field);
/**
* Adds <code>fields</code> to the set of fully-qualified field names to
* use when loading objects.
*/
- public FetchPlan addFields(String... fields) {
- return addFields(Arrays.asList(fields));
- }
+ public FetchPlan addFields(String... fields);
/**
* Adds <code>fields</code> to the set of field names to
* use when loading objects.
*/
- public FetchPlan addFields(Class cls, String... fields) {
- return addFields(cls, Arrays.asList(fields));
- }
+ public FetchPlan addFields(Class cls, String... fields);
/**
* Adds <code>fields</code> to the set of fully-qualified field names to
* use when loading objects.
*/
- public FetchPlan addFields(Collection fields) {
- _fetch.addFields(fields);
- return this;
- }
+ public FetchPlan addFields(Collection fields);
/**
* Adds <code>fields</code> to the set of field names to
* use when loading objects.
*/
- public FetchPlan addFields(Class cls, Collection fields) {
- return addFields(toFieldNames(cls, fields));
- }
+ public FetchPlan addFields(Class cls, Collection fields);
/**
* Remove the given fully-qualified field.
*/
- public FetchPlan removeField(String field) {
- _fetch.removeField(field);
- return this;
- }
+ public FetchPlan removeField(String field);
/**
* Remove the given field.
*/
- public FetchPlan removeField(Class cls, String field) {
- return removeField(toFieldName(cls, field));
- }
+ public FetchPlan removeField(Class cls, String field);
/**
* Removes <code>fields</code> from the set of fully-qualified field names
* to use when loading objects.
*/
- public FetchPlan removeFields(String... fields) {
- return removeFields(Arrays.asList(fields));
- }
+ public FetchPlan removeFields(String... fields);
/**
* Removes <code>fields</code> from the set of field names
* to use when loading objects.
*/
- public FetchPlan removeFields(Class cls, String... fields) {
- return removeFields(cls, Arrays.asList(fields));
- }
+ public FetchPlan removeFields(Class cls, String... fields);
/**
* Removes <code>fields</code> from the set of fully-qualified field names
* to use when loading objects.
*/
- public FetchPlan removeFields(Collection fields) {
- _fetch.removeFields(fields);
- return this;
- }
+ public FetchPlan removeFields(Collection fields);
/**
* Removes <code>fields</code> from the set of field names
* to use when loading objects.
*/
- public FetchPlan removeFields(Class cls, Collection fields) {
- return removeFields(toFieldNames(cls, fields));
- }
+ public FetchPlan removeFields(Class cls, Collection fields);
/**
* Clears the set of field names to use wen loading
* data. After this operation is invoked, only those fields in
* the configured fetch groups will be loaded when loading an object.
*/
- public FetchPlan clearFields() {
- _fetch.clearFields();
- return this;
- }
-
- /**
- * Combine the class and field to a fully-qualified field name.
- */
- private static String toFieldName(Class cls, String field) {
- return cls.getName() + "." + field;
- }
-
- /**
- * Combine the class and fields to fully-qualified field names.
- */
- private static Collection toFieldNames(Class cls, Collection fields) {
- if (fields.isEmpty())
- return fields;
- Collection names = new ArrayList(fields);
- for (Iterator itr = fields.iterator(); itr.hasNext();)
- names.add(toFieldName(cls, (String) itr.next()));
- return names;
- }
+ public FetchPlan clearFields();
/**
* The number of milliseconds to wait for an object lock, or -1 for no
* limit.
*/
- public int getLockTimeout() {
- return _fetch.getLockTimeout();
- }
+ public int getLockTimeout();
/**
* The number of milliseconds to wait for an object lock, or -1 for no
* limit.
*/
- public FetchPlan setLockTimeout(int timeout) {
- _fetch.setLockTimeout(timeout);
- return this;
- }
+ public FetchPlan setLockTimeout(int timeout);
/**
* The lock level to use for locking loaded objects.
*/
- public LockModeType getReadLockMode() {
- return EntityManagerImpl.fromLockLevel(_fetch.getReadLockLevel());
- }
+ public LockModeType getReadLockMode();
/**
* The lock level to use for locking loaded objects.
*/
- public FetchPlan setReadLockMode(LockModeType mode) {
- _fetch.setReadLockLevel(EntityManagerImpl.toLockLevel(mode));
- return this;
- }
+ public FetchPlan setReadLockMode(LockModeType mode);
/**
* The lock level to use for locking dirtied objects.
*/
- public LockModeType getWriteLockMode() {
- return EntityManagerImpl.fromLockLevel(_fetch.getWriteLockLevel());
- }
+ public LockModeType getWriteLockMode();
/**
* The lock level to use for locking dirtied objects.
*/
- public FetchPlan setWriteLockMode(LockModeType mode) {
- _fetch.setWriteLockLevel(EntityManagerImpl.toLockLevel(mode));
- return this;
- }
-
- public int hashCode() {
- return _fetch.hashCode();
- }
-
- public boolean equals(Object other) {
- if (other == this)
- return true;
- if (!(other instanceof FetchPlan))
- return false;
- return _fetch.equals(((FetchPlan) other)._fetch);
- }
+ public FetchPlan setWriteLockMode(LockModeType mode);
}
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/Generator.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/Generator.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/Generator.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/Generator.java Wed Sep 6 09:35:03 2006
@@ -24,76 +24,39 @@
* Represents a store sequence.
*
* @author Abe White
- * @since 0.4.0
+ * @author Pinaki Poddar
+ * @since 0.4.1
* @published
*/
-public class Generator {
+public interface Generator {
public static final String UUID_HEX = "uuid-hex";
public static final String UUID_STRING = "uuid-string";
- private final DelegatingSeq _seq;
- private final String _name;
- private final StoreContext _ctx;
- private final ClassMetaData _meta;
-
- /**
- * Constructor; supply delegate.
- */
- public Generator(Seq seq, String name, StoreContext ctx,
- ClassMetaData meta) {
- _seq = new DelegatingSeq(seq, PersistenceExceptions.TRANSLATOR);
- _name = name;
- _ctx = ctx;
- _meta = meta;
- }
-
/**
* Delegate.
*/
- public Seq getDelegate() {
- return _seq.getDelegate();
- }
+ public Seq getDelegate();
/**
* The sequence name.
*/
- public String getName() {
- return _name;
- }
+ public String getName();
/**
* The next sequence value.
*/
- public Object next() {
- return _seq.next(_ctx, _meta);
- }
+ public Object next();
/**
* The current sequence value, or null if the sequence does not
* support current values.
*/
- public Object current() {
- return _seq.current(_ctx, _meta);
- }
+ public Object current();
/**
* Hint to the sequence to allocate additional values up-front for
* efficiency.
*/
- public void allocate(int additional) {
- _seq.allocate(additional, _ctx, _meta);
- }
-
- public int hashCode() {
- return _seq.hashCode();
- }
-
- public boolean equals(Object other) {
- if (other == this)
- return true;
- if (!(other instanceof Generator))
- return false;
- return _seq.equals(((Generator) other)._seq);
- }
+ public void allocate(int additional);
}
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java Wed Sep 6 09:35:03 2006
@@ -79,7 +79,7 @@
OpenJPAEntityManagerFactory emf = (OpenJPAEntityManagerFactory)
factory.getUserObject(EMF_KEY);
if (emf == null) {
- emf = new EntityManagerFactoryImpl(factory);
+ emf = newEntityManagerFactory(factory);
factory.putUserObject(EMF_KEY, emf);
}
return emf;
@@ -90,6 +90,10 @@
}
}
+ protected static OpenJPAEntityManagerFactory newEntityManagerFactory(BrokerFactory factory) {
+ return new EntityManagerFactoryImpl(factory);
+ }
+
/**
* Return the underlying broker factory for the given persistence manager
* factory facade.
@@ -125,6 +129,8 @@
broker.unlock();
}
}
+
+
/**
* Return the underlying broker for the given entity manager facade.
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java Wed Sep 6 09:35:03 2006
@@ -17,6 +17,7 @@
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
+import java.lang.reflect.Method;
import java.security.ProtectionDomain;
import java.util.Map;
import java.util.Properties;
@@ -31,6 +32,8 @@
import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.enhance.PCClassFileTransformer;
import org.apache.openjpa.kernel.Bootstrap;
+import org.apache.openjpa.kernel.BrokerFactory;
+import org.apache.openjpa.lib.conf.ConfigurationProvider;
import org.apache.openjpa.lib.conf.Configurations;
import org.apache.openjpa.meta.MetaDataModes;
import org.apache.openjpa.meta.MetaDataRepository;
@@ -43,7 +46,7 @@
* @see Persistence#createEntityManagerFactory(String,Map)
*/
public class PersistenceProviderImpl
- implements PersistenceProvider {
+ implements PersistenceProvider, PersistenceProviderExtension {
static final String CLASS_TRANSFORMER_OPTIONS =
"openjpa.ClassTransformerOptions";
@@ -60,13 +63,13 @@
*/
public EntityManagerFactory createEntityManagerFactory(String name,
String resource, Map m) {
- ConfigurationProviderImpl cp = new ConfigurationProviderImpl();
+ ConfigurationProviderImpl cp = newConfigurationProviderImpl();
try {
if (cp.load(resource, name, m))
- return OpenJPAPersistence.toEntityManagerFactory(
- Bootstrap.newBrokerFactory(cp, cp.getClassLoader()));
+ return toEntityManagerFactory(
+ Bootstrap.newBrokerFactory(cp, cp.getClassLoader()));
else
- return null;
+ return null;
} catch (Exception e) {
throw PersistenceExceptions.toPersistenceException(e);
}
@@ -78,11 +81,10 @@
public EntityManagerFactory createContainerEntityManagerFactory(
PersistenceUnitInfo pui, Map map) {
- ConfigurationProviderImpl cp = new ConfigurationProviderImpl();
+ ConfigurationProviderImpl cp = newConfigurationProviderImpl();
try {
if (cp.load(pui, map)) {
- OpenJPAEntityManagerFactory emf =
- OpenJPAPersistence.toEntityManagerFactory(
+ OpenJPAEntityManagerFactory emf = toEntityManagerFactory(
Bootstrap.newBrokerFactory(cp, cp.getClassLoader()));
Properties p = pui.getProperties();
String ctOpts = null;
@@ -98,7 +100,15 @@
throw PersistenceExceptions.toPersistenceException(e);
}
}
-
+
+ public ConfigurationProviderImpl newConfigurationProviderImpl() {
+ return new ConfigurationProviderImpl();
+ }
+
+ public OpenJPAEntityManagerFactory toEntityManagerFactory(BrokerFactory factory) {
+ return OpenJPAPersistence.toEntityManagerFactory(factory);
+ }
+
/**
* Java EE 5 class transformer.
*/
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryResultCache.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryResultCache.java?view=diff&rev=440775&r1=440774&r2=440775
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryResultCache.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryResultCache.java Wed Sep 6 09:35:03 2006
@@ -27,88 +27,38 @@
* Query result cache.
*
* @author Abe White
- * @since 0.4.0
+ * @since 0.4.1
* @published
*/
-public class QueryResultCache {
-
- private final DelegatingQueryCache _cache;
-
- /**
- * Constructor; supply delegate.
- */
- public QueryResultCache(QueryCache cache) {
- _cache = new DelegatingQueryCache(cache,
- PersistenceExceptions.TRANSLATOR);
- }
+public interface QueryResultCache {
/**
* Delegate.
*/
- public QueryCache getDelegate() {
- return _cache.getDelegate();
- }
+ public QueryCache getDelegate();
/**
* Pin the given query's result to the cache.
*/
- public void pin(Query q) {
- if (_cache.getDelegate() != null)
- _cache.pin(toQueryKey(q));
- }
+ public void pin(Query q);
/**
* Unpin a previously-pinned query result.
*/
- public void unpin(Query q) {
- if (_cache.getDelegate() != null)
- _cache.unpin(toQueryKey(q));
- }
+ public void unpin(Query q);
/**
* Evict a query result from the cache.
*/
- public void evict(Query q) {
- if (_cache.getDelegate() != null)
- _cache.remove(toQueryKey(q));
- }
+ public void evict(Query q);
/**
* Clear the cache.
*/
- public void evictAll() {
- _cache.clear();
- }
+ public void evictAll();
/**
* Evict all result for queries involving the given class.
*/
- public void evictAll(Class cls) {
- _cache.onTypesChanged(new TypesChangedEvent(this,
- Collections.singleton(cls)));
- }
-
- /**
- * Return a cache key for the given query.
- */
- private QueryKey toQueryKey(Query q) {
- QueryImpl impl = (QueryImpl) q;
- if (impl.hasPositionalParameters())
- return QueryKey.newInstance(impl.getDelegate(),
- impl.getPositionalParameters());
- return QueryKey.newInstance(impl.getDelegate(),
- impl.getNamedParameters());
- }
-
- public int hashCode() {
- return _cache.hashCode();
- }
-
- public boolean equals(Object other) {
- if (other == this)
- return true;
- if (!(other instanceof QueryResultCache))
- return false;
- return _cache.equals(((QueryResultCache) other)._cache);
- }
+ public void evictAll(Class cls);
}