Hi,
> I don't know hoe i implement the DistributionPolicy interface
Added is an example policy that distributes between two slices named "One"
and "Two" based on the first letter in Person's name. To use this policy in
your configuration:
<property name="openjpa.slice.DistributionPolicy"
value="org.apache.openjpa.slice.policy.UserDistributionPolicy"/>
/**
* Exemplar {@(protected)
distributes
* based on attributes of the given instance.
*
* @author Pinaki Poddar
*
*/
package org.apache.openjpa.slice.policy;
import
java.util.List;
import
org.apache.openjpa.slice.DistributionPolicy;
import org.apache.openjpa.slice.PObject;
import org.apache.openjpa.slice.Person;
public class UserDistributionPolicy implements DistributionPolicy {
/**
* Distribute the given instance.
* Assumes that two configured slices are named as <em>One</em> and
* <em>Two</em>.<br>
* The policy is only implemented for PObject and Person i.e. two of three
* known classes. No policy is implemented for Address because Address is
* persisted always by cascade and hence Slice should assign automatically
* the same slice as its owner Person.
*
*/
public String distribute(Object pc, List<String> slices, Object context) {
assertValidSlices(slices);
if (pc instanceof PObject)
return distribute((PObject)pc);
if (pc instanceof Person) {
return distribute((Person)pc);
}
throw new RuntimeException("No policy for " + pc.getClass());
}
void assertValidSlices(List<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);
}
/**
* 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";
}
}
thiago ananias wrote:
>
>
> My "persistence.xml" is in this post and i specified the "<property
> name="openjpa.BrokerFactory" value="slice"/>"
>
> I don't know hoe i implement the DistributionPolicy interface
>
> i think that's wrong in my code!
>
> thanks
>
>
> Pinaki Poddar wrote:
>>
>> Hi,
>> this line from stack trace
>>>
org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory (
JDBCConfigurationImpl.java:784)
>>
>> indicates that the correct configuration has not been picked up.
>>
>> Did you specify
>> <property name="openjpa.BrokerFactory" value="slice"/>
>>
>> in your persistence.xml file?
>>
>>
>
>
--
Sent from the OpenJPA Users mailing list archive at Nabble.com.