tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwilli...@apache.org
Subject svn commit: r428100 - in /incubator/tuscany/java/das/rdb/src: main/java/org/apache/tuscany/das/rdb/ main/java/org/apache/tuscany/das/rdb/config/wrapper/ test/java/org/apache/tuscany/das/rdb/test/
Date Wed, 02 Aug 2006 19:20:04 GMT
Author: kwilliams
Date: Wed Aug  2 12:20:03 2006
New Revision: 428100

URL: http://svn.apache.org/viewvc?rev=428100&view=rev
Log:
Brent's patch for TUSCANY-590 to extend the capability of ConfigHelper

Modified:
    incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/ConfigHelper.java
    incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/config/wrapper/MappingWrapper.java
    incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CorrectedDefectTests.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/ProgrammaticConfigTests.java

Modified: incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/ConfigHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/ConfigHelper.java?rev=428100&r1=428099&r2=428100&view=diff
==============================================================================
--- incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/ConfigHelper.java
(original)
+++ incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/ConfigHelper.java
Wed Aug  2 12:20:03 2006
@@ -16,8 +16,10 @@
  */
 package org.apache.tuscany.das.rdb;
 
+import org.apache.tuscany.das.rdb.config.Command;
 import org.apache.tuscany.das.rdb.config.Config;
 import org.apache.tuscany.das.rdb.config.ConfigFactory;
+import org.apache.tuscany.das.rdb.config.Table;
 import org.apache.tuscany.das.rdb.config.impl.ConfigFactoryImpl;
 import org.apache.tuscany.das.rdb.config.wrapper.MappingWrapper;
 
@@ -53,15 +55,49 @@
         configWrapper.addRelationship(parentName, childName);
     }
     
-    public void addTable(String name, String propertyName) {
-        configWrapper.addTable(name, propertyName);
+    public Table addTable(String name, String propertyName) {
+        return configWrapper.addTable(name, propertyName);
     }
     
-    public void addUpdateStatement(String statement, String tableName, String parameters)
{
-        configWrapper.addUpdateCommand(tableName, statement, parameters);
+    public void addUpdateStatement(Table table, String statement, String parameters) {
+        configWrapper.addUpdateStatement(table, statement, parameters);
     }     
     
+    public void addCreateStatement(Table table, String statement, String parameters) {
+    	configWrapper.addCreateStatement(table, statement, parameters);
+    }
+    
+    public void addDeleteStatement(Table table, String statement, String parameters) {
+    	configWrapper.addDeleteStatement(table, statement, parameters);
+    }
+    
+    public void addConnectionInfo(String dataSourceName, boolean managedtx) {
+    	configWrapper.addConnectionInfo(dataSourceName, managedtx);
+    }
+    
+    public void addConnectionInfo(String dataSourceName) {
+    	configWrapper.addConnectionInfo(dataSourceName, true);
+    }
+    
+    public void setDataObjectModel(String dataObjectModel) {
+    	configWrapper.getConfig().setDataObjectModel(dataObjectModel);
+    }
+    
+    public Command addSelectCommand(String name, String sql) {
+    	return configWrapper.addCommand(name, sql, "select");
+    }
+    
+    public Command addUpdateCommand(String name, String sql) {
+    	return configWrapper.addCommand(name, sql, "update");
+    }
+    
+    public Command addInsertCommand(String name, String sql) {
+    	return configWrapper.addCommand(name, sql, "insert");    	
+    }
     
+    public Command addDeleteCommand(String name, String sql) {
+    	return configWrapper.addCommand(name, sql, "delete");
+    }
     
     public Config getConfig() {
         return config;

Modified: incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/config/wrapper/MappingWrapper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/config/wrapper/MappingWrapper.java?rev=428100&r1=428099&r2=428100&view=diff
==============================================================================
--- incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/config/wrapper/MappingWrapper.java
(original)
+++ incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/config/wrapper/MappingWrapper.java
Wed Aug  2 12:20:03 2006
@@ -24,8 +24,12 @@
 import java.util.List;
 
 import org.apache.tuscany.das.rdb.config.Column;
+import org.apache.tuscany.das.rdb.config.Command;
 import org.apache.tuscany.das.rdb.config.Config;
 import org.apache.tuscany.das.rdb.config.ConfigFactory;
+import org.apache.tuscany.das.rdb.config.ConnectionInfo;
+import org.apache.tuscany.das.rdb.config.Create;
+import org.apache.tuscany.das.rdb.config.Delete;
 import org.apache.tuscany.das.rdb.config.KeyPair;
 import org.apache.tuscany.das.rdb.config.Relationship;
 import org.apache.tuscany.das.rdb.config.Table;
@@ -190,7 +194,7 @@
         return propertyName;
     }
 
-    public void addTable(String tableName, String typeName) {
+    public Table addTable(String tableName, String typeName) {
         Table table = getTable(tableName);
         if (table != null)
             throw new RuntimeException("Table " + tableName + "already exists");
@@ -200,6 +204,7 @@
         table.setTypeName(typeName);
         config.getTable().add(table);
 
+        return table;
     }
 
     private Table findOrCreateTable(String tableName) {
@@ -355,13 +360,51 @@
         throw new RuntimeException("Could not find relationship " + name + " in the configuration");
     }
 
-    public void addUpdateCommand(String tableName, String statement, String parameters) {
-        Table table = findOrCreateTable(tableName);
+    public void addUpdateStatement(Table table, String statement, String parameters) {
+    
         Update update = ConfigFactoryImpl.eINSTANCE.createUpdate();
         update.setSql(statement);
         update.setParameters(parameters);
         table.setUpdate(update);
         
     }
+
+    public void addDeleteStatement(Table table, String statement,
+			String parameters) {
+
+		Delete delete = ConfigFactoryImpl.eINSTANCE.createDelete();
+		delete.setSql(statement);
+		delete.setParameters(parameters);
+		table.setDelete(delete);
+
+	}
+
+    
+    public void addCreateStatement(Table table, String statement,
+			String parameters) {
+
+		Create create = ConfigFactoryImpl.eINSTANCE.createCreate();
+		create.setSql(statement);
+		create.setParameters(parameters);
+		table.setCreate(create);
+
+	}
+	public void addConnectionInfo(String dataSourceName, boolean managedtx) {
+		ConnectionInfo info = ConfigFactoryImpl.eINSTANCE.createConnectionInfo();
+		info.setDataSource(dataSourceName);
+		info.setManagedtx(managedtx);
+		config.setConnectionInfo(info);		
+	}
+
+	public Command addCommand(String name, String sql, String kind) {
+		Command cmd = ConfigFactoryImpl.eINSTANCE.createCommand();
+		cmd.setName(name);
+		cmd.setKind(kind);
+		cmd.setSQL(sql);
+		
+		config.getCommand().add(cmd);
+		
+		return cmd;
+	}
 
 }

Modified: incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CorrectedDefectTests.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CorrectedDefectTests.java?rev=428100&r1=428099&r2=428100&view=diff
==============================================================================
--- incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CorrectedDefectTests.java
(original)
+++ incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CorrectedDefectTests.java
Wed Aug  2 12:20:03 2006
@@ -28,6 +28,7 @@
 import org.apache.tuscany.das.rdb.Command;
 import org.apache.tuscany.das.rdb.ConfigHelper;
 import org.apache.tuscany.das.rdb.DAS;
+import org.apache.tuscany.das.rdb.config.Table;
 import org.apache.tuscany.das.rdb.test.data.CompanyData;
 import org.apache.tuscany.das.rdb.test.data.CompanyDeptData;
 import org.apache.tuscany.das.rdb.test.data.CustomerData;
@@ -261,7 +262,8 @@
 
         // Provide updatecommand programmatically via config
         ConfigHelper helper = new ConfigHelper();
-        helper.addUpdateStatement("update CUSTOMER set LASTNAME = ? where ID = ?", "CUSTOMER",
"LASTNAME ID");         
+        Table customerTable = helper.addTable("CUSTOMER", "CUSTOMER");
+        helper.addUpdateStatement(customerTable, "update CUSTOMER set LASTNAME = ? where
ID = ?", "LASTNAME ID");         
         
     	DAS das = DAS.FACTORY.createDAS(helper.getConfig(), getConnection());
     	

Modified: incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CrudWithChangeHistory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/CrudWithChangeHistory.java?rev=428100&r1=428099&r2=428100&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 Aug  2 12:20:03 2006
@@ -30,6 +30,7 @@
 import org.apache.tuscany.das.rdb.Command;
 import org.apache.tuscany.das.rdb.ConfigHelper;
 import org.apache.tuscany.das.rdb.DAS;
+import org.apache.tuscany.das.rdb.config.Table;
 import org.apache.tuscany.das.rdb.test.data.CustomerData;
 import org.apache.tuscany.das.rdb.test.data.OrderDetailsData;
 import org.apache.tuscany.das.rdb.test.framework.DasTest;
@@ -91,8 +92,9 @@
 
         // Provide updatecommand programmatically via config
         ConfigHelper helper = new ConfigHelper();
-        helper.addUpdateStatement("update CUSTOMER set LASTNAME = ?, ADDRESS = ? where ID
= ?",
-                "CUSTOMER", "LASTNAME ADDRESS ID");
+        Table customerTable = helper.addTable("CUSTOMER", "CUSTOMER");
+        helper.addUpdateStatement(customerTable, "update CUSTOMER set LASTNAME = ?, ADDRESS
= ? where ID = ?",
+                "LASTNAME ADDRESS ID");
 
         DAS das = DAS.FACTORY.createDAS(helper.getConfig(), getConnection());
         // Read customer 1

Modified: incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ProgrammaticConfigTests.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ProgrammaticConfigTests.java?rev=428100&r1=428099&r2=428100&view=diff
==============================================================================
--- incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ProgrammaticConfigTests.java
(original)
+++ incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/ProgrammaticConfigTests.java
Wed Aug  2 12:20:03 2006
@@ -16,9 +16,14 @@
  */
 package org.apache.tuscany.das.rdb.test;
 
+import java.util.List;
+
 import org.apache.tuscany.das.rdb.Command;
 import org.apache.tuscany.das.rdb.ConfigHelper;
 import org.apache.tuscany.das.rdb.DAS;
+import org.apache.tuscany.das.rdb.config.Config;
+import org.apache.tuscany.das.rdb.config.ConnectionInfo;
+import org.apache.tuscany.das.rdb.config.Table;
 import org.apache.tuscany.das.rdb.test.data.BookData;
 import org.apache.tuscany.das.rdb.test.data.CustomerData;
 import org.apache.tuscany.das.rdb.test.data.OrderData;
@@ -142,5 +147,151 @@
         root = select.executeQuery();
         assertEquals("Ant Colonies of the Old World", root.getString("Book[1]/NAME"));
         
+    }
+    
+    /**
+     * Simple unit test for ConnectionInfo
+     * @throws Exception
+     */
+    public void testConnectionInfo() throws Exception {
+    	ConfigHelper helper = new ConfigHelper();
+    	helper.addConnectionInfo("jdbc/adatasource");
+    	
+    	Config config = helper.getConfig();
+    	ConnectionInfo info = config.getConnectionInfo();
+    	assertEquals(info.getDataSource(), "jdbc/adatasource");
+    	assertEquals(info.isManagedtx(), true);
+    }
+    
+    /**
+     * Simple unit test for ConnectionInfo
+     * @throws Exception
+     */
+    public void testConnectionInfo2() throws Exception {
+    	ConfigHelper helper = new ConfigHelper();
+    	helper.addConnectionInfo("jdbc/adatasource", false);
+    	
+    	Config config = helper.getConfig();
+    	ConnectionInfo info = config.getConnectionInfo();
+    	assertEquals(info.getDataSource(), "jdbc/adatasource");
+    	assertEquals(info.isManagedtx(), false);
+    }
+    
+    /**
+     * Simple unit test for adding a select command
+     * @throws Exception
+     */
+    public void testAddSelectCommand() throws Exception {
+    	ConfigHelper helper = new ConfigHelper();
+    	helper.addSelectCommand("get all customers", "select * from customers");
+    	
+    	Config config = helper.getConfig();
+    	List commands = config.getCommand();
+    	assertEquals(1, commands.size());
+    	org.apache.tuscany.das.rdb.config.Command cmd = (org.apache.tuscany.das.rdb.config.Command)
commands.get(0);
+    	assertEquals("select", cmd.getKind());
+    	assertEquals("get all customers", cmd.getName());
+    	assertEquals("select * from customers", cmd.getSQL());
+    }
+    
+    
+    /**
+     * Simple unit test for adding an update command
+     * @throws Exception
+     */
+    public void testAddUpdateCommand() throws Exception {
+    	ConfigHelper helper = new ConfigHelper();
+    	helper.addUpdateCommand("update a customer", "update customers set name = ? where id
= ?");
+    	
+    	Config config = helper.getConfig();
+    	List commands = config.getCommand();
+    	assertEquals(1, commands.size());
+    	org.apache.tuscany.das.rdb.config.Command cmd = (org.apache.tuscany.das.rdb.config.Command)
commands.get(0);
+    	assertEquals("update", cmd.getKind());
+    	assertEquals("update a customer", cmd.getName());
+    	assertEquals("update customers set name = ? where id = ?", cmd.getSQL());
+    }
+    
+    /**
+     * Simple unit test for adding an insert command
+     * @throws Exception
+     */
+    public void testAddInsertCommand() throws Exception {
+    	ConfigHelper helper = new ConfigHelper();
+    	helper.addInsertCommand("insert customer", "insert into customers(ID,NAME) values (?,?)");
+    	
+    	Config config = helper.getConfig();
+    	List commands = config.getCommand();
+    	assertEquals(1, commands.size());
+    	org.apache.tuscany.das.rdb.config.Command cmd = (org.apache.tuscany.das.rdb.config.Command)
commands.get(0);
+    	assertEquals("insert", cmd.getKind());
+    	assertEquals("insert customer", cmd.getName());
+    	assertEquals("insert into customers(ID,NAME) values (?,?)", cmd.getSQL());
+    }
+    
+    /**
+     * Simple unit test for adding a delete command
+     * @throws Exception
+     */
+    public void testAddDeleteCommand() throws Exception {
+    	ConfigHelper helper = new ConfigHelper();
+    	helper.addDeleteCommand("delete customer", "delete from customers where id = ?");
+    	
+    	Config config = helper.getConfig();
+    	List commands = config.getCommand();
+    	assertEquals(1, commands.size());
+    	org.apache.tuscany.das.rdb.config.Command cmd = (org.apache.tuscany.das.rdb.config.Command)
commands.get(0);
+    	assertEquals("delete", cmd.getKind());
+    	assertEquals("delete customer", cmd.getName());
+    	assertEquals("delete from customers where id = ?", cmd.getSQL());
+    }
+    
+    /**
+     * Simple unit test for DataObjectModel
+     * @throws Exception
+     */
+    public void testDataObjectModel() throws Exception {
+    	ConfigHelper helper = new ConfigHelper();
+    	helper.setDataObjectModel("org.apache.tuscany/mytypes");
+    	
+    	Config config = helper.getConfig();
+    	assertEquals("org.apache.tuscany/mytypes", config.getDataObjectModel());
+    	
+    }
+    
+    /**
+     * Simple unit test for adding a Delete statement to a Table
+     * @throws Exception
+     */
+    public void testAddDeleteStatement() throws Exception {
+    	ConfigHelper helper = new ConfigHelper();
+    	Table table = helper.addTable("widgets", "WIDGETS");
+    	helper.addDeleteStatement(table, "delete from widgets where id = ?", "ID");
+    	
+    	Config cfg = helper.getConfig();
+    	assertEquals(1, cfg.getTable().size());
+    	Table widgets = (Table) cfg.getTable().get(0);
+    	assertEquals("delete from widgets where id = ?", widgets.getDelete().getSql());
+    	assertEquals("WIDGETS", widgets.getTypeName());
+    	assertEquals("ID", widgets.getDelete().getParameters());
+    	
+    }
+    
+    /**
+     * Simple unit test for adding a Create statement to a Table
+     * @throws Exception
+     */
+    public void testAddCreateStatement() throws Exception {
+    	ConfigHelper helper = new ConfigHelper();
+    	Table table = helper.addTable("widgets", "WIDGETS");
+    	helper.addCreateStatement(table, "insert into widgets values (?,?)", "ID NAME");
+    	
+    	Config cfg = helper.getConfig();
+    	assertEquals(1, cfg.getTable().size());
+    	Table widgets = (Table) cfg.getTable().get(0);
+    	assertEquals("insert into widgets values (?,?)", widgets.getCreate().getSql());
+    	assertEquals("WIDGETS", widgets.getTypeName());
+    	assertEquals("ID NAME", widgets.getCreate().getParameters());
+    	
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message