Mule 查询语言 - Order by 子句

发布于 2025-01-08 06:10:19 字数 2212 浏览 0 评论 0原文

寻找与 java 对象一起使用的查询语言。找到了 MQL(Mule 查询语言)。 它处于测试阶段,我没有找到太多文档。尝试了一些东西,例如 where 子句和 select 子句。但订单条款不起作用。

List users = new ArrayList(); 
users.add(new User("Dan", "[email protected]",2,13000 , address)); 
address = new Address("International pkway","Atlatna","GA","USA"); 
users.add(new User("Joe", "[email protected]", 1,14000, address)); 
users.add(new User("John", "[email protected]", 1,16000, address)); 
users.add(new User("Scott", "[email protected]", 1,15000, address)); 
users.add(new User("Andy", "[email protected]", 1,7000, address)); 

Query query = new QueryBuilder() 
.as("p") 
.orderby("income") 
// .max(3) 
.where(eq(property("companyId"), 1)) 
.select(newObject() 
.set("name", "name") 
.set("income", "income") 
.set("email", "email")).build(); 

Collection result1 = query.execute(users); 

如果有人有幸使用 MQL 或建议任何其他好的框架来查询 java 对象,请告诉我。


Another error – when the result set is not hashmap.

Exception in thread “main” java.lang.ClassCastException: com.mql.test.User cannot be cast to java.util.Map
at com.mulesoft.mql.impl.OrderByComparator.compare(OrderByComparator.java:11)
at java.util.Arrays.mergeSort(Arrays.java:1270)
at java.util.Arrays.sort(Arrays.java:1210)
at java.util.Collections.sort(Collections.java:159)
at com.mulesoft.mql.Query.order(Query.java:214)
at com.mulesoft.mql.Query.execute(Query.java:189)

    List persons = getPersons();

    Query query = new QueryBuilder()
    //  .where(and(eq(property(“division”), “Sales”),
    // eq(property(“firstName”), “Joe”)))
    .orderby(“income”)
    .max(3)
    .build();

Looking for query language to work with java objects. Found MQL ( Mule Query Language ).
It's in beta, I didn't find much documentation. tried couple of things like where clause and select clause. But order clause is not working.

List users = new ArrayList(); 
users.add(new User("Dan", "[email protected]",2,13000 , address)); 
address = new Address("International pkway","Atlatna","GA","USA"); 
users.add(new User("Joe", "[email protected]", 1,14000, address)); 
users.add(new User("John", "[email protected]", 1,16000, address)); 
users.add(new User("Scott", "[email protected]", 1,15000, address)); 
users.add(new User("Andy", "[email protected]", 1,7000, address)); 

Query query = new QueryBuilder() 
.as("p") 
.orderby("income") 
// .max(3) 
.where(eq(property("companyId"), 1)) 
.select(newObject() 
.set("name", "name") 
.set("income", "income") 
.set("email", "email")).build(); 

Collection result1 = query.execute(users); 

Please let me know , if any one has luck playing with MQL or suggest any other good framework to query java objects.


Another error – when the result set is not hashmap.

Exception in thread “main” java.lang.ClassCastException: com.mql.test.User cannot be cast to java.util.Map
at com.mulesoft.mql.impl.OrderByComparator.compare(OrderByComparator.java:11)
at java.util.Arrays.mergeSort(Arrays.java:1270)
at java.util.Arrays.sort(Arrays.java:1210)
at java.util.Collections.sort(Collections.java:159)
at com.mulesoft.mql.Query.order(Query.java:214)
at com.mulesoft.mql.Query.execute(Query.java:189)

    List persons = getPersons();

    Query query = new QueryBuilder()
    //  .where(and(eq(property(“division”), “Sales”),
    // eq(property(“firstName”), “Joe”)))
    .orderby(“income”)
    .max(3)
    .build();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

给不了的爱 2025-01-15 06:10:19
  public int compare(Object o1, Object o2) {

        Object r1 = null, r2 = null;
        if(o1 instanceof Map && o2 instanceof Map) {
            Map<String,Object> o1Map = (Map<String,Object>) o1;
            Map<String,Object> o2Map = (Map<String,Object>)  o2;
             r1 = MVEL.executeExpression(expression,o1Map.get(queryBuilder.getAs()), o1Map);
             r2 = MVEL.executeExpression(expression, o2Map.get(queryBuilder.getAs()), o2Map);

        }else {
             r1 = MVEL.executeExpression(expression,  o1);
             r2 = MVEL.executeExpression(expression,  o2);

        }


        if (r1 instanceof Comparable && r2 instanceof Comparable) {
            return ((Comparable)r1).compareTo(r2);
        }

        if (r1 == null && r2 == null) {
            return 0;
        }

        if (r1 == null) {
            return -1;
        }

        if (r2 == null) {
            return 1;
        }

        return r1.toString().compareTo(r2.toString());
    }
  public int compare(Object o1, Object o2) {

        Object r1 = null, r2 = null;
        if(o1 instanceof Map && o2 instanceof Map) {
            Map<String,Object> o1Map = (Map<String,Object>) o1;
            Map<String,Object> o2Map = (Map<String,Object>)  o2;
             r1 = MVEL.executeExpression(expression,o1Map.get(queryBuilder.getAs()), o1Map);
             r2 = MVEL.executeExpression(expression, o2Map.get(queryBuilder.getAs()), o2Map);

        }else {
             r1 = MVEL.executeExpression(expression,  o1);
             r2 = MVEL.executeExpression(expression,  o2);

        }


        if (r1 instanceof Comparable && r2 instanceof Comparable) {
            return ((Comparable)r1).compareTo(r2);
        }

        if (r1 == null && r2 == null) {
            return 0;
        }

        if (r1 == null) {
            return -1;
        }

        if (r2 == null) {
            return 1;
        }

        return r1.toString().compareTo(r2.toString());
    }
月下凄凉 2025-01-15 06:10:19

我查看了mql源代码。 OrderByComparator 类中存在错误(拼写错误)。

Object r1 = MVEL.executeExpression(expression, o1.get(queryBuilder.getAs()), o1);
Object r2 = MVEL.executeExpression(expression, o1.get(queryBuilder.getAs()), **o1)**;

应该是:

Object r2 = MVEL.executeExpression(expression, o1.get(queryBuilder.getAs()), **o2);**

I looked at the mql source code. We have a bug (typo) in the OrderByComparator class.

Object r1 = MVEL.executeExpression(expression, o1.get(queryBuilder.getAs()), o1);
Object r2 = MVEL.executeExpression(expression, o1.get(queryBuilder.getAs()), **o1)**;

should be:

Object r2 = MVEL.executeExpression(expression, o1.get(queryBuilder.getAs()), **o2);**
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文