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 大石頭 閱讀(297) 評論(0)  編輯  收藏 所屬分類: Groovy

          主站蜘蛛池模板: 濮阳县| 垣曲县| 关岭| 瑞昌市| 额济纳旗| 阿坝县| 陇西县| 齐河县| 鲁甸县| 潼南县| 保亭| 镇巴县| 攀枝花市| 名山县| 富顺县| 菏泽市| 河北省| 万源市| 青州市| 宁武县| 青铜峡市| 始兴县| 枣强县| 宜城市| 图片| 沙坪坝区| 闽侯县| 宜川县| 原平市| 山东省| 清远市| 焉耆| 东山县| 凯里市| 镇原县| 阿瓦提县| 蓝山县| 吉水县| 云和县| 湖州市| 临城县|