tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lrese...@apache.org
Subject svn commit: r733965 - in /tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb: config/wrapper/ graphbuilder/impl/
Date Mon, 12 Jan 2009 23:28:57 GMT
Author: lresende
Date: Mon Jan 12 15:28:56 2009
New Revision: 733965

URL: http://svn.apache.org/viewvc?rev=733965&view=rev
Log:
TUSCANY-2767 - Appling performance enhancements patch from Florian Pinel

Modified:
    tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/config/wrapper/RelationshipWrapper.java
    tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/DataObjectMaker.java
    tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/GraphBuilderMetadata.java
    tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/MultiTableRegistry.java
    tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultMetadata.java
    tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultSetProcessor.java
    tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultSetRow.java
    tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/RowObjects.java
    tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/TableData.java

Modified: tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/config/wrapper/RelationshipWrapper.java
URL: http://svn.apache.org/viewvc/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/config/wrapper/RelationshipWrapper.java?rev=733965&r1=733964&r2=733965&view=diff
==============================================================================
--- tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/config/wrapper/RelationshipWrapper.java
(original)
+++ tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/config/wrapper/RelationshipWrapper.java
Mon Jan 12 15:28:56 2009
@@ -29,19 +29,22 @@
 public class RelationshipWrapper {
 
     private Relationship relationship;
+    private List foreignKeys;
 
     public RelationshipWrapper(Relationship r) {
         this.relationship = r;
     }
 
     public Collection getForeignKeys() {
-        List keys = new ArrayList();
-        Iterator i = this.relationship.getKeyPair().iterator();
-        while (i.hasNext()) {
-            KeyPair pair = (KeyPair) i.next();
-            keys.add(pair.getForeignKeyColumn());
-        }
-        return keys;
+    	if (foreignKeys == null) {
+    		foreignKeys = new ArrayList();
+            Iterator i = this.relationship.getKeyPair().iterator();
+            while (i.hasNext()) {
+                KeyPair pair = (KeyPair) i.next();
+                foreignKeys.add(pair.getForeignKeyColumn());
+            }
+    	}
+        return foreignKeys;
     }
-
+    
 }

Modified: tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/DataObjectMaker.java
URL: http://svn.apache.org/viewvc/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/DataObjectMaker.java?rev=733965&r1=733964&r2=733965&view=diff
==============================================================================
--- tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/DataObjectMaker.java
(original)
+++ tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/DataObjectMaker.java
Mon Jan 12 15:28:56 2009
@@ -27,11 +27,11 @@
 import commonj.sdo.Type;
 import commonj.sdo.helper.DataFactory;
 
-public class DataObjectMaker {
+public final class DataObjectMaker {
 
     private final DataObject rootObject;
 
-    private final Logger logger = Logger.getLogger(DataObjectMaker.class);
+    private static final Logger logger = Logger.getLogger(DataObjectMaker.class);
 
     public DataObjectMaker(DataObject root) {
         this.rootObject = root;

Modified: tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/GraphBuilderMetadata.java
URL: http://svn.apache.org/viewvc/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/GraphBuilderMetadata.java?rev=733965&r1=733964&r2=733965&view=diff
==============================================================================
--- tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/GraphBuilderMetadata.java
(original)
+++ tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/GraphBuilderMetadata.java
Mon Jan 12 15:28:56 2009
@@ -41,15 +41,17 @@
 
 /**
  */
-public class GraphBuilderMetadata {
+public final class GraphBuilderMetadata {
 
-	private final Logger logger = Logger.getLogger(GraphBuilderMetadata.class);
+	private static final Logger logger = Logger.getLogger(GraphBuilderMetadata.class);
 	
     private MappingWrapper configWrapper;
 
     private final Collection resultSets = new ArrayList();
-
+    
     private String typeURI;
+    
+    private List definedTypes;
 
     private Type rootType;
 
@@ -57,7 +59,7 @@
     private HelperContext helperContext = HelperProvider.getInstance().getDefaultContext();

  
 
-    public GraphBuilderMetadata(Collection results, Config model, ResultSetShape shape) throws
SQLException {
+    public GraphBuilderMetadata(List results, Config model, ResultSetShape shape) throws
SQLException {
         this.configWrapper = new MappingWrapper(model);
         if (model != null) {
             this.typeURI = model.getDataObjectModel();
@@ -70,7 +72,7 @@
             resultSets.add(resultMetadata);
         }
 
-    }
+     }
 
     /**
      * Returns the collection of ResultMetadata objects
@@ -78,7 +80,7 @@
     public Collection getResultMetadata() {
         return this.resultSets;
     }
-
+    
     /**
      * Returns the set of defined relationships
      */
@@ -122,55 +124,55 @@
 
             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(helperContext, getDefaultURI(), tableName,
false);
-                    Property property = SDOUtil.createProperty(root, tableName, tableType);
-                    SDOUtil.setMany(property, true);
-                    SDOUtil.setContainment(property, true);
-                    if (this.logger.isDebugEnabled()) {
-               			this.logger.debug("GBMD.createDynamicTypes():CREATING NEW TABLE TYPE &
PROPERTY :"+tableName);
-               		}                    
-                }
-            }
-
-            // TODO tablePropertyMap is temporary until Tuscany-203 is fixed
-            Map tablePropertyMap = new HashMap();
+			// 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(helperContext, getDefaultURI(), tableName, false);
+					Property property = SDOUtil.createProperty(root, tableName, tableType);
+					SDOUtil.setMany(property, true);
+					SDOUtil.setContainment(property, true);
+					if (this.logger.isDebugEnabled()) {
+						this.logger.debug("GBMD.createDynamicTypes():CREATING NEW TABLE TYPE & PROPERTY
:"+tableName);
+					}                    
+				}
+			}
+
+			// TODO tablePropertyMap is temporary until Tuscany-203 is fixed
+			Map tablePropertyMap = new HashMap();
+
+			for (int i = 1; i <= resultMetadata.getResultSetSize(); i++) {
+
+				Property ref = root.getProperty(resultMetadata.getTablePropertyName(i));
+
+				if (ref == null) {
+					throw new RuntimeException("Could not find table " + resultMetadata.getTablePropertyName(i)

+							+ " in the SDO model");
+				}
+
+				// TODO Temporary code to check to see if a property has already been added.
+				// Replace when Tuscany-203 is fixed
+				List addedProperties = (List) tablePropertyMap.get(ref.getName());
+				if (addedProperties == null) {
+					addedProperties = new ArrayList();
+					tablePropertyMap.put(ref.getName(), addedProperties);
+				}
 
-            for (int i = 1; i <= resultMetadata.getResultSetSize(); i++) {
 
-                Property ref = root.getProperty(resultMetadata.getTablePropertyName(i));
-
-                if (ref == null) {
-                    throw new RuntimeException("Could not find table " + resultMetadata.getTablePropertyName(i)

-                            + " in the SDO model");
-                }
-                
-                // TODO Temporary code to check to see if a property has already been added.
-                // Replace when Tuscany-203 is fixed
-                List addedProperties = (List) tablePropertyMap.get(ref.getName());
-                if (addedProperties == null) {
-                    addedProperties = new ArrayList();
-                    tablePropertyMap.put(ref.getName(), addedProperties);
-                }
-
- 
 
-                String columnName = resultMetadata.getColumnPropertyName(i);
+				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);
 
-                // 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);
 
-                    SDOUtil.createProperty(ref.getType(), columnName, atype);
+				}
 
-                }
-
-            }
+			}
         }
 
         MappingWrapper wrapper = getConfigWrapper();
@@ -243,37 +245,39 @@
     }
 
     public List getDefinedTypes() {
-    	List types = null;
-    	List defaultTypes = null;
-        if (this.typeURI == null) {
-        	types = SDOUtil.getTypes(helperContext, getDefaultURI());
-        	defaultTypes = SDOUtil.getTypes(defaultHelperContext, getDefaultURI());
-        	if(defaultTypes != null){
-	            if(types == null) {
-	            	types = defaultTypes;
-	            }
-	            else {
-	            	types.addAll(defaultTypes);	
-	            }
-        	}
-            return types;
-        } 
-            
-        types = SDOUtil.getTypes(helperContext, typeURI);        
-        defaultTypes = SDOUtil.getTypes(defaultHelperContext, typeURI);
-        if(defaultTypes != null){
-	        if(types == null) {
-	        	types = defaultTypes;
-	        }
-	        else {
-	        	types.addAll(defaultTypes);	
-	        }   
-        }
-        
-        if(rootType != null)
-        	types.add(rootType);
-        return types;
-        
+    	if (this.definedTypes == null) {
+        	List types = null;
+        	List defaultTypes = null;
+            if (this.typeURI == null) {
+            	types = SDOUtil.getTypes(helperContext, getDefaultURI());
+            	defaultTypes = SDOUtil.getTypes(defaultHelperContext, getDefaultURI());
+            	if(defaultTypes != null){
+    	            if(types == null) {
+    	            	types = defaultTypes;
+    	            }
+    	            else {
+    	            	types.addAll(defaultTypes);	
+    	            }
+            	}
+            	this.definedTypes = types;
+            } else {
+                types = SDOUtil.getTypes(helperContext, typeURI);        
+                defaultTypes = SDOUtil.getTypes(defaultHelperContext, typeURI);
+                if(defaultTypes != null){
+        	        if(types == null) {
+        	        	types = defaultTypes;
+        	        }
+        	        else {
+        	        	types.addAll(defaultTypes);	
+        	        }   
+                }
+                
+                if(rootType != null)
+                	types.add(rootType);
+                this.definedTypes = types;
+            }
+    	}
+    	return this.definedTypes;
     }
 
 }

Modified: tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/MultiTableRegistry.java
URL: http://svn.apache.org/viewvc/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/MultiTableRegistry.java?rev=733965&r1=733964&r2=733965&view=diff
==============================================================================
--- tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/MultiTableRegistry.java
(original)
+++ tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/MultiTableRegistry.java
Mon Jan 12 15:28:56 2009
@@ -33,7 +33,7 @@
  * efficient if we could use LinkedHashMap from JDK 1.4
  */
 public class MultiTableRegistry implements TableRegistry {
-    private final Logger logger = Logger.getLogger(MultiTableRegistry.class);
+    private static final Logger logger = Logger.getLogger(MultiTableRegistry.class);
 
     private Map tableNameMap;
 

Modified: tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultMetadata.java
URL: http://svn.apache.org/viewvc/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultMetadata.java?rev=733965&r1=733964&r2=733965&view=diff
==============================================================================
--- tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultMetadata.java
(original)
+++ tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultMetadata.java
Mon Jan 12 15:28:56 2009
@@ -39,7 +39,7 @@
 
 import commonj.sdo.Type;
 
-public class ResultMetadata {
+public final class ResultMetadata {
 
     private Map tableToPropertyMap = new HashMap();
 

Modified: tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultSetProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultSetProcessor.java?rev=733965&r1=733964&r2=733965&view=diff
==============================================================================
--- tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultSetProcessor.java
(original)
+++ tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultSetProcessor.java
Mon Jan 12 15:28:56 2009
@@ -31,13 +31,15 @@
  * A ResultSetProcessor is used to transform the data in a ResultSet into a set of inter-related
EDataObjects.
  */
 public class ResultSetProcessor {
-    private final Logger logger = Logger.getLogger(ResultSetProcessor.class);
+    private static final Logger logger = Logger.getLogger(ResultSetProcessor.class);
 
     private TableRegistry registry;
 
     private GraphBuilderMetadata metadata;
 
     private final DataObjectMaker doMaker;
+    
+    private final RowObjects tableObjects;
 
     public ResultSetProcessor(DataObject g, GraphBuilderMetadata gbmd) {
 
@@ -49,6 +51,8 @@
         }
 
         doMaker = new DataObjectMaker(g);
+        
+        tableObjects = new RowObjects(metadata, registry);
 
         if (this.logger.isDebugEnabled()) {
             this.logger.debug(metadata);
@@ -80,20 +84,19 @@
             // results.getStatement().close();
             results.close();
         }
-
     }
 
     private void processResultSet(ResultSet rs, ResultMetadata rsMetadata, int start, int
end) throws SQLException {
-
+        ResultSetRow rsr = new ResultSetRow(rsMetadata);
         if (rs.getType() == ResultSet.TYPE_FORWARD_ONLY) {
             while (rs.next() && start < end) {
-                ResultSetRow rsr = new ResultSetRow(rs, rsMetadata);
+            	rsr.processRow(rs);
                 addRowToGraph(rsr, rsMetadata);
                 ++start;
             }
         } else {
             while (rs.absolute(start) && start < end) {
-                ResultSetRow rsr = new ResultSetRow(rs, rsMetadata);
+            	rsr.processRow(rs);
                 addRowToGraph(rsr, rsMetadata);
                 ++start;
             }
@@ -105,8 +108,8 @@
      * @param resultMetadata
      */
     private void addRowToGraph(ResultSetRow row, ResultMetadata resultMetadata) {
-        RowObjects tableObjects = new RowObjects(metadata, registry);
-        Iterator tables = row.getAllTableData().iterator();
+        tableObjects.clear();
+    	Iterator tables = row.getAllTableData().iterator();
         while (tables.hasNext()) {
             TableData rawDataFromRow = (TableData) tables.next();
 
@@ -120,7 +123,8 @@
 
             String tableName = rawDataFromRow.getTableName();
             DataObject tableObject = registry.get(tableName, rawDataFromRow.getPrimaryKeyValues());
-            if (tableObject == null
+            boolean newlyCreated = (tableObject == null);
+            if (newlyCreated
             		&& !rawDataFromRow.hasNullPrimaryKey()) {//2nd check for null data
in PK,
             	//as TableData.addData() - hasValidPrimaryKey=false is commented for a reason
             	//with this, DataObjs with null PK will not be added to registry and tableObjects
@@ -143,7 +147,7 @@
             	if (this.logger.isDebugEnabled()) {
                     this.logger.debug("Do not allow any Null tableObject in tableObjects");
                 }
-            	tableObjects.put(tableName, tableObject);
+            	tableObjects.put(tableName, tableObject, newlyCreated);
             }
         }
 

Modified: tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultSetRow.java
URL: http://svn.apache.org/viewvc/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultSetRow.java?rev=733965&r1=733964&r2=733965&view=diff
==============================================================================
--- tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultSetRow.java
(original)
+++ tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultSetRow.java
Mon Jan 12 15:28:56 2009
@@ -27,89 +27,117 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.log4j.Logger;
 
 /**
  * 
- * A ResultSetRow is used to transform a single row of a ResultSet into a set of EDataObjects.
+ * A ResultSetRow is used to transform a row of a ResultSet into a set of EDataObjects.
  */
 public class ResultSetRow {
-    private final Logger logger = Logger.getLogger(ResultSetRow.class);
+    private static final Logger logger = Logger.getLogger(ResultSetRow.class);
 
     private final ResultMetadata metadata;
-
+    private final boolean recursive;
+    private final int resultSetSize;
+    private Collection allTableNames;
+    private Set tablesWithNoPK = new HashSet();
+    private String[] tablePropertyNames;
+    private String[] columnPropertyNames;
+    private boolean[] isPKColumn;
     private Map tableMap = new HashMap();
-
     private List allTableData;
 
     /**
      * Method ResultSetRow.
      * 
+     * @param m
+     *            the result metadata
+     */
+    public ResultSetRow(ResultMetadata m) throws SQLException {
+        this.metadata = m;
+        this.recursive = m.isRecursive();
+        this.resultSetSize = m.getResultSetSize();
+        cacheMetadata();
+        getAllTableNamesForRS();
+        getTablesWithNoPK();
+    }
+    
+    /**
+     * Processes a single row in the ResultSet.
+     * 
      * @param rs
      *            A ResultSet positioned on the desired row
-     * @param ePackage
-     *            The package used to create EDataObjects
      */
-    public ResultSetRow(ResultSet rs, ResultMetadata m) throws SQLException {
-        this.metadata = m;
-        if (m.isRecursive()) {
+    public void processRow(ResultSet rs)  throws SQLException {
+    	// clear previous data 
+    	for (Iterator itTableData = tableMap.values().iterator(); itTableData.hasNext(); ) {
+    		TableData tableData = (TableData) itTableData.next();
+    		tableData.clear();
+    	}
+        allTableData = null;
+
+        // process row
+        if (recursive) {
             processRecursiveRow(rs);
         } else {
-            processRow(rs);
+        	processNonRecursiveRow(rs);
         }
     }
 
-    /**
-     * Processes a single row in the ResultSet Method processRow.
-     * 
-     * @param rs
-     */
-    private void processRow(ResultSet rs) throws SQLException {
+    private void processNonRecursiveRow(ResultSet rs) throws SQLException {
 
         if (this.logger.isDebugEnabled()) {
             this.logger.debug("");
         }
-        for (int i = 1; i <= metadata.getResultSetSize(); i++) {
-            Object data = getObject(rs, i);
-
-            TableData table = getRawData(metadata.getTablePropertyName(i));
+        for (int i = 1; i <= resultSetSize; i++) {
+        	Object data = getObject(rs, i);
+			TableData table = getRawData(tablePropertyNames[i]);
             if (this.logger.isDebugEnabled()) {
-                this.logger.debug("Adding column: " + metadata.getColumnPropertyName(i) +
"\tValue: " 
+                this.logger.debug("Adding column: " + columnPropertyNames[i] + "\tValue:
" 
                         + data + "\tTable: "
-                        + metadata.getTablePropertyName(i));
+                        + tablePropertyNames[i]);
             }
-            table.addData(metadata.getColumnPropertyName(i), metadata.isPKColumn(i), data);
-        }
-        
+            table.addData(columnPropertyNames[i], isPKColumn[i], data);
+		}
         checkResultSetMissesPK();
-    }
+        }
 
     //get all table names involved in current result set
     //can not use metadata.getAllTablePropertyNames()
     //as it gives table names for all tables from Config
-    public Collection getAllTableNamesForRS(){
-    	Collection allTableNamesForRS = new HashSet();
-    	for (int i = 1; i <= metadata.getResultSetSize(); i++) {
-    		allTableNamesForRS.add(metadata.getTablePropertyName(i));
+    private void getAllTableNamesForRS(){
+    	allTableNames = new HashSet(resultSetSize);
+    	for (int i = 1; i <= resultSetSize; i++) {
+    		allTableNames.add(tablePropertyNames[i]);
     	}
-    	return allTableNamesForRS;
+    }
+    
+    private void cacheMetadata() {
+    	tablePropertyNames = new String[resultSetSize + 1];
+    	columnPropertyNames = new String[resultSetSize + 1];
+    	isPKColumn = new boolean[resultSetSize + 1];
+        for (int i = 1; i <= resultSetSize; i++) {
+        	tablePropertyNames[i] = metadata.getTablePropertyName(i);
+        	columnPropertyNames[i] = metadata.getColumnPropertyName(i);
+        	isPKColumn[i] = metadata.isPKColumn(i);
+        }
     }
     	
-    //case when result set omits PK column, take care of compound PKs too
-    public void checkResultSetMissesPK(){
+    private void getTablesWithNoPK(){
+        //case when result set omits PK column, take care of compound PKs too
         boolean tableRSHasPK;
-        Collection allTableNames = getAllTableNamesForRS();
         Iterator itr = allTableNames.iterator();
         while(itr.hasNext()){
         	tableRSHasPK = false;
         	String currentTableName = (String)itr.next();
         	HashSet pks = metadata.getAllPKsForTable(currentTableName);
         	HashSet pksInRS = new HashSet();
-        	for(int j=1; j<=metadata.getResultSetSize(); j++){
-            	if(currentTableName.equals(metadata.getTablePropertyName(j)) &&
-            			metadata.isPKColumn(j) ){
-            		pksInRS.add(metadata.getColumnPropertyName(j));
+        	for(int j=1; j<=resultSetSize; j++){
+            	if(currentTableName.equals(tablePropertyNames[j]) &&
+            			isPKColumn[j] ){
+            		pksInRS.add(columnPropertyNames[j]);
             	}
             }
         	
@@ -148,49 +176,51 @@
         		}
         	}        	
         	
-        	//Default is TRUE(from TableData), so consider only FALSE case
-            if(!tableRSHasPK){
-            	TableData table = getRawData(currentTableName);
-            	table.setValidPrimaryKey(tableRSHasPK);
-            }
+        	if (!tableRSHasPK) tablesWithNoPK.add(currentTableName);
+
+    		if (this.logger.isDebugEnabled()) {
+            	this.logger.debug("table "+currentTableName+" hasValidPK "+tableRSHasPK);
+    		}
+        }
+    }
+
+    private void checkResultSetMissesPK(){
+    	//Default is TRUE(from TableData), so consider only FALSE case
+        Iterator itr = tablesWithNoPK.iterator();
+        while(itr.hasNext()){
+        	String currentTableName = (String)itr.next();
+           	TableData table = getRawData(currentTableName);
+           	table.setValidPrimaryKey(false);
         }
-        
-        //for testing
-		if (this.logger.isDebugEnabled()) {
-	        for (int i = 1; i <= metadata.getResultSetSize(); i++) {
-	        	TableData table = getRawData(metadata.getTablePropertyName(i));
-	        	this.logger.debug("table "+table.getTableName()+" hasValidPK "+table.hasValidPrimaryKey());
-	        }			
-		}
     }
     
-    public void processRecursiveRow(ResultSet rs) throws SQLException {
+    private void processRecursiveRow(ResultSet rs) throws SQLException {
         this.allTableData = new ArrayList();
         int i = 1;
 
-        while (i <= metadata.getResultSetSize()) {
-            TableData table = new TableData(metadata.getTablePropertyName(i));
+        while (i <= resultSetSize) {
+            TableData table = new TableData(tablePropertyNames[i]);
             this.allTableData.add(table);
 
-            while ((i <= metadata.getResultSetSize()) && (metadata.isPKColumn(i)))
{
+            while ((i <= resultSetSize) && (isPKColumn[i])) {
                 Object data = getObject(rs, i);
                 if (this.logger.isDebugEnabled()) {
-                    this.logger.debug("Adding column: " + metadata.getColumnPropertyName(i)

+                    this.logger.debug("Adding column: " + columnPropertyNames[i]
                             + "\tValue: " + data + "\tTable: "
-                            + metadata.getTablePropertyName(i));
+                            + tablePropertyNames[i]);
                 }
-                table.addData(metadata.getColumnPropertyName(i), true, data);
+                table.addData(columnPropertyNames[i], true, data);
                 i++;
             }
 
-            while ((i <= metadata.getResultSetSize()) && (!metadata.isPKColumn(i)))
{
+            while ((i <= resultSetSize) && (!isPKColumn[i])) {
                 Object data = getObject(rs, i);
                 if (this.logger.isDebugEnabled()) {
-                    this.logger.debug("Adding column: " + metadata.getColumnPropertyName(i)

+                    this.logger.debug("Adding column: " + columnPropertyNames[i] 
                             + "\tValue: " + data + "\tTable: "
-                            + metadata.getTablePropertyName(i));
+                            + tablePropertyNames[i]);
                 }
-                table.addData(metadata.getColumnPropertyName(i), false, data);
+                table.addData(columnPropertyNames[i], false, data);
                 i++;
             }
         }
@@ -247,7 +277,7 @@
 
         return table;
     }
-
+    
     public List getAllTableData() {
         if (this.allTableData == null) {
             this.allTableData = new ArrayList();

Modified: tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/RowObjects.java
URL: http://svn.apache.org/viewvc/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/RowObjects.java?rev=733965&r1=733964&r2=733965&view=diff
==============================================================================
--- tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/RowObjects.java
(original)
+++ tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/RowObjects.java
Mon Jan 12 15:28:56 2009
@@ -20,9 +20,11 @@
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.log4j.Logger;
 import org.apache.tuscany.das.rdb.config.KeyPair;
@@ -33,36 +35,63 @@
 import commonj.sdo.Property;
 
 public class RowObjects {
-    private final Logger logger = Logger.getLogger(RowObjects.class);
+    private static final Logger logger = Logger.getLogger(RowObjects.class);
 
     private Map objectsByTableName;
 
     private List tableObjects;
+    
+    private Set newTableObjectNames;
+
+    private Map tableTypeNames;
 
     private final GraphBuilderMetadata metadata;
 
     private final TableRegistry registry;
+    
+    private final MappingWrapper configWrapper;
+    
+    private final boolean hasRecursiveRelationships;
 
     public RowObjects(GraphBuilderMetadata metadata, TableRegistry registry) {
         objectsByTableName = new HashMap();
         tableObjects = new ArrayList();
+        newTableObjectNames = new HashSet();
+        tableTypeNames = new HashMap();
         this.metadata = metadata;
         this.registry = registry;
+        this.configWrapper = metadata.getConfigWrapper();
+        this.hasRecursiveRelationships = configWrapper.hasRecursiveRelationships();
+    }
+    
+    public void clear() {
+    	objectsByTableName.clear();
+    	tableObjects.clear();
+    	newTableObjectNames.clear();
     }
 
-    public void put(String key, DataObject value) {
+    public void put(String key, DataObject value, boolean newlyCreated) {
         objectsByTableName.put(key, value);
         tableObjects.add(value);
+        if (newlyCreated) newTableObjectNames.add(key);
     }
 
     public DataObject get(String tablePropertyName) {
         return (DataObject) objectsByTableName.get(tablePropertyName);
     }
+    
+    private String getTableTypeName(String tableName) {
+    	String typeName = (String) tableTypeNames.get(tableName);
+    	if (typeName == null) {
+    		typeName = configWrapper.getTableTypeName(tableName);
+    		tableTypeNames.put(tableName, typeName);
+    	}
+    	return typeName;
+    }
 
-    void processRelationships() {
-        MappingWrapper wrapper = metadata.getConfigWrapper();
-        if (wrapper.hasRecursiveRelationships()) {
-            processRecursiveRelationships(wrapper);
+    public void processRelationships() {
+        if (hasRecursiveRelationships) {
+            processRecursiveRelationships(configWrapper);
             return;
         }
 
@@ -70,20 +99,22 @@
         while (i.hasNext()) {
             Relationship r = (Relationship) i.next();
 
-            DataObject parentTable = get(wrapper.getTableTypeName(r.getPrimaryKeyTable()));
-            DataObject childTable = get(wrapper.getTableTypeName(r.getForeignKeyTable()));
+            String parentTypeName = getTableTypeName(r.getPrimaryKeyTable());
+            String childTypeName = getTableTypeName(r.getForeignKeyTable());
 
-            if (this.logger.isDebugEnabled()) {
-                this.logger.debug("Parent table: " + parentTable);
-                this.logger.debug("Child table: " + childTable);
-            }
-            if ((parentTable == null) || (childTable == null)) {
-                continue;
-            }
-
-            Property p = parentTable.getType().getProperty(r.getName());
-            setOrAdd(parentTable, childTable, p);
+            // the relationship needs to be set only if the parent or the child is newly
created
+            // otherwise the relationship has already been set
+            if (newTableObjectNames.contains(parentTypeName) || newTableObjectNames.contains(childTypeName))
{
+                DataObject parent = get(parentTypeName);
+                DataObject child = get(childTypeName);
+
+                if (this.logger.isDebugEnabled()) {
+                    this.logger.debug("Parent table: " + parent);
+                    this.logger.debug("Child table: " + child);
+                }
 
+                setOrAdd(parent, child, r.getName());
+            }
         }
     }
 
@@ -98,18 +129,16 @@
 
                 DataObject parentTable = findParentTable(table, r, wrapper);
 
-                if (parentTable == null) {
-                    continue;
-                }
 
-                Property p = parentTable.getType().getProperty(r.getName());
-                setOrAdd(parentTable, table, p);
+                setOrAdd(parentTable, table, r.getName());
             }
 
         }
     }
 
-    private void setOrAdd(DataObject parent, DataObject child, Property p) {
+    private void setOrAdd(DataObject parent, DataObject child, String propertyName) {
+        if (parent == null || child == null) return;
+        Property p = parent.getType().getProperty(propertyName);
         if (p.isMany()) {
             parent.getList(p).add(child);
         } else {

Modified: tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/TableData.java
URL: http://svn.apache.org/viewvc/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/TableData.java?rev=733965&r1=733964&r2=733965&view=diff
==============================================================================
--- tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/TableData.java
(original)
+++ tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/TableData.java
Mon Jan 12 15:28:56 2009
@@ -25,12 +25,12 @@
 
 import org.apache.log4j.Logger;
 
-public class TableData {
-    private final Logger logger = Logger.getLogger(TableData.class);
+public final class TableData {
+    private static final Logger logger = Logger.getLogger(TableData.class);
 
-    private Map columnData = new HashMap();
+    private Map columnData;
 
-    private List primaryKey = new ArrayList();
+    private List primaryKey;;
 
     private final String name;
 
@@ -44,6 +44,15 @@
         }
 
         this.name = tableName;
+        this.columnData = new HashMap();
+        this.primaryKey = new ArrayList();
+    }
+    
+    public void clear() {
+    	columnData.clear();
+    	primaryKey.clear();
+    	hasValidPrimaryKey = true;
+    	hasNullPrimaryKey = false;
     }
 
     public void addData(String columnName, boolean isPrimaryKeyColumn, Object data) {
@@ -58,14 +67,11 @@
                 if (this.logger.isDebugEnabled()) {
                     this.logger.debug("Column " + columnName + " is a primary key column
and is null");
                 }
+            	hasNullPrimaryKey = true;
                 //hasValidPrimaryKey = false; - if uncommented and JIRA-1464, RecursiveTests.testReadEngineParts()
will fail
-            }
-            if(data != null){
+            } else {
             	primaryKey.add(data);
             }
-            else{
-            	hasNullPrimaryKey = true;
-            }
         }
     }
 



Mime
View raw message