我正在使用带有springbase服务器4.1的专业社交网络应用程序,使用带有弹簧数据的基础2.2.4在使用java 1.8的弹簧启动应用程序中。 我想用基于N1QL的查询替换下一个使用数据库中的特定公司搜索LikeEntity的流,该查询使用相同的先前likeEntity unnested搜索用户:
@Service
class CompanyServiceImpl implements CompanyService{
@Override
public void addCompanyToLike(UserEntity user, Company company){
int incrementValue=1;
LikeEntity existingLike=user.getLikeEntities()
.stream()
.filter(le->le.getCompany().getName().equals(company.getName()))
.findFirst();
//rest of process
}
}
@Document
@ViewIndexed(designDoc = "user")
class UserEntity implements Serializable{
@Field private String id;
@Reference
private List<LikeEntity> likeEntities=new ArrayList<LikeEntity>();
//Other attributes plus getters and setters:
}
@Document
class LikeEntity implements serializable{
@Reference
private Company company;
@Reference
private Job job;
// other attributes plus getters and setters
}
@Document
@ViewIndexed(designDoc = "company")
class Company implements Serializable{
@Field private String id;
@Field private String name;
//Other attributes plus getters and setters
}
@Repository
@N1qlPrimaryIndexed
@N1qlSecondaryIndexed(indexName = "user")
public interface UserRepository extends CouchbaseRepository<UserEntity, String> {
@Query("SELECT b.*, likeEntity FROM #{#n1ql.bucket} AS b UNNEST b.likeEntities AS likeEntity WHERE b.id=$1 AND likeEntity.company.name=$2")
UserEntity findByLikedCompanyName(String idUser
, String companyName);
}
我正在寻找你的答案,并且提前非常感谢你。