use of org.dbflute.helper.jdbc.connection.DfFittingDataSource in project dbflute-core by dbflute.
the class DfSchemaXmlSerializer method processTable.
// -----------------------------------------------------
// Table
// -----
protected void processTable(final Connection conn, final DatabaseMetaData metaData, final List<DfTableMeta> tableList) throws SQLException {
_log.info("");
_log.info("$ /= = = = = = = = = = = = = = = = = = = = = = = = = =");
_log.info("$ [Table List]");
final int runnerCount = getMetaDataCountDownRaceRunnerCount();
if (runnerCount > 1 && _dataSource.getDataSource() instanceof DfFittingDataSource) {
countDownRaceProcessTable(tableList, runnerCount, (DfFittingDataSource) _dataSource.getDataSource());
} else {
for (DfTableMeta tableMeta : tableList) {
doProcessTable(conn, metaData, tableMeta);
}
}
for (Element element : _tableElementStagingMap.values()) {
_databaseNode.appendChild(element);
}
_log.info("$ ");
_log.info("$ [Table Count]");
_log.info("$ " + _tableElementStagingMap.size());
_log.info("$ = = = = = = = = = =/");
_log.info("");
}
use of org.dbflute.helper.jdbc.connection.DfFittingDataSource in project dbflute-core by dbflute.
the class DfSchemaSyncChecker method prepareTargetDataSource.
protected DataSource prepareTargetDataSource() {
final DfDataSourceHandler handler = new DfDataSourceHandler();
// inherit
handler.setDriver(getDatabaseProperties().getDatabaseDriver());
final String url = getDocumentProperties().getSchemaSyncCheckDatabaseUrl();
// may inherit
handler.setUrl(url);
final String user = getDocumentProperties().getSchemaSyncCheckDatabaseUser();
if (Srl.is_Null_or_TrimmedEmpty(user)) {
// just in case
String msg = "The user for sync target schema was not found: " + user;
throw new IllegalStateException(msg);
}
handler.setUser(user);
handler.setPassword(getDocumentProperties().getSchemaSyncCheckDatabasePassword());
// inherit
handler.setConnectionProperties(getDatabaseProperties().getConnectionProperties());
handler.setAutoCommit(true);
_log.info("...Preparing data source for SchemaSyncCheck target:");
_log.info(" url = " + url);
_log.info(" user = " + user);
return new DfFittingDataSource(handler);
}
use of org.dbflute.helper.jdbc.connection.DfFittingDataSource 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