我有一个基类 Record,它代表数据库中的记录。我有扩展记录的客户和工作类。我以前从未使用过注释,但我想我想做的是创建一个自定义注释并在我的 Customer 类中标记一个返回其 Jobs 对象的方法,这样我就知道在保存 Customer 时将 Jobs 对象保存到数据库.
像这样的东西
class Record{
private int id;
public void save(){
//look up all methods in the current object that are marked as @alsoSaveList,
//call those methods, and save them as well.
//look up all methods in the current object that are marked as @alsoSaveRecord,
//call those methods, and save the returned Record.
}
}
class Customer extends Record{
@alsoSaveList
public List<Job> jobs(){
return list of all of customers jobs objects;
}
}
class Job extends Record{
@alsoSaveRecord
public Customer customer(){
return its customer object;
}
}
这可能吗?有人能指出我正确的方向吗?