Difference between revisions of "EclipseLink/UserGuide/JPA/Advanced JPA Development/Data Partitioning"

From Eclipsepedia

Jump to: navigation, search
Line 14: Line 14:
  
 
.
 
.
 +
== Configuration Files ==
 +
 +
=== orm.xml ===
 +
<source lang="xml">
 +
<partitioning-policy class="org.acme.MyPolicy"/>
 +
<round-robin-policy replicate-writes="true">
 +
  <connection-pool>node1</connection-pool>
 +
  <connection-pool>node2</connection-pool>
 +
</round-robin-policy>
 +
<random-policy replicate-writes="true">
 +
  <connection-pool>node1</connection-pool>
 +
  <connection-pool>node2</connection-pool>
 +
</random-policy>
 +
<replication-policy>
 +
  <connection-pool>node1</connection-pool>
 +
  <connection-pool>node2</connection-pool>
 +
</replication-policy>
 +
<range-partitioning-policy parameter-name="id" exclusive-connection="true" union-unpartitionable-queries="true">
 +
  <range-partition connection-pool="node1" start-value="0" end-value="100000" value-type="java.lang.Integer"/>
 +
  <range-partition connection-pool="node2" start-value="100001" end-value="200000" value-type="java.lang.Integer"/>
 +
  <range-partition connection-pool="node3" start-value="200001" value-type="java.lang.Integer"/>
 +
</range-partitioning-policy>
 +
</source>
 +
 +
=== persistence.xml ===
 +
<source lang="xml">
 +
</source>
 +
== Examples ==
 +
<source lang="java">
 +
@Entity
 +
@IdClass(EmployeePK.class)
 +
@UnionPartitioning(
 +
        name="UnionPartitioningAllNodes",
 +
        replicateWrites=true)
 +
@ValuePartitioning(
 +
        name="ValuePartitioningByLOCATION",
 +
        partitionColumn=@Column(name="LOCATION"),
 +
        unionUnpartitionableQueries=true,
 +
        defaultConnectionPool="default",
 +
        partitions={
 +
            @ValuePartition(connectionPool="node2", value="Ottawa"),
 +
            @ValuePartition(connectionPool="node3", value="Toronto")
 +
        })
 +
@Partitioned("ValuePartitioningByLOCATION")
 +
public class Employee {
 +
    @Id
 +
    @Column(name = "EMP_ID")
 +
    private Integer id;
 +
 +
    @Id
 +
    private String location;
 +
    ...
 +
 +
    @ManyToMany(cascade = { PERSIST, MERGE })
 +
    @Partitioned("UnionPartitioningAllNodes")
 +
    private Collection<Project> projects;
 +
    ...
 +
}
 +
</source>
 +
 +
<source lang="java">
 +
@Entity
 +
@RangePartitioning(
 +
        name="RangePartitioningByPROJ_ID",
 +
        partitionColumn=@Column(name="PROJ_ID"),
 +
        partitionValueType=Integer.class,
 +
        unionUnpartitionableQueries=true,
 +
        partitions={
 +
            @RangePartition(connectionPool="default", startValue="0", endValue="1000"),
 +
            @RangePartition(connectionPool="node2", startValue="1000", endValue="2000"),
 +
            @RangePartition(connectionPool="node3", startValue="2000")
 +
        })
 +
@Partitioned("RangePartitioningByPROJ_ID")
 +
public class Project {
 +
    @Id
 +
    @Column(name="PROJ_ID")
 +
    private Integer id;
 +
    ...
 +
}
 +
</source>
 
{{EclipseLink_JPA
 
{{EclipseLink_JPA
 
|previous =[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Schema_Generation/Index|@Index]]
 
|previous =[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Schema_Generation/Index|@Index]]

Revision as of 15:52, 20 January 2011

EclipseLink JPA


Data Partitioning

.

Configuration Files

orm.xml

<partitioning-policy class="org.acme.MyPolicy"/>
<round-robin-policy replicate-writes="true">
  <connection-pool>node1</connection-pool>
  <connection-pool>node2</connection-pool>
</round-robin-policy>
<random-policy replicate-writes="true">
  <connection-pool>node1</connection-pool>
  <connection-pool>node2</connection-pool>
</random-policy>
<replication-policy>
  <connection-pool>node1</connection-pool>
  <connection-pool>node2</connection-pool>
</replication-policy>
<range-partitioning-policy parameter-name="id" exclusive-connection="true" union-unpartitionable-queries="true">
  <range-partition connection-pool="node1" start-value="0" end-value="100000" value-type="java.lang.Integer"/>
  <range-partition connection-pool="node2" start-value="100001" end-value="200000" value-type="java.lang.Integer"/>
  <range-partition connection-pool="node3" start-value="200001" value-type="java.lang.Integer"/>
</range-partitioning-policy>

persistence.xml

 

Examples

@Entity
@IdClass(EmployeePK.class)
@UnionPartitioning(
        name="UnionPartitioningAllNodes",
        replicateWrites=true)
@ValuePartitioning(
        name="ValuePartitioningByLOCATION",
        partitionColumn=@Column(name="LOCATION"),
        unionUnpartitionableQueries=true,
        defaultConnectionPool="default",
        partitions={
            @ValuePartition(connectionPool="node2", value="Ottawa"),
            @ValuePartition(connectionPool="node3", value="Toronto")
        })
@Partitioned("ValuePartitioningByLOCATION")
public class Employee {
    @Id
    @Column(name = "EMP_ID")
    private Integer id;
 
    @Id
    private String location;
    ...
 
    @ManyToMany(cascade = { PERSIST, MERGE })
    @Partitioned("UnionPartitioningAllNodes")
    private Collection<Project> projects;
    ...
}
@Entity
@RangePartitioning(
        name="RangePartitioningByPROJ_ID",
        partitionColumn=@Column(name="PROJ_ID"),
        partitionValueType=Integer.class,
        unionUnpartitionableQueries=true,
        partitions={
            @RangePartition(connectionPool="default", startValue="0", endValue="1000"),
            @RangePartition(connectionPool="node2", startValue="1000", endValue="2000"),
            @RangePartition(connectionPool="node3", startValue="2000")
        })
@Partitioned("RangePartitioningByPROJ_ID")
public class Project {
    @Id
    @Column(name="PROJ_ID")
    private Integer id;
    ...
}

Eclipselink-logo.gif
Version: 2.2.0 DRAFT
Other versions...