fixes for OPENJPA-102 and OPENJPA-104

git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@497185 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Patrick Linskey 2007-01-17 21:40:37 +00:00
parent d58ba3b25b
commit c7128669c7
5 changed files with 21 additions and 3 deletions

View File

@ -30,11 +30,13 @@ class AutoDetachValue
public static final String DETACH_CLOSE = "close";
public static final String DETACH_COMMIT = "commit";
public static final String DETACH_ROLLBACK= "rollback";
public static final String DETACH_NONTXREAD = "nontx-read";
private static String[] ALIASES = new String[]{
DETACH_CLOSE, String.valueOf(AutoDetach.DETACH_CLOSE),
DETACH_COMMIT, String.valueOf(AutoDetach.DETACH_COMMIT),
DETACH_ROLLBACK, String.valueOf(AutoDetach.DETACH_ROLLBACK),
DETACH_NONTXREAD, String.valueOf(AutoDetach.DETACH_NONTXREAD),
// for compatibility with JDO DetachAllOnCommit
"true", String.valueOf(AutoDetach.DETACH_COMMIT),

View File

@ -35,4 +35,9 @@ public interface AutoDetach {
* nontransactional operation uses a new persistence context in essence.
*/
public static final int DETACH_NONTXREAD = 2 << 2;
/**
* Detach context on failed transaction commit / rollback.
*/
public static final int DETACH_ROLLBACK = 2 << 3;
}

View File

@ -1710,7 +1710,7 @@ public class BrokerImpl
/**
* Mark the operation over. If outermost caller of stack, returns true
* and will detach manageed instances if necessary.
* and will detach managed instances if necessary.
*/
public boolean endOperation() {
try {
@ -1779,6 +1779,10 @@ public class BrokerImpl
if ((_autoDetach & DETACH_COMMIT) != 0)
detachAllInternal(null);
else if (status == Status.STATUS_ROLLEDBACK
&& (_autoDetach & DETACH_ROLLBACK) != 0) {
detachAllInternal(null);
}
// in an ee context, it's possible that the user tried to close
// us but we didn't actually close because we were waiting on this

View File

@ -40,6 +40,7 @@ import org.apache.openjpa.meta.ClassMetaData;
import org.apache.openjpa.meta.FieldMetaData;
import org.apache.openjpa.meta.JavaTypes;
import org.apache.openjpa.util.CallbackException;
import org.apache.openjpa.util.ObjectNotFoundException;
import org.apache.openjpa.util.Proxy;
import org.apache.openjpa.util.ProxyManager;
import org.apache.openjpa.util.UserException;
@ -148,7 +149,12 @@ public class DetachManager
exclude = StoreContext.EXCLUDE_ALL;
else if (detachMode == DETACH_ALL)
loadMode = StateManagerImpl.LOAD_ALL;
sm.load(broker.getFetchConfiguration(), loadMode, exclude, null, false);
try {
sm.load(broker.getFetchConfiguration(), loadMode, exclude, null,
false);
} catch (ObjectNotFoundException onfe) {
// consume the exception
}
// create bitset of fields to detach; if mode is all we can use
// currently loaded bitset clone, since we know all fields are loaded

View File

@ -188,7 +188,8 @@ public class EntityManagerFactoryImpl
false);
// we should allow the user to specify these settings in conf
// regardless of PersistenceContextType
broker.setAutoDetach(AutoDetach.DETACH_CLOSE);
broker.setAutoDetach(AutoDetach.DETACH_CLOSE
| AutoDetach.DETACH_ROLLBACK);
broker.setDetachedNew(false);
OpenJPAEntityManager em = newEntityManagerImpl(broker);