java - Returning a HashMap collection with simple property keys in QueryDsl -
in querydsl, return simple map<string, object>
collection. imagine there's simple way it. i've used qmap, returns keys qualified properties instead of simple properties.
so instead of items looking using qmap collection:
{ poolmaster.calculatevalue: "y" poolmaster.downloadstats: "y" poolmaster.maxplayervalue: 25 poolmaster.minplayervalue: 5 poolmaster.pickdeadline: 1430366400000 size(poolmaster.poolsequences): 1 poolmaster.year: 2015 }
i'd items this:
{ calculatevalue: "y" downloadstats: "y" maxplayervalue: 25 minplayervalue: 5 pickdeadline: 1430366400000 poolsequencescount: 1 year: 2015 }
this elaborate solution far, i'm hoping querydsl has built in.
public collection<map<string, object>> findall() { return this.from(poolmaster) .orderby(poolmaster.year.desc()) .list( map( poolmaster.year, poolmaster.pickdeadline, poolmaster.downloadstats, poolmaster.calculatevalue, poolmaster.minplayervalue, poolmaster.maxplayervalue, poolmaster.poolsequences.size() ) ).stream() .map(tohashmap()) .collect(tolist()); } public static function<map<expression<?>, ?>, map<string, object>> tohashmap() { return expressionmap -> { map<string, object> map = new hashmap<>(); (expression<?> key : expressionmap.keyset()) { path path = null; string suffix = ""; if(key instanceof numberoperation) { numberoperation op = (numberoperation) key; if(op.getoperator().getid().equals(ops.col_size.getid())) { suffix = "count"; } path = (path) op.getarg(0); } if(key instanceof path) { path = (path) key; } if(path != null) { map.put(path.getmetadata().getname() + suffix, expressionmap.get(key)); } } return map; }; }
i suggest use factoryexpression
interface implement transformation. should more performant , compliant how transformations done in querydsl.
map transformations results available via qtuple
, qmap
. sources of these 2 classes should give direction on how create map transformation.
Comments
Post a Comment