labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r606973 - in /labs/fluid/slice/src/test/java: domain/Address.java domain/Person.java org/apache/openjpa/slice/TestBasic.java org/apache/openjpa/slice/TestConfiguration.java org/apache/openjpa/slice/policy/UserDistributionPolicy.java
Date Wed, 26 Dec 2007 23:43:44 GMT
Author: ppoddar
Date: Wed Dec 26 15:43:39 2007
New Revision: 606973

URL: http://svn.apache.org/viewvc?rev=606973&view=rev
Log:
Automatic collocation by cascading relations

Modified:
    labs/fluid/slice/src/test/java/domain/Address.java
    labs/fluid/slice/src/test/java/domain/Person.java
    labs/fluid/slice/src/test/java/org/apache/openjpa/slice/TestBasic.java
    labs/fluid/slice/src/test/java/org/apache/openjpa/slice/TestConfiguration.java
    labs/fluid/slice/src/test/java/org/apache/openjpa/slice/policy/UserDistributionPolicy.java

Modified: labs/fluid/slice/src/test/java/domain/Address.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/test/java/domain/Address.java?rev=606973&r1=606972&r2=606973&view=diff
==============================================================================
--- labs/fluid/slice/src/test/java/domain/Address.java (original)
+++ labs/fluid/slice/src/test/java/domain/Address.java Wed Dec 26 15:43:39 2007
@@ -68,4 +68,8 @@
 	public long getId() {
 		return id;
 	}
+	
+	public String toString() {
+		return city;
+	}
 }

Modified: labs/fluid/slice/src/test/java/domain/Person.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/test/java/domain/Person.java?rev=606973&r1=606972&r2=606973&view=diff
==============================================================================
--- labs/fluid/slice/src/test/java/domain/Person.java (original)
+++ labs/fluid/slice/src/test/java/domain/Person.java Wed Dec 26 15:43:39 2007
@@ -59,4 +59,8 @@
 	public long getId() {
 		return id;
 	}
+	
+	public String toString() {
+		return name;
+	}
 }

Modified: labs/fluid/slice/src/test/java/org/apache/openjpa/slice/TestBasic.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/test/java/org/apache/openjpa/slice/TestBasic.java?rev=606973&r1=606972&r2=606973&view=diff
==============================================================================
--- labs/fluid/slice/src/test/java/org/apache/openjpa/slice/TestBasic.java (original)
+++ labs/fluid/slice/src/test/java/org/apache/openjpa/slice/TestBasic.java Wed Dec 26 15:43:39
2007
@@ -23,7 +23,6 @@
 import javax.persistence.EntityManager;
 
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
-import org.apache.openjpa.slice.jdbc.DistributedJDBCBrokerFactory;
 
 import domain.Address;
 import domain.PObject;
@@ -33,7 +32,8 @@
 	private static String persistenceUnitName = "slice";
 
 	public void setUp() throws Exception {
-		super.setUp(PObject.class, Person.class, Address.class);
+		if (emf == null)
+			super.setUp(PObject.class, Person.class, Address.class);
 		assertNotNull("No unit for " + persistenceUnitName, emf);
 	}
 	

Modified: labs/fluid/slice/src/test/java/org/apache/openjpa/slice/TestConfiguration.java
URL: http://svn.apache.org/viewvc/labs/fluid/slice/src/test/java/org/apache/openjpa/slice/TestConfiguration.java?rev=606973&r1=606972&r2=606973&view=diff
==============================================================================
--- labs/fluid/slice/src/test/java/org/apache/openjpa/slice/TestConfiguration.java (original)
+++ labs/fluid/slice/src/test/java/org/apache/openjpa/slice/TestConfiguration.java Wed Dec
26 15:43:39 2007
@@ -2,6 +2,7 @@
 
 import java.util.Set;
 
+import org.apache.openjpa.kernel.Broker;
 import org.apache.openjpa.kernel.BrokerFactory;
 import org.apache.openjpa.persistence.EntityManagerFactoryImpl;
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
@@ -21,7 +22,9 @@
 		assertEquals("jdbc:mysql://localhost/slice1", conf.getSlice("One").getConnectionURL());
 		assertEquals("jdbc:mysql://localhost/slice2", conf.getSlice("Two").getConnectionURL());
 		BrokerFactory bf = ((EntityManagerFactoryImpl)emf).getBrokerFactory();
+		Broker broker = bf.newBroker();
 		assertEquals(DistributedJDBCBrokerFactory.class, bf.getClass());
+		assertEquals(DistributedBrokerImpl.class, broker.getClass());
 		assertNotNull(conf.getDistributionPolicyInstance());
 		
 		emf.createEntityManager();

Modified: 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=606973&r1=606972&r2=606973&view=diff
==============================================================================
--- labs/fluid/slice/src/test/java/org/apache/openjpa/slice/policy/UserDistributionPolicy.java
(original)
+++ labs/fluid/slice/src/test/java/org/apache/openjpa/slice/policy/UserDistributionPolicy.java
Wed Dec 26 15:43:39 2007
@@ -18,7 +18,6 @@
  */
 package org.apache.openjpa.slice.policy;
 
-import java.util.List;
 import java.util.Set;
 
 import org.apache.openjpa.slice.DistributionPolicy;
@@ -36,25 +35,39 @@
  */
 public class UserDistributionPolicy implements DistributionPolicy {
 
+	/**
+	 * Distribute the given instance.
+	 * Assumes that two configured slices are named as <em>One</em> and 
+	 * <em>Two</em>.
+	 */
 	public String distribute(Object pc, Set<String> slices, Object context) {
+		assertValidSlices(slices);
 		if (pc instanceof PObject)
-			return "One";
+			return distribute((PObject)pc);
 		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";
+	void assertValidSlices(Set<String> slices) {
+		if (slices.contains("One") && slices.contains("Two"))
+			return;
+		throw new RuntimeException("This policy assumes two slices named " +
+				"One and Two. But configured slices are " + slices); 
 	}
 	
-	String distribute(Address addr) {
-		return distribute(addr.getOwner());
+	/**
+	 * Distribute PObject based on odd-even value of its id.
+	 */
+	String distribute(PObject pc) {
+		return (pc.getId()%2 == 0) ? "One" : "Two";
+	}
+	
+	/**
+	 * Distribute Person based on first character of its name.
+	 */
+	String distribute(Person pc) {
+		return (pc.getName().startsWith("A")) ? "One" : "Two";
 	}
-
 }



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


Mime
View raw message