diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java b/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java index 784680e7b..62717e593 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java @@ -20,8 +20,8 @@ import java.util.BitSet; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.ListIterator; import java.util.Map; @@ -510,13 +510,17 @@ public class DataCacheStoreManager for (Iterator itr = states.iterator(); itr.hasNext();) { sm = (OpenJPAStateManager) itr.next(); - if (sm.getPCState() == PCState.PNEW) { + if (sm.getPCState() == PCState.PNEW && !sm.isFlushed()) { if (_inserts == null) - _inserts = new LinkedList(); + _inserts = new ArrayList(); _inserts.add(sm); - } else if (_inserts != null && - (sm.getPCState() == PCState.PNEWDELETED || - sm.getPCState() == PCState.PNEWFLUSHEDDELETED)) + + // may have been re-persisted + if (_deletes != null) + _deletes.remove(sm); + } else if (_inserts != null + && (sm.getPCState() == PCState.PNEWDELETED + || sm.getPCState() == PCState.PNEWFLUSHEDDELETED)) _inserts.remove(sm); else if (sm.getPCState() == PCState.PDIRTY) { if (_updates == null) @@ -524,7 +528,7 @@ public class DataCacheStoreManager _updates.put(sm, sm.getDirty()); } else if (sm.getPCState() == PCState.PDELETED) { if (_deletes == null) - _deletes = new LinkedList(); + _deletes = new HashSet(); _deletes.add(sm); } } @@ -572,10 +576,10 @@ public class DataCacheStoreManager */ private static class Modifications { - public final List additions = new LinkedList(); - public final List newUpdates = new LinkedList(); - public final List existingUpdates = new LinkedList(); - public final List deletes = new LinkedList(); + public final List additions = new ArrayList(); + public final List newUpdates = new ArrayList(); + public final List existingUpdates = new ArrayList(); + public final List deletes = new ArrayList(); } private static class PCDataHolder { diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java index f4944aff5..786fce496 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java @@ -259,20 +259,17 @@ public class DetachManager * Return a detached version of the given instance. */ public Object detach(Object toDetach) { - CallbackException excep = null; + List exceps = null; try { return detachInternal(toDetach); } catch (CallbackException ce) { - excep = ce; + exceps = new ArrayList(1); + exceps.add(ce); return null; // won't be reached as exception will be rethrown } finally { - List exceps = null; - - if (excep == null || !_failFast) { + if (exceps == null || !_failFast) exceps = invokeAfterDetach(Collections.singleton(toDetach), - null); - } else - exceps = Collections.singletonList(excep); + exceps); if (_detached != null) _detached.clear(); throwExceptions(exceps); @@ -303,11 +300,8 @@ public class DetachManager failFast = true; exceps = add(exceps, re); } finally { - // invoke post callbacks unless all failed - if (!failFast && (exceps == null - || exceps.size() < instances.size())) { + if (!failFast) exceps = invokeAfterDetach(instances, exceps); - } if (_detached != null) _detached.clear(); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java index 46c853a18..a57670380 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java @@ -76,8 +76,8 @@ class SingleFieldManager if (proxy == null) { proxy = (Proxy) _sm.newFieldProxy(field); ((Date) proxy).setTime(((Date) objval).getTime()); - if (proxy instanceof Timestamp && - objval instanceof Timestamp) + if (proxy instanceof Timestamp + && objval instanceof Timestamp) ((Timestamp) proxy).setNanos(((Timestamp) objval). getNanos()); ret = true; @@ -89,12 +89,7 @@ class SingleFieldManager proxy = checkProxy(); if (proxy == null) { proxy = (Proxy) _sm.newFieldProxy(field); - if (objval != null) { - Calendar pcal = (Calendar) proxy; - Calendar ocal = (Calendar) objval; - pcal.setTime(ocal.getTime()); - pcal.setTimeZone(ocal.getTimeZone()); - } + ((Calendar) proxy).setTime(((Calendar) objval).getTime()); ret = true; } break; diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/package.html b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/package.html new file mode 100644 index 000000000..9504c1d84 --- /dev/null +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/package.html @@ -0,0 +1,9 @@ + +
+JPA Query Language Support
+ ++ Allow any spec or store to use JPQL. +
+ + diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java index 4ab3b9c37..14dd20671 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java @@ -40,6 +40,7 @@ public abstract class AbstractMetaDataDefaults (AbstractMetaDataDefaults.class); private int _access = ClassMetaData.ACCESS_FIELD; + private int _identity = ClassMetaData.ID_UNKNOWN; private boolean _ignore = true; private boolean _interface = true; private boolean _pcRegistry = true; @@ -63,18 +64,34 @@ public abstract class AbstractMetaDataDefaults /** * The default access type for base classes with ACCESS_UNKNOWN. - * Returns ACCESS_FIELD by default. + * ACCESS_FIELD by default. + */ + public int getDefaultAccessType() { + return _access; + } + + /** + * The default access type for base classes with ACCESS_UNKNOWN. + * ACCESS_FIELD by default. */ public void setDefaultAccessType(int access) { _access = access; } /** - * The default access type for base classes with ACCESS_UNKNOWN. - * Returns ACCESS_FIELD by default. + * The default identity type for unmapped classes without primary + * key fields. ID_UNKNOWN by default. */ - public int getDefaultAccessType() { - return _access; + public int getDefaultIdentityType() { + return _identity; + } + + /** + * The default identity type for unmapped classes without primary + * key fields. ID_UNKNOWN by default. + */ + public void setDefaultIdentityType(int identity) { + _identity = identity; } public int getCallbackMode() { diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java index 86a4a348d..1d16e8d39 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java @@ -379,12 +379,13 @@ public class ClassMetaData ClassMetaData sup = getPCSuperclassMetaData(); if (sup != null && sup.getIdentityType() != ID_UNKNOWN) _identity = sup.getIdentityType(); - else { - if (getPrimaryKeyFields().length > 0) - _identity = ID_APPLICATION; - else - _identity = (isMapped()) ? ID_DATASTORE : ID_UNKNOWN; - } + else if (getPrimaryKeyFields().length > 0) + _identity = ID_APPLICATION; + else if (isMapped()) + _identity = ID_DATASTORE; + else + _identity = _repos.getMetaDataFactory().getDefaults(). + getDefaultIdentityType(); } return _identity; } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java index 63564dac9..e6eb92e6a 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java @@ -28,11 +28,17 @@ public interface MetaDataDefaults extends CallbackModes { /** - * Return the default access type for base persistent class with + * Return the default access type for a base persistent class with * {@link ClassMetaData#ACCESS_UNKNOWN} access type. */ public int getDefaultAccessType(); + /** + * Return the default identity type for unmapped classes without primary + * key fields. + */ + public int getDefaultIdentityType(); + /** * What to do on lifecycle callback exceptions. */ diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java index ae7c325df..d22e99704 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java @@ -1377,8 +1377,6 @@ public class MetaDataRepository * 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) { @@ -1386,6 +1384,10 @@ public class MetaDataRepository updateImpls(cls, leastDerived, sup); } + // allow users to query on any implemented interfaces unless defaults + // say the user must create persistent interfaces explicitly + if (!_factory.getDefaults().isDeclaredInterfacePersistent()) + return; Class[] ints = check.getInterfaces(); for (int i = 0; i < ints.length; i++) { // don't map java-standard interfaces diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java index 0ec15ffd5..2524f312a 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java @@ -93,6 +93,10 @@ public class NoneMetaDataFactory return ClassMetaData.ACCESS_UNKNOWN; } + public int getDefaultIdentityType() { + return ClassMetaData.ID_UNKNOWN; + } + public int getCallbackMode() { return CALLBACK_IGNORE; }