gpt4 book ai didi

java - 在 hazel 转换中使用 sql 谓词的嵌套获取/更新函数

转载 作者:行者123 更新时间:2023-12-01 18:26:43 24 4
gpt4 key购买 nike

是否可以在嵌套的对象列表中查询(即)让我们考虑以下示例,

class A implements Serializable{
public int id;
public List<B> incomingBs;
public A(int x){ this.id=x; }
}

class B implements Serializable{
public int id;
public List<A> outgoingAs;
public B(int x){ this.id=x; }
}

我开始知道如果一个对象包含在另一个对象中,我们可以使用以下查询在 hazel cast sql 谓词中进行查询,

System.out.println(map.values(new SqlPredicate("something > 0 and complexMember.someString like 'val%'")));

但是如果A类有B类的列表,如何使用sql谓词在列表中查询?

或者有其他方法可以实现这个用例。

感谢和问候,哈利

最佳答案

我使用了谓词的概念,它可以实现到任何类并在其中编写我们自己的逻辑。

查看我的代码,

public class ListPredicate implements Predicate<String,Object>{

private Set<String> switchIds = null;

public ListPredicate(Set<String> switchIds) {
this.switchIds = switchIds;
}

@Override
public boolean apply(Entry<String, Object> mapEntry) {
Container container = (Container) mapEntry.getValue();
for(String switchId : container.getFrameSwitchIdList()) {
if(switchIds.contains(switchId)) {
return true;
}
}
return false;
}

}

使用您自己的谓词作为查询,

Collection<Container> containerList = containerMap.values(new ListPredicate(switchIds));

关于java - 在 hazel 转换中使用 sql 谓词的嵌套获取/更新函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25866526/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com