Guest User

Untitled

a guest
Nov 20th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. public void genericProcedure(Connection conn, String functionName, PlsqlParameter ... queryParams) throws Exception
  2. {
  3. CallableStatement cstm = null;
  4.  
  5. String query = getQueryProcedure(functionName, queryParams).toString();
  6. boolean paramEmpty = queryParams.length==1 && queryParams[0]==null;
  7.  
  8. try
  9. {
  10. cstm = conn.prepareCall(query);
  11. int i=1;
  12. if (!paramEmpty)
  13. {
  14. for (PlsqlParameter ob:queryParams)
  15. {
  16. ob.setParameter(i++, cstm);
  17. }
  18. }
  19.  
  20. cstm.execute();
  21. if (!paramEmpty)
  22. {
  23. i=1;
  24. for (PlsqlParameter ob:queryParams)
  25. {
  26. ob.getItemFromStatement(i++, cstm);
  27. }
  28. }
  29. }
  30. catch (Exception e)
  31. {
  32. traceErrorLog(e, query, (Object[])queryParams);
  33. throw e;
  34.  
  35. } finally
  36. {
  37. if (cstm!=null)
  38. {
  39. cstm.close();
  40. }
  41. }
  42. }
  43.  
  44. public class InPlsqlParameter <T> implements PlsqlParameter {
  45.  
  46. ItemContainer<T> item;
  47.  
  48. public InPlsqlParameter() {
  49. super();
  50. }
  51.  
  52.  
  53. public InPlsqlParameter(T item) {
  54. super();
  55. this.item = new SingleItem<T>(item);
  56. }
  57.  
  58. public InPlsqlParameter(ItemContainer<T> item) {
  59. super();
  60. this.item = item;
  61. }
  62.  
  63. @Override
  64. public void setParameter(int parameterIndex, CallableStatement cstm) throws SQLException {
  65. cstm.setObject(parameterIndex, item!=null ? item.getObject() : null);
  66. }
  67.  
  68. @Override
  69. public ItemContainer<?> getItemFromStatement(int parameterIndex,
  70. CallableStatement cstm) throws Exception {
  71. return null;
  72. }
  73.  
  74. @Override
  75. public String toString() {
  76. return item!=null ? item.toString() : "";
  77. }
  78.  
  79. }
  80.  
  81. public class OutPlsqlParameter implements PlsqlParameter {
  82.  
  83. ItemContainer<?> item;
  84.  
  85. public OutPlsqlParameter(ItemContainer<?> item) {
  86. super();
  87. this.item = item;
  88. }
  89.  
  90. @Override
  91. public void setParameter(int parameterIndex, CallableStatement cstm) throws SQLException {
  92. item.setOutParameter(parameterIndex, cstm);
  93. }
  94.  
  95. @Override
  96. public ItemContainer<?> getItemFromStatement(int parameterIndex, CallableStatement cstm) throws Exception
  97. {
  98. return item.getObjectFromStatement(parameterIndex, cstm);
  99. }
  100.  
  101. @Override
  102. public String toString() {
  103. return item!=null ? item.toString() : "";
  104. }
  105.  
  106. }
Add Comment
Please, Sign In to add comment