Esempio n. 1
0
 @Override
 public List<Map<String, Object>> getRecords(Query query) {
   if (query.getSteps().size() == 1 && query.getFields().size() == 1) {
     StepField field = query.getFields().get(0);
     if (field instanceof AggregatedField) {
       AggregatedField af = (AggregatedField) field;
       if (af.getAggregationType() == AggregatedField.AGGREGATION_TYPE_COUNT
           || af.getAggregationType()
               == AggregatedField
                   .AGGREGATION_TYPE_COUNT_DISTINCT // we count for one field so it is automaticly
       // distinct
       ) {
         if (query.getConstraint() != null) {
           throw new UnsupportedOperationException(
               "Query '" + query.toSql() + "' has a constraint, that is not yet supported");
         } else {
           String tableName = query.getSteps().get(0).getTableName();
           Set<String> wantedNodeManagers =
               getNodeManagerAndDescendants(cloud.getNodeManager(tableName));
           int count = 0;
           for (MockCloudContext.NodeDescription nd : cloud.cloudContext.nodes.values()) {
             // System.out.println("Checking " + nd);
             if (wantedNodeManagers.contains(nd.type)) {
               count++;
             }
           }
           Map<String, Object> result = new HashMap<String, Object>();
           String key = field.getAlias();
           if (key == null) key = field.getFieldName();
           result.put(key, count);
           List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
           list.add(result);
           // System.out.println("Count " + result);
           return list;
         }
       } else {
         throw new UnsupportedOperationException(
             "Aggregation " + af.getAggregationType() + " is not supported");
       }
     } else {
       throw new UnsupportedOperationException(
           "Field should be AggregatedField, but is " + field.getClass()); // RuntimeException ?
     }
   } else {
     throw new UnsupportedOperationException(
         "Query '" + query.toSql() + "' has more than one field, which is not yet supported");
   }
 }
Esempio n. 2
0
 /** A function returning a Node as a bridge object, but based on a Map of values. */
 public Node nodeFunction2() {
   Map<String, String> map = new HashMap<String, String>();
   map.put("bloe", parameter1);
   return new org.mmbase.bridge.util.MapNode(map);
 }
Esempio n. 3
0
 /** A function returning a Map */
 public Map<String, String> mapFunction() {
   Map<String, String> map = new HashMap<String, String>();
   map.put("bloe", parameter1);
   return map;
 }