@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, ",")); }
@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, ", "); }