Clustering - Java

Click here to view in C++

When you create an instance of a persistence-capable class, you make it persistent (instead of transient) by clustering it. Clustering a container assigns it to a database; clustering a basic object assigns it to a particular logical page within a particular container. Clustering thus determines the location of persistent objects in the logical storage hierarchy and affects their physical proximity on disk. Therefore, it's important to design your database around this concept for better performance.

You can set the session's clustering strategy at anytime by calling it's setClusterStrategy function or you can set each individual object's cluster strategy by passing it through the new operator.

Defining your cluster strategy:

DefaultClusterStrategy newStrategy = new DefaultClusterStrategy(ClusterStrategy.newPage | ClusterStrategy.newContainer | ClusterStrategy.newDatabase); 



Setting session's cluster strategy:

ooSession session = ...
session.setClusterStrategy(newStrategy);



Specifying the cluster strategy for individual objects:

Car carObj = new Car();
newStrategy.cluster(carObj);


For more information on terms, priorities, default priorities, and clustering rules, visit our FAQ.