在ADF中实现动态范围分区的选项,可以使用以下代码示例:
public class YourEntityObjectImpl extends EntityImpl { private static final int DEFAULT_PARTITION = 0;
public YourEntityObjectImpl() { super(); }
protected void create(AttributeList attributeList) { super.create(attributeList);
// Set the default partition
setPartitionId(DEFAULT_PARTITION);
}
public void setPartitionId(Number partitionId) { if (partitionId == null) { // Set the default partition if the partitionId is null partitionId = DEFAULT_PARTITION; }
PartitionManager partitionManager =
PartitioningHelper.getPartitionManager("YOUR_PARTITION_COLUMN_NAME");
// Set the current partition
setCurrentPartition(partitionManager.getPartition(partitionId));
// Update the entity instance with the new partition
setAttributeValue("YOUR_PARTITION_COLUMN_NAME", partitionId);
} }
public void commit() { super.commit();
// Save the partition change YourEntityObjectImpl entity = (YourEntityObjectImpl)getEntity(YourEntityObjectImpl.class);
if (entity != null) { entity.setPartitionId(getCurrentPartitionId()); } }