Diffkit question in Java

117 views
Skip to first unread message

Ben SA

unread,
Aug 23, 2014, 10:06:10 AM8/23/14
to diffki...@googlegroups.com
Hello,

I am busy working with the DiffKit in Java, but I do not seem to get any further. I want to compare two MySql tables in the same database. And I want to write a diff
file with the columns and records in csv to disk. 

How can I do this? Below is some code with pieces on which I am working right now.... not really working code. Except I can read the tables in Mysql..

Thanks in advance.

public class CompareTool {

    private static final String PROBE_TABLE_NAME = "tab1";
    private static final String COMPARE_TABLE_NAME = "tab2";
    private static final String CONNECTION_INFO_CONFIG_FILE_PATH = "./dbConnectionInfo.xml";
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws SQLException {
        DKDBConnectionInfo connectionInfo = (DKDBConnectionInfo) DKSpringUtil.getBean(
         "connectionInfo", new String[] { CONNECTION_INFO_CONFIG_FILE_PATH },
         DKDemoDB.class.getClassLoader());
      if (connectionInfo == null)
         throw new RuntimeException(String.format(
            "cannot find connectionInfo in Spring config file->%s",
            CONNECTION_INFO_CONFIG_FILE_PATH));
        System.out.println("connectionInfo->{}"+connectionInfo);
      DKDatabase connectionSource = new DKDatabase(connectionInfo);
      DKDBTableDataAccess tableDataAccess = new DKDBTableDataAccess(connectionSource);
      DKDBTable table = tableDataAccess.getTable(PROBE_TABLE_NAME);
      System.out.println("table->{1}"+table.containsColumn("cardid"));
     
      DKDBTable table2 = tableDataAccess.getTable(COMPARE_TABLE_NAME);
      System.out.println("table->{2}"+table2.containsColumn("cardid"));
      
      DKTableModel tm1 = DKTableModelUtil.createDefaultTableModel(DKDBFlavor.MYSQL, table,table.getPrimaryKeyColumnNames());
      DKTableModel tm2 = DKTableModelUtil.createDefaultTableModel(DKDBFlavor.MYSQL, table2,table2.getPrimaryKeyColumnNames());
      
      DKColumnModel[] lhsColumns = tm1.getColumns();
      int[] lhsKey = tm1.getKey();
      DKColumnModel[] rhsColumns = tm2.getColumns();
      int[] rhsKey = tm2.getKey();
      DKComparatorChain chain = new DKComparatorChain();
      Object[] lhrow_ = new Object[100];
      for (int i = 0; i < lhsKey.length; i++) {
         Comparator<Comparable[]> comparator = new DKElementComparator<Comparable>(
            lhsColumns[lhsKey[i]]._index, rhsColumns[rhsKey[i]]._index,
            DKComparableComparator.getInstance());
         
         Float _numberTolerance = new Float(0);
         Map<String, Float> toleranceMap_ = null;
         DKColumnModel lhColumnModel = lhsColumns[lhsKey[i]];
         DKColumnModel rhColumnModel = lhsColumns[lhsKey[i]];
         DKColumnComparison columnPlan = new DKColumnComparison(lhColumnModel, rhColumnModel, DKEqualsDiffor.getInstance());
DKColumnComparison[] map = createDefaultMap(tm1,tm2, _numberTolerance, toleranceMap_);
         int[][] displayIndexes_;
          
         DKDiffor dkfor = DKEqualsDiffor.getInstance();
         
         DKColumnComparison cmp = new DKColumnComparison(lhsColumns[lhsKey[i]], rhsColumns[rhsKey[i]], dkfor);
         cmp.validate(tm2, tm2);
   
         
         Object obj = cmp.getLHValue(lhsColumns);
          System.out.println(""+obj);
         chain.addComparator(comparator);
          System.out.println(""+chain.toString());
     
      }
        System.out.println(""+lhrow_.length);
        for (int lh=0; lh<lhrow_.length;lh++)
        {
            //System.out.println(""+lhrow_[lh]);
        }
      
        System.out.println(""+lhsColumns.length);
       DKColumnModel dkm = tm1.getColumn("cardid");
       
       DKColumnComparison dcc;
        System.out.println(""+chain.size());
        //chain.compare(tm1, tm2);
      //DKStandardTableComparison dc = new DKStandardTableComparison(., null, DKDiff.Kind.BOTH, map_, diffIndexes_, displayIndexes_, maxDiffs_);
        int[][] _displayIndexes;
        long _maxDiffs;
        
        DKMagicPlan dkmp = new DKMagicPlan();
        dkmp.setDbConnectionInfo(connectionInfo);
        
        dkmp.setLhsDBTableName(PROBE_TABLE_NAME);
        dkmp.setRhsDBTableName(COMPARE_TABLE_NAME);
        dkmp.setDiffKind(DKDiff.Kind.BOTH);
        dkmp.getWithSummary();
        dkmp.setSinkFilePath("D:\test");
    }
    
}


Mark

unread,
Aug 25, 2014, 4:17:28 AM8/25/14
to diffki...@googlegroups.com
Hi,
 
My understanding is that you should not need to write any Java code to do what you intend.   you should be able to accomplish the whole thing by feeding diffkit with the right parameters.
 
Regards,
Mark
Reply all
Reply to author
Forward
0 new messages