import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import javax.xml.namespace.QName;
import javax.xml.xpath.XPath;
TEtat sEtatc = spc.getEtat(etatModel.getId());
TElement sec = sEtatc.getElement(elementModel.getId());
String mainTableName = sEtatc.getMaintable().getBaseName();
- String sCond = (sec == null ? null : sec.getSpecialCond());
+ String definedCondition = (sec == null ? null : sec.getSpecialCond());
String fromClause = StringUtils.EMPTY;
String whereClause = StringUtils.EMPTY;
+ /**
+ * Ici le code est merdique. Pas d'utilisation d'un parser donc tous les
+ * cas ne sont pas gérés. Pour le moment ça marchouille...
+ */
+
// ----------- WHERE condition supplementaire dans la conf -------------
- if (!StringUtils.isEmpty(sCond)) {
- sCond = sCond.trim();
- // on split sur . => schema.table.colonne
- String[] sCondOperand = StringUtils.split(sCond, "=");
- String[] sCondParts = StringUtils.split(sCondOperand[0], ".");
- String sCondTableName;
-
- if (sCondParts.length == 1) {
- // on rajoute le prefix de table à la condition
- sCond = mainTableName + "." + sCond;
- sCondTableName = mainTableName;
- } else if (sCondParts.length == 2) {
- sCondTableName = sCondParts[0];
- } else {
- sCondTableName = sCondParts[1];
+ if (!StringUtils.isEmpty(definedCondition)) {
+ definedCondition = definedCondition.trim();
+
+ // ---- dans le cas de condition multiple, on split sur AND/OR -----
+ Pattern splitter = Pattern.compile("^((.*)(AND|OR)(.*))*$", Pattern.CASE_INSENSITIVE);
+ Matcher matcher = splitter.matcher(definedCondition);
+ List<String> allConditions = new LinkedList<String>();
+ boolean isMultipleCond = false;
+
+ while (matcher.find()) {
+ allConditions.add(matcher.group(2));
+ allConditions.add(matcher.group(4));
+ isMultipleCond = true;
}
- sCondTableName = sCondTableName.trim();
-
- // on vérifie que la table de la condition est dans le FROM
- if (!sql.contains(sCondTableName) && !fromClause.contains(sCondTableName)) {
- // on aurait pu mettre un string builder...
- fromClause += " LEFT OUTER JOIN " + sCondTableName + " ON " + sCondTableName + ".DOC_ID = " + mainTableName + ".DOC_ID AND " + sCondTableName + ".COLLECTIVITE = " + mainTableName + ".COLLECTIVITE AND " + sCondTableName + ".BUDGET = "
- + mainTableName + ".BUDGET";
+ // pas de AND/OR donc condition simple
+ if (!isMultipleCond) {
+ allConditions.add(definedCondition);
}
+ // ------------------------
+
+ for (String condition : allConditions) {
+ // on split sur . => schema.table.colonne
+ String[] condOperands = StringUtils.split(condition, "=");
+ String[] condParts = StringUtils.split(condOperands[0], ".");
+ String condTableName;
+
+ if (condParts.length == 1) {
+ // on rajoute le prefix de table à la condition
+ condTableName = mainTableName;
+ } else if (condParts.length == 2) {
+ condTableName = condParts[0];
+ } else {
+ condTableName = condParts[1];
+ }
+
+ condTableName = condTableName.trim();
+ // on vérifie que la table de la condition est dans le FROM
+ if (!sql.contains(condTableName) && !fromClause.contains(condTableName)) {
+ // on aurait pu mettre un string builder...
+ fromClause += " LEFT OUTER JOIN " + condTableName + " ON " + condTableName + ".DOC_ID = " + mainTableName + ".DOC_ID AND " + condTableName + ".COLLECTIVITE = " + mainTableName + ".COLLECTIVITE AND " + condTableName
+ + ".BUDGET = " + mainTableName + ".BUDGET";
+ }
+ }
+
// on aurait pu mettre un string builder...
- whereClause += " AND " + sCond;
+ whereClause += " AND " + definedCondition;
}
// ----------- ORDER BY -----------
String paginedResultRequest = "SELECT DOC_ID FROM (SELECT DOC_ID, ROWNUM R FROM (SELECT DISTINCT DOC_ID FROM (" + innerRequest + "))) WHERE R >= " + (currentPage * pageSize) + " AND R < " + (currentPage + 1) * pageSize;
String countTotalDocRequest = "SELECT COUNT(DISTINCT DOC_ID) FROM (" + innerRequest + ")";
- String countTotalRowRequest = "SELECT COUNT(*) FROM ("+ innerRequest + ")";
-
+ String countTotalRowRequest = "SELECT COUNT(*) FROM (" + innerRequest + ")";
+
logger.debug("paginedResultRequest=" + paginedResultRequest);
logger.debug("countDocRequest=" + countTotalDocRequest);
logger.debug("countRowRequest=" + countTotalRowRequest);
} finally {
docIdCountRs.close();
}
-
+
// on compte le nombre total de ligne (non-paginé) - i.e. sous element dans le document
ResultSet rowCountRs = st.executeQuery(countTotalRowRequest);
try {
output.addAttribute("current-page", currentPage);
output.addAttribute("estimated-size", totalDocIdCount);
-
output.addAttribute("collectivite", collectivite.key);
output.addAttribute("budget", budget.key);