use of org.dbflute.helper.thread.CountDownRaceExecution in project dbflute-core by dbflute.
the class DfSchemaXmlSerializer method countDownRaceProcessTable.
protected void countDownRaceProcessTable(final List<DfTableMeta> tableList, int runnerCount, final DfFittingDataSource fittingDs) {
final CountDownRace fireMan = new CountDownRace(runnerCount);
fireMan.readyGo(new CountDownRaceExecution() {
public void execute(CountDownRaceRunner resource) {
final Object lockObj = resource.getLockObj();
// for exception message
String currentTable = null;
Connection runnerConn = null;
try {
runnerConn = fittingDs.newConnection();
prepareThreadDataSource(fittingDs, runnerConn);
final DatabaseMetaData newMetaData = runnerConn.getMetaData();
for (DfTableMeta tableMeta : tableList) {
final String tableKey = tableMeta.getTableFullQualifiedName();
synchronized (lockObj) {
if (_tableMetaDataSyncSet.contains(tableKey)) {
continue;
}
_tableMetaDataSyncSet.add(tableKey);
}
currentTable = tableKey;
doProcessTable(runnerConn, newMetaData, tableMeta);
}
} catch (SQLException e) {
String msg = "Failed to get the table meta data: " + currentTable;
throw new IllegalStateException(msg, e);
} finally {
if (runnerConn != null) {
try {
runnerConn.close();
} catch (SQLException e) {
}
}
DfDataSourceContext.clearDataSource();
}
}
protected void prepareThreadDataSource(final DfFittingDataSource fittingDs, final Connection runnerConn) {
if (DfDataSourceContext.isExistDataSource()) {
return;
}
final Connection threadConn = new NotClosingConnectionWrapper(runnerConn);
DfDataSourceContext.setDataSource(new HandlingDataSourceWrapper(fittingDs, new DataSourceHandler() {
public Connection getConnection(DataSource dataSource) throws SQLException {
return threadConn;
}
}));
}
});
}
Aggregations