Commit f4e62df9a8483d6b9b76cd4bdb894a48265a64cc
1 parent
d325cd69
Exists in
master
Melhoria nos métodos DataManager
Showing
1 changed file
with
15 additions
and
37 deletions
Show diff stats
cit-esi-api/src/main/java/br/com/centralit/esi/api/data/service/impl/DataManager.java
| ... | ... | @@ -264,7 +264,7 @@ public class DataManager { |
| 264 | 264 | } |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - public void executeUpdate(DataObject dataObject, String SQLName, HashMap<String, Object> map) { | |
| 267 | + public HashMap<String, Object> executeUpdate(DataObject dataObject, String SQLName, HashMap<String, Object> map) { | |
| 268 | 268 | boolean defaultSQL = UtilString.isNullOrEmpty(SQLName) || SQLName.equalsIgnoreCase("Default"); |
| 269 | 269 | String sql = DataObjectUtil.buildSQL(dataObject, SqlClauseTypeEnum.UPDATE, defaultSQL, SQLName); |
| 270 | 270 | if (sql == null) { |
| ... | ... | @@ -284,6 +284,8 @@ public class DataManager { |
| 284 | 284 | this.dataSourceService.commit(connection); |
| 285 | 285 | |
| 286 | 286 | this.updateRelationships(dataObject, map); |
| 287 | + | |
| 288 | + return map; | |
| 287 | 289 | } catch (Exception e) { |
| 288 | 290 | this.dataSourceService.rollback(connection); |
| 289 | 291 | throw new EsiBusinessException(e); |
| ... | ... | @@ -458,45 +460,21 @@ public class DataManager { |
| 458 | 460 | public Object executeTransaction(SqlClauseTypeEnum SQLType, String SQLName, DataObject dataObject, HashMap<String, Object> map) { |
| 459 | 461 | Object result = null; |
| 460 | 462 | |
| 461 | - boolean defaultSQL = UtilString.isNullOrEmpty(SQLName) || SQLName.equalsIgnoreCase("Default"); | |
| 462 | - String sql = DataObjectUtil.buildSQL(dataObject, SQLType, defaultSQL, SQLName); | |
| 463 | - if (sql == null) { | |
| 464 | - throw new EsiExecutionException("SQL não encontrado"); | |
| 465 | - } | |
| 466 | - Connection connection = this.dataSourceService.connect(dataObject.getDataSource()); | |
| 467 | - | |
| 468 | - try{ | |
| 469 | - if (SQLType.equals(SqlClauseTypeEnum.SELECT)) { | |
| 470 | - result = DataObjectUtil.executeQuery(dataObject, connection, sql, map); | |
| 471 | - }else { | |
| 472 | - if (SQLType.equals(SqlClauseTypeEnum.INSERT) && dataObject.getInsertRule() != null) { | |
| 473 | - map = this.executeBusinessRule(connection, dataObject, map, dataObject.getInsertRule()); | |
| 474 | - }else if (SQLType.equals(SqlClauseTypeEnum.UPDATE) && dataObject.getUpdateRule() != null) { | |
| 475 | - map = this.executeBusinessRule(connection, dataObject, map, dataObject.getUpdateRule()); | |
| 476 | - }else if (SQLType.equals(SqlClauseTypeEnum.DELETE) && dataObject.getDeleteRule() != null) { | |
| 477 | - map = this.executeBusinessRule(connection, dataObject, map, dataObject.getDeleteRule()); | |
| 478 | - } | |
| 479 | - | |
| 480 | - DataObjectUtil.executeSQL(dataObject, connection, sql, map); | |
| 481 | - if (SQLType.equals(SqlClauseTypeEnum.INSERT)) { | |
| 482 | - DataObjectUtil.verifyIdentity(dataObject, connection, map); | |
| 483 | - } | |
| 484 | - this.dataSourceService.commit(connection); | |
| 485 | - | |
| 486 | - if (!SQLType.equals(SqlClauseTypeEnum.DELETE)) { | |
| 487 | - this.updateRelationships(dataObject, map); | |
| 488 | - } | |
| 489 | - | |
| 463 | + switch (SQLType) { | |
| 464 | + case SELECT: | |
| 465 | + result = this.executeQuery(dataObject, SQLName, map); | |
| 466 | + break; | |
| 467 | + case UPDATE: | |
| 468 | + result = this.executeUpdate(dataObject, SQLName, map); | |
| 469 | + break; | |
| 470 | + case DELETE: | |
| 471 | + this.executeDelete(dataObject, SQLName, map); | |
| 490 | 472 | result = map; |
| 491 | - } | |
| 492 | - } catch (Exception e) { | |
| 493 | - this.dataSourceService.rollback(connection); | |
| 494 | - throw new EsiBusinessException(e); | |
| 495 | - }finally{ | |
| 496 | - this.dataSourceService.close(connection); | |
| 473 | + break; | |
| 474 | + default: | |
| 475 | + break; | |
| 497 | 476 | } |
| 498 | 477 | |
| 499 | - | |
| 500 | 478 | return result; |
| 501 | 479 | } |
| 502 | 480 | ... | ... |