MySQL NDB Cluster 8.1 手册
MySQL NDB Cluster 8.0 手册
NDB Cluster 内部原理手册
在 ClusterJ 中(如在 JPA 中),注解用于描述接口如何映射到数据库中的表。带注解的接口如下所示
@PersistenceCapable(table="employee")
@Index(name="idx_uhash")
public interface Employee {
@PrimaryKey
int getId();
void setId(int id);
String getFirst();
void setFirst(String first);
String getLast();
void setLast(String last);
@Column(name="municipality")
@Index(name="idx_municipality")
String getCity();
void setCity(String city);
Date getStarted();
void setStarted(Date date);
Date getEnded();
void setEnded(Date date);
Integer getDepartment();
void setDepartment(Integer department);
}
此接口映射了七个列:id、first、last、municipality started、ended 和 department。注解 @PersistenceCapable(table="employee") 用于让 ClusterJ 知道将 Employee 映射到哪个数据库表(在本例中为 employee 表)。使用 @Column 注解是因为 getCity() 和 setCity() 方法隐含的 city 属性名称与映射的列名 municipality 不同。注解 @PrimaryKey 和 @Index 通知 ClusterJ 数据库表中的索引。
此接口的实现是由 ClusterJ 在运行时动态创建的。调用 newInstance() 方法时,ClusterJ 会为 Employee 接口创建一个实现类;此类将值存储在内部对象数组中。
ClusterJ 不要求每个属性都有注解。ClusterJ 自动检测表的 primary key;虽然 ClusterJ 中有一个注解允许用户描述表的 primary key(参见前面的示例),但指定后,当前会被忽略。(此注解的预期用途是从域对象模型接口生成模式,但这尚不受支持。)
注解本身必须从 ClusterJ API 导入。它们可以在包 com.mysql.clusterj.annotation 中找到,可以像这样导入
import com.mysql.clusterj.annotation.Column;
import com.mysql.clusterj.annotation.Index;
import com.mysql.clusterj.annotation.PersistenceCapable;
import com.mysql.clusterj.annotation.PrimaryKey;