The Artima Developer Community
Sponsored Link

Java Buzz Forum
AppFuse Tip: Backup and Restore Data with DbUnit

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Matt Raible

Posts: 422
Nickname: mraible
Registered: Jul, 2003

Matt Raible is a J2EE Consultant in Denver, Colorado.
AppFuse Tip: Backup and Restore Data with DbUnit Posted: Dec 13, 2004 8:46 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Matt Raible.
Original Post: AppFuse Tip: Backup and Restore Data with DbUnit
Feed Title: Raible Designs ~ We Build Web Apps
Feed URL: http://static.raibledesigns.com/500.html
Feed Description: Opinions and tips on how to build web applications using Java. Currently using Hibernate, Struts, XHTML, CSS, Ant, JUnit and XDoclet.
Latest Java Buzz Posts
Latest Java Buzz Posts by Matt Raible
Latest Posts From Raible Designs ~ We Build Web Apps

Advertisement
One of the nice things about having DbUnit integrated into AppFuse is you can easily import and export data. I've often used this feature to export a test database (or even production) into my development environment to try and reproduce data-related errors. Here's how to do it:

  1. Run "ant db-export -Ddatabase.host=otherhost". This exports all the data into an XML file named "db-export.xml" in the current directory.
  2. Run "ant db-load -Dfile=db-export.xml" to import the data into your local database.

I've used the db-export task for other things too - like populating the database through the UI and then updating the test data. All you have to do for this is to copy the db-export.xml file to metadata/sql/sample-data.xml.

NOTES:

  • For Oracle, you need to add a "schema" attribute to all the <dbunit> tasks in build.xml. You also need to do this for the "db-export" target for PostgreSQL.
  • If you want to limit the tables exported (i.e. from a production database), simply nest a bunch of <table name="table_name"/> elements inside the <export> element.
  • If you get errors about foreign key constraints when running "db-load" after "db-export" - you need to re-arrange the order of your tables in the imported XML file.
  • To clear out tables before your tests, add an empty <table name="table_name"/> element to sample-data.xml.

Read: AppFuse Tip: Backup and Restore Data with DbUnit

Topic: Does Slashdot Look Like This In Your Firefox? Previous Topic   Next Topic Topic: [Dec 3, 2004 12:27 PST] 6 Links

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use