org.apache.synapse.mediators.db
Class AbstractDBMediator

java.lang.Object
  extended by org.apache.synapse.mediators.AbstractMediator
      extended by org.apache.synapse.mediators.db.AbstractDBMediator
All Implemented Interfaces:
AspectConfigurable, ManagedLifecycle, Mediator, SynapseArtifact
Direct Known Subclasses:
DBLookupMediator, DBReportMediator

public abstract class AbstractDBMediator
extends AbstractMediator
implements ManagedLifecycle

This abstract DB mediator will perform common DB connection pooling etc. for all DB mediators


Field Summary
 
Fields inherited from class org.apache.synapse.mediators.AbstractMediator
log, trace, traceState
 
Constructor Summary
AbstractDBMediator()
           
 
Method Summary
 void addDataSourceProperty(QName name, String value)
           
 void addDataSourceProperty(String name, String value)
           
 void addStatement(Statement stmnt)
           
protected  DataSource createCustomDataSource(DataSourceInformation dataSourceInformation)
          Create a custom DataSource using the specified data source information.
 void destroy()
          Destroys the mediator.
 DataSource getDataSource()
           
 Map<Object,String> getDataSourceProps()
           
 DBPoolView getDbPoolView()
           
protected  String getDSName()
          Return the name or (hopefully) unique connection URL specific to the DataSource being used This is used for logging purposes only
protected  PreparedStatement getPreparedStatement(Statement stmnt, MessageContext msgCtx)
          Return a Prepared statement for the given Statement object, which is ready to be executed
 List<Statement> getStatementList()
           
protected  void handleException(String message)
           
 void init(SynapseEnvironment se)
          Initializes the mediator - either an existing data source will be looked up from an in- or external JNDI provider or a custom data source will be created based on the provide configuration (using Apache DBCP).
 boolean mediate(MessageContext synCtx)
          Process each SQL statement against the current message
protected abstract  void processStatement(Statement query, MessageContext msgCtx)
          Subclasses must specify how each SQL statement is processed
 void setDataSource(DataSource dataSource)
           
 void setDataSourceInformation(DataSourceInformation dataSourceInformation)
           
 void setDataSourceName(String dataSourceName)
           
 void setDbPoolView(DBPoolView dbPoolView)
           
 void setJndiProperties(Properties jndiProperties)
           
 
Methods inherited from class org.apache.synapse.mediators.AbstractMediator
auditLog, auditWarn, configure, disableStatistics, enableStatistics, getAspectConfiguration, getDescription, getLog, getTraceState, getType, handleException, handleException, isStatisticsEnable, isTraceOn, isTraceOrDebugOn, setDescription, setEffectiveTraceState, setTraceState, shouldTrace, traceOrDebug, traceOrDebugWarn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDBMediator

public AbstractDBMediator()
Method Detail

init

public void init(SynapseEnvironment se)
Initializes the mediator - either an existing data source will be looked up from an in- or external JNDI provider or a custom data source will be created based on the provide configuration (using Apache DBCP).

Specified by:
init in interface ManagedLifecycle
Parameters:
se - the Synapse environment reference

destroy

public void destroy()
Destroys the mediator. If we are using our custom DataSource, then shut down the connections

Specified by:
destroy in interface ManagedLifecycle

mediate

public boolean mediate(MessageContext synCtx)
Process each SQL statement against the current message

Specified by:
mediate in interface Mediator
Parameters:
synCtx - the current message
Returns:
true, always

processStatement

protected abstract void processStatement(Statement query,
                                         MessageContext msgCtx)
Subclasses must specify how each SQL statement is processed

Parameters:
query - the SQL statement
msgCtx - current message

getDSName

protected String getDSName()
Return the name or (hopefully) unique connection URL specific to the DataSource being used This is used for logging purposes only

Returns:
a unique name or URL to refer to the DataSource being used

setDataSourceInformation

public void setDataSourceInformation(DataSourceInformation dataSourceInformation)

setJndiProperties

public void setJndiProperties(Properties jndiProperties)

getDataSource

public DataSource getDataSource()

setDataSource

public void setDataSource(DataSource dataSource)

setDataSourceName

public void setDataSourceName(String dataSourceName)

addDataSourceProperty

public void addDataSourceProperty(QName name,
                                  String value)

addDataSourceProperty

public void addDataSourceProperty(String name,
                                  String value)

addStatement

public void addStatement(Statement stmnt)

getStatementList

public List<Statement> getStatementList()

getDbPoolView

public DBPoolView getDbPoolView()

setDbPoolView

public void setDbPoolView(DBPoolView dbPoolView)

getPreparedStatement

protected PreparedStatement getPreparedStatement(Statement stmnt,
                                                 MessageContext msgCtx)
                                          throws SQLException
Return a Prepared statement for the given Statement object, which is ready to be executed

Parameters:
stmnt - SQL stataement to be executed
msgCtx - Current message context
Returns:
a PreparedStatement
Throws:
SQLException - on error

createCustomDataSource

protected DataSource createCustomDataSource(DataSourceInformation dataSourceInformation)
Create a custom DataSource using the specified data source information.

Parameters:
dataSourceInformation - the data source information to create a data source
Returns:
a DataSource created using specified properties

handleException

protected void handleException(String message)

getDataSourceProps

public Map<Object,String> getDataSourceProps()


Copyright © 2005-2012 Apache Software Foundation. All Rights Reserved.