Commit 5196c90c371efc4e4cbb8ceadde0c1a287e5ebf1
1 parent
11b49b02
Exists in
master
Alteração do mecanismo de atualização da classe executeSQL
Showing
3 changed files
with
69 additions
and
6 deletions
Show diff stats
cit-esi-api/src/main/java/br/com/centralit/esi/api/data/core/DataObjectUtil.java
@@ -167,7 +167,10 @@ public final class DataObjectUtil { | @@ -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 | if (dataColumn == null) { | 174 | if (dataColumn == null) { |
172 | dataColumn = new DataColumn(arg, new DataType(javaClass)); | 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,12 +59,12 @@ public class DatabaseSql extends Activity { | ||
59 | @JsonView({ Views.GenericView.class}) | 59 | @JsonView({ Views.GenericView.class}) |
60 | private String returnSqlVariable; | 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 | @Column(nullable = true, length=120) | 63 | @Column(nullable = true, length=120) |
64 | @JsonView({ Views.GenericView.class}) | 64 | @JsonView({ Views.GenericView.class}) |
65 | private String listSqlVariable; | 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 | @Column(nullable = true, length=120) | 68 | @Column(nullable = true, length=120) |
69 | @JsonView({ Views.GenericView.class}) | 69 | @JsonView({ Views.GenericView.class}) |
70 | private String beanName; | 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,11 +16,14 @@ import org.apache.commons.lang.text.StrSubstitutor; | ||
16 | import org.json.JSONArray; | 16 | import org.json.JSONArray; |
17 | import org.json.JSONObject; | 17 | import org.json.JSONObject; |
18 | 18 | ||
19 | +import br.com.centralit.esi.api.data.core.DataObjectUtil; | ||
19 | import br.com.centralit.esi.api.enumerated.SqlClauseTypeEnum; | 20 | import br.com.centralit.esi.api.enumerated.SqlClauseTypeEnum; |
20 | import br.com.centralit.esi.api.runtime.RuntimeEnvironment; | 21 | import br.com.centralit.esi.api.runtime.RuntimeEnvironment; |
22 | +import br.com.centralit.esi.exception.EsiBusinessException; | ||
21 | import br.com.centralit.esi.exception.EsiExecutionException; | 23 | import br.com.centralit.esi.exception.EsiExecutionException; |
22 | 24 | ||
23 | public class ExecuteSql { | 25 | public class ExecuteSql { |
26 | + | ||
24 | public static void execute(RuntimeEnvironment runtimeEnvironment) { | 27 | public static void execute(RuntimeEnvironment runtimeEnvironment) { |
25 | String connName = (String) runtimeEnvironment.getObject("CONNECTIONNAME"); | 28 | String connName = (String) runtimeEnvironment.getObject("CONNECTIONNAME"); |
26 | String sql = (String) runtimeEnvironment.getObject("SQLCONTENT"); | 29 | String sql = (String) runtimeEnvironment.getObject("SQLCONTENT"); |
@@ -41,6 +44,7 @@ public class ExecuteSql { | @@ -41,6 +44,7 @@ public class ExecuteSql { | ||
41 | } | 44 | } |
42 | runtimeEnvironment.addOrUpdateObject(nameResultSql, saida); | 45 | runtimeEnvironment.addOrUpdateObject(nameResultSql, saida); |
43 | } | 46 | } |
47 | + | ||
44 | public static Object executaSelect(Connection connection, RuntimeEnvironment runtimeEnvironment, String sqlQuery) { | 48 | public static Object executaSelect(Connection connection, RuntimeEnvironment runtimeEnvironment, String sqlQuery) { |
45 | Object saida = null; | 49 | Object saida = null; |
46 | try { | 50 | try { |
@@ -64,8 +68,9 @@ public class ExecuteSql { | @@ -64,8 +68,9 @@ public class ExecuteSql { | ||
64 | } | 68 | } |
65 | return saida; | 69 | return saida; |
66 | } | 70 | } |
71 | + | ||
67 | @SuppressWarnings("rawtypes") | 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 | String listNameForEach = (String) runtimeEnvironment.getObject("LISTFOREACH"); | 74 | String listNameForEach = (String) runtimeEnvironment.getObject("LISTFOREACH"); |
70 | String nameBeanSubt = (String) runtimeEnvironment.getObject("NAMEBEANSUBST"); | 75 | String nameBeanSubt = (String) runtimeEnvironment.getObject("NAMEBEANSUBST"); |
71 | Object beanObj = null; | 76 | Object beanObj = null; |
@@ -87,10 +92,61 @@ public class ExecuteSql { | @@ -87,10 +92,61 @@ public class ExecuteSql { | ||
87 | } | 92 | } |
88 | return retorno; | 93 | return retorno; |
89 | }else{ | 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 | @SuppressWarnings({ "unchecked", "unused" }) | 150 | @SuppressWarnings({ "unchecked", "unused" }) |
95 | public static String preparaSqlUpdate(Connection connection, RuntimeEnvironment runtimeEnvironment, String sqlUpdate, Object bean, Object beanSubt2) { | 151 | public static String preparaSqlUpdate(Connection connection, RuntimeEnvironment runtimeEnvironment, String sqlUpdate, Object bean, Object beanSubt2) { |
96 | Map<String, Object> valuesMapFinal = new HashMap<String, Object>(); | 152 | Map<String, Object> valuesMapFinal = new HashMap<String, Object>(); |
@@ -138,6 +194,7 @@ public class ExecuteSql { | @@ -138,6 +194,7 @@ public class ExecuteSql { | ||
138 | return sqlUpdate; | 194 | return sqlUpdate; |
139 | } | 195 | } |
140 | } | 196 | } |
197 | + | ||
141 | public static String executaSqlUpdate(Connection connection, RuntimeEnvironment runtimeEnvironment, String sqlUpdate) { | 198 | public static String executaSqlUpdate(Connection connection, RuntimeEnvironment runtimeEnvironment, String sqlUpdate) { |
142 | int resQtde = 0; | 199 | int resQtde = 0; |
143 | try { | 200 | try { |
@@ -161,6 +218,7 @@ public class ExecuteSql { | @@ -161,6 +218,7 @@ public class ExecuteSql { | ||
161 | } | 218 | } |
162 | return "{\"count\":\"" + resQtde + "\"}"; | 219 | return "{\"count\":\"" + resQtde + "\"}"; |
163 | } | 220 | } |
221 | + | ||
164 | public static Object geraSaidaSelect(ResultSet result, RuntimeEnvironment runtimeEnvironment) throws SQLException { | 222 | public static Object geraSaidaSelect(ResultSet result, RuntimeEnvironment runtimeEnvironment) throws SQLException { |
165 | String tipoSaida = (String) runtimeEnvironment.getObject("OUTPUT"); | 223 | String tipoSaida = (String) runtimeEnvironment.getObject("OUTPUT"); |
166 | if (tipoSaida == null){ | 224 | if (tipoSaida == null){ |
@@ -173,6 +231,7 @@ public class ExecuteSql { | @@ -173,6 +231,7 @@ public class ExecuteSql { | ||
173 | } | 231 | } |
174 | return ""; | 232 | return ""; |
175 | } | 233 | } |
234 | + | ||
176 | public static JSONArray geraSaidaSelectJSON(ResultSet result, RuntimeEnvironment runtimeEnvironment) throws SQLException { | 235 | public static JSONArray geraSaidaSelectJSON(ResultSet result, RuntimeEnvironment runtimeEnvironment) throws SQLException { |
177 | JSONArray jsonArray = new JSONArray(); | 236 | JSONArray jsonArray = new JSONArray(); |
178 | 237 | ||
@@ -190,6 +249,7 @@ public class ExecuteSql { | @@ -190,6 +249,7 @@ public class ExecuteSql { | ||
190 | 249 | ||
191 | return jsonArray; | 250 | return jsonArray; |
192 | } | 251 | } |
252 | + | ||
193 | public static List<Object> geraSaidaSelectLIST(ResultSet result, RuntimeEnvironment runtimeEnvironment) throws SQLException { | 253 | public static List<Object> geraSaidaSelectLIST(ResultSet result, RuntimeEnvironment runtimeEnvironment) throws SQLException { |
194 | ResultSetMetaData metaData = result.getMetaData(); | 254 | ResultSetMetaData metaData = result.getMetaData(); |
195 | int columnCount = metaData.getColumnCount(); | 255 | int columnCount = metaData.getColumnCount(); |