Home » synapse-1.2-src » org.apache.synapse.mediators.db » [javadoc | source]

    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one
    3    *  or more contributor license agreements.  See the NOTICE file
    4    *  distributed with this work for additional information
    5    *  regarding copyright ownership.  The ASF licenses this file
    6    *  to you under the Apache License, Version 2.0 (the
    7    *  "License"); you may not use this file except in compliance
    8    *  with the License.  You may obtain a copy of the License at
    9    *
   10    *   http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    *  Unless required by applicable law or agreed to in writing,
   13    *  software distributed under the License is distributed on an
   14    *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    *  KIND, either express or implied.  See the License for the
   16    *  specific language governing permissions and limitations
   17    *  under the License.
   18    */
   19   
   20   package org.apache.synapse.mediators.db;
   21   
   22   import org.apache.synapse.MessageContext;
   23   
   24   import java.sql.PreparedStatement;
   25   import java.sql.SQLException;
   26   import java.sql.Connection;
   27   
   28   /**
   29    * A mediator that writes (i.e. inserts one row) to a table using message information
   30    */
   31   public class DBReportMediator extends AbstractDBMediator {
   32   
   33       protected void processStatement(Statement stmnt, MessageContext msgCtx) {
   34   
   35           boolean traceOn = isTraceOn(msgCtx);
   36           boolean traceOrDebugOn = isTraceOrDebugOn(traceOn);
   37   
   38           Connection con = null;
   39           try {
   40               PreparedStatement ps = getPreparedStatement(stmnt, msgCtx);
   41               con = ps.getConnection();
   42               int count = ps.executeUpdate();
   43   
   44               if (count > 0) {
   45                   if (traceOrDebugOn) {
   46                       traceOrDebug(traceOn,
   47                           "Inserted " + count + " row/s using statement : " + stmnt.getRawStatement());
   48                   }
   49               } else {
   50                   if (traceOrDebugOn) {
   51                       traceOrDebug(traceOn,
   52                           "No rows were inserted for statement : " + stmnt.getRawStatement());
   53                   }
   54               }
   55               con.commit();
   56   
   57           } catch (SQLException e) {
   58               handleException("Error execuring insert statement : " + stmnt.getRawStatement() +
   59                   " against DataSource : " + getDSName(), e, msgCtx);
   60           } finally {
   61               if (con != null) {
   62                   try {
   63                       con.close();
   64                   } catch (SQLException ignore) {}
   65               }
   66           }
   67       }
   68   }

Home » synapse-1.2-src » org.apache.synapse.mediators.db » [javadoc | source]