Beispiel #1
0
    @Override
    public Object exec(List args) throws TemplateModelException {
      if (args.isEmpty()) return "";

      TemplateHashModelEx aliases = (TemplateHashModelEx) args.get(0);
      TemplateHashModelEx rec = (TemplateHashModelEx) args.get(1);
      TemplateHashModelEx add = args.size() >= 3 ? (TemplateHashModelEx) args.get(2) : null;

      List<TemplateModel> recKeys = readList(rec.keys());
      List<TemplateModel> recVals = readList(rec.values());

      ArrayList<String> fl = new ArrayList<String>();
      ArrayList<String> vl = new ArrayList<String>();
      for (int i = 0; i < rec.size(); i++) {
        TemplateModel key = recKeys.get(i);
        TemplateModel val = recVals.get(i);
        String key1 = str(aliases.get(str(key)));
        fl.add(key1);
        vl.add(vstr(val));
      }

      if (add != null) {
        recKeys = readList(add.keys());
        recVals = readList(add.values());
        for (int i = 0; i < add.size(); i++) {
          fl.add(str(recKeys.get(i)));
          vl.add(vstr(recVals.get(i)));
        }
      }

      return String.format(
          "(%s) VALUES (%s)", StringUtils.join(fl, ","), StringUtils.join(vl, ","));
    }
Beispiel #2
0
    @Override
    public Object exec(List args) throws TemplateModelException {
      if (args.isEmpty()) return "";

      TemplateHashModelEx a1 = (TemplateHashModelEx) args.get(0);
      List<TemplateModel> keys = readList(a1.keys());
      List<TemplateModel> vals = readList(a1.values());

      ArrayList<String> l = new ArrayList<String>();
      for (int i = 0; i < keys.size(); i++) {
        TemplateModel key = keys.get(i);
        TemplateModel val = vals.get(i);
        l.add(str(key) + "=" + vstr(val));
      }
      return StringUtils.join(l, ", ");
    }
Beispiel #3
0
    @Override
    public Object exec(List args) throws TemplateModelException {
      if (args.isEmpty()) return "";

      TemplateHashModelEx a1 = (TemplateHashModelEx) args.get(0);
      List<TemplateModel> cols = args.size() >= 2 ? readList((TemplateModel) args.get(1)) : null;
      if (cols == null) cols = readList(a1.keys());

      ArrayList<String> l = new ArrayList<String>();
      for (TemplateModel col : cols) {
        String cv = vstr(col);
        String c = str(col);
        String f = str(a1.get(c));
        l.add(f + " AS " + cv);
      }
      return StringUtils.join(l, ", ");
    }
 public Collection<Entity<?>> convert(TemplateHashModelEx hash, String... ignore) {
   List<Entity<?>> entities = new LinkedList<Entity<?>>();
   List<String> ignoreList = Arrays.asList(ignore);
   TemplateCollectionModel keys;
   try {
     keys = hash.keys();
     for (TemplateModelIterator iterator = keys.iterator(); iterator.hasNext(); ) {
       TemplateModel model = iterator.next();
       String key = model.toString();
       if (!ignoreList.contains(key)) {
         entities.add(new SimpleEntityModel(key, hash.get(key).toString()));
       }
     }
     Collections.sort(entities, new EntityComparator());
     return entities;
   } catch (TemplateModelException e) {
     throw new RuntimeException(e);
   }
 }