synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asan...@apache.org
Subject svn commit: r577714 - in /webservices/synapse/trunk/java: ./ modules/core/src/main/java/org/apache/synapse/ modules/core/src/main/java/org/apache/synapse/config/xml/ modules/core/src/main/java/org/apache/synapse/core/axis2/ modules/core/src/main/java/o...
Date Thu, 20 Sep 2007 12:20:11 GMT
Author: asankha
Date: Thu Sep 20 05:20:10 2007
New Revision: 577714

URL: http://svn.apache.org/viewvc?rev=577714&view=rev
Log:
refactor DB mediators
Move them to core from extensions
Extract abstract classes to reduce code and complexity
use apache DBCP for DataSource/Connection pooling
TODO - do error handling and logging/tracing

Added:
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBLookupMediatorFactory.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBLookupMediatorSerializer.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBReportMediatorFactory.java
      - copied, changed from r577213, webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/dbreport/DBReportMediatorFactory.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBReportMediatorSerializer.java
      - copied, changed from r577194, webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/dbreport/DBReportMediatorSerializer.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBReportMediator.java
      - copied, changed from r577194, webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/dbreport/DBReportMediator.java
Modified:
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/MessageContext.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBLookupMediator.java
    webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/TestMessageContext.java
    webservices/synapse/trunk/java/pom.xml

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/MessageContext.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/MessageContext.java?rev=577714&r1=577713&r2=577714&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/MessageContext.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/MessageContext.java
Thu Sep 20 05:20:10 2007
@@ -27,6 +27,7 @@
 import org.apache.synapse.config.SynapseConfiguration;
 import org.apache.synapse.core.SynapseEnvironment;
 import org.apache.synapse.endpoints.Endpoint;
+import org.apache.commons.logging.Log;
 
 import java.util.Set;
 import java.util.Stack;
@@ -314,4 +315,9 @@
 
     public void pushFaultHandler(FaultHandler fault);
 
+    /**
+     * Return the service level Log for this message context or null
+     * @return the service level Log for the message
+     */
+    public Log getServiceLog();
 }

Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBLookupMediatorFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBLookupMediatorFactory.java?rev=577714&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBLookupMediatorFactory.java
(added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBLookupMediatorFactory.java
Thu Sep 20 05:20:10 2007
@@ -0,0 +1,63 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.synapse.config.xml;
+
+import org.apache.synapse.Mediator;
+import org.apache.synapse.SynapseConstants;
+import org.apache.synapse.mediators.db.DBLookupMediator;
+import org.apache.axiom.om.OMElement;
+
+import javax.xml.namespace.QName;
+
+/**
+ * <dblookup>
+ *   <connection>
+ *     <pool>
+ *       <driver/>
+ *       <url/>
+ *       <user/>
+ *       <password/>
+ *       <property name="name" value="value"/>*
+ *     </pool>
+ *   </connection>
+ *   <statement>
+ *     <sql>select something from table where something_else = ?</sql>
+ *     <parameter [value="" | expression=""] type="int|string"/>*
+ *     <result name="string" column="int|string"/>*
+ *   </statement>+
+ * </dblookup>
+ */
+public class DBLookupMediatorFactory extends AbstractDBMediatorFactory {
+
+    private static final QName DBLOOKUP_Q =
+        new QName(SynapseConstants.SYNAPSE_NAMESPACE, "dblookup");
+
+    public Mediator createMediator(OMElement elem) {
+
+        DBLookupMediator mediator = new DBLookupMediator();
+        buildDataSource(elem, mediator);
+        processStatements(elem, mediator);
+        return mediator;
+    }
+
+    public QName getTagQName() {
+        return DBLOOKUP_Q;
+    }
+}

Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBLookupMediatorSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBLookupMediatorSerializer.java?rev=577714&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBLookupMediatorSerializer.java
(added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBLookupMediatorSerializer.java
Thu Sep 20 05:20:10 2007
@@ -0,0 +1,76 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.synapse.config.xml;
+
+import org.apache.synapse.config.xml.AbstractMediatorSerializer;
+import org.apache.synapse.Mediator;
+import org.apache.axiom.om.OMElement;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.mediators.db.DBLookupMediator;
+import org.apache.synapse.mediators.db.Statement;
+
+import javax.xml.namespace.QName;
+import java.util.Iterator;
+import java.util.Map;
+import java.sql.Types;
+
+/**
+ * <dblookup>
+ *   <connection>
+ *     <jdbc>
+ *       <driver/>
+ *       <url/>
+ *       <user/>
+ *       <password/>
+ *     </jdbc>
+ *   </connection>
+ *   <query setAttribute="queue_name">
+ *     <sql>select queue from table where device_id = ?</sql>
+ *     <parameter [property="" | xpath=""] type="int|string"/>*
+ *   </query>+
+ * </dblookup>
+ */
+public class DBLookupMediatorSerializer extends AbstractDBMediatorSerializer {
+
+    private static final Log log = LogFactory.getLog(DBLookupMediatorSerializer.class);
+
+    public OMElement serializeMediator(OMElement parent, Mediator m) {
+
+        if (!(m instanceof DBLookupMediator)) {
+            handleException("Unsupported mediator passed in for serialization : " + m.getType());
+        }
+
+        DBLookupMediator mediator = (DBLookupMediator) m;
+        OMElement dbLookup = fac.createOMElement("dblookup", synNS);
+        finalizeSerialization(dbLookup,mediator);
+        serializeDBInformation(mediator, dbLookup);
+
+        if (parent != null) {
+            parent.addChild(dbLookup);
+        }
+        return dbLookup;
+    }
+
+    public String getMediatorClassName() {
+        return DBLookupMediator.class.getName();
+    }
+}

Copied: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBReportMediatorFactory.java
(from r577213, webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/dbreport/DBReportMediatorFactory.java)
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBReportMediatorFactory.java?p2=webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBReportMediatorFactory.java&p1=webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/dbreport/DBReportMediatorFactory.java&r1=577213&r2=577714&rev=577714&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/dbreport/DBReportMediatorFactory.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBReportMediatorFactory.java
Thu Sep 20 05:20:10 2007
@@ -17,161 +17,43 @@
  *  under the License.
  */
 
-package org.apache.synapse.mediators.dbreport;
+package org.apache.synapse.config.xml;
 
-import org.apache.synapse.config.xml.AbstractMediatorFactory;
 import org.apache.synapse.Mediator;
 import org.apache.synapse.SynapseConstants;
-import org.apache.synapse.SynapseException;
-import org.apache.synapse.mediators.dblookup.Query;
+import org.apache.synapse.mediators.db.DBReportMediator;
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMAttribute;
-import org.apache.axiom.om.xpath.AXIOMXPath;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jaxen.JaxenException;
 
 import javax.xml.namespace.QName;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.Iterator;
 
 /**
  * <dbreport>
  *   <connection>
- *     <jdbc>
+ *     <pool>
  *       <driver/>
  *       <url/>
  *       <user/>
  *       <password/>
- *     </jdbc>
+ *       <property name="name" value="value"/>*
+ *     </pool>
  *   </connection>
- *   <insert>
+ *   <statement>
  *     <sql>insert into table values (?, ?, ..)</sql>
- *     <parameter [property="" | xpath=""] type="int|string"/>*
- *   </insert>+
+ *     <parameter [value="" | expression=""] type="int|string"/>*
+ *   </statement>+
  * </dbreport>
  */
-public class DBReportMediatorFactory extends AbstractMediatorFactory {
+public class DBReportMediatorFactory extends AbstractDBMediatorFactory {
 
-    private static final Log log = LogFactory.getLog(DBReportMediatorFactory.class);
-
-    private static final QName DBREPORT_Q = new QName(SynapseConstants.SYNAPSE_NAMESPACE,
"dbreport");
-
-    private static final QName DRIVER_Q   =
-        new QName(org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE, "driver");
-    private static final QName URL_Q      =
-        new QName(org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE, "url");
-    private static final QName USER_Q     =
-        new QName(org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE, "user");
-    private static final QName PASS_Q     =
-        new QName(org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE, "password");
-
-    private static final QName INSERT_Q   =
-        new QName(org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE, "insert");
-    private static final QName SQL_Q      =
-        new QName(org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE, "sql");
-    private static final QName PARAM_Q    =
-        new QName(org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE, "parameter");
-
-    private static final QName PROPERTY_Q = new QName("property");
-    private static final QName XPATH_Q    = new QName("xpath");
-    private static final QName TYPE_Q     = new QName("type");
+    private static final QName DBREPORT_Q =
+        new QName(SynapseConstants.SYNAPSE_NAMESPACE, "dbreport");
 
     public Mediator createMediator(OMElement elem) {
-
         DBReportMediator mediator = new DBReportMediator();
-        Connection conn = null;
-
-        try {
-            AXIOMXPath xpath = new AXIOMXPath("//syn:connection/syn:jdbc");
-            xpath.addNamespace("syn", org.apache.synapse.config.xml.XMLConfigConstants.SYNAPSE_NAMESPACE);
-            OMElement jdbc = (OMElement) xpath.selectSingleNode(elem);
-
-            try {
-                Class.forName(getValue(jdbc, DRIVER_Q));
-                conn = DriverManager.getConnection(
-                            getValue(jdbc, URL_Q), getValue(jdbc, USER_Q), getValue(jdbc,
PASS_Q));
-                mediator.setConn(conn);
-                mediator.addJDBCProperty(DRIVER_Q, getValue(jdbc, DRIVER_Q));
-                mediator.addJDBCProperty(URL_Q,  getValue(jdbc, URL_Q));
-                mediator.addJDBCProperty(USER_Q, getValue(jdbc, USER_Q));
-                mediator.addJDBCProperty(PASS_Q, getValue(jdbc, PASS_Q));
-
-            } catch (SQLException e) {
-                handleException("Error connecting to Database using : " + jdbc, e);
-            } catch (ClassNotFoundException e) {
-                handleException("Error loading JDBC driver using : " + jdbc, e);
-            }
-
-        } catch (JaxenException e) {
-            // in future handle connection pools and data sources, but for now fail if not
jdbc
-            handleException("JDBC Database connection information must be specified");
-        }
-
-        Iterator iter = elem.getChildrenWithName(INSERT_Q);
-        while (iter.hasNext()) {
-
-            OMElement qryElt = (OMElement) iter.next();
-            Query query = new Query();
-
-            try {
-                query.setStatement(conn.prepareStatement(getValue(qryElt, SQL_Q)));
-                query.setRawStatement(getValue(qryElt, SQL_Q));
-            } catch (SQLException e) {
-                handleException("Invalid SQL query for Lookup : " + getValue(qryElt, SQL_Q),
e);
-            }
-
-            Iterator paramIter = qryElt.getChildrenWithName(PARAM_Q);
-            while (paramIter.hasNext()) {
-
-                OMElement paramElt = (OMElement) paramIter.next();
-                try {
-                    query.addParameter(
-                        getAttribute(paramElt, PROPERTY_Q),
-                        getAttribute(paramElt, XPATH_Q),
-                        getAttribute(paramElt, TYPE_Q));
-                } catch (JaxenException e) {
-                    handleException("Invalid XPath expression for query : "
-                        + getAttribute(paramElt, XPATH_Q));
-                }
-            }
-
-            mediator.addQuery(query);
-        }
-
+        buildDataSource(elem, mediator);
+        processStatements(elem, mediator);
         return mediator;
     }
-
-    private String getValue(OMElement elt, QName qName) {
-        OMElement e = elt.getFirstChildWithName(qName);
-        if (e != null) {
-            return e.getText();
-        } else {
-            handleException("Unable to read configuration value for : " + qName);
-        }
-        return null;
-    }
-
-    private String getAttribute(OMElement elt, QName qName) {
-        OMAttribute a = elt.getAttribute(qName);
-        if (a != null) {
-            return a.getAttributeValue();
-        }
-        return null;
-    }
-
-    private void handleException(String msg) {
-        log.error(msg);
-        throw new SynapseException(msg);
-    }
-
-    private void handleException(String msg, Exception e) {
-        log.error(msg, e);
-        throw new SynapseException(msg, e);
-    }
-
 
     public QName getTagQName() {
         return DBREPORT_Q;

Copied: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBReportMediatorSerializer.java
(from r577194, webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/dbreport/DBReportMediatorSerializer.java)
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBReportMediatorSerializer.java?p2=webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBReportMediatorSerializer.java&p1=webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/dbreport/DBReportMediatorSerializer.java&r1=577194&r2=577714&rev=577714&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/dbreport/DBReportMediatorSerializer.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/DBReportMediatorSerializer.java
Thu Sep 20 05:20:10 2007
@@ -17,19 +17,19 @@
  *  under the License.
  */
 
-package org.apache.synapse.mediators.dbreport;
+package org.apache.synapse.config.xml;
 
 import org.apache.synapse.config.xml.AbstractMediatorSerializer;
 import org.apache.synapse.Mediator;
 import org.apache.synapse.SynapseException;
-import org.apache.synapse.mediators.dblookup.Query;
+import org.apache.synapse.mediators.db.Statement;
+import org.apache.synapse.mediators.db.DBReportMediator;
 import org.apache.axiom.om.OMElement;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import javax.xml.namespace.QName;
 import java.util.Iterator;
-import java.util.List;
 import java.sql.Types;
 
 /**
@@ -48,7 +48,7 @@
  *   </insert>+
  * </dbreport>
  */
-public class DBReportMediatorSerializer extends AbstractMediatorSerializer {
+public class DBReportMediatorSerializer extends AbstractDBMediatorSerializer {
 
     private static final Log log = LogFactory.getLog(DBReportMediatorSerializer.class);
 
@@ -59,76 +59,14 @@
         }
 
         DBReportMediator mediator = (DBReportMediator) m;
-        OMElement dbReport = fac.createOMElement("dbreport", synNS);
-        finalizeSerialization(dbReport, mediator);
-
-        // process jdbc info
-        OMElement connElt = fac.createOMElement("connection", synNS);
-        OMElement jdbcElt = fac.createOMElement("jdbc", synNS);
-
-        Iterator iter = mediator.getJdbcProps().keySet().iterator();
-        while (iter.hasNext()) {
-            QName name = (QName) iter.next();
-            OMElement elt = fac.createOMElement(name);
-            elt.setText((String) mediator.getJdbcProps().get(name));
-            jdbcElt.addChild(elt);
-        }
-        connElt.addChild(jdbcElt);
-        dbReport.addChild(connElt);
-
-        // process queries
-        iter = mediator.getQueryList().iterator();
-
-        while (iter.hasNext()) {
-            Query query = (Query) iter.next();
-
-            OMElement insertElt = fac.createOMElement("insert", synNS);
-
-            OMElement sqlElt = fac.createOMElement("sql", synNS);
-            sqlElt.setText(query.getRawStatement());
-            insertElt.addChild(sqlElt);
-
-            for (Iterator it = query.getParameters().iterator(); it.hasNext(); ) {
-
-                Query.Parameter param = (Query.Parameter) it.next();
-                OMElement paramElt = fac.createOMElement("parameter", synNS);
-
-                if (param.getPropertyName() != null) {
-                    paramElt.addAttribute(
-                        fac.createOMAttribute("property", nullNS, param.getPropertyName()));
-                }
-                if (param.getXpath() != null) {
-                    paramElt.addAttribute(
-                        fac.createOMAttribute("xpath", nullNS, param.getXpath().toString()));
-                    super.serializeNamespaces(paramElt, param.getXpath());
-                }
-
-                switch (param.getType()) {
-                    case Types.VARCHAR: {
-                        paramElt.addAttribute(fac.createOMAttribute("type", nullNS, "string"));
-                        break;
-                    }
-                    case Types.INTEGER: {
-                        paramElt.addAttribute(fac.createOMAttribute("type", nullNS, "int"));
-                        break;
-                    }
-                    default:
-                        // TODO handle
-                }
-                insertElt.addChild(paramElt);
-            }
-            dbReport.addChild(insertElt);
-        }
+        OMElement dbReport = fac.createOMElement("dbReport", synNS);
+        finalizeSerialization(dbReport,mediator);
+        serializeDBInformation(mediator, dbReport);
 
         if (parent != null) {
             parent.addChild(dbReport);
         }
         return dbReport;
-    }
-
-    private void handleException(String msg) {
-        log.error(msg);
-        throw new SynapseException(msg);
     }
 
     public String getMediatorClassName() {

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java?rev=577714&r1=577713&r2=577714&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java
Thu Sep 20 05:20:10 2007
@@ -26,8 +26,6 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.SynapseException;
 import org.apache.synapse.Mediator;
-import org.apache.synapse.config.xml.XSLTMediatorFactory;
-import org.apache.synapse.config.xml.ValidateMediatorFactory;
 import org.apache.synapse.config.XMLToObjectMapper;
 import sun.misc.Service;
 
@@ -65,7 +63,9 @@
         ValidateMediatorFactory.class,
         XSLTMediatorFactory.class,
         POJOCommandMediatorFactory.class,
-        CloneMediatorFactory.class
+        CloneMediatorFactory.class,
+        DBReportMediatorFactory.class,
+        DBLookupMediatorFactory.class
     };
 
     private static MediatorFactoryFinder instance = null;

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java?rev=577714&r1=577713&r2=577714&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java
Thu Sep 20 05:20:10 2007
@@ -23,8 +23,6 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.SynapseException;
 import org.apache.synapse.Mediator;
-import org.apache.synapse.config.xml.ValidateMediatorSerializer;
-import org.apache.synapse.config.xml.XSLTMediatorSerializer;
 import sun.misc.Service;
 
 import java.util.HashMap;
@@ -53,7 +51,9 @@
         ValidateMediatorSerializer.class,
         XSLTMediatorSerializer.class,
         POJOCommandMediatorSerializer.class,
-        CloneMediatorSerializer.class
+        CloneMediatorSerializer.class,
+        DBLookupMediatorSerializer.class,
+        DBReportMediatorSerializer.class
     };
 
     private static MediatorSerializerFinder instance = null;

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java?rev=577714&r1=577713&r2=577714&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java
Thu Sep 20 05:20:10 2007
@@ -337,6 +337,19 @@
         this.faultStack.push(fault);
     }
 
+    /**
+     * Return the service level Log for this message context or null
+     * @return the service level Log for the message
+     */
+    public Log getServiceLog() {
+        String serviceName = (String) getProperty(SynapseConstants.PROXY_SERVICE);
+        if (serviceName != null && synCfg.getProxyService(serviceName) != null) {
+            return LogFactory.getLog(SynapseConstants.SERVICE_LOGGER_PREFIX + serviceName);
+        } else {
+            return null;
+        }
+    }
+
     public org.apache.axis2.context.MessageContext getAxis2MessageContext() {
         return axis2MessageContext;
     }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBLookupMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBLookupMediator.java?rev=577714&r1=577713&r2=577714&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBLookupMediator.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBLookupMediator.java
Thu Sep 20 05:20:10 2007
@@ -17,93 +17,65 @@
  *  under the License.
  */
 
-package org.apache.synapse.mediators.dblookup;
+package org.apache.synapse.mediators.db;
 
-import org.apache.synapse.mediators.AbstractMediator;
 import org.apache.synapse.MessageContext;
-import org.apache.synapse.ManagedLifecycle;
-import org.apache.synapse.core.SynapseEnvironment;
 import org.apache.synapse.core.axis2.Axis2MessageContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import javax.xml.namespace.QName;
 import java.sql.*;
 import java.util.*;
 
 /**
  * Simple database table lookup mediator. Designed only for read/lookup
  */
-public class DBLookupMediator extends AbstractMediator implements ManagedLifecycle {
+public class DBLookupMediator extends AbstractDBMediator {
 
     private static final Log log = LogFactory.getLog(DBLookupMediator.class);
 
-    /** Hold JDBC properties */
-    private Map jdbcProps = new HashMap();
-    /** The connection to the database */
-    Connection conn = null;
-    /** Query map */
-    Map queryMap = new HashMap();
     /** Result cache */
     Map cacheMap = new HashMap();
 
-    public boolean mediate(MessageContext msgCtx) {
-
-        for (Iterator iter = queryMap.keySet().iterator(); iter.hasNext(); ) {
-            processQuery((String) iter.next(), msgCtx);
-        }
-        return true;
-    }
-
-    private void processQuery(String attName, MessageContext msgCtx) {
+    protected void processStatement(Statement stmnt, MessageContext msgCtx) {
 
+/*
         // if available in cache, serve from cache and return
         String result = (String) cacheMap.get(attName);
         if (result != null) {
             msgCtx.setProperty(attName, result);
             return;
         }
-
-        Query query = (Query) queryMap.get(attName);
-
+*/
+        // execute the prepared statement, and extract the first result row and
+        // set as message context properties, any results that have been specified
         try {
-            PreparedStatement ps = query.getStatement();
+            PreparedStatement ps = getPreparedStatement(stmnt, msgCtx);
+            ResultSet rs = ps.executeQuery();
 
-            // set parameters if any
-            List params = query.getParameters();
-            int column = 1;
-            for (Iterator pi = params.iterator(); pi.hasNext(); ) {
-                Query.Parameter param = (Query.Parameter) pi.next();
-                switch (param.getType()) {
-                    case Types.VARCHAR: {
-                        ps.setString(column++,
-                            param.getPropertyName() != null ?
-                                (String) msgCtx.getProperty(param.getPropertyName()) :
-                                Axis2MessageContext.getStringValue(param.getXpath(), msgCtx));
-                        break;
-                    }
-                    case Types.INTEGER: {
-                        ps.setInt(column++,
-                            Integer.parseInt(param.getPropertyName() != null ?
-                                (String) msgCtx.getProperty(param.getPropertyName()) :
-                                Axis2MessageContext.getStringValue(param.getXpath(), msgCtx)));
-                        break;
+            if (rs.next()) {
+                Iterator propNameIter = stmnt.getResultsMap().keySet().iterator();
+                while (propNameIter.hasNext()) {
+                    String propName = (String) propNameIter.next();
+                    String columnStr = (String) stmnt.getResultsMap().get(propName);
+
+                    Object obj = null;
+                    try {
+                        int colNum = Integer.parseInt(columnStr);
+                        obj = rs.getObject(colNum);
+                    } catch (NumberFormatException ignore) {
+                        obj = rs.getObject(columnStr);
                     }
-                    default: {
+
+                    if (obj != null) {
+                        msgCtx.setProperty(propName, obj.toString());
+                        cacheMap.put(propName, obj.toString());
+                    } else {
                         // todo handle this
                     }
                 }
-            }
-
-            ResultSet rs = ps.executeQuery();
-            if (rs.next()) {
-                Object obj = rs.getObject(1);
-                if (obj != null) {
-                    msgCtx.setProperty(attName, obj.toString());
-                    cacheMap.put(attName, obj.toString());
-                } else {
-                    // todo handle this
-                }
+            } else {
+                // todo
             }
         } catch (SQLException e) {
             // todo handle this
@@ -111,37 +83,4 @@
         }
     }
 
-    public void init(SynapseEnvironment se) {
-        // establish database connection
-    }
-
-    public void destroy() {
-        // disconnect from the database
-        log.debug("Shutting down database connection of the DB Lookup mediator");
-        try {
-            conn.close();
-        } catch (SQLException e) {
-            log.warn("Error shutting down the database connection", e);
-        }
-    }
-
-    public void setConn(Connection conn) {
-        this.conn = conn;
-    }
-
-    public void addQuery(String name, Query q) {
-        queryMap.put(name, q);
-    }
-
-    public void addJDBCProperty(QName name, String value) {
-        jdbcProps.put(name, value);
-    }
-
-    public Map getJdbcProps() {
-        return jdbcProps;
-    }
-
-    public Map getQueryMap() {
-        return queryMap;
-    }
 }

Copied: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBReportMediator.java
(from r577194, webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/dbreport/DBReportMediator.java)
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBReportMediator.java?p2=webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBReportMediator.java&p1=webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/dbreport/DBReportMediator.java&r1=577194&r2=577714&rev=577714&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/dbreport/DBReportMediator.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBReportMediator.java
Thu Sep 20 05:20:10 2007
@@ -17,70 +17,25 @@
  *  under the License.
  */
 
-package org.apache.synapse.mediators.dbreport;
+package org.apache.synapse.mediators.db;
 
-import org.apache.synapse.mediators.AbstractMediator;
-import org.apache.synapse.mediators.dblookup.Query;
-import org.apache.synapse.ManagedLifecycle;
+import org.apache.synapse.mediators.db.Statement;
 import org.apache.synapse.MessageContext;
-import org.apache.synapse.core.SynapseEnvironment;
 import org.apache.synapse.core.axis2.Axis2MessageContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import javax.xml.namespace.QName;
 import java.util.*;
 import java.sql.*;
 
-public class DBReportMediator extends AbstractMediator implements ManagedLifecycle {
+public class DBReportMediator extends AbstractDBMediator {
 
     private static final Log log = LogFactory.getLog(DBReportMediator.class);
 
-    /** Hold JDBC properties */
-    private Map jdbcProps = new HashMap();
-    /** The connection to the database */
-    Connection conn = null;
-    /** Query map */
-    List queryList = new ArrayList();
-
-    public boolean mediate(MessageContext msgCtx) {
-        for (Iterator iter = queryList.iterator(); iter.hasNext(); ) {
-            processQuery((Query) iter.next(), msgCtx);
-        }
-        return true;
-    }
-
-    private void processQuery(Query query, MessageContext msgCtx) {
+    protected void processStatement(Statement stmnt, MessageContext msgCtx) {
 
         try {
-            PreparedStatement ps = query.getStatement();
-
-            // set parameters if any
-            List params = query.getParameters();
-            int column = 1;
-            for (Iterator pi = params.iterator(); pi.hasNext(); ) {
-                Query.Parameter param = (Query.Parameter) pi.next();
-                switch (param.getType()) {
-                    case Types.VARCHAR: {
-                        ps.setString(column++,
-                            param.getPropertyName() != null ?
-                                (String) msgCtx.getProperty(param.getPropertyName()) :
-                                Axis2MessageContext.getStringValue(param.getXpath(), msgCtx));
-                        break;
-                    }
-                    case Types.INTEGER: {
-                        ps.setInt(column++,
-                            Integer.parseInt(param.getPropertyName() != null ?
-                                (String) msgCtx.getProperty(param.getPropertyName()) :
-                                Axis2MessageContext.getStringValue(param.getXpath(), msgCtx)));
-                        break;
-                    }
-                    default: {
-                        // todo handle this
-                    }
-                }
-            }
-
+            PreparedStatement ps = getPreparedStatement(stmnt, msgCtx);
             if (ps.executeUpdate() > 0) {
                 if (log.isDebugEnabled()) {
                     log.debug("Added a row to the table");
@@ -90,39 +45,5 @@
             // todo handle this
             e.printStackTrace();
         }
-    }
-
-    public void init(SynapseEnvironment se) {
-        // establish database connection
-    }
-
-    public void destroy() {
-        // disconnect from the database
-        log.debug("Shutting down database connection of the DB Report mediator");
-        try {
-            conn.close();
-        } catch (SQLException e) {
-            log.warn("Error shutting down the database connection", e);
-        }
-    }
-
-    public void setConn(Connection conn) {
-        this.conn = conn;
-    }
-
-    public void addQuery(Query q) {
-        queryList.add(q);
-    }
-
-    public void addJDBCProperty(QName name, String value) {
-        jdbcProps.put(name, value);
-    }
-
-    public Map getJdbcProps() {
-        return jdbcProps;
-    }
-
-    public List getQueryList() {
-        return queryList;
     }
 }

Modified: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/TestMessageContext.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/TestMessageContext.java?rev=577714&r1=577713&r2=577714&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/TestMessageContext.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/TestMessageContext.java
Thu Sep 20 05:20:10 2007
@@ -28,6 +28,7 @@
 import org.apache.synapse.config.SynapseConfiguration;
 import org.apache.synapse.core.SynapseEnvironment;
 import org.apache.synapse.endpoints.Endpoint;
+import org.apache.commons.logging.Log;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -260,6 +261,10 @@
 
     public void pushFaultHandler(FaultHandler fault) {
         faultStack.push(fault);
+    }
+
+    public Log getServiceLog() {
+        return null;
     }
 
     public MessageContext getSynapseContext() {

Modified: webservices/synapse/trunk/java/pom.xml
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/pom.xml?rev=577714&r1=577713&r2=577714&view=diff
==============================================================================
--- webservices/synapse/trunk/java/pom.xml (original)
+++ webservices/synapse/trunk/java/pom.xml Thu Sep 20 05:20:10 2007
@@ -334,6 +334,17 @@
             </dependency>
 
             <dependency>
+                <groupId>commons-dbcp</groupId>
+                <artifactId>commons-dbcp</artifactId>
+                <version>${commons.dbcp.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>commons-pool</groupId>
+                <artifactId>commons-pool</artifactId>
+                <version>${commons.pool.version}</version>
+            </dependency>
+
+            <dependency>
                 <groupId>wsdl4j</groupId>
                 <artifactId>wsdl4j</artifactId>
                 <version>${wsdl4j.version}</version>
@@ -554,6 +565,16 @@
             <artifactId>js</artifactId>
             <version>${js.version}</version>
         </dependency>
+        <dependency>
+            <groupId>commons-dbcp</groupId>
+            <artifactId>commons-dbcp</artifactId>
+            <version>${commons.dbcp.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-pool</groupId>
+            <artifactId>commons-pool</artifactId>
+            <version>${commons.pool.version}</version>
+        </dependency>
 
         <!-- dependencies for transports module -->
         <dependency>
@@ -883,6 +904,8 @@
         <synapse.version>SNAPSHOT</synapse.version>
         <httpcore.nio.version>4.0-alpha6-SNAPSHOT</httpcore.nio.version>
         <jms.spec.version>1.0</jms.spec.version>
+        <commons.dbcp.version>1.2.2</commons.dbcp.version>
+        <commons.pool.version>1.3</commons.pool.version>
         <commons.vfs.version>1.0</commons.vfs.version>
         <commons.net.version>1.4.1</commons.net.version>
         <jsch.version>0.1.31</jsch.version>



---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org


Mime
View raw message