我收到了使用数据映射器模式为数据层实现小型系统的任务 .
我不想为每个单独的实体编写每个映射器的重复性任务,并且我被限制为不使用任何库或框架来进行映射,因此我使用反射实现了通用映射器以使用以下接口生成SQL脚本(伪样):
Mapper {
create (Class) {
create table in database using Class as reference;
}
create (object) {
insert object into database;
}
read (Class, filters...) {
return a list of objects that match the class specification in the database using the provided filters;
}
update(object) {
update row of the database that has object's primary key with the values in object;
}
delete(Class) {
drop table in the database that has the Class specification;
}
delete(object) {
remove row that has the object's primary key;
}
}
然后,我将使用Java注释指定主键和外键以及我想要使用它的类中的字符串大小约束 .
在完成任务给我的老师后,他告诉我 I had implemented an active record instead of a data mapper ,现在我'm confused as to whether that'是否正确 .
这真的不是映射器吗?他没有给我一个理由,只是说我基本上实现了Hibernate并且它不是一个映射器 .