cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r814869 - in /cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization: BaseDeserializer.java SubgraphNode.java xstream/PersistentCloneUnmarshalConverter.java xstream/XStreamDeserializer.java
Date Mon, 14 Sep 2009 21:34:45 GMT
Author: aadamchik
Date: Mon Sep 14 21:34:44 2009
New Revision: 814869

URL: http://svn.apache.org/viewvc?rev=814869&view=rev
Log:
prototyping (de)serializer based on XStream

Modified:
    cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/BaseDeserializer.java
    cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/SubgraphNode.java
    cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/xstream/PersistentCloneUnmarshalConverter.java
    cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/xstream/XStreamDeserializer.java

Modified: cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/BaseDeserializer.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/BaseDeserializer.java?rev=814869&r1=814868&r2=814869&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/BaseDeserializer.java
(original)
+++ cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/BaseDeserializer.java
Mon Sep 14 21:34:44 2009
@@ -29,10 +29,16 @@
 public abstract class BaseDeserializer implements SubgraphDeserializer {
 
 	protected int commitCountThreshold = 1000;
+	protected boolean committing = true;
 
 	public abstract <T> T deserialize(ObjectContext context,
 			Subgraph<T> subgraph, InputStream in);
 
+	/**
+	 * Returns the max size of the commit batch. This is needed to constrain
+	 * memory use. The default is 1000 objects. Note that setting "committing"
+	 * flag to false would cause deserializer to ignore this setting.
+	 */
 	public int getCommitCountThreshold() {
 		return commitCountThreshold;
 	}
@@ -40,4 +46,16 @@
 	public void setCommitCountThreshold(int commitCountThreshold) {
 		this.commitCountThreshold = commitCountThreshold;
 	}
+
+	/**
+	 * Returns true if deserializer will commit deserialized objects. True is
+	 * the default.
+	 */
+	public boolean isCommitting() {
+		return committing;
+	}
+
+	public void setCommitting(boolean committing) {
+		this.committing = committing;
+	}
 }

Modified: cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/SubgraphNode.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/SubgraphNode.java?rev=814869&r1=814868&r2=814869&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/SubgraphNode.java
(original)
+++ cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/SubgraphNode.java
Mon Sep 14 21:34:44 2009
@@ -70,8 +70,8 @@
 	}
 
 	SubgraphNode(ArcProperty incomingProperty) {
+		this(incomingProperty.getTargetDescriptor());
 		this.incomingProperty = incomingProperty;
-		this.classDescriptor = incomingProperty.getTargetDescriptor();
 	}
 
 	/**

Modified: cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/xstream/PersistentCloneUnmarshalConverter.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/xstream/PersistentCloneUnmarshalConverter.java?rev=814869&r1=814868&r2=814869&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/xstream/PersistentCloneUnmarshalConverter.java
(original)
+++ cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/xstream/PersistentCloneUnmarshalConverter.java
Mon Sep 14 21:34:44 2009
@@ -69,6 +69,8 @@
 				.getClassDescriptor(entityName);
 
 		final Object object = descriptor.createObject();
+		
+		objectContext.registerNewObject(object);
 
 		DeserializerCounter deserializerCounter = getDeserialierCounter(context);
 

Modified: cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/xstream/XStreamDeserializer.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/xstream/XStreamDeserializer.java?rev=814869&r1=814868&r2=814869&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/xstream/XStreamDeserializer.java
(original)
+++ cayenne/sandbox/cayenne-serialization/src/main/java/org/apache/cayenne/serialization/xstream/XStreamDeserializer.java
Mon Sep 14 21:34:44 2009
@@ -37,10 +37,19 @@
 		XStream xstream = XStreamUtil.defaultXStream(subgraph.getRootNode()
 				.getClassDescriptor());
 
+		int commitCountThreshold = isCommitting() ? getCommitCountThreshold()
+				: 0;
+
 		xstream.registerConverter(new PersistentCloneUnmarshalConverter(
 				context, commitCountThreshold));
 
-		return (T) xstream.fromXML(in);
+		T object = (T) xstream.fromXML(in);
+
+		if (isCommitting()) {
+			context.commitChanges();
+		}
+
+		return object;
 	}
 
 }



Mime
View raw message