Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
eobjects.org AnalyzerBeans Copyright (C) 2010 eobjects.org This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the GNU Lesser General Public License, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this distribution; if not, write to: Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor Boston, MA 02110-1301 USA
 
 package org.eobjects.analyzer.beans;
 
 import java.util.List;
 
 
 
 @AnalyzerBean("Compare schema structures")
 public class CompareSchemasAnalyzer implements Explorer<SchemaComparisonResult> {
 
 	@Configured("First schema")
 
 	@Configured("Second schema")
 
 
 	public CompareSchemasAnalyzer(Schema schema1Schema schema2) {
 		this. = schema1;
 		this. = schema2;
 	}
 
 	public CompareSchemasAnalyzer() {
 	}
 
 		return ;
 	}
 
 	public void run(DataContext dc) {
 		assert  != null;
 		assert  != null;
 
 		List<SchemaDifference<?>> differences = new ArrayList<SchemaDifference<?>>();
 		List<TableComparisonResulttableComparisonResults = new ArrayList<TableComparisonResult>();
 
 		if ( == ) {
 			 = new SchemaComparisonResult(differencestableComparisonResults);
 			return;
 		}
 
 		addDiff(differences"name".getName(), .getName());
 
 		List<StringtableNames1 = Arrays.asList(.getTableNames());
 		List<StringtableNames2 = Arrays.asList(.getTableNames());
 
 		List<StringtablesOnlyInSchema1 = new ArrayList<String>(tableNames1);
 		tablesOnlyInSchema1.removeAll(tableNames2);
 
 		for (String tableName : tablesOnlyInSchema1) {
 			SchemaDifference<Stringdiff = new SchemaDifference<String>("unmatched table"tableName,
 					null);
 			differences.add(diff);
 		}
 
 		List<StringtablesOnlyInSchema2 = new ArrayList<String>(tableNames2);
 		tablesOnlyInSchema2.removeAll(tableNames1);
 
 		for (String tableName : tablesOnlyInSchema2) {
 			SchemaDifference<Stringdiff = new SchemaDifference<String>("unmatched table"null,
 					tableName);
 			differences.add(diff);
 		}
		List<StringtablesInBothSchemas = new ArrayList<String>(tableNames1);
		tablesInBothSchemas.retainAll(tableNames2);
		for (String tableName : tablesInBothSchemas) {
			Table table1 = .getTableByName(tableName);
			Table table2 = .getTableByName(tableName);
			CompareTablesAnalyzer analyzer = new CompareTablesAnalyzer(table1table2);
			analyzer.run(dc);
			TableComparisonResult tableComparisonResult = analyzer.getResult();
			if (!tableComparisonResult.isTablesEqual()) {
				tableComparisonResults.add(tableComparisonResult);
			}
		}
		// TODO: Include relationship analysis?
		 = new SchemaComparisonResult(differencestableComparisonResults);
	}
	private <T> void addDiff(List<SchemaDifference<?>> differencesString valueName, T value1, T value2) {
		if (!EqualsBuilder.equals(value1value2)) {
			SchemaDifference<T> diff = new SchemaDifference<T>(valueNamevalue1value2);
			differences.add(diff);
		}
	}
New to GrepCode? Check out our FAQ X