From 9ab9c5b31b0c2d0ec7d0f27cb532ff5b21f735de Mon Sep 17 00:00:00 2001 From: saurabhjdas786 Date: Wed, 23 Mar 2022 20:48:44 -0300 Subject: [PATCH] refactor(AbstractNamedBuilderFactory): extract method - buildWhereClause() is a long method hence extracted the "counting of unit op params" computation from the function. - Improves readability of buildWhereClause(). --- .../factory/AbstractNamedBuilderFactory.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jfaster/mango/crud/named/factory/AbstractNamedBuilderFactory.java b/src/main/java/org/jfaster/mango/crud/named/factory/AbstractNamedBuilderFactory.java index 6abb2836..3a240af4 100644 --- a/src/main/java/org/jfaster/mango/crud/named/factory/AbstractNamedBuilderFactory.java +++ b/src/main/java/org/jfaster/mango/crud/named/factory/AbstractNamedBuilderFactory.java @@ -72,22 +72,33 @@ private int metchSize(String name) { return 0; } + private int getCountOfOpUnitParams(List opUnits) { + int countOfOpUnitParams = 0; + + for (OpUnit opUnit : opUnits) { + countOfOpUnitParams += opUnit.getOp().paramCount(); + } + + return countOfOpUnitParams; + } + protected void buildWhereClause( StringBuilder tailOfSql, List opUnits, List logics, CrudMeta cm, List parameterTypes, String methodName, Class clazz) { + int countOfOpUnitParams; + if (opUnits.size() == 0) { throw new IllegalStateException(); // TODO msg } if (opUnits.size() != (logics.size() + 1)) { throw new IllegalStateException(); // TODO msg } - int count = 0; - for (OpUnit opUnit : opUnits) { - count = count + opUnit.getOp().paramCount(); - } - if (parameterTypes.size() < count) { + + countOfOpUnitParams = getCountOfOpUnitParams(opUnits); + + if (parameterTypes.size() < countOfOpUnitParams) { throw new CrudException("the name of method [" + methodName + "] is error, " + - "the number of parameters expected greater or equal than " + count + ", but " + parameterTypes.size()); + "the number of parameters expected greater or equal than " + countOfOpUnitParams + ", but " + parameterTypes.size()); } tailOfSql.append("where "); int paramIndex = 1;