use of org.dbunit.database.QueryDataSet in project ORCID-Source by ORCID.
the class DBUnitTest method cleanAll.
private static void cleanAll(IDatabaseConnection connection) throws DatabaseUnitException, SQLException {
QueryDataSet dataSet = new QueryDataSet(connection);
for (String table : tables) {
dataSet.addTable(table);
}
DatabaseOperation.DELETE.execute(connection, dataSet);
}
use of org.dbunit.database.QueryDataSet in project activityinfo by bedatadriven.
the class ExtractDbUnit method main.
/**
* Utility to create a dbunit xml file from a local mysql database
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
Connection jdbcConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/activityinfo?zeroDateTimeBehavior=convertToNull", "root", "root");
IDatabaseConnection connection = new MySqlConnection(jdbcConnection, null);
// partial database export
QueryDataSet partialDataSet = new QueryDataSet(connection);
//
// partialDataSet.addTable("userlogin", "select * from userlogin where userid in " +
// "(select owneruserid from userdatabase where databaseid=1100)");
int databaseId = 4;
partialDataSet.addTable("country", "select * from country where countryid in (select countryId from userdatabase where databaseid=" + databaseId + ")");
partialDataSet.addTable("locationtype", "select * from locationtype where locationTypeId=1");
partialDataSet.addTable("location", "select * from location where locationtypeid = 1");
partialDataSet.addTable("userdatabase", "select * from userdatabase where databaseid=" + databaseId + "");
partialDataSet.addTable("partnerindatabase", "select * from partnerindatabase where databaseid=" + databaseId + "");
partialDataSet.addTable("partner", "select * from partner where partnerid in (select partnerid from partnerindatabase where databaseid=" + databaseId + ")");
partialDataSet.addTable("activity", "select * from activity where activityId=33");
partialDataSet.addTable("indicator", "select * from indicator where activityId=33");
partialDataSet.addTable("attributegroupinactivity", "select * from attributegroupinactivity where activityid = 33");
partialDataSet.addTable("attributegroup", "select * from attributegroup where attributegroupid in" + " (select attributegroupid from attributegroupinactivity where activityId=33)");
partialDataSet.addTable("attribute", "select * from attribute where attributegroupid in" + " (select attributegroupid from attributegroupinactivity where activityId=33)");
partialDataSet.addTable("userlogin", "select * from userlogin where userid in " + "(select userId from sitehistory where siteid in (302007470, 968196924, 1379807452, 1435486740))");
partialDataSet.addTable("site", "select * from site where siteid in (302007470, 968196924, 1379807452, 1435486740)");
partialDataSet.addTable("sitehistory", "select * from sitehistory where siteid in (302007470, 968196924, 1379807452, 1435486740)");
FlatXmlDataSet.write(partialDataSet, new FileOutputStream("store/mysql/src/test/resources/org/activityinfo/store/mysql/history.db.xml"));
}
use of org.dbunit.database.QueryDataSet in project openmrs-core by openmrs.
the class TestUtil method printOutTableContents.
/**
* Print the contents of the given tableName to system.out<br>
* <br>
* Call this from any {@link BaseContextSensitiveTest} child by:
* TestUtil.printOutTableContents(getConnection(), "encounter");
*
* @param sqlConnection the connection to use
* @param tableNames the name(s) of the table(s) to print out
* @throws Exception
*/
public static void printOutTableContents(Connection sqlConnection, String... tableNames) throws Exception {
for (String tableName : tableNames) {
System.out.println("The contents of table: " + tableName);
IDatabaseConnection connection = new DatabaseConnection(sqlConnection);
DatabaseConfig config = connection.getConfig();
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());
QueryDataSet outputSet = new QueryDataSet(connection);
outputSet.addTable(tableName);
FlatXmlDataSet.write(outputSet, System.out);
}
}
Aggregations