Author: hiranya
Date: Sun Sep 26 07:20:32 2010
New Revision: 1001374
URL: http://svn.apache.org/viewvc?rev=1001374&view=rev
Log:
Fixing a bug related to data sources in DB mediators
- Added test cases
- Fixed sample 363
- Updated docs
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/AbstractDBMediator.java
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/DBLookupMediatorSerializationTest.java
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/DBReportMediatorSerializationTest.java
synapse/trunk/java/src/site/xdoc/Synapse_Configuration_Language.xml
synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java?rev=1001374&r1=1001373&r2=1001374&view=diff
==============================================================================
---
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java
(original)
+++
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java
Sun Sep 26 07:20:32 2010
@@ -102,18 +102,18 @@ public abstract class AbstractDBMediator
static final QName ATT_COLUMN = new QName("column");
static final QName ATT_TYPE = new QName("type");
-
+
/**
* Reads the data source configuration for all mediators based on the
<code>AbstractDBMediator</code>
* and stores the configuration in the mediator for datasource
initialization and de-serialization.
- *
+ *
* @param elem the configuration element of the mediator
* @param mediator the mediator on which the configuration shall be stored
*/
protected void buildDataSource(OMElement elem, AbstractDBMediator
mediator) {
OMElement pool;
-
+
try {
// get the 'pool' element and determine if we need to create a
DataSource or
// lookup using JNDI
@@ -134,34 +134,18 @@ public abstract class AbstractDBMediator
}
private void readLookupConfig(AbstractDBMediator mediator, OMElement pool)
{
- DataSourceInformation dataSourceInformation = new
DataSourceInformation();
- dataSourceInformation.setUrl(getValue(pool, URL_Q));
String dataSourceName = getValue(pool, DSNAME_Q);
mediator.setDataSourceName(dataSourceName);
saveElementConfig(pool, DSNAME_Q, mediator);
- SecretInformation secretInformation = new SecretInformation();
- secretInformation.setUser(getValue(pool, USER_Q));
- secretInformation.setAliasSecret(getValue(pool, PASS_Q));
- dataSourceInformation.setSecretInformation(secretInformation);
- Iterator poolPropIter = pool.getChildrenWithName(PROP_Q);
- if(poolPropIter != null){
- while (poolPropIter.hasNext()){
- OMElement poolProp = (OMElement) poolPropIter.next();
- readPoolProperty(mediator, dataSourceInformation, poolProp);
- }
- }
- mediator.setDataSourceInformation(dataSourceInformation);
-
if (pool.getFirstChildWithName(ICCLASS_Q) != null) {
-
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, getValue(pool,
ICCLASS_Q));
props.put(Context.PROVIDER_URL, getValue(pool, URL_Q));
props.put(Context.SECURITY_PRINCIPAL, getValue(pool, USER_Q));
props.put(Context.SECURITY_CREDENTIALS, getValue(pool, PASS_Q));
mediator.setJndiProperties(props);
-
+
// Save element configuration for later de-serialization
saveElementConfig(pool, ICCLASS_Q, mediator);
saveElementConfig(pool, URL_Q, mediator);
@@ -172,37 +156,37 @@ public abstract class AbstractDBMediator
private void readCustomDataSourceConfig(OMElement pool, AbstractDBMediator
mediator) {
- DataSourceInformation dataSourceInformation = new
DataSourceInformation();
+ DataSourceInformation dataSourceInformation = new
DataSourceInformation();
- dataSourceInformation.setDriver(getValue(pool, DRIVER_Q));
- dataSourceInformation.setUrl(getValue(pool, URL_Q));
-
- SecretInformation secretInformation = new SecretInformation();
- secretInformation.setUser(getValue(pool, USER_Q));
- secretInformation.setAliasSecret(getValue(pool, PASS_Q));
- dataSourceInformation.setSecretInformation(secretInformation);
+ dataSourceInformation.setDriver(getValue(pool, DRIVER_Q));
+ dataSourceInformation.setUrl(getValue(pool, URL_Q));
- // Save element configuration for later de-serialization
- saveElementConfig(pool, DRIVER_Q, mediator);
- saveElementConfig(pool, URL_Q, mediator);
- saveElementConfig(pool, USER_Q, mediator);
- saveElementConfig(pool, PASS_Q, mediator);
-
- Iterator poolPropIter = pool.getChildrenWithName(PROP_Q);
- while (poolPropIter.hasNext()) {
- OMElement poolProp = (OMElement) poolPropIter.next();
- readPoolProperty(mediator, dataSourceInformation, poolProp);
- }
+ SecretInformation secretInformation = new SecretInformation();
+ secretInformation.setUser(getValue(pool, USER_Q));
+ secretInformation.setAliasSecret(getValue(pool, PASS_Q));
+ dataSourceInformation.setSecretInformation(secretInformation);
- mediator.setDataSourceInformation(dataSourceInformation);
+ // Save element configuration for later de-serialization
+ saveElementConfig(pool, DRIVER_Q, mediator);
+ saveElementConfig(pool, URL_Q, mediator);
+ saveElementConfig(pool, USER_Q, mediator);
+ saveElementConfig(pool, PASS_Q, mediator);
+
+ Iterator poolPropIter = pool.getChildrenWithName(PROP_Q);
+ while (poolPropIter.hasNext()) {
+ OMElement poolProp = (OMElement) poolPropIter.next();
+ readPoolProperty(mediator, dataSourceInformation, poolProp);
+ }
+
+ mediator.setDataSourceInformation(dataSourceInformation);
}
private void readPoolProperty(AbstractDBMediator mediator,
DataSourceInformation dataSourceInformation,
- OMElement prop) {
+ OMElement prop) {
String name = prop.getAttribute(ATT_NAME).getAttributeValue();
String value = prop.getAttribute(ATT_VALUE).getAttributeValue();
mediator.addDataSourceProperty(name, value);
-
+
if ("autocommit".equals(name)) {
if ("true".equals(value)) {
dataSourceInformation.setDefaultAutoCommit(true);
@@ -347,7 +331,7 @@ public abstract class AbstractDBMediator
}
return null;
}
-
+
private void saveElementConfig(OMElement element, QName qname,
AbstractDBMediator mediator) {
mediator.addDataSourceProperty(qname, getValue(element, qname));
}
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/AbstractDBMediator.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/AbstractDBMediator.java?rev=1001374&r1=1001373&r2=1001374&view=diff
==============================================================================
---
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/AbstractDBMediator.java
(original)
+++
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/AbstractDBMediator.java
Sun Sep 26 07:20:32 2010
@@ -142,11 +142,16 @@ public abstract class AbstractDBMediator
* @return a unique name or URL to refer to the DataSource being used
*/
protected String getDSName() {
- String name = dataSourceInformation.getUrl();
- if (name == null) {
- name = dataSourceInformation.getDatasourceName();
+ if (dataSourceName != null) {
+ return dataSourceName;
+ } else if (dataSourceInformation != null) {
+ String name = dataSourceInformation.getUrl();
+ if (name == null) {
+ name = dataSourceInformation.getDatasourceName();
+ }
+ return name;
}
- return name;
+ return null;
}
public void setDataSourceInformation(DataSourceInformation
dataSourceInformation) {
@@ -195,10 +200,10 @@ public abstract class AbstractDBMediator
/**
* Return a Prepared statement for the given Statement object, which is
ready to be executed
- * @param stmnt
- * @param msgCtx
- * @return
- * @throws SQLException
+ * @param stmnt SQL stataement to be executed
+ * @param msgCtx Current message context
+ * @return a PreparedStatement
+ * @throws SQLException on error
*/
protected PreparedStatement getPreparedStatement(Statement stmnt,
MessageContext msgCtx)
throws SQLException {
@@ -355,8 +360,8 @@ public abstract class AbstractDBMediator
dataSource = finder.find(dataSourceName);
}
- if(dataSource == null){
- // decrypt the password if needed
+ if (dataSource == null) {
+ // decrypt the password if needed
String password =
jndiProperties.getProperty(Context.SECURITY_CREDENTIALS);
if (password != null && !"".equals(password)) {
jndiProperties.put(Context.SECURITY_CREDENTIALS,
getActualPassword(password));
@@ -369,12 +374,13 @@ public abstract class AbstractDBMediator
" properties :" + jndiProperties);
}
}
+
MBeanRepository mBeanRepository =
DatasourceMBeanRepository.getInstance();
Object mBean = mBeanRepository.getMBean(dataSourceName);
if (mBean instanceof DBPoolView) {
setDbPoolView((DBPoolView) mBean);
}
- log.info("Sunccessfully looked up datasource " + dataSourceName + ".");
+ log.info("Successfully looked up datasource " + dataSourceName + ".");
return dataSource;
}
@@ -390,7 +396,7 @@ public abstract class AbstractDBMediator
DataSource dataSource =
DataSourceFactory.createDataSource(dataSourceInformation);
if (dataSource != null) {
- log.info("Sunccessfully created data source for " +
dataSourceInformation.getUrl() + ".");
+ log.info("Successfully created data source for " +
dataSourceInformation.getUrl() + ".");
}
return dataSource;
Modified:
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/DBLookupMediatorSerializationTest.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/DBLookupMediatorSerializationTest.java?rev=1001374&r1=1001373&r2=1001374&view=diff
==============================================================================
---
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/DBLookupMediatorSerializationTest.java
(original)
+++
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/DBLookupMediatorSerializationTest.java
Sun Sep 26 07:20:32 2010
@@ -46,4 +46,38 @@ public class DBLookupMediatorSerializati
assertTrue(serialization(inputXml, dbLookupFactory,
dbLookupSerializer));
assertTrue(serialization(inputXml, dbLookupSerializer));
}
+
+ public void testDBLookupMediatorSerializationScenarioTwo() throws
Exception {
+
+ String inputXml =
+ "<syn:dblookup
xmlns:syn=\"http://synapse.apache.org/ns/2010/04/configuration\">" +
+
"<syn:connection><syn:pool><syn:dsName>lookupdb</syn:dsName>" +
+ "</syn:pool></syn:connection><syn:statement><syn:sql>" +
+ "<![CDATA[insert into table values (?, ?,
..)]]></syn:sql>" +
+ "<syn:parameter value=\"ABC\" type=\"VARCHAR\"/>" +
+ "<syn:parameter expression=\"4\" type=\"INTEGER\"/>" +
+ "<syn:result name=\"2\"
column=\"int\"/></syn:statement></syn:dblookup>";
+
+ assertTrue(serialization(inputXml, dbLookupFactory,
dbLookupSerializer));
+ assertTrue(serialization(inputXml, dbLookupSerializer));
+ }
+
+ public void testDBLookupMediatorSerializationScenarioThree() throws
Exception {
+
+ String inputXml =
+ "<syn:dblookup
xmlns:syn=\"http://synapse.apache.org/ns/2010/04/configuration\">" +
+
"<syn:connection><syn:pool><syn:dsName>lookupdb</syn:dsName>" +
+
"<syn:icClass>com.sun.jndi.rmi.registry.RegistryContextFactory</syn:icClass>" +
+ "<syn:url>rmi://localhost:2199</syn:url>" +
+ "<syn:user>user</syn:user>" +
+ "<syn:password>password</syn:password>" +
+ "</syn:pool></syn:connection><syn:statement><syn:sql>" +
+ "<![CDATA[insert into table values (?, ?,
..)]]></syn:sql>" +
+ "<syn:parameter value=\"ABC\" type=\"VARCHAR\"/>" +
+ "<syn:parameter expression=\"4\" type=\"INTEGER\"/>" +
+ "<syn:result name=\"2\"
column=\"int\"/></syn:statement></syn:dblookup>";
+
+ assertTrue(serialization(inputXml, dbLookupFactory,
dbLookupSerializer));
+ assertTrue(serialization(inputXml, dbLookupSerializer));
+ }
}
Modified:
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/DBReportMediatorSerializationTest.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/DBReportMediatorSerializationTest.java?rev=1001374&r1=1001373&r2=1001374&view=diff
==============================================================================
---
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/DBReportMediatorSerializationTest.java
(original)
+++
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/DBReportMediatorSerializationTest.java
Sun Sep 26 07:20:32 2010
@@ -59,4 +59,17 @@ public class DBReportMediatorSerializati
assertTrue(serialization(inputXml, dbReportMediatorFactory,
dbReportMediatorSerializer));
assertTrue(serialization(inputXml, dbReportMediatorSerializer));
}
+
+ public void testDBReportMediatorSerializationWithExternalDataSource2()
throws Exception {
+ String inputXml = "<dbreport
xmlns=\"http://synapse.apache.org/ns/2010/04/configuration\">" +
+ "<connection><pool>" +
+ "<dsName>DataServiceName</dsName></pool>" +
+ "</connection><statement><sql><![CDATA[update
company set price=? " +
+ "where name =?]]></sql><parameter
expression=\"//m0:return/m0:last/child::text()\" " +
+ "xmlns:m0=\"http://services.samples/xsd\"
type=\"DOUBLE\"/><parameter " +
+ "expression=\"//m0:return/m0:symbol/child::text()\"
" +
+ "xmlns:m0=\"http://services.samples/xsd\"
type=\"VARCHAR\"/></statement></dbreport>";
+ assertTrue(serialization(inputXml, dbReportMediatorFactory,
dbReportMediatorSerializer));
+ assertTrue(serialization(inputXml, dbReportMediatorSerializer));
+ }
}
\ No newline at end of file
Modified: synapse/trunk/java/src/site/xdoc/Synapse_Configuration_Language.xml
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/src/site/xdoc/Synapse_Configuration_Language.xml?rev=1001374&r1=1001373&r2=1001374&view=diff
==============================================================================
--- synapse/trunk/java/src/site/xdoc/Synapse_Configuration_Language.xml
(original)
+++ synapse/trunk/java/src/site/xdoc/Synapse_Configuration_Language.xml Sun Sep
26 07:20:32 2010
@@ -1739,6 +1739,9 @@ where "sequence/dynamic_seq_1.xml" refer
<url/>
<user/>
<password/>
+ <property name="name" value="value"/>*
+ |
+ <dsName/>
|
<dsName/>
<icClass/>
@@ -1746,7 +1749,6 @@ where "sequence/dynamic_seq_1.xml" refer
<user/>
<password/>
)
- <property name="name" value="value"/>*
</pool>
</connection>
<statement>
@@ -1830,6 +1832,9 @@ where "sequence/dynamic_seq_1.xml" refer
<url/>
<user/>
<password/>
+ <property name="name" value="value"/>*
+ |
+ <dsName/>
|
<dsName/>
<icClass/>
@@ -1837,7 +1842,6 @@ where "sequence/dynamic_seq_1.xml" refer
<user/>
<password/>
)
- <property name="name" value="value"/>*
</pool>
</connection>
<statement>
Modified: synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml?rev=1001374&r1=1001373&r2=1001374&view=diff
==============================================================================
--- synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml (original)
+++ synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml Sun Sep 26 07:20:32
2010
@@ -3714,7 +3714,7 @@ INFO LogMediator text = Stock price - 15
<strong>Objective: Demonstrate the use of reusable database connection
pools</strong></p>
<p>
<strong>Prerequisites:</strong>
-<br/>>Setting up DataBase and DataSources according to the
+<br/>Set up the database and Data sources according to the
<a href="Synapse_Samples_Setup.html">sample setup guide</a>
<br/>Start the Synapse configuration numbered 363: i.e. synapse -sample 363
<br/>Start the Axis2 server and deploy the SimpleStockQuoteService if not
already done </p>