Hi,

It is quite easy to backup a database using DBUnit in java. So I gues you
would have to create a plugin to best achieve it.

But the steps you will need to execute are:

create a new DatabaseConnection object. (note the use of the public schema
for postgresql when the tables are not in a specific schema)

Something like:
        java.lang.Class.forName("org.postgresql.Driver");
        java.sql.Connection jdbcConnection = DriverManager.getConnection
("jdbc:postgresql://localhost:5432/database", "postgres", "postgres");
        DatabaseConnection databaseConnection = new
DatabaseConnection(jdbcConnection, "public");


Create the dataSet of the data to backup (can use complex queries to filter
data) and write it in a file. The XmlDataSet format is hard to read compared
to FlatXmlDataSet but is better to handle null values.

        QueryDataSet dataSet = new QueryDataSet(databaseConnection);
        dataSet.addTable("table1");
        dataSet.addTable("table2");
        dataSet.addTable("table3", "select * from table3 where xxx > 5000");

        XmlDataSet.write(dataSet, new
FileOutputStream("C:/tmp/dataSet.xml"));


Then re-import the data when it is done

        XmlDataSet dataSet2 = new XmlDataSet(new
FileInputStream("C:/tmp/dataSet.xml"));
        DatabaseOperation.CLEAN_INSERT.execute(databaseConnection,
dataSet2);


Hope it can help

Daniel



On 12/7/05, Charles A <[EMAIL PROTECTED]> wrote:
>
>
>         Hi All,
>
>           I'm using Hibernate and Postgresql DB in our project. Now my
> maven script creating .War file.
>         But problem is i have to take back-up and delete my database
> before run the maven script and restore the back-up database, once new
> database has created.
>         I have checked DBUNIT and ddlutils site, but i didn't get clear
> idea where to start? and  how to proceed?
>
>         Thanks in advance
>
>         Thanks & Regards
>         Charles
>
>
>

Reply via email to