openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r1383727 - in /openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel: AuditManager.java Audited.java
Date Wed, 12 Sep 2012 01:23:32 GMT
Author: ppoddar
Date: Wed Sep 12 01:23:32 2012
New Revision: 1383727

URL: http://svn.apache.org/viewvc?rev=1383727&view=rev
Log:
OPENJPA-2253: Clear temporary storage for audit to prevent memory leak

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AuditManager.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Audited.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AuditManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AuditManager.java?rev=1383727&r1=1383726&r2=1383727&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AuditManager.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AuditManager.java
Wed Sep 12 01:23:32 2012
@@ -43,7 +43,7 @@ import org.apache.openjpa.event.Transact
 /**
  * Controller for audit facility.
  * This controller performs the following basic duties:
- * <LI> Records auditable types at class laoding time
+ * <LI> Records auditable types at class loading time
  * <LI> Listens to instance life cycle changes and transaction.
  * <LI> Collects auditable instances on instance life cycle changes.
  * <LI> Delegates real auditing to the {@link Auditor} at transaction boundary.
@@ -143,24 +143,32 @@ public class AuditManager extends InMemo
 		}
 	}
 	
+	private void forget(Broker broker) {
+		AuditCallback cb = _saved.remove(broker);
+		if (cb != null) {
+			broker.removeLifecycleListener(cb);
+			cb.clear();
+		}
+	}
+	
 	@Override
 	public void afterCommit(TransactionEvent event) {
-		_saved.remove(event.getSource());
+		forget((Broker)event.getSource());
 	}
 
 	@Override
 	public void afterRollback(TransactionEvent event) {
-		_saved.remove(event.getSource());
+		forget((Broker)event.getSource());
 	}
 
 	@Override
 	public void afterCommitComplete(TransactionEvent event) {
-		_saved.remove(event.getSource());
+		forget((Broker)event.getSource());
 	}
 
 	@Override
 	public void afterRollbackComplete(TransactionEvent event) {
-		_saved.remove(event.getSource());
+		forget((Broker)event.getSource());
 	}
 	
 	@Override
@@ -294,6 +302,10 @@ public class AuditManager extends InMemo
 			}
 		}
 		
+		void clear() {
+			_audits.clear();
+		}
+		
 		/**
 		 * Life-cycle callbacks 
 		 */

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Audited.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Audited.java?rev=1383727&r1=1383726&r2=1383727&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Audited.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Audited.java Wed
Sep 12 01:23:32 2012
@@ -22,6 +22,8 @@ import java.util.BitSet;
 
 import org.apache.openjpa.audit.AuditableOperation;
 import org.apache.openjpa.enhance.PersistenceCapable;
+import org.apache.openjpa.enhance.Reflection;
+import org.apache.openjpa.meta.FieldMetaData;
 
 /**
  * Carries immutable information about an audited persistent instance.
@@ -73,12 +75,42 @@ public final class Audited {
 		String[] names = new String[dirty.cardinality()];
 		int j = 0;
 		for (int pos = dirty.nextSetBit(0); pos != -1; pos = dirty.nextSetBit(pos+1)) {
-			names[j++] = _sm.getMetaData().getField(pos).getName();
+			names[j++] = _sm.getMetaData().getField(pos).getName();		
 		}
 		return names;
 	}
 	
 	/**
+	 * Gets the value of the given field of the managed object.
+	 * 
+	 * @param field name of a persistent property
+	 * @return value of the given field in the managed instance
+	 * @exception IllegalArgumentException if the named field is not a persistent property 
+	 */
+	public Object getManangedFieldValue(String field) {
+		FieldMetaData fmd = _sm.getMetaData().getField(field);
+		if (fmd == null) {
+			throw new IllegalArgumentException(field + " does not exist in " + _original);
+		}
+		return _sm.fetch(fmd.getIndex());
+	}
+	
+	/**
+	 * Gets the value of the given field of the original state of the object.
+	 * 
+	 * @param field name of a persistent property
+	 * @return value of the given field in the original instance
+	 * @exception IllegalArgumentException if the named field is not a persistent property 
+	 */
+	public Object getOriginalFieldValue(String field) {
+		try {
+			return Reflection.getValue(_original, field, true);
+		} catch (Exception e) {
+			throw new IllegalArgumentException(field + " does not exist in " + _original);
+		}
+	}
+	
+	/**
 	 * Gets the type of this audit.
 	 */
 	public AuditableOperation getType() {



Mime
View raw message