Search in sources :

Example 1 with DfFittingDataSource

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("");
}
Also used : DfFittingDataSource(org.dbflute.helper.jdbc.connection.DfFittingDataSource) Element(org.w3c.dom.Element) DfTableMeta(org.dbflute.logic.jdbc.metadata.info.DfTableMeta) Constraint(org.apache.torque.engine.database.model.Constraint)

Example 2 with DfFittingDataSource

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);
}
Also used : DfFittingDataSource(org.dbflute.helper.jdbc.connection.DfFittingDataSource) DfDataSourceHandler(org.dbflute.helper.jdbc.connection.DfDataSourceHandler)

Example 3 with DfFittingDataSource

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;
                }
            }));
        }
    });
}
Also used : DataSourceHandler(org.dbflute.jdbc.DataSourceHandler) CountDownRaceRunner(org.dbflute.helper.thread.CountDownRaceRunner) SQLException(java.sql.SQLException) Connection(java.sql.Connection) DatabaseMetaData(java.sql.DatabaseMetaData) DfFittingDataSource(org.dbflute.helper.jdbc.connection.DfFittingDataSource) DataSource(javax.sql.DataSource) CountDownRace(org.dbflute.helper.thread.CountDownRace) CountDownRaceExecution(org.dbflute.helper.thread.CountDownRaceExecution) HandlingDataSourceWrapper(org.dbflute.jdbc.HandlingDataSourceWrapper) DfFittingDataSource(org.dbflute.helper.jdbc.connection.DfFittingDataSource) DfTableMeta(org.dbflute.logic.jdbc.metadata.info.DfTableMeta) NotClosingConnectionWrapper(org.dbflute.jdbc.NotClosingConnectionWrapper)

Aggregations

DfFittingDataSource (org.dbflute.helper.jdbc.connection.DfFittingDataSource)3 DfTableMeta (org.dbflute.logic.jdbc.metadata.info.DfTableMeta)2 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 SQLException (java.sql.SQLException)1 DataSource (javax.sql.DataSource)1 Constraint (org.apache.torque.engine.database.model.Constraint)1 DfDataSourceHandler (org.dbflute.helper.jdbc.connection.DfDataSourceHandler)1 CountDownRace (org.dbflute.helper.thread.CountDownRace)1 CountDownRaceExecution (org.dbflute.helper.thread.CountDownRaceExecution)1 CountDownRaceRunner (org.dbflute.helper.thread.CountDownRaceRunner)1 DataSourceHandler (org.dbflute.jdbc.DataSourceHandler)1 HandlingDataSourceWrapper (org.dbflute.jdbc.HandlingDataSourceWrapper)1 NotClosingConnectionWrapper (org.dbflute.jdbc.NotClosingConnectionWrapper)1 Element (org.w3c.dom.Element)1