Author: kwilliams
Date: Wed Apr 26 18:51:18 2006
New Revision: 397355
URL: http://svn.apache.org/viewcvs?rev=397355&view=rev
Log:
Cleaning up Command interface (TUSCANY-230)
Modified:
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CUDGeneration.java
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ConverterTests.java
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CrudWithChangeHistory.java
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/GeneratedId.java
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/OCCTests.java
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/PartialUpdateTests.java
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/PassiveConnectionTests.java
Modified:
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CUDGeneration.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CUDGeneration.java?rev=397355&r1=397354&r2=397355&view=diff
==============================================================================
---
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CUDGeneration.java
(original)
+++
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CUDGeneration.java
Wed Apr 26 18:51:18 2006
@@ -78,7 +78,6 @@
customer.set("ADDRESS", "asdfasdf");
ApplyChangesCommand apply =
Command.FACTORY.createApplyChangesCommand();
- apply.addPrimaryKey("CUSTOMER.ID");
apply.setConnection(getConnection());
apply.execute(root);
Modified:
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ConverterTests.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ConverterTests.java?rev=397355&r1=397354&r2=397355&view=diff
==============================================================================
---
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ConverterTests.java
(original)
+++
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ConverterTests.java
Wed Apr 26 18:51:18 2006
@@ -99,10 +99,8 @@
//Modify
root.setDate("CUSTOMER[1]/LASTNAME", tbday);
- ApplyChangesCommand write =
Command.FACTORY.createApplyChangesCommand();
- write.addPrimaryKey("CUSTOMER.ID");
+ ApplyChangesCommand write =
Command.FACTORY.createApplyChangesCommand(getConfig("CustomerConfigWithConverter.xml"));
write.setConnection(getConnection());
- write.addConverter("CUSTOMER.LASTNAME",
"org.apache.tuscany.das.rdb.test.mappings.SillyDateStringConverter");
write.execute(root);
//Read
Modified:
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CrudWithChangeHistory.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CrudWithChangeHistory.java?rev=397355&r1=397354&r2=397355&view=diff
==============================================================================
---
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CrudWithChangeHistory.java
(original)
+++
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CrudWithChangeHistory.java
Wed Apr 26 18:51:18 2006
@@ -145,9 +145,6 @@
//Build apply changes command
ApplyChangesCommand apply =
Command.FACTORY.createApplyChangesCommand();
apply.setConnection( getConnection() );
- //programatically add the only part of the mapping model needed for
this simple case.
- //The ID designation is needed to generate the CUD statements
- apply.addPrimaryKey( "CUSTOMER.ID" );
//Flush changes
apply.execute( root );
Modified:
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/GeneratedId.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/GeneratedId.java?rev=397355&r1=397354&r2=397355&view=diff
==============================================================================
---
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/GeneratedId.java
(original)
+++
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/GeneratedId.java
Wed Apr 26 18:51:18 2006
@@ -32,270 +32,263 @@
public class GeneratedId extends DasTest {
- protected void setUp() throws Exception {
- super.setUp();
+ protected void setUp() throws Exception {
+ super.setUp();
- new CompanyData(getAutoConnection()).refresh();
- new DepartmentData(getAutoConnection()).refresh();
+ new CompanyData(getAutoConnection()).refresh();
+ new DepartmentData(getAutoConnection()).refresh();
- }
+ }
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- // Test insert into row with generated ID
- public void testInsert() throws Exception {
-
- Command insert = Command.FACTORY
- .createCommand("insert into COMPANY (NAME)
values (:NAME)");
- insert.setConnection(getConnection());
- insert.setParameterValue("NAME", "AAA Rental");
- insert.execute();
-
- // Verify insert
- // Verify
- Command select = Command.FACTORY
- .createCommand("Select ID, NAME from COMPANY");
- select.setConnection(getConnection());
- DataObject root = select.executeQuery();
-
- assertEquals(4, root.getList("COMPANY").size());
- assertTrue(root.getInt("COMPANY[1]/ID") > 0);
-
- }
-
- // Test back to back insertions with the same command
- public void testInsert2() throws Exception {
-
- Command insert = Command.FACTORY
- .createCommand("insert into COMPANY (NAME)
values (:NAME)");
- insert.setConnection(getConnection());
- insert.setParameterValue("NAME", "AAA Rental");
- insert.execute();
-
- // insert another using same command
- insert.setParameterValue("NAME", "BBB Rental");
- insert.execute();
-
- // Verify insert
- // Verify
- Command select = Command.FACTORY
- .createCommand("Select ID, NAME from COMPANY");
- select.setConnection(getConnection());
- DataObject root = select.executeQuery();
-
- assertEquals(5, root.getList("COMPANY").size());
-
- }
-
- // Test ability to retrieve and utilize the generated key
- public void testInsert3() throws Exception {
-
- Command insert = Command.FACTORY
- .createCommand("insert into COMPANY (NAME)
values (:NAME)");
- insert.setConnection(getConnection());
- insert.setParameterValue("NAME", "AAA Rental");
- insert.execute();
- Integer key = (Integer)
insert.getParameterValue("generated_key");
-
- // Verify insert
- Command select = Command.FACTORY
- .createCommand("Select ID, NAME from COMPANY
where ID = :ID");
- select.setConnection(getConnection());
- select.setParameterValue("ID", key);
- DataObject root = select.executeQuery();
- assertEquals(key, root.get("COMPANY[1]/ID"));
-
- }
-
- // Test ability to propogate generated values back to owning data
objects
- public void testPropagateIds() throws Exception {
-
- Command select = Command.FACTORY.createCommand("Select * from
COMPANY");
- select.setConnection(getConnection());
- DataObject root = select.executeQuery();
-
- // Create a new Company
- DataObject company = root.createDataObject("COMPANY");
- company.setString("NAME", "Do-rite Pest Control");
-
- // Create apply command
- ApplyChangesCommand apply =
Command.FACTORY.createApplyChangesCommand();
- apply.setConnection(getConnection());
-
- // Programatically set minimum metadata necessary
- apply.addGeneratedPrimaryKey("COMPANY.ID");
-
- // verify pre-condition (id is not there until after flush)
- assertNull(company.get("ID"));
-
- // Flush changes
- apply.execute(root);
-
- // Save the id
- Integer id = (Integer) company.get("ID");
-
- // Verify the change
- select = Command.FACTORY
- .createCommand("Select * from COMPANY where ID
= :ID");
- select.setConnection(getConnection());
- select.setParameterValue("ID", id);
- root = select.executeQuery();
- assertEquals("Do-rite Pest Control",
root.getDataObject("COMPANY[1]")
- .getString("NAME"));
-
- }
-
- /**
- * Same as above but metadata provided by XML config file
- */
- public void testPropagateIdsXML() throws Exception {
-
- Command select = Command.FACTORY.createCommand("Select * from
COMPANY", getConfig("basicCompanyMapping.xml"));
- select.setConnection(getConnection());
- DataObject root = select.executeQuery();
-
- // Create a new Company
- DataObject company = root.createDataObject("COMPANY");
- company.setString("NAME", "Do-rite Pest Control");
-
- // Create apply command
- ApplyChangesCommand apply =
Command.FACTORY.createApplyChangesCommand(getConfig("basicCompanyMapping.xml"));
- apply.setConnection(getConnection());
-
- // verify pre-condition (id is not there until after flush)
- assertNull(company.get("ID"));
-
- // Flush changes
- apply.execute(root);
-
- // Save the id
- Integer id = (Integer) company.get("ID");
-
- // Verify the change
- select = Command.FACTORY
- .createCommand("Select * from COMPANY where ID
= :ID");
- select.setConnection(getConnection());
- select.setParameterValue("ID", id);
- root = select.executeQuery();
- assertEquals("Do-rite Pest Control",
root.getDataObject("COMPANY[1]")
- .getString("NAME"));
-
- }
-
- /**
- * Test ability to correctly flush heirarchy of objects that have
generated
- * keys
- */
- public void testFlushCreateHeirarchy() throws Exception {
-
- String selectCompanys = "SELECT * FROM COMPANY LEFT JOIN
DEPARTMENT ON COMPANY.ID = DEPARTMENT.COMPANYID";
-
- Command select = Command.FACTORY.createCommand(selectCompanys,
getConfig("basicCompanyDepartmentMapping.xml"));
- select.setConnection(getConnection());
- DataObject root = select.executeQuery();
-
- // Create a new Company
- DataObject company = root.createDataObject("COMPANY");
- company.setString("NAME", "Do-rite Pest Control");
-
- // Create a new Department
- //Do not set ID or CompanyID since these are generated
- //ID INT, NAME VARCHAR(30), LOCATION VARCHAR(30), NUMBER
VARCHAR(10), COMPANYID INT, EOTM INT
- DataObject department = root.createDataObject("DEPARTMENT");
- department.setString("NAME", "Do-rite Pest Control");
- department.setString("LOCATION", "The boonies");
- department.setString("NUMBER", "101");
-
- // Associate the new department with the new company
- company.getList("departments").add(department);
-
- // Create apply command
- ApplyChangesCommand apply =
Command.FACTORY.createApplyChangesCommand(getConfig("basicCompanyDepartmentMapping.xml"));
- apply.setConnection(getConnection());
-
- // Flush changes
- apply.execute(root);
-
- // Save the id
- Integer id = (Integer) company.get("ID");
-
- // Verify the change
- String selectString = "SELECT * FROM COMPANY LEFT JOIN
DEPARTMENT ON COMPANY.ID = DEPARTMENT.COMPANYID WHERE COMPANY.ID = :ID";
-
- select = Command.FACTORY.createCommand(selectString);
- select.setConnection(getConnection());
- select.setParameterValue("ID", id);
- root = select.executeQuery();
- assertEquals("Do-rite Pest Control",
root.getDataObject("COMPANY[1]")
- .getString("NAME"));
-
- }
-
- /**
- * Test ability to correctly flush heirarchy of objects that have
generated
- * keys even when a created object has legal but NULL property values
- */
- public void testFlushCreateHeirarchy2() throws Exception {
-
- String selectCompanys = "SELECT * FROM COMPANY LEFT JOIN
DEPARTMENT ON COMPANY.ID = DEPARTMENT.COMPANYID";
-
- Command select = Command.FACTORY.createCommand(selectCompanys,
getConfig("basicCompanyDepartmentMapping.xml"));
- select.setConnection(getConnection());
- DataObject root = select.executeQuery();
-
- // Create a new Company
- DataObject company = root.createDataObject("COMPANY");
- company.setString("NAME", "Do-rite Pest Control");
-
- // Create a new Department
- //Do not set ID or CompanyID since these are generated
- //ID INT, NAME VARCHAR(30), LOCATION VARCHAR(30), NUMBER
VARCHAR(10), COMPANYID INT, EOTM INT
- DataObject department = root.createDataObject("DEPARTMENT");
- department.setString("NAME", "Do-rite Pest Control");
- //Do not set this property to force storing NULL to DB
-// department.setString("LOCATION", "The boonies");
- department.setString("NUMBER", "101");
-
- // Associate the new department with the new company
- company.getList("departments").add(department);
-
- // Create apply command
- ApplyChangesCommand apply =
Command.FACTORY.createApplyChangesCommand(getConfig("basicCompanyDepartmentMapping.xml"));
- apply.setConnection(getConnection());
-
- // Flush changes
- apply.execute(root);
-
- // Save the id
- Integer id = (Integer) company.get("ID");
-
- // Verify the change
- String selectString = "SELECT * FROM COMPANY LEFT JOIN
DEPARTMENT ON COMPANY.ID = DEPARTMENT.COMPANYID WHERE COMPANY.ID = :ID";
-
- select = Command.FACTORY.createCommand(selectString);
- select.setConnection(getConnection());
- select.setParameterValue("ID", id);
- root = select.executeQuery();
- assertEquals("Do-rite Pest Control",
root.getDataObject("COMPANY[1]").getString("NAME"));
-
- }
-
-
- // Test that error is thrown when no key has been generated (as in a
select)
- public void testRead() throws Exception {
-
- Command select = Command.FACTORY.createCommand("Select * from
COMPANY");
- select.setConnection(getConnection());
- select.executeQuery();
-
- try {
- select.getParameterValue("generated_id");
- fail("Should throw Error");
- } catch (RuntimeException e) {
- // OK
- }
- }
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ // Test insert into row with generated ID
+ public void testInsert() throws Exception {
+
+ Command insert = Command.FACTORY.createCommand("insert into COMPANY
(NAME) values (:NAME)");
+ insert.setConnection(getConnection());
+ insert.setParameterValue("NAME", "AAA Rental");
+ insert.execute();
+
+ // Verify insert
+ // Verify
+ Command select = Command.FACTORY.createCommand("Select ID, NAME from
COMPANY");
+ select.setConnection(getConnection());
+ DataObject root = select.executeQuery();
+
+ assertEquals(4, root.getList("COMPANY").size());
+ assertTrue(root.getInt("COMPANY[1]/ID") > 0);
+
+ }
+
+ // Test back to back insertions with the same command
+ public void testInsert2() throws Exception {
+
+ Command insert = Command.FACTORY.createCommand("insert into COMPANY
(NAME) values (:NAME)");
+ insert.setConnection(getConnection());
+ insert.setParameterValue("NAME", "AAA Rental");
+ insert.execute();
+
+ // insert another using same command
+ insert.setParameterValue("NAME", "BBB Rental");
+ insert.execute();
+
+ // Verify insert
+ // Verify
+ Command select = Command.FACTORY.createCommand("Select ID, NAME from
COMPANY");
+ select.setConnection(getConnection());
+ DataObject root = select.executeQuery();
+
+ assertEquals(5, root.getList("COMPANY").size());
+
+ }
+
+ // Test ability to retrieve and utilize the generated key
+ public void testInsert3() throws Exception {
+
+ Command insert = Command.FACTORY.createCommand("insert into COMPANY
(NAME) values (:NAME)");
+ insert.setConnection(getConnection());
+ insert.setParameterValue("NAME", "AAA Rental");
+ insert.execute();
+ Integer key = (Integer) insert.getParameterValue("generated_key");
+
+ // Verify insert
+ Command select = Command.FACTORY.createCommand("Select ID, NAME from
COMPANY where ID = :ID");
+ select.setConnection(getConnection());
+ select.setParameterValue("ID", key);
+ DataObject root = select.executeQuery();
+ assertEquals(key, root.get("COMPANY[1]/ID"));
+
+ }
+
+ // Test ability to propogate generated values back to owning data objects
+ public void testPropagateIds() throws Exception {
+
+ Command select = Command.FACTORY.createCommand("Select * from
COMPANY");
+ select.setConnection(getConnection());
+ DataObject root = select.executeQuery();
+
+ // Create a new Company
+ DataObject company = root.createDataObject("COMPANY");
+ company.setString("NAME", "Do-rite Pest Control");
+
+ // Create apply command
+ ApplyChangesCommand apply =
Command.FACTORY.createApplyChangesCommand(getConfig("CompanyConfig.xml"));
+ apply.setConnection(getConnection());
+
+ // verify pre-condition (id is not there until after flush)
+ assertNull(company.get("ID"));
+
+ // Flush changes
+ apply.execute(root);
+
+ // Save the id
+ Integer id = (Integer) company.get("ID");
+
+ // Verify the change
+ select = Command.FACTORY.createCommand("Select * from COMPANY where ID
= :ID");
+ select.setConnection(getConnection());
+ select.setParameterValue("ID", id);
+ root = select.executeQuery();
+ assertEquals("Do-rite Pest Control",
root.getDataObject("COMPANY[1]").getString("NAME"));
+
+ }
+
+ /**
+ * Same as above but metadata provided by XML config file
+ */
+ public void testPropagateIdsXML() throws Exception {
+
+ Command select = Command.FACTORY.createCommand("Select * from COMPANY",
+ getConfig("basicCompanyMapping.xml"));
+ select.setConnection(getConnection());
+ DataObject root = select.executeQuery();
+
+ // Create a new Company
+ DataObject company = root.createDataObject("COMPANY");
+ company.setString("NAME", "Do-rite Pest Control");
+
+ // Create apply command
+ ApplyChangesCommand apply = Command.FACTORY
+
.createApplyChangesCommand(getConfig("basicCompanyMapping.xml"));
+ apply.setConnection(getConnection());
+
+ // verify pre-condition (id is not there until after flush)
+ assertNull(company.get("ID"));
+
+ // Flush changes
+ apply.execute(root);
+
+ // Save the id
+ Integer id = (Integer) company.get("ID");
+
+ // Verify the change
+ select = Command.FACTORY.createCommand("Select * from COMPANY where ID
= :ID");
+ select.setConnection(getConnection());
+ select.setParameterValue("ID", id);
+ root = select.executeQuery();
+ assertEquals("Do-rite Pest Control",
root.getDataObject("COMPANY[1]").getString("NAME"));
+
+ }
+
+ /**
+ * Test ability to correctly flush heirarchy of objects that have generated
+ * keys
+ */
+ public void testFlushCreateHeirarchy() throws Exception {
+
+ String selectCompanys = "SELECT * FROM COMPANY LEFT JOIN DEPARTMENT ON
COMPANY.ID = DEPARTMENT.COMPANYID";
+
+ Command select = Command.FACTORY.createCommand(selectCompanys,
+ getConfig("basicCompanyDepartmentMapping.xml"));
+ select.setConnection(getConnection());
+ DataObject root = select.executeQuery();
+
+ // Create a new Company
+ DataObject company = root.createDataObject("COMPANY");
+ company.setString("NAME", "Do-rite Pest Control");
+
+ // Create a new Department
+ // Do not set ID or CompanyID since these are generated
+ // ID INT, NAME VARCHAR(30), LOCATION VARCHAR(30), NUMBER VARCHAR(10),
+ // COMPANYID INT, EOTM INT
+ DataObject department = root.createDataObject("DEPARTMENT");
+ department.setString("NAME", "Do-rite Pest Control");
+ department.setString("LOCATION", "The boonies");
+ department.setString("NUMBER", "101");
+
+ // Associate the new department with the new company
+ company.getList("departments").add(department);
+
+ // Create apply command
+ ApplyChangesCommand apply = Command.FACTORY
+
.createApplyChangesCommand(getConfig("basicCompanyDepartmentMapping.xml"));
+ apply.setConnection(getConnection());
+
+ // Flush changes
+ apply.execute(root);
+
+ // Save the id
+ Integer id = (Integer) company.get("ID");
+
+ // Verify the change
+ String selectString = "SELECT * FROM COMPANY LEFT JOIN DEPARTMENT ON
COMPANY.ID = DEPARTMENT.COMPANYID WHERE COMPANY.ID = :ID";
+
+ select = Command.FACTORY.createCommand(selectString);
+ select.setConnection(getConnection());
+ select.setParameterValue("ID", id);
+ root = select.executeQuery();
+ assertEquals("Do-rite Pest Control",
root.getDataObject("COMPANY[1]").getString("NAME"));
+
+ }
+
+ /**
+ * Test ability to correctly flush heirarchy of objects that have generated
+ * keys even when a created object has legal but NULL property values
+ */
+ public void testFlushCreateHeirarchy2() throws Exception {
+
+ String selectCompanys = "SELECT * FROM COMPANY LEFT JOIN DEPARTMENT ON
COMPANY.ID = DEPARTMENT.COMPANYID";
+
+ Command select = Command.FACTORY.createCommand(selectCompanys,
+ getConfig("basicCompanyDepartmentMapping.xml"));
+ select.setConnection(getConnection());
+ DataObject root = select.executeQuery();
+
+ // Create a new Company
+ DataObject company = root.createDataObject("COMPANY");
+ company.setString("NAME", "Do-rite Pest Control");
+
+ // Create a new Department
+ // Do not set ID or CompanyID since these are generated
+ // ID INT, NAME VARCHAR(30), LOCATION VARCHAR(30), NUMBER VARCHAR(10),
+ // COMPANYID INT, EOTM INT
+ DataObject department = root.createDataObject("DEPARTMENT");
+ department.setString("NAME", "Do-rite Pest Control");
+ // Do not set this property to force storing NULL to DB
+ // department.setString("LOCATION", "The boonies");
+ department.setString("NUMBER", "101");
+
+ // Associate the new department with the new company
+ company.getList("departments").add(department);
+
+ // Create apply command
+ ApplyChangesCommand apply = Command.FACTORY
+
.createApplyChangesCommand(getConfig("basicCompanyDepartmentMapping.xml"));
+ apply.setConnection(getConnection());
+
+ // Flush changes
+ apply.execute(root);
+
+ // Save the id
+ Integer id = (Integer) company.get("ID");
+
+ // Verify the change
+ String selectString = "SELECT * FROM COMPANY LEFT JOIN DEPARTMENT ON
COMPANY.ID = DEPARTMENT.COMPANYID WHERE COMPANY.ID = :ID";
+
+ select = Command.FACTORY.createCommand(selectString);
+ select.setConnection(getConnection());
+ select.setParameterValue("ID", id);
+ root = select.executeQuery();
+ assertEquals("Do-rite Pest Control",
root.getDataObject("COMPANY[1]").getString("NAME"));
+
+ }
+
+ // Test that error is thrown when no key has been generated (as in a
select)
+ public void testRead() throws Exception {
+
+ Command select = Command.FACTORY.createCommand("Select * from
COMPANY");
+ select.setConnection(getConnection());
+ select.executeQuery();
+
+ try {
+ select.getParameterValue("generated_id");
+ fail("Should throw Error");
+ } catch (RuntimeException e) {
+ // OK
+ }
+ }
}
Modified:
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/OCCTests.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/OCCTests.java?rev=397355&r1=397354&r2=397355&view=diff
==============================================================================
---
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/OCCTests.java
(original)
+++
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/OCCTests.java
Wed Apr 26 18:51:18 2006
@@ -50,10 +50,8 @@
update.execute();
//Try to flush the change
- ApplyChangesCommand apply =
Command.FACTORY.createApplyChangesCommand();
+ ApplyChangesCommand apply =
Command.FACTORY.createApplyChangesCommand(getConfig("BooksConfig.xml"));
apply.setConnection(getConnection());
- apply.addPrimaryKey("BOOK.ID");
- apply.addCollisionColumn("BOOK.OCC");
try {
apply.execute(root);
@@ -62,6 +60,5 @@
if ( !ex.getMessage().equals("OCC Exception") )
throw ex;
}
-
}
}
Modified:
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/PartialUpdateTests.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/PartialUpdateTests.java?rev=397355&r1=397354&r2=397355&view=diff
==============================================================================
---
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/PartialUpdateTests.java
(original)
+++
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/PartialUpdateTests.java
Wed Apr 26 18:51:18 2006
@@ -23,86 +23,81 @@
import org.apache.tuscany.das.rdb.test.data.CustomerData;
import org.apache.tuscany.das.rdb.test.framework.DasTest;
-
import commonj.sdo.DataObject;
public class PartialUpdateTests extends DasTest {
- protected void setUp() throws Exception {
- super.setUp();
- new CustomerData(getAutoConnection()).refresh();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- public PartialUpdateTests() {
- super();
- }
-
- public void testPartialUpdate() throws SQLException {
- Command readCustomers = Command.FACTORY
- .createCommand("select * from CUSTOMER where ID
= 1");
- readCustomers.setConnection(getConnection());
-
- // Read
- DataObject root = readCustomers.executeQuery();
-
- DataObject customer = root.getDataObject("CUSTOMER[1]");
- // Verify
- assertEquals(1, customer.getInt("ID"));
-
- Command update = Command.FACTORY
- .createCommand("update CUSTOMER set LASTNAME =
'modified' where ID = 1");
- update.setConnection(getConnection());
- update.execute();
-
- customer.setString("ADDRESS", "main street");
-
- ApplyChangesCommand apply =
Command.FACTORY.createApplyChangesCommand();
- apply.addPrimaryKey("CUSTOMER.ID");
- apply.setConnection(getConnection());
- apply.execute(root);
-
- root = readCustomers.executeQuery();
-
- // If partial update was not used, LASTNAME would not be
'modified'
- customer = root.getDataObject("CUSTOMER[1]");
- assertEquals(1, customer.getInt("ID"));
- assertEquals("modified", customer.getString("LASTNAME"));
- assertEquals("main street", customer.getString("ADDRESS"));
- }
-
- public void testPartialInsert() throws SQLException {
- Command readCustomers = Command.FACTORY
- .createCommand("select * from CUSTOMER where ID
= 1");
- readCustomers.setConnection(getConnection());
-
- // Read
- DataObject root = readCustomers.executeQuery();
-
- //Create a new customer
- DataObject newCust = root.createDataObject("CUSTOMER");
- newCust.set("ID", new Integer(100));
- newCust.set("ADDRESS", "5528 Wells Fargo Drive");
- //Purposely do not set lastname to let it default to
'Garfugengheist'
- //newCust.set("LASTNAME", "Gerkin" );
-
- ApplyChangesCommand apply =
Command.FACTORY.createApplyChangesCommand();
- apply.addPrimaryKey("CUSTOMER.ID");
- apply.setConnection(getConnection());
- apply.execute(root);
-
- Command readNewCust = Command.FACTORY.createCommand("select *
from CUSTOMER where ID = 100");
- readNewCust.setConnection(getConnection());
- root = readNewCust.executeQuery();
-
- // If partial insert was not used, LASTNAME would not be
'Garfugengheist'
- newCust = root.getDataObject("CUSTOMER[1]");
- assertEquals(100, newCust.getInt("ID"));
- assertEquals("Garfugengheist", newCust.getString("LASTNAME"));
- assertEquals("5528 Wells Fargo Drive",
newCust.getString("ADDRESS"));
+ protected void setUp() throws Exception {
+ super.setUp();
+ new CustomerData(getAutoConnection()).refresh();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public PartialUpdateTests() {
+ super();
+ }
+
+ public void testPartialUpdate() throws SQLException {
+ Command readCustomers = Command.FACTORY.createCommand("select * from
CUSTOMER where ID = 1");
+ readCustomers.setConnection(getConnection());
+
+ // Read
+ DataObject root = readCustomers.executeQuery();
+
+ DataObject customer = root.getDataObject("CUSTOMER[1]");
+ // Verify
+ assertEquals(1, customer.getInt("ID"));
+
+ Command update = Command.FACTORY.createCommand("update CUSTOMER set
LASTNAME = 'modified' where ID = 1");
+ update.setConnection(getConnection());
+ update.execute();
+
+ customer.setString("ADDRESS", "main street");
+
+ ApplyChangesCommand apply =
Command.FACTORY.createApplyChangesCommand();
+ apply.setConnection(getConnection());
+ apply.execute(root);
+
+ root = readCustomers.executeQuery();
+
+ // If partial update was not used, LASTNAME would not be 'modified'
+ customer = root.getDataObject("CUSTOMER[1]");
+ assertEquals(1, customer.getInt("ID"));
+ assertEquals("modified", customer.getString("LASTNAME"));
+ assertEquals("main street", customer.getString("ADDRESS"));
+ }
+
+ public void testPartialInsert() throws SQLException {
+ Command readCustomers = Command.FACTORY.createCommand("select * from
CUSTOMER where ID = 1");
+ readCustomers.setConnection(getConnection());
+
+ // Read
+ DataObject root = readCustomers.executeQuery();
+
+ // Create a new customer
+ DataObject newCust = root.createDataObject("CUSTOMER");
+ newCust.set("ID", new Integer(100));
+ newCust.set("ADDRESS", "5528 Wells Fargo Drive");
+ // Purposely do not set lastname to let it default to 'Garfugengheist'
+ // newCust.set("LASTNAME", "Gerkin" );
+
+ ApplyChangesCommand apply =
Command.FACTORY.createApplyChangesCommand();
+ apply.setConnection(getConnection());
+ apply.execute(root);
+
+ Command readNewCust = Command.FACTORY.createCommand("select * from
CUSTOMER where ID = 100");
+ readNewCust.setConnection(getConnection());
+ root = readNewCust.executeQuery();
+
+ // If partial insert was not used, LASTNAME would not be
+ // 'Garfugengheist'
+ newCust = root.getDataObject("CUSTOMER[1]");
+ assertEquals(100, newCust.getInt("ID"));
+ assertEquals("Garfugengheist", newCust.getString("LASTNAME"));
+ assertEquals("5528 Wells Fargo Drive", newCust.getString("ADDRESS"));
- }
+ }
}
Modified:
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/PassiveConnectionTests.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/PassiveConnectionTests.java?rev=397355&r1=397354&r2=397355&view=diff
==============================================================================
---
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/PassiveConnectionTests.java
(original)
+++
incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/PassiveConnectionTests.java
Wed Apr 26 18:51:18 2006
@@ -17,8 +17,9 @@
package org.apache.tuscany.das.rdb.test;
/*
- * Test capability to participate in an extenrlly managed transaction.
The client is managing the
- * transaction boundary so the DAS will not issue commit/rollback
+ * Test capability to participate in an extenrlly managed transaction. The
+ * client is managing the transaction boundary so the DAS will not issue
+ * commit/rollback
*
*/
@@ -27,62 +28,58 @@
import org.apache.tuscany.das.rdb.test.data.CustomerData;
import org.apache.tuscany.das.rdb.test.framework.DasTest;
-
import commonj.sdo.DataObject;
public class PassiveConnectionTests extends DasTest {
- protected void setUp() throws Exception {
- super.setUp();
- new CustomerData(getAutoConnection()).refresh();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- /**
- * 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();
-
- try {
-
- // Read customer 1
- Command select = Command.FACTORY
- .createCommand("Select * from CUSTOMER
where ID = 1");
- select.setConnection(c);
- DataObject root = select.executeQuery();
-
- DataObject customer = (DataObject)
root.get("CUSTOMER[1]");
-
- // Modify customer
- customer.set("LASTNAME", "Pavick");
-
- // Build apply changes command
- ApplyChangesCommand apply = Command.FACTORY
- .createApplyChangesCommand();
- apply.setConnection(c, false);
- apply.addPrimaryKey("CUSTOMER.ID");
-
- // Flush changes
- apply.execute(root);
-
- // Verify changes
- root = select.executeQuery();
- assertEquals("Pavick",
root.getString("CUSTOMER[1]/LASTNAME"));
-
- // Since the DAS is not managing tx boundaries, I must
- } catch (Exception e) {
- c.rollback();
- } finally {
- c.commit();
- }
+ protected void setUp() throws Exception {
+ super.setUp();
+ new CustomerData(getAutoConnection()).refresh();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * 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();
+
+ try {
+
+ // Read customer 1
+ Command select = Command.FACTORY.createCommand("Select * from
CUSTOMER where ID = 1");
+ select.setConnection(c);
+ DataObject root = select.executeQuery();
+
+ DataObject customer = (DataObject) root.get("CUSTOMER[1]");
+
+ // Modify customer
+ customer.set("LASTNAME", "Pavick");
+
+ // Build apply changes command
+ ApplyChangesCommand apply =
Command.FACTORY.createApplyChangesCommand();
+ apply.setConnection(c, false);
+
+ // Flush changes
+ apply.execute(root);
+
+ // Verify changes
+ root = select.executeQuery();
+ assertEquals("Pavick", root.getString("CUSTOMER[1]/LASTNAME"));
+
+ // Since the DAS is not managing tx boundaries, I must
+ } catch (Exception e) {
+ c.rollback();
+ } finally {
+ c.commit();
+ }
- }
+ }
}