Commit 5196c90c371efc4e4cbb8ceadde0c1a287e5ebf1

Authored by carlos.alberto
1 parent 11b49b02
Exists in master

Alteração do mecanismo de atualização da classe executeSQL

cit-esi-api/src/main/java/br/com/centralit/esi/api/data/core/DataObjectUtil.java
... ... @@ -167,7 +167,10 @@ public final class DataObjectUtil {
167 167 }
168 168 }
169 169  
170   - DataColumn dataColumn = dataObject.getColumn(arg);
  170 + DataColumn dataColumn = null;
  171 + if (dataObject != null) {
  172 + dataColumn = dataObject.getColumn(arg);
  173 + }
171 174 if (dataColumn == null) {
172 175 dataColumn = new DataColumn(arg, new DataType(javaClass));
173 176 }
... ...
cit-esi-api/src/main/java/br/com/centralit/esi/api/design/model/connector/DatabaseSql.java
... ... @@ -59,12 +59,12 @@ public class DatabaseSql extends Activity {
59 59 @JsonView({ Views.GenericView.class})
60 60 private String returnSqlVariable;
61 61  
62   - @FlowElementProperty(tab=1, title="Variável de lista para várias operações SQL", type=PropertyElementTypeEnum.TEXT, maxLength=120)
  62 + @FlowElementProperty(tab=1, title="Variável de lista para várias operações SQL", type=PropertyElementTypeEnum.VARIABLE_NAME, maxLength=120)
63 63 @Column(nullable = true, length=120)
64 64 @JsonView({ Views.GenericView.class})
65 65 private String listSqlVariable;
66 66  
67   - @FlowElementProperty(tab=1, title="Variável de um bean usado pra substituir valores no SQL", type=PropertyElementTypeEnum.TEXT, maxLength=120)
  67 + @FlowElementProperty(tab=1, title="Variável do objeto usado pra substituir valores no SQL", type=PropertyElementTypeEnum.VARIABLE_NAME, maxLength=120)
68 68 @Column(nullable = true, length=120)
69 69 @JsonView({ Views.GenericView.class})
70 70 private String beanName;
... ...
cit-esi-api/src/main/java/br/com/centralit/esi/api/execution/component/ExecuteSql.java
... ... @@ -16,11 +16,14 @@ import org.apache.commons.lang.text.StrSubstitutor;
16 16 import org.json.JSONArray;
17 17 import org.json.JSONObject;
18 18  
  19 +import br.com.centralit.esi.api.data.core.DataObjectUtil;
19 20 import br.com.centralit.esi.api.enumerated.SqlClauseTypeEnum;
20 21 import br.com.centralit.esi.api.runtime.RuntimeEnvironment;
  22 +import br.com.centralit.esi.exception.EsiBusinessException;
21 23 import br.com.centralit.esi.exception.EsiExecutionException;
22 24  
23 25 public class ExecuteSql {
  26 +
24 27 public static void execute(RuntimeEnvironment runtimeEnvironment) {
25 28 String connName = (String) runtimeEnvironment.getObject("CONNECTIONNAME");
26 29 String sql = (String) runtimeEnvironment.getObject("SQLCONTENT");
... ... @@ -41,6 +44,7 @@ public class ExecuteSql {
41 44 }
42 45 runtimeEnvironment.addOrUpdateObject(nameResultSql, saida);
43 46 }
  47 +
44 48 public static Object executaSelect(Connection connection, RuntimeEnvironment runtimeEnvironment, String sqlQuery) {
45 49 Object saida = null;
46 50 try {
... ... @@ -64,8 +68,9 @@ public class ExecuteSql {
64 68 }
65 69 return saida;
66 70 }
  71 +
67 72 @SuppressWarnings("rawtypes")
68   - public static String executaUpdate(Connection connection, RuntimeEnvironment runtimeEnvironment, String sqlUpdate) {
  73 + public static Object executaUpdate(Connection connection, RuntimeEnvironment runtimeEnvironment, String sqlUpdate) {
69 74 String listNameForEach = (String) runtimeEnvironment.getObject("LISTFOREACH");
70 75 String nameBeanSubt = (String) runtimeEnvironment.getObject("NAMEBEANSUBST");
71 76 Object beanObj = null;
... ... @@ -87,10 +92,61 @@ public class ExecuteSql {
87 92 }
88 93 return retorno;
89 94 }else{
90   - String sqlAjustado = preparaSqlUpdate(connection, runtimeEnvironment, sqlUpdate, null, beanObj);
91   - return executaSqlUpdate(connection, runtimeEnvironment, sqlAjustado);
  95 + HashMap<String, Object> map = buildParams(null, beanObj);
  96 + try {
  97 + DataObjectUtil.executeSQL(null, connection, sqlUpdate, map);
  98 + } catch (SQLException e) {
  99 + e.printStackTrace();
  100 + throw new EsiBusinessException(e);
  101 + }
  102 +
  103 + return map;
  104 + }
  105 + }
  106 +
  107 + @SuppressWarnings({ "unchecked" })
  108 + public static HashMap<String, Object> buildParams(Object bean, Object beanSubt2) {
  109 + HashMap<String, Object> valuesMapFinal = new HashMap<String, Object>();
  110 + if (bean != null){
  111 + try {
  112 + Map<String, Object> valuesMap = null;
  113 + valuesMap = PropertyUtils.describe(bean);
  114 + if (valuesMap != null){
  115 + valuesMapFinal.putAll(valuesMap);
  116 + }
  117 + } catch (IllegalAccessException e) {
  118 + e.printStackTrace();
  119 + throw new EsiExecutionException(e);
  120 + } catch (InvocationTargetException e) {
  121 + e.printStackTrace();
  122 + throw new EsiExecutionException(e);
  123 + } catch (NoSuchMethodException e) {
  124 + e.printStackTrace();
  125 + throw new EsiExecutionException(e);
  126 + }
92 127 }
  128 + if (beanSubt2 != null){
  129 + try {
  130 + Map<String, Object> valuesMap = null;
  131 + valuesMap = PropertyUtils.describe(beanSubt2);
  132 + if (valuesMap != null){
  133 + valuesMapFinal.putAll(valuesMap);
  134 + }
  135 + } catch (IllegalAccessException e) {
  136 + e.printStackTrace();
  137 + throw new EsiExecutionException(e);
  138 + } catch (InvocationTargetException e) {
  139 + e.printStackTrace();
  140 + throw new EsiExecutionException(e);
  141 + } catch (NoSuchMethodException e) {
  142 + e.printStackTrace();
  143 + throw new EsiExecutionException(e);
  144 + }
  145 + }
  146 +
  147 + return valuesMapFinal;
93 148 }
  149 +
94 150 @SuppressWarnings({ "unchecked", "unused" })
95 151 public static String preparaSqlUpdate(Connection connection, RuntimeEnvironment runtimeEnvironment, String sqlUpdate, Object bean, Object beanSubt2) {
96 152 Map<String, Object> valuesMapFinal = new HashMap<String, Object>();
... ... @@ -138,6 +194,7 @@ public class ExecuteSql {
138 194 return sqlUpdate;
139 195 }
140 196 }
  197 +
141 198 public static String executaSqlUpdate(Connection connection, RuntimeEnvironment runtimeEnvironment, String sqlUpdate) {
142 199 int resQtde = 0;
143 200 try {
... ... @@ -161,6 +218,7 @@ public class ExecuteSql {
161 218 }
162 219 return "{\"count\":\"" + resQtde + "\"}";
163 220 }
  221 +
164 222 public static Object geraSaidaSelect(ResultSet result, RuntimeEnvironment runtimeEnvironment) throws SQLException {
165 223 String tipoSaida = (String) runtimeEnvironment.getObject("OUTPUT");
166 224 if (tipoSaida == null){
... ... @@ -173,6 +231,7 @@ public class ExecuteSql {
173 231 }
174 232 return "";
175 233 }
  234 +
176 235 public static JSONArray geraSaidaSelectJSON(ResultSet result, RuntimeEnvironment runtimeEnvironment) throws SQLException {
177 236 JSONArray jsonArray = new JSONArray();
178 237  
... ... @@ -190,6 +249,7 @@ public class ExecuteSql {
190 249  
191 250 return jsonArray;
192 251 }
  252 +
193 253 public static List<Object> geraSaidaSelectLIST(ResultSet result, RuntimeEnvironment runtimeEnvironment) throws SQLException {
194 254 ResultSetMetaData metaData = result.getMetaData();
195 255 int columnCount = metaData.getColumnCount();
... ...