Guest User

Untitled

a guest
Oct 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. public void genericProcedure(Connection conn, String functionName, PlsqlParameter ... queryParams) throws Exception
  2.  
  3. public class InPlsqlParameter <T> implements PlsqlParameter {
  4.  
  5. ItemContainer<T> item;
  6.  
  7. public InPlsqlParameter() {
  8. super();
  9. }
  10.  
  11.  
  12. public InPlsqlParameter(T item) {
  13. super();
  14. this.item = new SingleItem<T>(item);
  15. }
  16.  
  17. public InPlsqlParameter(ItemContainer<T> item) {
  18. super();
  19. this.item = item;
  20. }
  21.  
  22.  
  23. public void setParameter(int parameterIndex, CallableStatement cstm)
  24. throws SQLException {
  25. cstm.setObject(parameterIndex, item!=null ? item.getObject() : null);
  26. }
  27.  
  28.  
  29. public ItemContainer<?> getItemFromStatement(int parameterIndex,
  30. CallableStatement cstm) throws Exception {
  31. return null;
  32. }
  33.  
  34. }
  35.  
  36. public class ListItem <T extends Arrayable> extends ItemContainer<T> {
  37.  
  38. private List<T> listItem;
  39. private String oracleTypeName;
  40.  
  41. public ListItem(Class<T> inferedClass, String oracleTypeName) {
  42. super();
  43. super.inferedClass = inferedClass;
  44. this.oracleTypeName = oracleTypeName;
  45. }
  46.  
  47. public ListItem(List<T> listItem, String oracleTypeName) {
  48. super();
  49. this.listItem = listItem;
  50. this.oracleTypeName = oracleTypeName;
  51. }
  52.  
  53. @Override
  54. public int getOracleType() {
  55. return OracleTypes.ARRAY;
  56. }
  57.  
  58. @Override
  59. public T getObject() {
  60. return null;
  61. }
  62.  
  63. @Override
  64. public List<T> getList() {
  65. return listItem;
  66. }
  67.  
  68. @Override
  69. public void setOutParameter(int parameterIndex, CallableStatement cstm) throws SQLException {
  70. cstm.registerOutParameter(parameterIndex, getOracleType(), oracleTypeName);
  71.  
  72. }
  73.  
  74. @Override
  75. public ItemContainer<T> getObjectFromStatement(int parameterIndex,
  76. CallableStatement cstm) throws Exception {
  77. listItem = LazyJdbcDAO.getListFromSqlArray(cstm.getArray(parameterIndex), getGenericClass());
  78. return this;
  79. }
  80.  
  81. }
  82.  
  83. public class SingleItem <T> extends ItemContainer<T> {
  84.  
  85. private T item;
  86.  
  87. public SingleItem(Class<T> inferedClass) {
  88. super();
  89. super.inferedClass = inferedClass;
  90. }
  91.  
  92. public SingleItem(T item) {
  93. super();
  94. this.item = item;
  95. }
  96.  
  97. @Override
  98. public int getOracleType() {
  99. return LazyJdbcDAO.getOracleTypes(getGenericClass());
  100. }
  101.  
  102. @Override
  103. public T getObject() {
  104. return item;
  105. }
  106.  
  107. @Override
  108. public void setOutParameter(int parameterIndex, CallableStatement cstm) throws SQLException {
  109. cstm.registerOutParameter(parameterIndex, this.getOracleType());
  110.  
  111. }
  112.  
  113. @Override
  114. @SuppressWarnings("unchecked")
  115. public ItemContainer<T> getObjectFromStatement(int parameterIndex, CallableStatement cstm) throws SQLException {
  116. item = (T)cstm.getObject(parameterIndex);
  117. //You can use this from JDK 1.7:
  118. //cstm.getObject(1, t);
  119.  
  120. return this;
  121. }
  122.  
  123. @Override
  124. public List<T> getList() {
  125. return null;
  126. }
  127.  
  128. }
  129.  
  130. public class ListItem <T extends Arrayable> extends ItemContainer<T> {
  131.  
  132. private List<T> listItem;
  133. private String oracleTypeName;
  134.  
  135. public ListItem(Class<T> inferedClass, String oracleTypeName) {
  136. super();
  137. super.inferedClass = inferedClass;
  138. this.oracleTypeName = oracleTypeName;
  139. }
  140.  
  141. public ListItem(List<T> listItem, String oracleTypeName) {
  142. super();
  143. this.listItem = listItem;
  144. this.oracleTypeName = oracleTypeName;
  145. }
  146.  
  147. @Override
  148. public int getOracleType() {
  149. return OracleTypes.ARRAY;
  150. }
  151.  
  152. @Override
  153. public T getObject() {
  154. return null;
  155. }
  156.  
  157. @Override
  158. public List<T> getList() {
  159. return listItem;
  160. }
  161.  
  162. @Override
  163. public void setOutParameter(int parameterIndex, CallableStatement cstm) throws SQLException {
  164. cstm.registerOutParameter(parameterIndex, getOracleType(), oracleTypeName);
  165.  
  166. }
  167.  
  168. @Override
  169. public ItemContainer<T> getObjectFromStatement(int parameterIndex,
  170. CallableStatement cstm) throws Exception {
  171. listItem = LazyJdbcDAO.getListFromSqlArray(cstm.getArray(parameterIndex), getGenericClass());
  172. return this;
  173. }
  174.  
  175. }
Add Comment
Please, Sign In to add comment