tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdan...@apache.org
Subject svn commit: r441174 - in /incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb: graphbuilder/impl/GraphBuilderMetadata.java graphbuilder/schema/ESchemaMaker.java impl/ReadCommandImpl.java
Date Thu, 07 Sep 2006 18:53:06 GMT
Author: bdaniel
Date: Thu Sep  7 11:53:02 2006
New Revision: 441174

URL: http://svn.apache.org/viewvc?view=rev&rev=441174
Log:
Tuscany-710 Make use of new function in SDO to register Types with a DataGraph

Removed:
    incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/schema/ESchemaMaker.java
Modified:
    incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/GraphBuilderMetadata.java
    incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ReadCommandImpl.java

Modified: incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/GraphBuilderMetadata.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/GraphBuilderMetadata.java?view=diff&rev=441174&r1=441173&r2=441174
==============================================================================
--- incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/GraphBuilderMetadata.java
(original)
+++ incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/GraphBuilderMetadata.java
Thu Sep  7 11:53:02 2006
@@ -22,14 +22,20 @@
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 
 import org.apache.tuscany.das.rdb.config.Config;
+import org.apache.tuscany.das.rdb.config.Relationship;
 import org.apache.tuscany.das.rdb.config.wrapper.MappingWrapper;
-import org.apache.tuscany.das.rdb.graphbuilder.schema.ESchemaMaker;
 import org.apache.tuscany.das.rdb.impl.ResultSetShape;
+import org.apache.tuscany.sdo.util.DataObjectUtil;
+import org.apache.tuscany.sdo.util.SDOUtil;
 
+import commonj.sdo.Property;
 import commonj.sdo.Type;
+import commonj.sdo.helper.TypeHelper;
 
 
 /**
@@ -39,6 +45,8 @@
 	private MappingWrapper configWrapper;
 	private final Collection resultSets = new ArrayList();
 	private String typeURI;
+	private Type rootType = null;
+	private TypeHelper typeHelper = SDOUtil.createTypeHelper();
 
 
 	public GraphBuilderMetadata(Collection results, Config model, ResultSetShape shape) throws
SQLException {
@@ -56,13 +64,15 @@
 
 	}
 	
-
+	/**
+	 * Returns the collection of ResultMetadata objects	
+	 */
 	public Collection getResultMetadata() {
 		return this.resultSets;
 	}
 
 	/**
-	 * @return
+	 * Returns the set of defined relationships
 	 */
 	
 	public Collection getRelationships() {
@@ -71,18 +81,170 @@
 
 
 	/**
-	 * @return
+	 * Returns the root Type
 	 */
-	public Type getSchema() {
-		ESchemaMaker schemaMaker = new ESchemaMaker(this);
-		if ( this.typeURI == null ) {		
-			return schemaMaker.createTypes();
-		} else {
-			return schemaMaker.createTypes(this.typeURI);
+	public Type getRootType() {		
+		if ( this.rootType == null ) {
+			if ( this.typeURI == null ) 
+				createDynamicTypes();
+			else
+				createDynamicRoot();
 		}
+		
+		return this.rootType ;
 	}
 
 	public MappingWrapper getConfigWrapper() {
 		return this.configWrapper;
 	}
+	
+	/**
+	 * Creates a set of SDO Types based on the query results and supplied config information
+	 */
+
+	private void createDynamicTypes() {
+		
+		DataObjectUtil.initRuntime();	
+	
+		Type root = SDOUtil.createType(typeHelper, getDefaultURI(), "DataGraphRoot", false);	
+
+		Iterator iter = getResultMetadata().iterator();
+		while (iter.hasNext()) {
+
+			ResultMetadata resultMetadata = (ResultMetadata) iter.next();
+
+			// Create a Type for each Table represented in the ResultSet
+			Iterator names = resultMetadata.getAllTablePropertyNames()
+					.iterator();
+			while (names.hasNext()) {
+				String tableName = (String) names.next();
+	
+				if ( root.getProperty(tableName) == null ) {
+					Type tableType = SDOUtil.createType(typeHelper, getDefaultURI(), tableName, false);
									
+					Property property = SDOUtil.createProperty(root, tableName, tableType);
+					SDOUtil.setMany(property,true);		
+					SDOUtil.setContainment(property, true);
+				}
+			}
+		
+			// TODO tablePropertyMap is temporary until Tuscany-203 is fixed
+			HashMap tablePropertyMap = new HashMap();
+			
+			for (int i = 1; i <= resultMetadata.getResultSetSize(); i++) {
+
+				Property ref = root.getProperty(resultMetadata.getTablePropertyName(i));
+				
+				// TODO Temporary code to check to see if a property has already been added.
+				// Replace when Tuscany-203 is fixed
+				ArrayList addedProperties = (ArrayList) tablePropertyMap.get(ref.getName());
+				if ( addedProperties == null ) {
+					addedProperties = new ArrayList();
+					tablePropertyMap.put(ref.getName(), addedProperties);
+				}
+				
+				if (ref == null)
+					throw new RuntimeException("Could not find table "
+							+ resultMetadata.getTablePropertyName(i)
+							+ " in the SDO model");
+			
+				String columnName = resultMetadata.getColumnPropertyName(i);
+
+				// TODO temporary check until Tuscany-203 is fixed
+				if ( !addedProperties.contains(columnName)) {
+					addedProperties.add(columnName);
+					Type atype = resultMetadata.getDataType(i);					
+	
+					SDOUtil.createProperty(ref.getType(), columnName, atype);				
+					
+				}
+
+			}
+		}
+
+
+		MappingWrapper wrapper = getConfigWrapper();
+		Iterator i = getRelationships().iterator();
+		while (i.hasNext()) {
+			Relationship r = (Relationship) i.next();
+
+			String parentName = wrapper
+					.getTableTypeName(r.getPrimaryKeyTable());
+			String childName = wrapper.getTableTypeName(r.getForeignKeyTable());
+
+			if (parentName == null) {
+				throw new RuntimeException("The parent table ("
+						+ r.getPrimaryKeyTable() + ") in relationship "
+						+ r.getName()
+						+ " was not found in the mapping information.");
+			} else if (childName == null) {
+				throw new RuntimeException("The child table ("
+						+ r.getForeignKeyTable() + ") in relationship "
+						+ r.getName()
+						+ " was not found in the mapping information.");
+			}
+
+			Property parentProperty = root.getProperty(parentName);
+			Property childProperty = root.getProperty(childName);
+
+			if (parentProperty == null) {
+				throw new RuntimeException("The parent table (" + parentName
+						+ ") in relationship " + r.getName()
+						+ " was not found.");
+			} else if (childProperty == null) {
+				throw new RuntimeException("The child table (" + childName
+						+ ") in relationship " + r.getName()
+						+ " was not found.");
+			}
+
+			Type parent = parentProperty.getType();
+			Type child = childProperty.getType();
+
+			Property parentProp = SDOUtil.createProperty(parent, r.getName(),
+					child);
+			Property childProp = SDOUtil.createProperty(child, r.getName()
+					+ "_opposite", parent);
+			SDOUtil.setOpposite(parentProp, childProp);
+			SDOUtil.setOpposite(childProp, parentProp);
+			SDOUtil.setMany(parentProp, r.isMany());
+		}
+
+		
+		this.rootType = root;
+	}
+
+	private String getDefaultURI() {
+		return "http:///org.apache.tuscany.das.rdb/das";
+	}
+
+	/**
+	 * Create a dynamic root Type to act as a container Type for a set of generated Types
+	 *
+	 */
+	private void createDynamicRoot() {
+		Type root = SDOUtil.createType(typeHelper, getDefaultURI() + "/DataGraphRoot", "DataGraphRoot",
false);	
+		
+		List types = SDOUtil.getTypes(typeHelper, typeURI);
+		if ( types == null )
+			throw new RuntimeException("SDO Types have not been registered for URI " + typeURI);
+		
+		Iterator i = types.iterator();
+		while ( i.hasNext() ) {
+			Type type = (Type) i.next();
+			Property property = SDOUtil.createProperty(root, type.getName(), type);
+			SDOUtil.setContainment(property, true);
+			SDOUtil.setMany(property, true);			
+		}
+		this.rootType = root;
+	}
+
+	public List getDefinedTypes() {
+		if ( this.typeURI == null ) {
+			return SDOUtil.getTypes(typeHelper, getDefaultURI());
+		} else {
+			List types = SDOUtil.getTypes(typeHelper, typeURI);
+			types.add(rootType);
+			return types;
+		}
+	}	
+
 }

Modified: incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ReadCommandImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ReadCommandImpl.java?view=diff&rev=441174&r1=441173&r2=441174
==============================================================================
--- incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ReadCommandImpl.java
(original)
+++ incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ReadCommandImpl.java
Thu Sep  7 11:53:02 2006
@@ -81,9 +81,11 @@
         // Create the DataGraph
         DataGraph g = SDOUtil.createDataGraph();
 
-        // Create the root object
-        g.createRootObject(gbmd.getSchema());
+        // Create the root object       
+        g.createRootObject(gbmd.getRootType());
 
+        SDOUtil.registerDataGraphTypes(g, gbmd.getDefinedTypes());
+        
         ChangeSummary summary = g.getChangeSummary();
 
         ResultSetProcessor rsp = new ResultSetProcessor(g.getRootObject(), gbmd);



---------------------------------------------------------------------
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