Package org.apache.synapse.mediators.db
Class AbstractDBMediator
- java.lang.Object
-
- org.apache.synapse.mediators.AbstractMediator
-
- 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
Constructors Constructor Description AbstractDBMediator()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addDataSourceProperty(String name, String value)
void
addDataSourceProperty(QName name, String value)
void
addStatement(Statement stmnt)
protected abstract void
closeConnection(long key)
Close the connection of the current thread idprotected DataSource
createCustomDataSource(org.apache.synapse.commons.datasource.DataSourceInformation dataSourceInformation)
Create a custom DataSource using the specified data source information.void
destroy()
Destroys the mediator.DataSource
getDataSource()
Map<Object,String>
getDataSourceProps()
org.apache.synapse.commons.datasource.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 onlyprotected PreparedStatement
getPreparedStatement(Statement stmnt, Connection con, MessageContext msgCtx)
Return a Prepared statement for the given Statement object, which is ready to be executedList<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
isRegistryBasedDriverConfig()
boolean
isRegistryBasedPassConfig()
boolean
isRegistryBasedUrlConfig()
boolean
isRegistryBasedUserConfig()
boolean
mediate(MessageContext synCtx)
Process each SQL statement against the current messageprotected abstract void
processStatement(Statement query, MessageContext msgCtx)
Subclasses must specify how each SQL statement is processedvoid
setDataSource(DataSource dataSource)
void
setDataSourceInformation(org.apache.synapse.commons.datasource.DataSourceInformation dataSourceInformation)
void
setDataSourceName(String dataSourceName)
void
setDbPoolView(org.apache.synapse.commons.datasource.DBPoolView dbPoolView)
void
setJndiProperties(Properties jndiProperties)
void
setRegistryBasedDriverConfig(boolean registryBasedDriverConfig)
void
setRegistryBasedPassConfig(boolean registryBasedPassConfig)
void
setRegistryBasedUrlConfig(boolean registryBasedUrlConfig)
void
setRegistryBasedUserConfig(boolean registryBasedUserConfig)
-
Methods inherited from class org.apache.synapse.mediators.AbstractMediator
auditLog, auditWarn, configure, disableStatistics, disableTracing, divertMediationRoute, enableStatistics, enableTracing, getAspectConfiguration, getCommentsList, getDescription, getInputType, getLastSequenceFaultHandler, getLog, getMediatorName, getMediatorPosition, getOutputType, getRegisteredMediationFlowPoint, getShortDescription, getTraceState, getType, handleException, handleException, isBreakPoint, isContentAltering, isContentAware, isSkipEnabled, isStatisticsEnable, isTraceOn, isTraceOrDebugOn, isTracingEnabled, registerMediationFlowPoint, reportCloseStatistics, reportOpenStatistics, setBreakPoint, setCommentsList, setComponentStatisticsId, setDescription, setEffectiveTraceState, setMediatorPosition, setShortDescription, setSkipEnabled, setTraceState, shouldCaptureTracing, shouldTrace, shouldTrace, traceOrDebug, traceOrDebugWarn, unregisterMediationFlowPoint
-
-
-
-
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 interfaceManagedLifecycle
- 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 interfaceManagedLifecycle
-
mediate
public boolean mediate(MessageContext synCtx)
Process each SQL statement against the current message
-
processStatement
protected abstract void processStatement(Statement query, MessageContext msgCtx)
Subclasses must specify how each SQL statement is processed- Parameters:
query
- the SQL statementmsgCtx
- current message
-
closeConnection
protected abstract void closeConnection(long key)
Close the connection of the current thread id- Parameters:
key
- current thread id
-
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(org.apache.synapse.commons.datasource.DataSourceInformation dataSourceInformation)
-
setJndiProperties
public void setJndiProperties(Properties jndiProperties)
-
getDataSource
public DataSource getDataSource()
-
setDataSource
public void setDataSource(DataSource dataSource)
-
setDataSourceName
public void setDataSourceName(String dataSourceName)
-
addStatement
public void addStatement(Statement stmnt)
-
getDbPoolView
public org.apache.synapse.commons.datasource.DBPoolView getDbPoolView()
-
setDbPoolView
public void setDbPoolView(org.apache.synapse.commons.datasource.DBPoolView dbPoolView)
-
getPreparedStatement
protected PreparedStatement getPreparedStatement(Statement stmnt, Connection con, 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 executedcon
- The connection to be usedmsgCtx
- Current message context- Returns:
- a PreparedStatement
- Throws:
SQLException
- on error
-
createCustomDataSource
protected DataSource createCustomDataSource(org.apache.synapse.commons.datasource.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)
-
isRegistryBasedDriverConfig
public boolean isRegistryBasedDriverConfig()
-
setRegistryBasedDriverConfig
public void setRegistryBasedDriverConfig(boolean registryBasedDriverConfig)
-
isRegistryBasedUrlConfig
public boolean isRegistryBasedUrlConfig()
-
setRegistryBasedUrlConfig
public void setRegistryBasedUrlConfig(boolean registryBasedUrlConfig)
-
isRegistryBasedUserConfig
public boolean isRegistryBasedUserConfig()
-
setRegistryBasedUserConfig
public void setRegistryBasedUserConfig(boolean registryBasedUserConfig)
-
isRegistryBasedPassConfig
public boolean isRegistryBasedPassConfig()
-
setRegistryBasedPassConfig
public void setRegistryBasedPassConfig(boolean registryBasedPassConfig)
-
-