cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [2/2] cayenne git commit: CAY-2030 Capturing a stream of commit changes
Date Mon, 12 Oct 2015 18:44:59 GMT
CAY-2030 Capturing a stream of commit changes

API usability improvements


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/e00a641b
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/e00a641b
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/e00a641b

Branch: refs/heads/master
Commit: e00a641b82013dad61c3a01a7a868792166eac2a
Parents: 58c7c3b
Author: Andrus Adamchik <andrus@objectstyle.com>
Authored: Mon Oct 12 13:06:40 2015 -0400
Committer: aadamchik <aadamchik@apache.org>
Committed: Mon Oct 12 14:42:25 2015 -0400

----------------------------------------------------------------------
 .../lifecycle/changemap/AttributeChange.java    |  2 +-
 .../changemap/MutableAttributeChange.java       |  5 ++++
 .../changemap/MutableObjectChange.java          | 21 ++++++++++++-
 .../MutableToManyRelationshipChange.java        |  5 ++++
 .../MutableToOneRelationshipChange.java         |  5 ++++
 .../lifecycle/changemap/ObjectChange.java       |  2 ++
 .../lifecycle/changemap/PropertyChange.java     | 29 ++++++++++++++++++
 .../changemap/PropertyChangeVisitor.java        | 31 ++++++++++++++++++++
 .../changemap/ToManyRelationshipChange.java     |  2 +-
 .../changemap/ToOneRelationshipChange.java      |  2 +-
 10 files changed, 100 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/e00a641b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/AttributeChange.java
----------------------------------------------------------------------
diff --git a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/AttributeChange.java
b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/AttributeChange.java
index bdb9cb6..c70786c 100644
--- a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/AttributeChange.java
+++ b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/AttributeChange.java
@@ -24,7 +24,7 @@ package org.apache.cayenne.lifecycle.changemap;
  * 
  * @since 4.0
  */
-public interface AttributeChange {
+public interface AttributeChange extends PropertyChange {
 
 	Object getOldValue();
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e00a641b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableAttributeChange.java
----------------------------------------------------------------------
diff --git a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableAttributeChange.java
b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableAttributeChange.java
index 4d4ebbf..5dcb17a 100644
--- a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableAttributeChange.java
+++ b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableAttributeChange.java
@@ -26,6 +26,11 @@ public class MutableAttributeChange implements AttributeChange {
 	private Object oldValue;
 	private Object newValue;
 
+	@Override
+	public void accept(PropertyChangeVisitor visitor) {
+		visitor.visitAttribute(this);
+	}
+
 	public void setOldValue(Object oldValue) {
 		this.oldValue = oldValue;
 	}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e00a641b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableObjectChange.java
----------------------------------------------------------------------
diff --git a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableObjectChange.java
b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableObjectChange.java
index 95c81bc..47fa7b2 100644
--- a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableObjectChange.java
+++ b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableObjectChange.java
@@ -58,6 +58,25 @@ public class MutableObjectChange implements ObjectChange {
 	}
 
 	@Override
+	public Map<String, ? extends PropertyChange> getChanges() {
+		Map<String, PropertyChange> allChanges = new HashMap<>();
+
+		if (attributeChanges != null) {
+			allChanges.putAll(attributeChanges);
+		}
+
+		if (toOneRelationshipChanges != null) {
+			allChanges.putAll(toOneRelationshipChanges);
+		}
+
+		if (toManyRelationshipChanges != null) {
+			allChanges.putAll(toManyRelationshipChanges);
+		}
+
+		return allChanges;
+	}
+
+	@Override
 	public Map<String, ? extends AttributeChange> getAttributeChanges() {
 		return attributeChanges != null ? attributeChanges : Collections.<String, AttributeChange>
emptyMap();
 	}
@@ -158,7 +177,7 @@ public class MutableObjectChange implements ObjectChange {
 
 		return pChange;
 	}
-	
+
 	private MutableToManyRelationshipChange getOrCreateToManyChange(String property) {
 		MutableToManyRelationshipChange pChange = toManyRelationshipChanges != null
 				? toManyRelationshipChanges.get(property) : null;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e00a641b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableToManyRelationshipChange.java
----------------------------------------------------------------------
diff --git a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableToManyRelationshipChange.java
b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableToManyRelationshipChange.java
index 215a542..7b5a9cf 100644
--- a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableToManyRelationshipChange.java
+++ b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableToManyRelationshipChange.java
@@ -33,6 +33,11 @@ public class MutableToManyRelationshipChange implements ToManyRelationshipChange
 	private Collection<ObjectId> removed;
 
 	@Override
+	public void accept(PropertyChangeVisitor visitor) {
+		visitor.visitToManyRelationship(this);
+	}
+	
+	@Override
 	public Collection<ObjectId> getAdded() {
 		return added == null ? Collections.<ObjectId> emptyList() : added;
 	}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e00a641b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableToOneRelationshipChange.java
----------------------------------------------------------------------
diff --git a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableToOneRelationshipChange.java
b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableToOneRelationshipChange.java
index d0269d6..2501224 100644
--- a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableToOneRelationshipChange.java
+++ b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/MutableToOneRelationshipChange.java
@@ -29,6 +29,11 @@ public class MutableToOneRelationshipChange implements ToOneRelationshipChange
{
 	private ObjectId newValue;
 
 	@Override
+	public void accept(PropertyChangeVisitor visitor) {
+		visitor.visitToOneRelationship(this);
+	}
+
+	@Override
 	public ObjectId getOldValue() {
 		return oldValue;
 	}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e00a641b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/ObjectChange.java
----------------------------------------------------------------------
diff --git a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/ObjectChange.java
b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/ObjectChange.java
index 6f41d5f..b7ed806 100644
--- a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/ObjectChange.java
+++ b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/ObjectChange.java
@@ -35,6 +35,8 @@ public interface ObjectChange {
 
 	ObjectId getPostCommitId();
 
+	Map<String, ? extends PropertyChange> getChanges();
+
 	Map<String, ? extends AttributeChange> getAttributeChanges();
 
 	Map<String, ? extends ToOneRelationshipChange> getToOneRelationshipChanges();

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e00a641b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/PropertyChange.java
----------------------------------------------------------------------
diff --git a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/PropertyChange.java
b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/PropertyChange.java
new file mode 100644
index 0000000..852642f
--- /dev/null
+++ b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/PropertyChange.java
@@ -0,0 +1,29 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.lifecycle.changemap;
+
+/**
+ * A base interface for various types of property changes.
+ * 
+ * @since 4.0
+ */
+public interface PropertyChange {
+
+	void accept(PropertyChangeVisitor visitor);
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e00a641b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/PropertyChangeVisitor.java
----------------------------------------------------------------------
diff --git a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/PropertyChangeVisitor.java
b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/PropertyChangeVisitor.java
new file mode 100644
index 0000000..b49d4bc
--- /dev/null
+++ b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/PropertyChangeVisitor.java
@@ -0,0 +1,31 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.lifecycle.changemap;
+
+/**
+ * @since 4.0
+ */
+public interface PropertyChangeVisitor {
+
+	void visitAttribute(AttributeChange change);
+
+	void visitToOneRelationship(ToOneRelationshipChange change);
+
+	void visitToManyRelationship(ToManyRelationshipChange change);
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e00a641b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/ToManyRelationshipChange.java
----------------------------------------------------------------------
diff --git a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/ToManyRelationshipChange.java
b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/ToManyRelationshipChange.java
index 8fcdc59..95fb394 100644
--- a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/ToManyRelationshipChange.java
+++ b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/ToManyRelationshipChange.java
@@ -27,7 +27,7 @@ import org.apache.cayenne.ObjectId;
  * 
  * @since 4.0
  */
-public interface ToManyRelationshipChange {
+public interface ToManyRelationshipChange extends PropertyChange {
 
 	Collection<ObjectId> getAdded();
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e00a641b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/ToOneRelationshipChange.java
----------------------------------------------------------------------
diff --git a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/ToOneRelationshipChange.java
b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/ToOneRelationshipChange.java
index 0b592ea..7c5cc47 100644
--- a/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/ToOneRelationshipChange.java
+++ b/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/changemap/ToOneRelationshipChange.java
@@ -23,7 +23,7 @@ import org.apache.cayenne.ObjectId;
 /**
  * @since 4.0
  */
-public interface ToOneRelationshipChange {
+public interface ToOneRelationshipChange extends PropertyChange {
 
 	ObjectId getOldValue();
 


Mime
View raw message