简体   繁体   English

在Java规范模式库图案

[英]repository pattern with specification pattern in java

I am trying to implement the repository pattern to query users and the corresponding settings associated to each user.我想实现的存储库模式,以查询用户和关联到每个用户相应的设置。 I am having a repository interface which has the crud operations to be implemented by each and every repository.我有这必须由每个库执行CRUD操作的储存库接口。

import java.util.List;

public interface Repository<T> {

    void add(T item);
    void add(Iterable<T> items);
    void update(T item);
    void remove(T item);
    void remove(Specification specification);
    List<T> query(Specification specification);

}

I am reading about the specification pattern but i do not understand how to apply the concept to my usecase.我在阅读有关规范模式,但我不明白如何将概念应用到我的用例。

I have two repositories which implements the Repository interface.我有两个版本库,实现仓库接口。 My classes will be having the below operations which translate into the crud operations as mentioned in the interface在界面中提到我的班会具有低于转化为CRUD操作操作

GetSettingsForUserIDMatchingSettingName(string userid, string settingname);
CreateSettingForProfile(string userid, Setting setting);
Create(string userid, Setting setting);
Update(string userid, Setting setting); 
GetAllProfiles();
GetProfilesMatchingUserID(string userid);
GetSettingsForUserID(string userid);        
GetProfilesForUserIDWithSettingName(string userid, string settingname);

How to create my specification class or interface so that my specification caters to all the use cases.如何创建我的规范类或接口,以便我的规范迎合所有用例。

I am referring to the below github link to implement but i am lost.我指的是下面的github链接来实现,但我失去了。

https://github.com/patrikfr/specification/blob/master/specification/src/com/granular8/specification/genericspec/Specification.java https://github.com/patrikfr/specification/blob/master/specification/src/com/granular8/specification/genericspec/Specification.java

Kindly, help.请,帮助。

Specification pattern can help if you are querying or if you need it for filtering the objects that you want to delete from a certain repository thats fine.规格模式可以帮助,如果你要查询或如果你需要它来过滤要从某个库多数民众赞成罚款删除的对象。 There is a good implementation of the pattern in C#.这是一个很好的实现在C#中的格局。 Hopefully you translate it to Java since it already supports lambda expressions.希望你,因为它已经支持lambda表达式将其转换为Java。 https://github.com/jnicolau/NSpecifications https://github.com/jnicolau/NSpecifications

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM