0

I have a problem with maven-dbunit-plugin.

The common use of maven-dbunit-plugin is running a command like mvn dbunit:operation in the shell.

But now, I have a spring batch job. The work of this job is writing data by sample-data.xml file to the database.

The command mvn dbunit:operation depends on the maven project with the pom.xml. This is not the style what I want.

How to write code using maven-dbunit-plugin lib to resolve this problem?

dachi
  • 1,604
  • 11
  • 15

1 Answers1

0

There is no straight anwser to your question, or there is at least some misunderstanding.

Even if it's not really impossible, you try to use a tool for another goal that why it was designed.

Maven : build tool

As per doc, a build and "project comprehension tool", aimed toleverage the management of softwares. In a few words : it's related to Build phase (development).

So, provided features to help you during test / dev of your program : batch, webapp, .... or wathever you want.

Loading data

You are (or you seem) looking for a library that read data from an xml file, during Run Phase (production) and load them into a database.

There hopefully is a lot of way to achieve that, depending on your needs : do you have to make some operation on data before ? Which database are you using.

Here a few list of ideas :

Import Data into MySQL

http://www.mssqltips.com/sqlservertip/2899/importing-and-processing-data-from-xml-files-into-sql-server-tables/

INSERT INTO XMLwithOpenXML(XMLData, LoadedDateTime)
SELECT CONVERT(XML, BulkColumn) AS BulkColumn, GETDATE() 
FROM OPENROWSET(BULK 'D:\OpenXMLTesting.xml', SINGLE_BLOB) AS x;

Import Data into SQL Server

Import XML file into SQL Server without BULK

SELECT * 
FROM   OPENROWSET('MSDASQL',  
'Driver={Microsoft Text Driver (*.xml)};DefaultDir=C:\Radu\test.xml;', 
'SELECT * FROM [test.xml];' )

As a last solution, you may use dbunit, as a dependency, and call internal method, but once again, this is not the main usage of this library.

Community
  • 1
  • 1
Jean-Rémy Revy
  • 5,607
  • 3
  • 39
  • 65