Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions AnalyzerBeans Copyright (C) 2010 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 table structures")
 public class CompareTablesAnalyzer implements Explorer<TableComparisonResult> {
 	private static final Logger logger = LoggerFactory.getLogger(TableComparisonResult.class);
 	private boolean relationshipsAnalyzed;
 	public CompareTablesAnalyzer(Table table1Table table2) {
 		this. = table1;
 		this. = table2;
 		this. = false;
 	public CompareTablesAnalyzer() {
 		this. = true;
 	public void run(DataContext dc) {
 		assert  != null;
 		assert  != null;
 		List<TableDifference<?>> differences = new ArrayList<TableDifference<?>>();
 		List<ColumnComparisonResultcolumnComparisonResults = new ArrayList<ColumnComparisonResult>();
 		if ( == ) {
 			 = new TableComparisonResult(differencescolumnComparisonResults);
 		addDiff(differences"name".getName(), .getName());
 		addDiff(differences"type".getType(), .getType());
 		addDiff(differences"remarks".getRemarks(), .getRemarks());
 		List<StringcolumnNames1 = Arrays.asList(.getColumnNames());
 		List<StringcolumnNames2 = Arrays.asList(.getColumnNames());
 		List<StringcolumnsOnlyInTable1 = new ArrayList<String>(columnNames1);
 		for (String columnName : columnsOnlyInTable1) {
 			TableDifference<Stringdiff = new TableDifference<String>("unmatched column"columnNamenull);
 		List<StringcolumnsOnlyInTable2 = new ArrayList<String>(columnNames2);
 		for (String columnName : columnsOnlyInTable2) {
 			TableDifference<Stringdiff = new TableDifference<String>("unmatched column"nullcolumnName);
		List<StringcolumnsInBothTables = new ArrayList<String>(columnNames1);
		for (String columnName : columnsInBothTables) {
			Column column1 = .getColumnByName(columnName);
			Column column2 = .getColumnByName(columnName);
			CompareColumnsAnalyzer analyzer = new CompareColumnsAnalyzer(column1column2);;
			ColumnComparisonResult columnComparisonResult = analyzer.getResult();
			if (!columnComparisonResult.isColumnsEqual()) {
			// TODO: Include relationship analysis?
else {
			.debug("Skipping relationship analysis");
		 = new TableComparisonResult(differencescolumnComparisonResults);
	private <T> void addDiff(List<TableDifference<?>> differencesString valueName, T value1, T value2) {
		if (!EqualsBuilder.equals(value1value2)) {
			TableDifference<T> diff = new TableDifference<T>(valueNamevalue1value2);
		return ;
	public boolean isRelationshipsAnalyzed() {
	public void setRelationshipsAnalyzed(boolean relationshipsAnalyzed) {
		this. = relationshipsAnalyzed;
New to GrepCode? Check out our FAQ X