keep moving!

          We must not cease from exploration. And the end of all our exploring will be to arrive where we began and to know the place for the first time.
          隨筆 - 37, 文章 - 2, 評論 - 3, 引用 - 0
          數據加載中……

          數據文件比較

          def dbDefInfo = new XmlParser().parse(new File(".\\DbDef.xml"))
          def file1Path = ".\\fullConfig1.xml"
          def file2Path = ".\\fullConfig2.xml"

          println "~~~~~~~~~~~~~~~~~~~~~~~~~~  $file1Path to $file2Path   ~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n"
          compareXml(new File(file1Path),new File(file2Path),dbDefInfo)
          println "\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~   $file2Path to $file1Path   ~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n"
          compareXml(new File(file2Path),new File(file1Path),dbDefInfo)


          println 'fineshed'

          def compareXml(file1,file2,dbDef){
              def tablelist1 = new XmlParser().parse(file1)
              def tablelist2 = new XmlParser().parse(file2)

              tablelist1.DBTABLE.each {dbtable1 ->
                  for(dbRecord in dbtable1.DBRECORD){
                      def otherDbRecord = findDbRecord(dbtable1,dbRecord,tablelist2,dbDef)
                      compareDbRecord(dbRecord,otherDbRecord)
                   }
              }
          }

          def findDbRecord(dbtable1,dbRecord,tablelist2,dbDef){
              def tableDef = dbDef.Table.find {"${it.@Name}" == "${dbtable1.@name}"}
              if (tableDef == null){
                  println "${dbtable1.@name} is not exist in dbdef" ;
                  return null;
              }
              def priKeyMap = getPriKeyInfo(tableDef)
              def prikeyInfo = priKeyMap["${dbtable1.@name}"]
              def rdnMap = [:]

              dbRecord.FIELD.findAll{prikeyInfo.contains("${it.@name}")}.each{rdnMap.put("${it.@name}","${it.@value}")}
              def dbtable2 =

              tablelist2.DBTABLE.find{"${it.@name}" == "${dbtable1.@name}"}

              if(dbtable2 == null)
                  return null
              else
                  return dbtable2.DBRECORD.find{dbRecord2 ->
                      def field2s = dbRecord2.FIELD.findAll{rdnMap.containsKey("${it.@name}") && rdnMap.get("${it.@name}") == "${it.@value}"}
                      field2s.size() == rdnMap.size()
                      }
          }

          def compareDbRecord(dbRecord1,dbRecord2){

              if (dbRecord2==null){
                  printDbRecord(dbRecord1,dbRecord2)
                  return;
              }

              def sign1 = dbRecord1.FIELD.find{filed1 ->
                  dbRecord2.FIELD.find{filed2 ->
                      "${filed1.@name}"=="${filed2.@name}"?"${filed1.@value}"!="${filed2.@value}":false
                  }
              }

              def sign2 = dbRecord2.FIELD.find{filed1 ->
              dbRecord1.FIELD.find{filed2 ->
                      "${filed1.@name}"=="${filed2.@name}"?"${filed1.@value}"!="${filed2.@value}":false
              }
          }
              if (sign1  || sign2)
              {
                  printDbRecord(dbRecord1,dbRecord2)
              }
          }

          def printDbRecord(dbRecord1,dbRecord2){
              dbRecord1.FIELD.each{field ->
              field.attributes().each{print "$it.key $it.value "}
              }
              println ''
              if (dbRecord2!=null)
                  dbRecord2.FIELD.each{field ->
                  field.attributes().each{print "$it.key $it.value "}
              }
              println '\n'
          }

          def getPriKeyInfo(tableDef){
           def priKeyMap = [:]
           for(priKey in tableDef.PriKey){
            def tableName = "${priKey.@Name}"[0..("${priKey.@Name}".lastIndexOf("_PK")-1)]
            priKeyMap.put(tableName,priKey.PKI.collect{"${it.@Field}"})
           }
           return priKeyMap
          }

          posted on 2008-10-02 17:10 大石頭 閱讀(299) 評論(0)  編輯  收藏 所屬分類: Groovy

          主站蜘蛛池模板: 瓮安县| 常宁市| 文化| 晋江市| 古交市| 红桥区| 浦江县| 阿合奇县| 休宁县| 华亭县| 南雄市| 阿城市| 应城市| 兴山县| 古浪县| 尚义县| 托里县| 南郑县| 弥渡县| 洪湖市| 田阳县| 莱芜市| 化德县| 册亨县| 民权县| 静乐县| 怀集县| 太仆寺旗| 镇宁| 墨江| 揭东县| 彩票| 鹤岗市| 益阳市| 皋兰县| 高尔夫| 伊金霍洛旗| 广水市| 北碚区| 乐至县| 马关县|