Layered architecture and persistence annotations on the model beans?

橙三吉。 提交于 2019-12-04 15:26:01

A common solution is to apply the programming by interfaces principle, creating interfaces for each entity and relationship and implement them with SDN annotated classes. This way the model layer would only access entities by interfaces, having no knowledge about implementation. To astract database access operations, you can create DAO interfaces and implement them with SDN repositories and/or Cypher queries. An example:

public interface Item {
    String getName();
    ...
}

public interface ItemDAO {
    Item lookup(String name);
    ...
}

@NodeEntity
public class ItemNode implements Item {
    @GraphId private Long id;
    private String name;
    ...
    public String getName() { return name; }
    ...
}

public class Neo4jItemDAO implements ItemDAO {
    ...
    @Override
    public Item lookup(String name) {
        return neo4jOperations.lookup(ItemNode.class,"name", name).to(ItemNode.class).singleOrNull();
    }
}

In your model class you can access entities this way:

@Autowired ItemDAO itemDAO;
Item item = itemDAO.lookup("name");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!