Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void genericProcedure(Connection conn, String functionName, PlsqlParameter ... queryParams) throws Exception
- {
- CallableStatement cstm = null;
- String query = getQueryProcedure(functionName, queryParams).toString();
- boolean paramEmpty = queryParams.length==1 && queryParams[0]==null;
- try
- {
- cstm = conn.prepareCall(query);
- int i=1;
- if (!paramEmpty)
- {
- for (PlsqlParameter ob:queryParams)
- {
- ob.setParameter(i++, cstm);
- }
- }
- cstm.execute();
- if (!paramEmpty)
- {
- i=1;
- for (PlsqlParameter ob:queryParams)
- {
- ob.getItemFromStatement(i++, cstm);
- }
- }
- }
- catch (Exception e)
- {
- traceErrorLog(e, query, (Object[])queryParams);
- throw e;
- } finally
- {
- if (cstm!=null)
- {
- cstm.close();
- }
- }
- }
- public class InPlsqlParameter <T> implements PlsqlParameter {
- ItemContainer<T> item;
- public InPlsqlParameter() {
- super();
- }
- public InPlsqlParameter(T item) {
- super();
- this.item = new SingleItem<T>(item);
- }
- public InPlsqlParameter(ItemContainer<T> item) {
- super();
- this.item = item;
- }
- @Override
- public void setParameter(int parameterIndex, CallableStatement cstm) throws SQLException {
- cstm.setObject(parameterIndex, item!=null ? item.getObject() : null);
- }
- @Override
- public ItemContainer<?> getItemFromStatement(int parameterIndex,
- CallableStatement cstm) throws Exception {
- return null;
- }
- @Override
- public String toString() {
- return item!=null ? item.toString() : "";
- }
- }
- public class OutPlsqlParameter implements PlsqlParameter {
- ItemContainer<?> item;
- public OutPlsqlParameter(ItemContainer<?> item) {
- super();
- this.item = item;
- }
- @Override
- public void setParameter(int parameterIndex, CallableStatement cstm) throws SQLException {
- item.setOutParameter(parameterIndex, cstm);
- }
- @Override
- public ItemContainer<?> getItemFromStatement(int parameterIndex, CallableStatement cstm) throws Exception
- {
- return item.getObjectFromStatement(parameterIndex, cstm);
- }
- @Override
- public String toString() {
- return item!=null ? item.toString() : "";
- }
- }
Add Comment
Please, Sign In to add comment