/** Convert named parameters into an OrderedList. */ private void buildBindWhereRawSql(boolean buildSql, boolean parseRaw, DeployParser parser) { if (buildSql || bindParams != null) { whereRawSql = buildWhereRawSql(); boolean hasRaw = !"".equals(whereRawSql); if (hasRaw && parseRaw) { // parse with encrypted property awareness. This means that if we have // an encrypted property we will insert special named parameter place // holders for binding the encryption key values parser.setEncrypted(true); whereRawSql = parser.parse(whereRawSql); parser.setEncrypted(false); } if (bindParams != null) { if (hasRaw) { whereRawSql = BindParamsParser.parse(bindParams, whereRawSql, request.getBeanDescriptor()); } else if (query.isRawSql() && !buildSql) { // RawSql query hit cached query plan. Need to convert // named parameters into positioned parameters so that // the named parameters are bound RawSql.Sql sql = query.getRawSql().getSql(); String s = sql.isParsed() ? sql.getPreWhere() : sql.getUnparsedSql(); if (bindParams.requiresNamedParamsPrepare()) { BindParamsParser.parse(bindParams, s); } } } } }
private String deriveFilterMany(DeployParser deployParser) { if (isEmpty(filterManyExprSql)) { return null; } else { return deployParser.parse(filterManyExprSql); } }
/** Parse/Convert property names to database columns in the where and order by clauses etc. */ private void parsePropertiesToDbColumns(DeployParser deployParser) { // order by is dependent on the manyProperty (if there is one) String logicalOrderBy = deriveOrderByWithMany(request.getManyProperty()); if (logicalOrderBy != null) { dbOrderBy = deployParser.parse(logicalOrderBy); } // create a copy of the includes required to support the orderBy orderByIncludes = new HashSet<String>(deployParser.getIncludes()); dbWhere = deriveWhere(deployParser); dbFilterMany = deriveFilterMany(deployParser); dbHaving = deriveHaving(deployParser); // all includes including ones for manyWhere clause predicateIncludes = deployParser.getIncludes(); }
private String parse(String raw, String expr, DeployParser deployParser) { StringBuilder sb = new StringBuilder(); if (!isEmpty(raw)) { sb.append(raw); } if (!isEmpty(expr)) { if (sb.length() > 0) { sb.append(" and "); } sb.append(deployParser.parse(expr)); } return sb.toString(); }
private void buildBindHavingRawSql( boolean buildSql, boolean parseRaw, DeployParser deployParser) { if (buildSql || bindParams != null) { // having clause with named parameters... havingRawSql = query.getAdditionalHaving(); if (parseRaw) { havingRawSql = deployParser.parse(havingRawSql); } if (havingRawSql != null && bindParams != null) { // convert and order named parameters if required havingNamedParams = BindParamsParser.parseNamedParams(bindParams, havingRawSql); havingRawSql = havingNamedParams.getPreparedSql(); } } }
/** Build the actual set clause converting logical property names to db columns etc. */ public String buildSetClause(DeployParser deployParser) { int setCount = 0; StringBuilder sb = new StringBuilder(); for (Map.Entry<String, Value> entry : values.entrySet()) { String property = entry.getKey(); if (setCount++ > 0) { sb.append(", "); } // translate to db columns and remove table alias placeholders sb.append(deployParser.parse(property).replace("${}", "")); sb.append(entry.getValue().bindClause()); } return sb.toString(); }