tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwilli...@apache.org
Subject svn commit: r398698 - in /incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb: ConfigHelper.java config/wrapper/MappingWrapper.java impl/ChangeFactory.java
Date Mon, 01 May 2006 21:41:32 GMT
Author: kwilliams
Date: Mon May  1 14:41:30 2006
New Revision: 398698

URL: http://svn.apache.org/viewcvs?rev=398698&view=rev
Log:
Patches for TUSCANY-250,252
"Error on INSERT for aliased table" and "Duplicate where clause on update" respectively

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/main/java/org/apache/tuscany/das/rdb/impl/ChangeFactory.java

Modified: incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/ConfigHelper.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/ConfigHelper.java?rev=398698&r1=398697&r2=398698&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
Mon May  1 14:41:30 2006
@@ -39,7 +39,11 @@
     public void addRelationship(String parentName, String childName) {
         configWrapper.addRelationship(parentName, childName);
     }
-
+    
+    public void addTable(String name, String propertyName) {
+        configWrapper.addTable(name, propertyName);
+    }
+    
     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/viewcvs/incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/config/wrapper/MappingWrapper.java?rev=398698&r1=398697&r2=398698&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
Mon May  1 14:41:30 2006
@@ -34,379 +34,378 @@
 
 import commonj.sdo.Property;
 
-
 public class MappingWrapper {
 
-	private static final ConfigFactory factory = ConfigFactoryImpl.eINSTANCE;
+    private static final ConfigFactory factory = ConfigFactoryImpl.eINSTANCE;
+
+    private static final boolean debug = false;
+
+    private Config config;
+
+    public MappingWrapper() {
+        // Empty Constructor
+    }
+
+    public MappingWrapper(Config mapping) {
+        this.config = mapping;
+    }
 
-	private static final boolean debug = false;
+    public Config getConfig() {
+        return this.config;
+    }
 
-	private Config config;
+    public Table getTable(String name) {
+        if (config == null)
+            return null;
+        DebugUtil.debugln(getClass(), debug, "Looking for table " + name);
+        Iterator i = config.getTable().iterator();
+        while (i.hasNext()) {
+            Table t = (Table) i.next();
+            if (name.equals(t.getName()))
+                return t;
+        }
 
-	public MappingWrapper() {
-		// Empty Constructor
-	}
-
-	public MappingWrapper(Config mapping) {
-		this.config = mapping;
-	}
-
-	public Config getConfig() {
-		return this.config;
-	}
-
-
-	public Table getTable(String name) {
-		if (config == null)
-			return null;
-		DebugUtil.debugln(getClass(), debug, "Looking for table " + name);
-		Iterator i = config.getTable().iterator();
-		while (i.hasNext()) {
-			Table t = (Table) i.next();
-			if (name.equals(t.getName()))
-				return t;
-		}
-
-		return null;
-	}
-
-	public Table getTableByPropertyName(String name) {
-		if (config == null)
-			return null;
-		DebugUtil.debugln(getClass(), debug, "Looking for table by property: "
-				+ name);
-		Iterator i = config.getTable().iterator();
-		while (i.hasNext()) {
-			Table t = (Table) i.next();
-			TableWrapper wrapper = new TableWrapper(t);
-			if (name.equals(wrapper.getPropertyName()))
-				return t;
-		}
         return null;
+    }
+
+    public Table getTableByPropertyName(String name) {
+        if (config == null)
+            return null;
+        DebugUtil.debugln(getClass(), debug, "Looking for table by property: " + name);
+        Iterator i = config.getTable().iterator();
+        while (i.hasNext()) {
+            Table t = (Table) i.next();
+            TableWrapper wrapper = new TableWrapper(t);
+            if (name.equals(wrapper.getPropertyName()))
+                return t;
+        }
+        return null;
+
+        // throw new RuntimeException("Table with property name " + name
+        // + " not found.");
+
+    }
+
+    public void addRelationship(String parentName, String childName) {
+
+        if (config == null)
+            config = factory.createConfig();
+
+        QualifiedColumn parent = new QualifiedColumn(parentName);
+        QualifiedColumn child = new QualifiedColumn(childName);
+
+        Relationship r = factory.createRelationship();
+        r.setName(child.getTableName());
+        r.setPrimaryKeyTable(parent.getTableName());
+        r.setForeignKeyTable(child.getTableName());
+        DebugUtil.debugln(getClass(), debug, "Created relationship from " + r.getPrimaryKeyTable()
+ " to "
+                + r.getForeignKeyTable() + " named " + r.getName());
 
-//		throw new RuntimeException("Table with property name " + name
-//				+ " not found.");
+        KeyPair pair = factory.createKeyPair();
+        pair.setPrimaryKeyColumn(parent.getColumnName());
+        pair.setForeignKeyColumn(child.getColumnName());
+
+        r.getKeyPair().add(pair);
+        r.setMany(true);
+
+        config.getRelationship().add(r);
+
+    }
+
+    public void addRelationship(Key parentKey, Key childKey) {
+
+        if (config == null)
+            config = factory.createConfig();
+
+        QualifiedColumn parent = new QualifiedColumn((String) parentKey.getColumNames().get(0));
+        QualifiedColumn child = new QualifiedColumn((String) childKey.getColumNames().get(0));
+
+        Relationship r = factory.createRelationship();
+        r.setName(child.getTableName());
+        r.setPrimaryKeyTable(parent.getTableName());
+        r.setForeignKeyTable(child.getTableName());
+        DebugUtil.debugln(getClass(), debug, "Created relationship from " + r.getPrimaryKeyTable()
+ " to "
+                + r.getForeignKeyTable() + " named " + r.getName());
+
+        Iterator i = parentKey.getColumNames().iterator();
+        Iterator j = childKey.getColumNames().iterator();
+        while (i.hasNext() && j.hasNext()) {
+            parent = new QualifiedColumn((String) i.next());
+            child = new QualifiedColumn((String) j.next());
+            KeyPair pair = factory.createKeyPair();
+            pair.setPrimaryKeyColumn(parent.getColumnName());
+            pair.setForeignKeyColumn(child.getColumnName());
+
+            r.getKeyPair().add(pair);
+        }
+        r.setMany(true);
+        config.getRelationship().add(r);
+
+    }
+
+    public void addPrimaryKey(String columnName) {
+        Key k = new Key(columnName);
+        addPrimaryKey(k, false);
+    }
+
+    public void addPrimaryKey(Key key) {
+        addPrimaryKey(key, false);
+    }
+
+    public void addGeneratedPrimaryKey(String columnName) {
+        Key key = new Key(columnName);
+        addPrimaryKey(key, true);
+    }
+
+    private void addPrimaryKey(Key key, boolean generated) {
+        if (config == null)
+            config = factory.createConfig();
+
+        Iterator i = key.getColumNames().iterator();
+        while (i.hasNext()) {
+            String columnName = (String) i.next();
+
+            QualifiedColumn pkColumn = new QualifiedColumn(columnName);
+            Table t = findOrCreateTable(pkColumn.getTableName());
+            Column c = findOrCreateColumn(t, pkColumn.getColumnName());
+            c.setPrimaryKey(true);
+            if (generated)
+                c.setGenerated(true);
+        }
+    }
+
+    public String getTablePropertyName(String tableName) {
+        Table t = getTable(tableName);
+        if (t == null)
+            return tableName;
+        String propertyName = t.getPropertyName();
 
-	}
+        if (propertyName == null)
+            return tableName;
 
-	public void addRelationship(String parentName, String childName) {
+        return propertyName;
+    }
+
+    public Column getColumn(Table t, String name) {
+        if (t == null)
+            return null;
+        Iterator i = t.getColumn().iterator();
+        while (i.hasNext()) {
+            Column c = (Column) i.next();
+            if (c.getName().equals(name)) {
+                return c;
+            }
+        }
+        DebugUtil
+                .debugln(getClass(), debug, "WARNING: Could not find column " + name + "
in table " + t.getName());
+        return null;
+    }
 
-		if (config == null)
-			config = factory.createConfig();
-
-		QualifiedColumn parent = new QualifiedColumn(parentName);
-		QualifiedColumn child = new QualifiedColumn(childName);
-
-		Relationship r = factory.createRelationship();
-		r.setName(child.getTableName());
-		r.setPrimaryKeyTable(parent.getTableName());
-		r.setForeignKeyTable(child.getTableName());
-		DebugUtil.debugln(getClass(), debug, "Created relationship from "
-				+ r.getPrimaryKeyTable() + " to " + r.getForeignKeyTable() + " named "
-				+ r.getName());
-
-		KeyPair pair = factory.createKeyPair();
-		pair.setPrimaryKeyColumn(parent.getColumnName());
-		pair.setForeignKeyColumn(child.getColumnName());
-
-		r.getKeyPair().add(pair);
-		r.setMany(true);
-
-		config.getRelationship().add(r);
-
-	}
-
-	
-	public void addRelationship(Key parentKey, Key childKey) {
-
-		if (config == null)
-			config = factory.createConfig();
-
-		QualifiedColumn parent = new QualifiedColumn((String) parentKey.getColumNames().get(0));
-		QualifiedColumn child = new QualifiedColumn((String) childKey.getColumNames().get(0));
-		
-		Relationship r = factory.createRelationship();
-		r.setName(child.getTableName());
-		r.setPrimaryKeyTable(parent.getTableName());
-		r.setForeignKeyTable(child.getTableName());
-		DebugUtil.debugln(getClass(), debug, "Created relationship from "
-				+ r.getPrimaryKeyTable() + " to " + r.getForeignKeyTable() + " named "
-				+ r.getName());
-
-		
-		Iterator i = parentKey.getColumNames().iterator();
-		Iterator j = childKey.getColumNames().iterator();
-		while ( i.hasNext() && j.hasNext()) {
-			parent = new QualifiedColumn((String) i.next());
-			child = new QualifiedColumn((String) j.next());
-			KeyPair pair = factory.createKeyPair();
-			pair.setPrimaryKeyColumn(parent.getColumnName());
-			pair.setForeignKeyColumn(child.getColumnName());
-			
-			r.getKeyPair().add(pair);
-		}
-		r.setMany(true);
-		config.getRelationship().add(r);
-
-	}
-
-	public void addPrimaryKey(String columnName) {
-		Key k = new Key(columnName);
-		addPrimaryKey(k, false);
-	}
-
-	public void addPrimaryKey(Key key) {
-		addPrimaryKey(key, false);
-	}
-	
-	public void addGeneratedPrimaryKey(String columnName) {
-		Key key = new Key(columnName);
-		addPrimaryKey(key, true);
-	}
-
-	private void addPrimaryKey(Key key, boolean generated) {
-	if (config == null)
-			config = factory.createConfig();
-
-		Iterator i = key.getColumNames().iterator();
-		while (i.hasNext()) {
-			String columnName = (String) i.next();
-
-			QualifiedColumn pkColumn = new QualifiedColumn(columnName);
-			Table t = findOrCreateTable(pkColumn.getTableName());
-			Column c = findOrCreateColumn(t, pkColumn.getColumnName());
-			c.setPrimaryKey(true);
-			if ( generated )
-				c.setGenerated(true);
-			
-			t.getColumn().add(c);
-		}
-	}
-	
-
-
-	public String getTablePropertyName(String tableName) {
-		Table t = getTable(tableName);
-		if (t == null)
-			return tableName;
-		String propertyName = t.getPropertyName();
-
-		if (propertyName == null)
-			return tableName;
-
-		return propertyName;
-	}
-
-	public Column getColumn(Table t, String name) {
-		if (t == null)
-			return null;
-		Iterator i = t.getColumn().iterator();
-		while (i.hasNext()) {
-			Column c = (Column) i.next();
-			if (c.getName().equals(name)) {
-				return c;
-			}
-		}
-		DebugUtil.debugln(getClass(), debug, "WARNING: Could not find column "
-				+ name + " in table " + t.getName());
-		return null;
-	}
-    
     public Column getColumnByPropertyName(Table t, String propertyName) {
         if (t == null)
             return null;
         Iterator i = t.getColumn().iterator();
         while (i.hasNext()) {
             Column c = (Column) i.next();
-            if (c.getName().equals(propertyName)) 
+            if (c.getName().equals(propertyName))
                 return c;
             if (c.getPropertyName() != null && c.getPropertyName().equals(propertyName))
-               return c;
+                return c;
+        }
+        DebugUtil.debugln(getClass(), debug, "WARNING: Could not find column " + propertyName
+ " in table "
+                + t.getName());
+        return null;
+    }
+
+    public String getColumnPropertyName(String tableName, String columnName) {
+        Table t = getTable(tableName);
+        Column c = getColumn(t, columnName);
+        if (c == null)
+            return columnName;
+
+        String propertyName = c.getPropertyName();
+        if (propertyName == null)
+            return c.getName();
+
+        return propertyName;
+    }
+
+    public void addCollisionColumn(String columnName) {
+
+        if (config == null)
+            config = factory.createConfig();
+
+        QualifiedColumn occColumn = new QualifiedColumn(columnName);
+        Table t = findOrCreateTable(occColumn.getTableName());
+        Column c = findOrCreateColumn(t, occColumn.getColumnName());
+        c.setCollision(true);
+
+        config.getTable().add(t);
+    }
+
+    public void addTable(String tableName, String propertyName) {
+        Table table = getTable(tableName);
+        if (table != null)
+            throw new Error("Table " + tableName + "already exists");
+
+        table = ConfigFactoryImpl.eINSTANCE.createTable();
+        table.setName(tableName);
+        table.setPropertyName(propertyName);
+        config.getTable().add(table);
+
+    }
+
+    private Table findOrCreateTable(String tableName) {
+        Table table = getTable(tableName);
+        if (table == null) {
+            table = ConfigFactoryImpl.eINSTANCE.createTable();
+            table.setName(tableName);
+            config.getTable().add(table);
+        }
+        return table;
+
+    }
+
+    private Column findOrCreateColumn(Table t, String name) {
+        Iterator i = t.getColumn().iterator();
+        while (i.hasNext()) {
+            Column c = (Column) i.next();
+            if (name.equals(c.getName()))
+                return c;
+        }
+
+        Column c = ConfigFactoryImpl.eINSTANCE.createColumn();
+        c.setName(name);
+        t.getColumn().add(c);
+        return c;
+    }
+
+    public boolean hasRecursiveRelationships() {
+        if (config != null) {
+            Iterator i = getConfig().getRelationship().iterator();
+            while (i.hasNext()) {
+                Relationship r = (Relationship) i.next();
+                if (r.getPrimaryKeyTable().equals(r.getForeignKeyTable()))
+                    return true;
+            }
+        }
+        return false;
+    }
+
+    public Collection getRelationshipsByChildTable(String name) {
+        ArrayList results = new ArrayList();
+        if (config != null) {
+            Iterator i = getConfig().getRelationship().iterator();
+            while (i.hasNext()) {
+                Relationship r = (Relationship) i.next();
+                if (name.equals(r.getForeignKeyTable()))
+                    results.add(r);
+            }
+        }
+        return results;
+    }
+
+    // TODO optimize
+    public ArrayList getInsertOrder() {
+        DebugUtil.debugln(getClass(), debug, "Getting insert order");
+        ArrayList inserts = new ArrayList();
+        HashMap parentToChild = new HashMap();
+
+        ArrayList parents = new ArrayList();
+        ArrayList children = new ArrayList();
+        if (config != null) {
+            Iterator i = getConfig().getRelationship().iterator();
+            while (i.hasNext()) {
+                Relationship r = (Relationship) i.next();
+                parents.add(r.getPrimaryKeyTable());
+                children.add(r.getForeignKeyTable());
+                parentToChild.put(r.getPrimaryKeyTable(), r.getForeignKeyTable());
+            }
+
+            while (parents.size() > 0) {
+                String parent = (String) parents.get(0);
+                if (!children.contains(parent)) {
+                    if (!inserts.contains(parent))
+                        inserts.add(parent);
+
+                    String child = (String) parentToChild.get(parent);
+                    if (!inserts.contains(child))
+                        inserts.add(child);
+
+                    parents.remove(parent);
+                    children.remove(child);
+                } else {
+                    parents.add(parents.remove(0));
+                }
+            }
+            inserts.addAll(children);
+
         }
-        DebugUtil.debugln(getClass(), debug, "WARNING: Could not find column "
-                + propertyName + " in table " + t.getName());
+
+        DebugUtil.debugln(getClass(), debug, inserts);
+        return inserts;
+    }
+
+    public ArrayList getDeleteOrder() {
+        ArrayList deleteOrder = new ArrayList();
+        deleteOrder.addAll(getInsertOrder());
+        Collections.reverse(deleteOrder);
+        return deleteOrder;
+    }
+
+    public void addConverter(String name, String converter) {
+        if (config == null)
+            config = factory.createConfig();
+
+        QualifiedColumn column = new QualifiedColumn(name);
+        Table t = findOrCreateTable(column.getTableName());
+        Column c = findOrCreateColumn(t, column.getColumnName());
+        c.setConverterClassName(converter);
+
+    }
+
+    public String getConverter(String tableName, String columnName) {
+        Table t = getTable(tableName);
+        Column c = getColumn(t, columnName);
+        if (c != null)
+            return c.getConverterClassName();
         return null;
-    }    
-    
+    }
+
+    public HashMap getConverters(Table table) {
+        HashMap converters = new HashMap();
 
-	public String getColumnPropertyName(String tableName, String columnName) {
-		Table t = getTable(tableName);
-		Column c = getColumn(t, columnName);
-		if (c == null)
-			return columnName;
-
-		String propertyName = c.getPropertyName();
-		if (propertyName == null)
-			return c.getName();
-
-		return propertyName;
-	}
-
-	public void addCollisionColumn(String columnName) {
-
-		if (config == null)
-			config = factory.createConfig();
-
-		QualifiedColumn occColumn = new QualifiedColumn(columnName);
-		Table t = findOrCreateTable(occColumn.getTableName());
-		Column c = findOrCreateColumn(t, occColumn.getColumnName());
-		c.setCollision(true);
-
-		config.getTable().add(t);
-	}
-
-	private Table findOrCreateTable(String tableName) {
-		Table table = getTable(tableName);
-		if (table == null) {
-			table = ConfigFactoryImpl.eINSTANCE.createTable();
-			table.setName(tableName);
-			config.getTable().add(table);
-		}
-		return table;
-
-	}
-
-	private Column findOrCreateColumn(Table t, String name) {
-		Iterator i = t.getColumn().iterator();
-		while (i.hasNext()) {
-			Column c = (Column) i.next();
-			if (name.equals(c.getName()))
-				return c;
-		}
-
-		Column c = ConfigFactoryImpl.eINSTANCE.createColumn();
-		c.setName(name);
-		t.getColumn().add(c);
-		return c;
-	}
-
-	public boolean hasRecursiveRelationships() {
-		if (config != null) {
-			Iterator i = getConfig().getRelationship().iterator();
-			while (i.hasNext()) {
-				Relationship r = (Relationship) i.next();
-				if (r.getPrimaryKeyTable().equals(r.getForeignKeyTable()))
-					return true;
-			}
-		}
-		return false;
-	}
-
-	public Collection getRelationshipsByChildTable(String name) {
-		ArrayList results = new ArrayList();
-		if (config != null) {
-			Iterator i = getConfig().getRelationship().iterator();
-			while (i.hasNext()) {
-				Relationship r = (Relationship) i.next();
-				if (name.equals(r.getForeignKeyTable()))
-					results.add(r);
-			}
-		}
-		return results;
-	}
-
-	// TODO optimize
-	public ArrayList getInsertOrder() {
-		DebugUtil.debugln(getClass(), debug, "Getting insert order");
-		ArrayList inserts = new ArrayList();
-		HashMap parentToChild = new HashMap();
-
-		ArrayList parents = new ArrayList();
-		ArrayList children = new ArrayList();
-		if (config != null) {
-			Iterator i = getConfig().getRelationship().iterator();
-			while (i.hasNext()) {
-				Relationship r = (Relationship) i.next();
-				parents.add(r.getPrimaryKeyTable());
-				children.add(r.getForeignKeyTable());
-				parentToChild.put(r.getPrimaryKeyTable(), r.getForeignKeyTable());
-			}
-
-			while (parents.size() > 0) {
-				String parent = (String) parents.get(0);
-				if (!children.contains(parent)) {
-					if (!inserts.contains(parent))
-						inserts.add(parent);
-
-					String child = (String) parentToChild.get(parent);
-					if (!inserts.contains(child))
-						inserts.add(child);
-
-					parents.remove(parent);
-					children.remove(child);
-				} else {
-					parents.add(parents.remove(0));
-				}
-			}
-			inserts.addAll(children);
-
-		}
-
-		DebugUtil.debugln(getClass(), debug, inserts);
-		return inserts;
-	}
-
-	public ArrayList getDeleteOrder() {
-		ArrayList deleteOrder = new ArrayList();
-		deleteOrder.addAll(getInsertOrder());
-		Collections.reverse(deleteOrder);
-		return deleteOrder;
-	}
-
-	public void addConverter(String name, String converter) {
-		if (config == null)
-			config = factory.createConfig();
-
-		QualifiedColumn column = new QualifiedColumn(name);
-		Table t = findOrCreateTable(column.getTableName());
-		Column c = findOrCreateColumn(t, column.getColumnName());
-		c.setConverterClassName(converter);
-
-	}
-
-	public String getConverter(String tableName, String columnName) {
-		Table t = getTable(tableName);
-		Column c = getColumn(t, columnName);
-		if (c != null)
-			return c.getConverterClassName();
-		return null;
-	}
-
-	public HashMap getConverters(Table table) {
-		HashMap converters = new HashMap();
-		
-		Iterator columns = table.getColumn().iterator();
-		while ( columns.hasNext() ) {
-			Column c = (Column) columns.next();
-			if ( c.getConverterClassName() != null ) {
-				String property = c.getPropertyName();
-				if ( property == null )
-					property = c.getName();
-				converters.put(property, c.getConverterClassName());
-			}
-		}
-		return converters;
-	}
-
-	public Relationship getRelationshipByReference(Property ref) {
-		Iterator i = config.getRelationship().iterator();
-		while ( i.hasNext() ) {
-			Relationship r = (Relationship) i.next();
-			if ( ref.getName().equals (r.getName()) ||
-					ref.getOpposite().getName().equals(r.getName())) 
-				return r;
-		}
-		throw new RuntimeException("Could not find relationship " + ref.getName() + " in the configuration");
-	}
-	
-	public Relationship getRelationshipByName(String name) {
-		Iterator i = config.getRelationship().iterator();
-		while ( i.hasNext() ) {
-			Relationship r = (Relationship) i.next();
-			if ( name.equals (r.getName())) 
-				return r;
-		}
-		throw new RuntimeException("Could not find relationship " + name + " in the configuration");
-	}
+        Iterator columns = table.getColumn().iterator();
+        while (columns.hasNext()) {
+            Column c = (Column) columns.next();
+            if (c.getConverterClassName() != null) {
+                String property = c.getPropertyName();
+                if (property == null)
+                    property = c.getName();
+                converters.put(property, c.getConverterClassName());
+            }
+        }
+        return converters;
+    }
+
+    public Relationship getRelationshipByReference(Property ref) {
+        Iterator i = config.getRelationship().iterator();
+        while (i.hasNext()) {
+            Relationship r = (Relationship) i.next();
+            if (ref.getName().equals(r.getName()) || ref.getOpposite().getName().equals(r.getName()))
+                return r;
+        }
+        throw new RuntimeException("Could not find relationship " + ref.getName() + " in
the configuration");
+    }
+
+    public Relationship getRelationshipByName(String name) {
+        Iterator i = config.getRelationship().iterator();
+        while (i.hasNext()) {
+            Relationship r = (Relationship) i.next();
+            if (name.equals(r.getName()))
+                return r;
+        }
+        throw new RuntimeException("Could not find relationship " + name + " in the configuration");
+    }
 
 }

Modified: incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ChangeFactory.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ChangeFactory.java?rev=398698&r1=398697&r2=398698&view=diff
==============================================================================
--- incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ChangeFactory.java
(original)
+++ incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ChangeFactory.java
Mon May  1 14:41:30 2006
@@ -99,7 +99,7 @@
 	private InsertCommandImpl getCreateCommand(DataObject changedObject) {
 		
 		if ( createCommand == null ) {
-			Table table = mapping.getTable(changedObject.getType().getName());
+			Table table = mapping.getTableByPropertyName(changedObject.getType().getName());
 			if (table == null ) {
 				if (changedObject.getType().getProperty("ID") != null ) {
 					// If the table is not defined in the config, assume it has a primary key of "ID"
@@ -131,7 +131,7 @@
 	private DeleteCommandImpl getDeleteCommand(DataObject changedObject) {
 		
 		if ( deleteCommand == null ) {
-			Table table = mapping.getTable(changedObject.getType().getName());
+			Table table = mapping.getTableByPropertyName(changedObject.getType().getName());
 			if (table == null )  {
 				if (changedObject.getType().getProperty("ID") != null ) {
 					// If the table is not defined in the config, assume it has a primary key of "ID"



Mime
View raw message