The attached patch adds a "ConnectionInfo" element to Config that has
a "managedtx" attribute. The DataSource attribute has moved from
Config to this new element.
Brent
Index: src/test/java/org/apache/tuscany/das/rdb/test/PassiveConnectionTests.java
===================================================================
--- src/test/java/org/apache/tuscany/das/rdb/test/PassiveConnectionTests.java
(revision 420945)
+++ src/test/java/org/apache/tuscany/das/rdb/test/PassiveConnectionTests.java
(working copy)
@@ -42,38 +42,51 @@
}
/**
- * Read and modify a customer. Uses a "passive" connection
- */
+ * Read and modify a customer. Uses a "passive" connection
+ */
public void testReadModifyApply() throws Exception {
- // Create and initialize a DAS connection and initialize for externally
- // managed transaction boundaries
- java.sql.Connection c = getConnection();
+ // Create and initialize a DAS connection and initialize for
externally
+ // managed transaction boundaries
+ java.sql.Connection c = getConnection();
- try {
- DAS das = DAS.FACTORY.createDAS(c);
- // Read customer 1
- Command select = das.createCommand("Select * from CUSTOMER where
ID = 1");
- DataObject root = select.executeQuery();
+ DAS das =
DAS.FACTORY.createDAS(getConfig("passiveConnection.xml"), c);
+ // Read customer 1
+ Command select = das.getCommand("get a customer");
+ DataObject root = select.executeQuery();
- DataObject customer = (DataObject) root.get("CUSTOMER[1]");
+ DataObject customer = (DataObject) root.get("CUSTOMER[1]");
- // Modify customer
- customer.set("LASTNAME", "Pavick");
+ String lastName = customer.getString("LASTNAME");
+
+ // Modify customer
+ customer.set("LASTNAME", "Pavick");
- das.applyChanges(root);
+ try {
+ das.applyChanges(root);
- // Verify changes
- root = select.executeQuery();
- assertEquals("Pavick", root.getString("CUSTOMER[1]/LASTNAME"));
+ throw new Exception("Test Exception");
- // Since the DAS is not managing tx boundaries, I must
- } catch (Exception e) {
- c.rollback();
- } finally {
- c.commit();
- }
+ // Since the DAS is not managing tx boundaries, I must
+ } catch (Exception e) {
+ // assert here to make sure we didn't run into some
hidden error
+ assertEquals("Test Exception", e.getMessage());
+ // Roll back the transaction
+ c.rollback();
+ }
+ // Verify that the changes did not go through
+ root = select.executeQuery();
+ assertEquals(lastName, root.getString("CUSTOMER[1]/LASTNAME"));
+
+ // Try again
+ customer = (DataObject) root.get("CUSTOMER[1]");
+ customer.set("LASTNAME", "Pavick");
+ das.applyChanges(root);
+ c.commit();
+
+ root = select.executeQuery();
+ assertEquals("Pavick", root.getString("CUSTOMER[1]/LASTNAME"));
}
}
Index: src/test/resources/passiveConnection.xml
===================================================================
--- /dev/null (revision 0)
+++ src/test/resources/passiveConnection.xml (revision 0)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ Copyright (c) 2005 The Apache Software Foundation or its licensors, as
applicable.
+
+ Licensed 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.
+ -->
+<Config
xsi:noNamespaceSchemaLocation="http:///org.apache.tuscany.das.rdb/config.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <ConnectionInfo managedtx="false"/>
+
+ <Command name="get a customer" SQL="Select * from CUSTOMER where ID =
1" kind="select"/>
+
+ <Table tableName="CUSTOMER">
+ <Column columnName="ID" primaryKey="true"/>
+ <Column columnName="LASTNAME" />
+ <Column columnName="ADDRESS" />
+ </Table>
+
+</Config>
\ No newline at end of file
Index:
src/main/java/org/apache/tuscany/das/rdb/impl/ApplyChangesCommandImpl.java
===================================================================
--- src/main/java/org/apache/tuscany/das/rdb/impl/ApplyChangesCommandImpl.java
(revision 420945)
+++ src/main/java/org/apache/tuscany/das/rdb/impl/ApplyChangesCommandImpl.java
(working copy)
@@ -45,7 +45,8 @@
public ApplyChangesCommandImpl(Config config, Connection connection){
this.configWrapper = new MappingWrapper(config);
if ( connection != null )
- setConnection(connection);
+ setConnection(connection, config);
+
}
public void setConnection(ConnectionImpl connection) {
Index: src/main/java/org/apache/tuscany/das/rdb/impl/DASImpl.java
===================================================================
--- src/main/java/org/apache/tuscany/das/rdb/impl/DASImpl.java (revision
420945)
+++ src/main/java/org/apache/tuscany/das/rdb/impl/DASImpl.java (working copy)
@@ -115,7 +115,7 @@
if (!commands.containsKey(name))
throw new RuntimeException("CommandGroup has no command named: " +
name);
CommandImpl cmd = (CommandImpl) commands.get(name);
- cmd.setConnection(getConnection());
+ cmd.setConnection(getConnection(), config);
return cmd;
}
@@ -132,7 +132,9 @@
private void initializeConnection() {
- if (config == null || config.getDataSource() == null)
+ if (config == null ||
+ config.getConnectionInfo() == null ||
+ config.getConnectionInfo().getDataSource() == null)
throw new RuntimeException(
"No connection has been provided and no data source has
been specified");
@@ -146,7 +148,7 @@
}
try {
// TODO - I think we should rename this getDataSourceURL?
- DataSource ds = (DataSource) ctx.lookup(config.getDataSource());
+ DataSource ds = (DataSource)
ctx.lookup(config.getConnectionInfo().getDataSource());
try {
connection = ds.getConnection();
connection.setAutoCommit(false);
@@ -182,7 +184,7 @@
*/
private boolean managingConnections() {
- if (config.getDataSource() == null)
+ if (config.getConnectionInfo().getDataSource() == null)
return false;
else
return true;
@@ -221,7 +223,7 @@
throw new RuntimeException("SQL => " + sql + " is not valid");
}
- returnCmd.setConnection(getConnection());
+ returnCmd.setConnection(getConnection(), config);
return returnCmd;
}
Index: src/main/java/org/apache/tuscany/das/rdb/impl/BaseCommandImpl.java
===================================================================
--- src/main/java/org/apache/tuscany/das/rdb/impl/BaseCommandImpl.java
(revision 420945)
+++ src/main/java/org/apache/tuscany/das/rdb/impl/BaseCommandImpl.java
(working copy)
@@ -18,6 +18,7 @@
import java.sql.Connection;
+import org.apache.tuscany.das.rdb.config.Config;
import org.apache.tuscany.das.rdb.config.wrapper.MappingWrapper;
public abstract class BaseCommandImpl {
@@ -28,6 +29,13 @@
setConnection(new ConnectionImpl(connection));
}
+ public void setConnection(Connection connection, Config config) {
+ boolean managed = true;
+ if ( config != null && config.getConnectionInfo() != null )
+ managed = config.getConnectionInfo().isManagedtx();
+ setConnection(connection, managed);
+ }
+
public void setConnection(Connection connection, boolean
manageTransaction) {
ConnectionImpl c = new ConnectionImpl(connection);
c.setManageTransactions(manageTransaction);
Index: src/main/resources/config.xsd
===================================================================
--- src/main/resources/config.xsd (revision 420945)
+++ src/main/resources/config.xsd (working copy)
@@ -20,11 +20,17 @@
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Command"
type="org.apache.tuscany.das.rdb.config:Command"/>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Table"
type="org.apache.tuscany.das.rdb.config:Table"/>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Relationship"
type="org.apache.tuscany.das.rdb.config:Relationship"/>
- </xsd:sequence>
- <xsd:attribute name="dataSource" type="xsd:string"/>
+ <xsd:element maxOccurs="1" minOccurs="0" name="ConnectionInfo"
type="org.apache.tuscany.das.rdb.config:ConnectionInfo"/>
+ </xsd:sequence>
<xsd:attribute name="uri" type="xsd:string"/>
- <xsd:attribute name="dataObjectModel" type="xsd:string"/>
+ <xsd:attribute name="dataObjectModel" type="xsd:string"/>
</xsd:complexType>
+
+ <xsd:complexType name="ConnectionInfo">
+ <xsd:attribute name="dataSource" type="xsd:string"/>
+ <xsd:attribute name="managedtx" type="xsd:boolean"/>
+ </xsd:complexType>
+
<xsd:complexType name="Command">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Parameter"
type="org.apache.tuscany.das.rdb.config:Parameter"/>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]