use of com.microsoft.sqlserver.jdbc.bulkCopy.BulkCopyTestWrapper.ColumnMap in project mssql-jdbc by Microsoft.
the class BulkCopyTestUtil method performBulkCopy.
/**
* perform bulk copy using source and destination tables
*
* @param wrapper
* @param sourceTable
* @param destTable
* @param validateResult
*/
static void performBulkCopy(BulkCopyTestWrapper wrapper, DBTable sourceTable, DBTable destinationTable, boolean validateResult) {
try (DBConnection con = new DBConnection(wrapper.getConnectionString());
DBStatement stmt = con.createStatement();
DBResultSet srcResultSet = stmt.executeQuery("SELECT * FROM " + sourceTable.getEscapedTableName() + ";");
SQLServerBulkCopy bulkCopy = wrapper.isUsingConnection() ? new SQLServerBulkCopy((Connection) con.product()) : new SQLServerBulkCopy(wrapper.getConnectionString())) {
if (wrapper.isUsingBulkCopyOptions()) {
bulkCopy.setBulkCopyOptions(wrapper.getBulkOptions());
}
bulkCopy.setDestinationTableName(destinationTable.getEscapedTableName());
if (wrapper.isUsingColumnMapping()) {
for (int i = 0; i < wrapper.cm.size(); i++) {
ColumnMap currentMap = wrapper.cm.get(i);
if (currentMap.sourceIsInt && currentMap.destIsInt) {
bulkCopy.addColumnMapping(currentMap.srcInt, currentMap.destInt);
} else if (currentMap.sourceIsInt && (!currentMap.destIsInt)) {
bulkCopy.addColumnMapping(currentMap.srcInt, currentMap.destString);
} else if ((!currentMap.sourceIsInt) && currentMap.destIsInt) {
bulkCopy.addColumnMapping(currentMap.srcString, currentMap.destInt);
} else if ((!currentMap.sourceIsInt) && (!currentMap.destIsInt)) {
bulkCopy.addColumnMapping(currentMap.srcString, currentMap.destString);
}
}
}
bulkCopy.writeToServer((ResultSet) srcResultSet.product());
if (validateResult) {
validateValues(con, sourceTable, destinationTable);
}
} catch (SQLException ex) {
fail(ex.getMessage());
}
}
Aggregations