arminw 2005/06/15 12:31:57
Modified: src/java/org/apache/ojb/broker/core Tag: OJB_1_0_RELEASE
PersistenceBrokerAbstractImpl.java
PersistenceBrokerImpl.java
src/test/org/apache/ojb Tag: OJB_1_0_RELEASE OJB.properties
Log:
make check for running PB-tx on store/delete persistent objects configurable
via OJB.properties file, because in managed environments without caching it's
allowed to use OJB without PB-tx demarcation
Revision Changes Path
No revision
No revision
1.6.2.2 +33 -4
db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerAbstractImpl.java
Index: PersistenceBrokerAbstractImpl.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerAbstractImpl.java,v
retrieving revision 1.6.2.1
retrieving revision 1.6.2.2
diff -u -r1.6.2.1 -r1.6.2.2
--- PersistenceBrokerAbstractImpl.java 7 May 2005 16:51:09 -0000
1.6.2.1
+++ PersistenceBrokerAbstractImpl.java 15 Jun 2005 19:31:57 -0000
1.6.2.2
@@ -20,13 +20,12 @@
import org.apache.ojb.broker.PBListener;
import org.apache.ojb.broker.PBStateEvent;
import org.apache.ojb.broker.PBStateListener;
-import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.PersistenceBrokerEvent;
import org.apache.ojb.broker.PersistenceBrokerException;
import org.apache.ojb.broker.PersistenceBrokerInternal;
-import org.apache.ojb.broker.util.logging.LoggerFactory;
import org.apache.ojb.broker.util.configuration.Configuration;
import org.apache.ojb.broker.util.configuration.ConfigurationException;
+import org.apache.ojb.broker.util.logging.LoggerFactory;
/**
* Abstract Implementation of the [EMAIL PROTECTED]
org.apache.ojb.broker.PersistenceBroker}
@@ -46,6 +45,8 @@
private static final PBStateListener[] NO_STATE_LISTENERS = new
PBStateListener[0];
private static final PBLifeCycleListener[] NO_LIFECYCLE_LISTENERS = new
PBLifeCycleListener[0];
+ private boolean txCheck;
+
/**
* Array containing all permanent [EMAIL PROTECTED]
org.apache.ojb.broker.PBStateListener}
* instances.
@@ -77,7 +78,35 @@
*/
public void configure(Configuration pConfig) throws
ConfigurationException
{
- // noop
+ txCheck = pConfig.getBoolean("TxCheck", false);
+ }
+
+ /**
+ * Returns <em>true</em> if the development checks are enabled.
+ *
+ * @see #setTxCheck(boolean)
+ */
+ public boolean isTxCheck()
+ {
+ return txCheck;
+ }
+
+ /**
+ * This setting can be helpful during development if the
PersistenceBroker transaction
+ * demarcation was used (this is true in most cases). If set 'true' on
PB#store(...)
+ * and PB#delete(...) methods calls OJB check for active PB-tx and if no
active tx is
+ * found a error is logged. This can help to avoid store/delete calls
without a running
+ * PB-tx while development. Default setting is 'false'.
+ * <p/>
+ * <strong>Note:</strong> When using OJB in a managed
+ * environment <em>without</em> OJB-caching, it's valid to use
store/delete
+ * calls without a running PB-tx.
+ *
+ * @param txCheck Set <em>true</em> to enable the checks
+ */
+ public void setTxCheck(boolean txCheck)
+ {
+ this.txCheck = txCheck;
}
/**
1.83.2.23 +10 -23
db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
Index: PersistenceBrokerImpl.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
retrieving revision 1.83.2.22
retrieving revision 1.83.2.23
diff -u -r1.83.2.22 -r1.83.2.23
--- PersistenceBrokerImpl.java 4 Jun 2005 14:28:23 -0000
1.83.2.22
+++ PersistenceBrokerImpl.java 15 Jun 2005 19:31:57 -0000
1.83.2.23
@@ -482,29 +482,21 @@
*/
public void delete(Object obj, boolean ignoreReferences) throws
PersistenceBrokerException
{
- if(!isInTransaction())
+ if(isTxCheck() && !isInTransaction())
{
- String msg = "No running PB-tx found. Please, delete objects in
context of an PB-transaction" +
- " to avoid side-effects - e.g. when rollback of complex
objects.";
- if(logger.isEnabledFor(Logger.INFO))
+ if(logger.isEnabledFor(Logger.ERROR))
{
+ String msg = "No running PB-tx found. Please, only delete
objects in context of a PB-transaction" +
+ " to avoid side-effects - e.g. when rollback of complex
objects.";
try
{
- /*
- arminw:
- this could help user to find missing tx declaration in
stack trace
- */
throw new Exception("** Delete object without active
PersistenceBroker transaction **");
}
catch(Exception e)
{
- logger.info(msg, e);
+ logger.error(msg, e);
}
}
- else
- {
- logger.warn(msg + " Enable log-level INFO to get more
detailed message (stack trace).");
- }
}
try
{
@@ -843,15 +835,9 @@
//************************************************
// now store it:
- if(!isInTransaction())
+ if(isTxCheck() && !isInTransaction())
{
- logger.warn("No running tx found, please only store in context
of an PB-transaction" +
- ", to avoid side-effects - e.g. when rollback of complex
objects");
- /*
- arminw:
- this could help user to find missing tx declaration
- */
- if(logger.isEnabledFor(Logger.INFO))
+ if(logger.isEnabledFor(Logger.ERROR))
{
try
{
@@ -859,7 +845,8 @@
}
catch(Exception e)
{
- e.printStackTrace();
+ logger.error("No running tx found, please only store in
context of an PB-transaction" +
+ ", to avoid side-effects - e.g. when rollback of complex
objects", e);
}
}
}
No revision
No revision
1.75.2.10 +10 -1 db-ojb/src/test/org/apache/ojb/OJB.properties
Index: OJB.properties
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/OJB.properties,v
retrieving revision 1.75.2.9
retrieving revision 1.75.2.10
diff -u -r1.75.2.9 -r1.75.2.10
--- OJB.properties 8 Jun 2005 23:31:40 -0000 1.75.2.9
+++ OJB.properties 15 Jun 2005 19:31:57 -0000 1.75.2.10
@@ -63,6 +63,15 @@
# Using this implementation OJB works as a simple OODBMS
#PersistenceBrokerClass=org.apache.ojb.broker.prevayler.PBPrevaylerImpl
#
+#
+# This setting can be helpful during development if the PersistenceBroker
transaction
+# demarcation was used (this is true in most cases). If set 'true' on
PB#store(...)
+# and PB#delete(...) methods calls OJB check for active PB-tx and if no
active tx is
+# found a error is logged. This can help to avoid store/delete calls without
a running
+# PB-tx while development. Default setting is 'false'. (Note: When using OJB
in a managed
+# environment *without* OJB-caching, it's valid to use store/delete calls
without a running PB-tx)
+TxCheck=false
+#
#----------------------------------------------------------------------------------------
# PersistenceBroker pool
#----------------------------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]