Monday, December 27, 2010

Generating db patches with DiffKit

In the 0.8.7 release, DiffKit gained the ability to generate database "patches". These patches are analogous to the patch files produced by traditional *nix diff tools-- they can be read by a patching tool in order to edit the RHS so that it is identical to the LHS.
Table 1. DiffKit versus Diffutils
diff tool patch format patch tool
DiffKit
diffkit-app
sql DML
any DML applicator
Diffutils
diff
unidiff
patch
The "patch" files produced by DiffKit contain only INSERT, DELETE, and UPDATE statements. After the user applies those DML statements to the RHS table, using whichever tools and techniques they prefer, the RHS table will have identical contents to the LHS table. The DiffKit application will never directly modify your tables-- DiffKit is strictly a read-only application from the perspective of your table data.
DB patches are created by using a new Sink implementation: the SqlPatchSink. test26.plan.xml, in the eg/ (examples) folder, dmonstrates this:
test26.plan.xml
   ...
      <property name="sqlPatchFilePath" value="./test26.sink.patch" />
   ...
invoked this way:
java -jar ../diffkit-app.jar -planfiles test26.plan.xml,dbConnectionInfo.xml
produces this output in the patch file:
test26.sink.patch
DELETE FROM PUBLIC.TEST26_RHS_TABLE
WHERE (COLUMN1='1' );

INSERT INTO PUBLIC.TEST26_RHS_TABLE (COLUMN1, COLUMN2, COLUMN3, COLUMN4)
VALUES ('2', 'xxxx', 2, 'zz2zz');

UPDATE PUBLIC.TEST26_RHS_TABLE
SET COLUMN3=3
WHERE (COLUMN1='3' );

UPDATE PUBLIC.TEST26_RHS_TABLE
SET COLUMN2='5555', COLUMN3=4, COLUMN4='zz4zz'
WHERE (COLUMN1='4' );

INSERT INTO PUBLIC.TEST26_RHS_TABLE (COLUMN1, COLUMN2, COLUMN3, COLUMN4)
VALUES ('5', 'xxxx', 5, 'zz5zz');

DELETE FROM PUBLIC.TEST26_RHS_TABLE
WHERE (COLUMN1='6' );

18 comments:

  1. 锘? If your primary baby comes with lots of games, make an effort bursting individuals in classes after which turning him or her.moncler outlet , Not just might be that neater, it all puts a stop to a nice children right from getting to be overpowered (and after you through enhancement an existing gadget that he or she has not noticed in quite a long time, he can treat it want it truly is cutting edge! )
    Guide bins.moncler portugal , Motivate some appreciate just for examining just by trying to keep training books conveniently on the market.mbt , Earn examining a unique organization minute mainly because wellanuggle in concert to study out loud a well liked fairytale!

    ReplyDelete
  2. I get this error when executing:

    planfile(s)->[test26.plan.xml, dbConnectionInfo.xml]
    ERROR[11:28:42.101]{main}(DKApplication.main:135)-null
    java.lang.RuntimeException: java.lang.RuntimeException: Could not resolve automatically; need rule for dependency->Dependency[(DKPassthroughPlan,null)]
    at org.diffkit.diff.conf.DKMagicPlan.getBuiltPlan(DKMagicPlan.java:353) [diffkit-app.jar:na]

    ReplyDelete
  3. Got the below error. Any help ?

    java.lang.RuntimeException: java.lang.RuntimeException: Could not resolve automatically; need rule for dependency->Dependency[(DKPassthroughPlan,null)]
    at org.diffkit.diff.conf.DKMagicPlan.getBuiltPlan(DKMagicPlan.java:353) [bin/:na]
    at org.diffkit.diff.conf.DKMagicPlan.getLhsSource(DKMagicPlan.java:330) [bin/:na]
    ..
    ..
    ..

    Caused by: org.diffkit.common.DKConstructorNotFoundException: more than one longest Constructor: public java.lang.String(byte[],int,int,java.nio.charset.Charset) & public java.lang.String(byte[],int,int,java.lang.String) throws java.io.UnsupportedEncodingException
    at org.diffkit.util.DKClassUtil.findLongestConstructor(DKClassUtil.java:283) [bin/:na]
    at org.diffkit.diff.conf.DKMagicDependency.findConstructor(DKMagicDependency.java:205) [bin/:na]

    ReplyDelete
  4. Hi, This is Chandrika from Chennai. I have read your blog and I got some knowledgeable information through this blog. Really useful blog. Keep update your blog.

    Regards...
    Java Training Institutes in Chennai

    ReplyDelete
  5. We are offering webs service Website designs and much more......

    ReplyDelete
  6. awful piece of information, I had come to know about your blog from my friend vimal, mumbai,i have read atleast 3 posts of yours by now, and let me tell you, your blog gives the best and the most interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new posts, once again hats off to you! Thanks a million once again, RegardsGuidewire training in hyderabad

    ReplyDelete
  7. My Arcus offer java training with 100% placement. Our java training course that includes fundamentals and advance java training program with high priority jobs. java j2ee training with placement having more exposure in most of the industry nowadays in depth manner of java

    java training in chennai

    ReplyDelete
  8. excellent piece of information, and let me tell you, your site gives the best and the most interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new posts, once again hats off to you! Thanx a lot once again, Regards, devops training in hyderabad

    ReplyDelete
  9. Java Training Institutes Java Training Institutes
    Java Spring Hibernate Training Institutes in Chennai J2EE Training Institutes in Chennai J2EE Training Institutes in Chennai Java Spring Hibernate Training Institutes in Chennai | Hibernate Training Institutes in Chennai Core Java Training Institutes in Chennai Core Java Training Institutes in Chennai

    Hibernate Online Training Hibernate Online Training Hibernate Training in Chennai Hibernate Training in Chennai Java Online Training Java Online Training Hibernate Training Institutes in ChennaiHibernate Training Institutes in Chennai

    ReplyDelete
  10. Thank you for sharing such a nice and interesting blog with us. Hope it might be much useful for us. keep on updating...!! Java Training in Chennai

    ReplyDelete
  11. I found this website through search in google search engine and i found some impressive posts within the pages in which many useful information and nice to read and i really hope you keep on update this website with more and more wonderful post like one of those thank you so much. eCommerce Product Description

    ReplyDelete