You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by pp...@apache.org on 2007/12/25 07:18:20 UTC

svn commit: r606759 - in /labs/fluid/slice/src/test/java/org/apache/openjpa/slice/policy: ./ UserDistributionPolicy.java

Author: ppoddar
Date: Mon Dec 24 22:18:18 2007
New Revision: 606759

URL: http://svn.apache.org/viewvc?rev=606759&view=rev
Log:
repairing SVN

Added:
    labs/fluid/slice/src/test/java/org/apache/openjpa/slice/policy/
    labs/fluid/slice/src/test/java/org/apache/openjpa/slice/policy/UserDistributionPolicy.java

Added: labs/fluid/slice/src/test/java/org/apache/openjpa/slice/policy/UserDistributionPolicy.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/test/java/org/apache/openjpa/slice/policy/UserDistributionPolicy.java?rev=606759&view=auto
==============================================================================
--- labs/fluid/slice/src/test/java/org/apache/openjpa/slice/policy/UserDistributionPolicy.java (added)
+++ labs/fluid/slice/src/test/java/org/apache/openjpa/slice/policy/UserDistributionPolicy.java Mon Dec 24 22:18:18 2007
@@ -0,0 +1,60 @@
+/*
+ * 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.openjpa.slice.policy;
+
+import java.util.List;
+import java.util.Set;
+
+import org.apache.openjpa.slice.DistributionPolicy;
+
+import domain.Address;
+import domain.PObject;
+import domain.Person;
+
+/**
+ * Exemplar {@link DistributionPolicy} that maintains closure and distributes
+ * based on attributes of the given instance. 
+ * 
+ * @author Pinaki Poddar 
+ *
+ */
+public class UserDistributionPolicy implements DistributionPolicy {
+
+	public String distribute(Object pc, Set<String> slices, Object context) {
+		if (pc instanceof PObject)
+			return "One";
+		if (pc instanceof Person) {
+			return distribute((Person)pc);
+		}
+		if (pc instanceof Address) {
+			return distribute((Address)pc);
+		}
+		throw new RuntimeException("No policy for " + pc.getClass());
+	}
+	
+	String distribute(Person p) {
+		if (p.getName().startsWith("A")) return "One";
+		return "Two";
+	}
+	
+	String distribute(Address addr) {
+		return distribute(addr.getOwner());
+	}
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org