3.14.2.4. Data Distribution
The user application decides how the newly persistent instances be distributed across the slices.
The user application specifies the data distribution policy by implementing org.apache.openjpa.slice.DistributionPolicy.
The DistributionPolicy interface is simple with a single method.
The complete listing of the documented interface follows:
public interface DistributionPolicy {
/**
* Gets the name of the slice where the given newly persistent
* instance will be stored.
*
* @param pc The newly persistent or to-be-merged object.
* @param slices name of the configured slices.
* @param context persistence context managing the given instance.
*
* @return identifier of the slice. This name must match one of the
* configured slice names.
* @see DistributedConfiguration#getSliceNames()
*/
String distribute(Object pc, List<String> slices, Object context);
}
Slice runtime invokes this user-supplied method for the newly persistent instance that is explicit argument of the jakarta.persistence.EntityManager.persist(Object pc) method.
The user application must return a valid slice name from this method to designate the target slice for the given instance.
The data distribution policy may be based on the attribute of the data itself.
For example, all Customer whose first name begins with character 'A' to 'M' will be stored in one slice while names beginning with 'N' to 'Z' will be stored in another slice.
The noteworthy aspect of such policy implementation is the attribute values that participate in the distribution policy logic should be set before invoking EntityManager.persist() method.
The user application needs to specify the target slice only for the root instance i.e.
the explicit argument for the EntityManager.persist(Object pc) method.
Slice computes the transitive closure of the graph i.e.
the set of all instances directly or indirectly reachable from the root instance and stores them in the same target slice.
Slice tracks the original database for existing instances. When an application issues a query, the resultant instances can be loaded from different slices. As Slice tracks the original slice for each instance, any subsequent update to an instance is committed to the appropriate original database slice.
|
|
You can find the original slice of an instance |