cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r813630 - in /cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization: Subgraph.java SubgraphNode.java xstream/PersistentMarshalConverter.java
Date Thu, 10 Sep 2009 22:56:52 GMT
Author: aadamchik
Date: Thu Sep 10 22:56:51 2009
New Revision: 813630

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

cleanup/refactoring

Modified:
    cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/Subgraph.java
    cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/SubgraphNode.java
    cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/xstream/PersistentMarshalConverter.java

Modified: cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/Subgraph.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/Subgraph.java?rev=813630&r1=813629&r2=813630&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/Subgraph.java
(original)
+++ cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/Subgraph.java
Thu Sep 10 22:56:51 2009
@@ -26,7 +26,7 @@
 
 /**
  * Represents a subgraph of the Cayenne-mapped persistent object graph. Used as
- * a model for (de)serialization.
+ * a model for serialization.
  */
 public class Subgraph<T> {
 
@@ -55,7 +55,11 @@
 		return rootNode;
 	}
 
-	public void addPath(String path) {
+	/**
+	 * Adds a subgraph path based on a relationship. On deserialization a new
+	 * object will be created in the database.
+	 */
+	public void addSerializeByValuePath(String path) {
 		StringTokenizer tokens = new StringTokenizer(path, ".");
 
 		SubgraphNode node = rootNode;
@@ -64,20 +68,19 @@
 		}
 	}
 
-	public void addReversePath(String path, Class<?> targetClass,
-			String reverseRelationship) {
-
-		// TODO: implement me
-	}
-
-	public void addReferencePath(String path) {
+	/**
+	 * Adds a subgraph path to a related entity that should be serialized as a
+	 * reference to its ObjectId. Such objects will be matched against the
+	 * existing DB rows, and no new objects will be created for them.
+	 */
+	public void addSerializeByReferencePath(String path) {
 		StringTokenizer tokens = new StringTokenizer(path, ".");
 
 		SubgraphNode node = rootNode;
 		while (tokens.hasMoreTokens()) {
 			String token = tokens.nextToken();
 			node = node.getOrAppendChild(token);
-			node.setReference(!tokens.hasMoreTokens());
+			node.setSerializedByReference(!tokens.hasMoreTokens());
 		}
 	}
 }

Modified: cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/SubgraphNode.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/SubgraphNode.java?rev=813630&r1=813629&r2=813630&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/SubgraphNode.java
(original)
+++ cayenne/sandbox/cayenne-xstream/src/main/java/org/apache/cayenne/serialization/SubgraphNode.java
Thu Sep 10 22:56:51 2009
@@ -41,8 +41,8 @@
 	private ClassDescriptor classDescriptor;
 	private ArcProperty incomingProperty;
 	private Map<String, SubgraphNode> children;
-	private boolean reference;
-	private List<Property> attributeProperties;
+	private boolean serializedByReference;
+	private List<AttributeProperty> attributeProperties;
 
 	/**
 	 * Creates a root subgraph node.
@@ -51,7 +51,7 @@
 		this.classDescriptor = classDescriptor;
 
 		// cache properties
-		this.attributeProperties = new ArrayList<Property>();
+		this.attributeProperties = new ArrayList<AttributeProperty>();
 
 		classDescriptor.visitProperties(new PropertyVisitor() {
 			public boolean visitAttribute(AttributeProperty property) {
@@ -78,20 +78,12 @@
 	 * Returns true if only a reference should be serialized for this node,
 	 * instead of serializing object data.
 	 */
-	public boolean isReference() {
-		return reference;
+	public boolean isSerializedByReference() {
+		return serializedByReference;
 	}
 
-	void setReference(boolean reference) {
-		this.reference = reference;
-	}
-
-	SubgraphNode getChild(String path) {
-		if (children != null) {
-			return children.get(path);
-		} else {
-			return null;
-		}
+	void setSerializedByReference(boolean reference) {
+		this.serializedByReference = reference;
 	}
 
 	SubgraphNode getOrAppendChild(String path) {
@@ -131,10 +123,14 @@
 		return classDescriptor;
 	}
 
-	public List<Property> getAttributeProperties() {
+	public List<AttributeProperty> getAttributeProperties() {
 		return attributeProperties;
 	}
 
+	/**
+	 * Returns a property that connects parent node to this node. It will be
+	 * null for the root node.
+	 */
 	public ArcProperty getIncomingProperty() {
 		return incomingProperty;
 	}

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=813630&r1=813629&r2=813630&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:56:51 2009
@@ -27,6 +27,7 @@
 import org.apache.cayenne.access.ResultIterator;
 import org.apache.cayenne.query.RelationshipQuery;
 import org.apache.cayenne.reflect.ArcProperty;
+import org.apache.cayenne.reflect.AttributeProperty;
 import org.apache.cayenne.reflect.Property;
 import org.apache.cayenne.serialization.Subgraph;
 import org.apache.cayenne.serialization.SubgraphNode;
@@ -59,7 +60,7 @@
 
 		SubgraphNode node = serializerContext.peekNode();
 
-		for (Property property : node.getAttributeProperties()) {
+		for (AttributeProperty property : node.getAttributeProperties()) {
 			marshalAttribute(object, property, writer, context);
 		}
 
@@ -69,7 +70,7 @@
 			serializerContext.pushNode(child);
 
 			ArcProperty incoming = child.getIncomingProperty();
-			if (child.isReference()) {
+			if (child.isSerializedByReference()) {
 				if (incoming.getRelationship().isToMany()) {
 					marshalToManyReference(object, incoming, writer, context);
 				} else {



Mime
View raw message