cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r813625 - in /cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization: BaseSerializer.java xstream/PersistentMarshalConverter.java xstream/XStreamSerializer.java
Date Thu, 10 Sep 2009 22:44:08 GMT
Author: aadamchik
Date: Thu Sep 10 22:44:07 2009
New Revision: 813625

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

parameterizing fetch size

Added:
    cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/BaseSerializer.java
Modified:
    cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/xstream/PersistentMarshalConverter.java
    cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/xstream/XStreamSerializer.java

Added: cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/BaseSerializer.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/BaseSerializer.java?rev=813625&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/BaseSerializer.java
(added)
+++ cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/BaseSerializer.java
Thu Sep 10 22:44:07 2009
@@ -0,0 +1,28 @@
+package org.apache.cayenne.serialization;
+
+import java.io.OutputStream;
+
+public abstract class BaseSerializer implements SubgraphSerializer {
+
+	protected int statementFetchSize;
+
+	public abstract <T> void serialize(T object, Subgraph<T> subgraph,
+			OutputStream out);
+
+	public int getStatementFetchSize() {
+		return statementFetchSize;
+	}
+
+	/**
+	 * Sets a JDBC Statement "fetch size", which is a critical hint for
+	 * serializing large datasets.
+	 * <p>
+	 * MySQL Note: per <a href="http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-implementation-notes.html"
+	 * >MySQL docs</a> to enable streaming fetch size must be equal to
+	 * Integer.MIN_VALUE. For other databases it should be a non-negative number
+	 * per JDBC standard.
+	 */
+	public void setStatementFetchSize(int statementFetchSize) {
+		this.statementFetchSize = statementFetchSize;
+	}
+}

Modified: cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/xstream/PersistentMarshalConverter.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/xstream/PersistentMarshalConverter.java?rev=813625&r1=813624&r2=813625&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/xstream/PersistentMarshalConverter.java
(original)
+++ cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/xstream/PersistentMarshalConverter.java
Thu Sep 10 22:44:07 2009
@@ -44,9 +44,12 @@
 			+ "_TRAVERSAL_CONTEXT";
 
 	private Subgraph<T> subgraph;
+	private int statementFetchSize;
 
-	public PersistentMarshalConverter(Subgraph<T> subgraph) {
+	public PersistentMarshalConverter(Subgraph<T> subgraph,
+			int statementFetchSize) {
 		this.subgraph = subgraph;
+		this.statementFetchSize = statementFetchSize;
 	}
 
 	public void marshal(Object object, HierarchicalStreamWriter writer,
@@ -142,14 +145,9 @@
 		RelationshipQuery query = new RelationshipQuery(persistent
 				.getObjectId(), arc.getName());
 
-		// "fetchSize" is absolutely critical on MySQL and probably other DB's
-		// to avoid storing the entire ResultSet in memory.
-
-		// TODO: caveat: a negative number is for MySQL per
-		// http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-implementation-notes.html
-		// For other DB's this hint may also be needed, but it should be a non
-		// negative number
-		query.setStatementFetchSize(Integer.MIN_VALUE);
+		// "fetchSize" is absolutely critical to avoid storing the entire
+		// ResultSet in memory.
+		query.setStatementFetchSize(statementFetchSize);
 
 		DataContext dataContext = (DataContext) persistent.getObjectContext();
 

Modified: cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/xstream/XStreamSerializer.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/xstream/XStreamSerializer.java?rev=813625&r1=813624&r2=813625&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/xstream/XStreamSerializer.java
(original)
+++ cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/xstream/XStreamSerializer.java
Thu Sep 10 22:44:07 2009
@@ -20,13 +20,14 @@
 
 import java.io.OutputStream;
 
+import org.apache.cayenne.serialization.BaseSerializer;
 import org.apache.cayenne.serialization.Subgraph;
-import org.apache.cayenne.serialization.SubgraphSerializer;
 
 import com.thoughtworks.xstream.XStream;
 
-public class XStreamSerializer implements SubgraphSerializer {
+public class XStreamSerializer extends BaseSerializer {
 
+	@Override
 	public <T> void serialize(T object, Subgraph<T> subgraph, OutputStream out)
{
 
 		// TODO: make sure all the converters are stateless... then we can cache
@@ -34,7 +35,8 @@
 		XStream xstream = XStreamUtil.defaultXStream(subgraph.getRootNode()
 				.getClassDescriptor());
 
-		xstream.registerConverter(new PersistentMarshalConverter<T>(subgraph));
+		xstream.registerConverter(new PersistentMarshalConverter<T>(subgraph,
+				statementFetchSize));
 		xstream.registerConverter(new ObjectIdMarshalConverter());
 
 		xstream.toXML(object, out);



Mime
View raw message