private void fillTableToPrimaryKeysMap()

in rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ResultMetadata.java [173:229]


    private void fillTableToPrimaryKeysMap(){
	    Iterator itr = tableToPropertyMap.keySet().iterator();
	    while(itr.hasNext()){
	    	String curTableName = (String)itr.next();
	    	boolean treatAllPKs = false;//flag for, when all cols need to be treated as PKs
	    	
	    	if(tableToPrimaryKeysMap.containsKey(curTableName)){
	    		continue;//don't keep refilling same hashset for each ResultMetadata constructor,
	    	}
	    	
	    	List columnsForTable = null;
	    	if(configWrapper.getTableByTypeName(curTableName) != null) {
	    		 columnsForTable = configWrapper.getTableByTypeName(curTableName).getColumn();        		 
	    	}
	    	else if(configWrapper.getTable(curTableName) != null){
			 columnsForTable = configWrapper.getTable(curTableName).getColumn();
			 configWrapper.getTable(curTableName).setTypeName(curTableName);//keep configWrapper consistent with Type info
	    	}
	    	else{
	    		treatAllPKs = true;//can not find table/type, need to consider all columns as PKs
	    	}
	    	
	    	if(columnsForTable != null){
	            for(int ii=0; ii<columnsForTable.size(); ii++){
	            	Column curCol = (Column)columnsForTable.get(ii);
	            	
	            	if(curCol.isPrimaryKey() || curCol.getColumnName().equalsIgnoreCase("ID")){//need to compare col name
	            		//with ID as that is the one from dbms metadata or resul set shape metadata
	            		//but when putting in map, need to put property and if not present then column
	    	            Collection pks = (Collection) tableToPrimaryKeysMap.get(curTableName);
	    	            if(pks == null){
	    	            	pks = new HashSet();
	    	            }
	
	    	            if(curCol.getPropertyName() != null){
	    	            	pks.add(curCol.getPropertyName());
	    	            }
	    	            else{
	        	            pks.add(curCol.getColumnName());
	        	            curCol.setPropertyName(curCol.getColumnName());//make config consistent
	        	            if(!((Collection)tableToPropertyMap.get(curTableName)).contains(curCol.getColumnName())){
	        	            	((Collection)tableToPropertyMap.get(curTableName)).add(curCol.getColumnName());
	        	            }
	    	            }
	    	            tableToPrimaryKeysMap.put(curTableName, pks);	        	            		
	            	}
	            }        		
	    	}
	    	else{
	    		treatAllPKs = true;//table present in cfg , but no cols
	    	}
	    	
	    	if(treatAllPKs){
	    		tableToPrimaryKeysMap.put(curTableName, null);//case when all columns are considered PKs
	    	}
	    }
    }