Search in sources :

Example 1 with DfOutsideSqlProperties

use of org.dbflute.properties.DfOutsideSqlProperties in project dbflute-core by dbflute.

the class DfProcedureExecutionMetaExtractor method extractExecutionMetaData.

// ===================================================================================
// Process
// =======
public void extractExecutionMetaData(DataSource dataSource, List<DfProcedureMeta> procedureList) throws SQLException {
    final DfOutsideSqlProperties prop = getProperties().getOutsideSqlProperties();
    for (DfProcedureMeta procedure : procedureList) {
        final String procedureFullQualifiedName = procedure.getProcedureFullQualifiedName();
        final String procedureSchemaQualifiedName = procedure.getProcedureSchemaQualifiedName();
        final String procedureName = procedure.getProcedureName();
        if (prop.isExecutionMetaProcedureName(procedureFullQualifiedName) || prop.isExecutionMetaProcedureName(procedureSchemaQualifiedName) || prop.isExecutionMetaProcedureName(procedureName)) {
            doExtractExecutionMetaData(dataSource, procedure);
        }
    }
}
Also used : DfOutsideSqlProperties(org.dbflute.properties.DfOutsideSqlProperties) DfProcedureMeta(org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta)

Example 2 with DfOutsideSqlProperties

use of org.dbflute.properties.DfOutsideSqlProperties in project dbflute-core by dbflute.

the class DfProcedureExtractor method setupProcedureSynonym.

// -----------------------------------------------------
// Procedure Synonym
// -----------------
protected void setupProcedureSynonym(List<DfProcedureMeta> procedureList) {
    if (_procedureSynonymDataSource == null) {
        return;
    }
    final DfOutsideSqlProperties prop = getOutsideSqlProperties();
    final ProcedureSynonymHandlingType handlingType = prop.getProcedureSynonymHandlingType();
    if (handlingType.equals(ProcedureSynonymHandlingType.NONE)) {
        return;
    }
    final DfProcedureSynonymExtractor extractor = createProcedureSynonymExtractor();
    if (extractor == null) {
        // unsupported at the database
        return;
    }
    final Map<String, DfProcedureSynonymMeta> procedureSynonymMap = extractor.extractProcedureSynonymMap();
    if (handlingType.equals(ProcedureSynonymHandlingType.INCLUDE)) {
    // only add procedure synonyms to the procedure list
    } else if (handlingType.equals(ProcedureSynonymHandlingType.SWITCH)) {
        log("...Clearing normal procedures: count=" + procedureList.size());
        // because of switch
        procedureList.clear();
    } else {
        String msg = "Unexpected handling type of procedure sysnonym: " + handlingType;
        throw new IllegalStateException(msg);
    }
    log("...Adding procedure synonyms as procedure: count=" + procedureSynonymMap.size());
    final List<DfProcedureMeta> procedureSynonymList = new ArrayList<DfProcedureMeta>();
    for (Entry<String, DfProcedureSynonymMeta> entry : procedureSynonymMap.entrySet()) {
        final DfProcedureSynonymMeta metaInfo = entry.getValue();
        if (!isSynonymAllowedSchema(metaInfo)) {
            continue;
        }
        // merge synonym to procedure (create copied instance)
        final String beforeName = metaInfo.getProcedureMetaInfo().buildProcedureLoggingName();
        final DfProcedureMeta mergedProcedure = metaInfo.createMergedProcedure();
        final String afterName = mergedProcedure.buildProcedureLoggingName();
        log("  " + beforeName + " to " + afterName);
        procedureSynonymList.add(mergedProcedure);
    }
    procedureList.addAll(procedureSynonymList);
}
Also used : DfProcedureSynonymExtractor(org.dbflute.logic.jdbc.metadata.synonym.DfProcedureSynonymExtractor) DfProcedureSynonymMeta(org.dbflute.logic.jdbc.metadata.info.DfProcedureSynonymMeta) DfOutsideSqlProperties(org.dbflute.properties.DfOutsideSqlProperties) ArrayList(java.util.ArrayList) DfProcedureMeta(org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta) ProcedureSynonymHandlingType(org.dbflute.properties.DfOutsideSqlProperties.ProcedureSynonymHandlingType)

Example 3 with DfOutsideSqlProperties

use of org.dbflute.properties.DfOutsideSqlProperties in project dbflute-core by dbflute.

the class DfProcedureExtractor method setupProcedureToDBLinkIncluded.

// -----------------------------------------------------
// Included Procedure to DBLink
// ----------------------------
protected void setupProcedureToDBLinkIncluded(List<DfProcedureMeta> procedureList) {
    if (_procedureToDBLinkDataSource == null) {
        return;
    }
    final DfProcedureNativeTranslatorOracle translator = new DfProcedureNativeTranslatorOracle(_procedureToDBLinkDataSource);
    final DfOutsideSqlProperties prop = getOutsideSqlProperties();
    final List<String> procedureNameToDBLinkList = prop.getTargetProcedureNameToDBLinkList();
    for (String propertyName : procedureNameToDBLinkList) {
        final String packageName;
        final String procedureName;
        final String dbLinkName;
        final String nameResource;
        if (propertyName.contains(".")) {
            packageName = Srl.substringLastFront(propertyName, ".");
            nameResource = Srl.substringLastRear(propertyName, ".");
        } else {
            packageName = null;
            nameResource = propertyName;
        }
        procedureName = Srl.substringLastFront(nameResource, "@");
        dbLinkName = Srl.substringLastRear(nameResource, "@");
        final DfProcedureMeta meta = translator.translateProcedureToDBLink(packageName, procedureName, dbLinkName, this);
        if (meta == null) {
            throwProcedureToDBLinkTranslationFailureException(propertyName, packageName, procedureName, dbLinkName);
        }
        meta.setIncludedProcedureToDBLink(true);
        procedureList.add(meta);
    }
}
Also used : DfOutsideSqlProperties(org.dbflute.properties.DfOutsideSqlProperties) DfProcedureMeta(org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta) DfProcedureNativeTranslatorOracle(org.dbflute.logic.jdbc.metadata.procedure.DfProcedureNativeTranslatorOracle)

Example 4 with DfOutsideSqlProperties

use of org.dbflute.properties.DfOutsideSqlProperties in project dbflute-core by dbflute.

the class Table method switchSql2EntityDtoMapperOutputDirectory.

public void switchSql2EntityDtoMapperOutputDirectory() {
    final DfOutsideSqlProperties prop = getProperties().getOutsideSqlProperties();
    if (_sql2EntitySqlFile != null && _sql2EntitySqlFile.isSqlAp()) {
        prop.switchSql2EntityOutputDirectory(_sql2EntitySqlFile.getSql2EntityOutputDirectory());
    } else {
        final String outputDirectory = getProperties().getSimpleDtoProperties().getDtoMapperOutputDirectory();
        prop.switchSql2EntityOutputDirectory(outputDirectory);
    }
}
Also used : DfOutsideSqlProperties(org.dbflute.properties.DfOutsideSqlProperties)

Example 5 with DfOutsideSqlProperties

use of org.dbflute.properties.DfOutsideSqlProperties in project dbflute-core by dbflute.

the class DfOutsideSqlTestTask method getSqlFileRunner.

protected DfSqlFileRunnerExecute getSqlFileRunner(final DfRunnerInformation runInfo) {
    final String nonTargetMark = "df:x";
    final DBDef currentDBDef = getDatabaseTypeFacadeProp().getCurrentDBDef();
    return new DfSqlFileRunnerExecute(runInfo, getDataSource()) {

        protected DfOutsideSqlChecker _outsideSqlChecker;

        @Override
        protected String filterSql(String sql) {
            // /- - - - - - - - - - - - - - - - - - - - - - - - - -
            // check parameter comments in the SQL before filtering
            // - - - - - - - - - -/
            checkParameterComment(_sqlFile, sql);
            // filter comments if it needs.
            if (!currentDBDef.dbway().isBlockCommentSupported()) {
                sql = removeBlockComment(sql);
            }
            if (!currentDBDef.dbway().isLineCommentSupported()) {
                sql = removeLineComment(sql);
            }
            return super.filterSql(sql);
        }

        protected String removeBlockComment(final String sql) {
            return Srl.removeBlockComment(sql);
        }

        protected String removeLineComment(final String sql) {
            return Srl.removeLineComment(sql);
        }

        @Override
        protected boolean isTargetSql(String sql) {
            final String entityName = getEntityName(sql);
            if (entityName != null && nonTargetMark.equalsIgnoreCase(entityName)) {
                // non-target SQL
                _nonTargetSqlFileSet.add(_sqlFile);
                _log.info("...Skipping the SQL by non-target mark '" + nonTargetMark + "'");
                return false;
            }
            return super.isTargetSql(sql);
        }

        @Override
        protected void traceSql(String sql) {
            _log.info("SQL:" + ln() + sql);
        }

        @Override
        protected void traceResult(int goodSqlCount, int totalSqlCount) {
            _log.info(" -> success=" + goodSqlCount + " failure=" + (totalSqlCount - goodSqlCount) + ln());
        }

        protected String getEntityName(final String sql) {
            return getTargetString(sql, "#");
        }

        protected String getTargetString(final String sql, final String mark) {
            final List<String> targetList = getTargetList(sql, mark);
            return !targetList.isEmpty() ? targetList.get(0) : null;
        }

        protected List<String> getTargetList(final String sql, final String mark) {
            if (sql == null || sql.trim().length() == 0) {
                String msg = "The sql is invalid: " + sql;
                throw new IllegalArgumentException(msg);
            }
            final List<String> betweenBeginEndMarkList = getListBetweenBeginEndMark(sql, "--" + mark, mark);
            if (!betweenBeginEndMarkList.isEmpty()) {
                return betweenBeginEndMarkList;
            } else {
                // basically for MySQL
                return getListBetweenBeginEndMark(sql, "-- " + mark, mark);
            }
        }

        protected List<String> getListBetweenBeginEndMark(String targetStr, String beginMark, String endMark) {
            final List<ScopeInfo> scopeList = Srl.extractScopeList(targetStr, beginMark, endMark);
            final List<String> resultList = DfCollectionUtil.newArrayList();
            for (ScopeInfo scope : scopeList) {
                resultList.add(scope.getContent());
            }
            return resultList;
        }

        protected void checkParameterComment(File sqlFile, String sql) {
            final DfOutsideSqlProperties outsideSqlProp = getOutsideSqlProperties();
            if (outsideSqlProp.isSuppressParameterCommentCheck()) {
                return;
            }
            if (_outsideSqlChecker == null) {
                _outsideSqlChecker = createOutsideSqlChecker(outsideSqlProp);
            }
            _outsideSqlChecker.check(sqlFile.getName(), sql);
        }
    };
}
Also used : DfOutsideSqlProperties(org.dbflute.properties.DfOutsideSqlProperties) DfSqlFileRunnerExecute(org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerExecute) DfOutsideSqlChecker(org.dbflute.logic.outsidesqltest.DfOutsideSqlChecker) DBDef(org.dbflute.dbway.DBDef) ScopeInfo(org.dbflute.util.Srl.ScopeInfo) File(java.io.File) DfSpecifiedSqlFile(org.dbflute.task.bs.assistant.DfSpecifiedSqlFile)

Aggregations

DfOutsideSqlProperties (org.dbflute.properties.DfOutsideSqlProperties)11 DfProcedureMeta (org.dbflute.logic.jdbc.metadata.info.DfProcedureMeta)4 Properties (java.util.Properties)3 ArrayList (java.util.ArrayList)2 File (java.io.File)1 CallableStatement (java.sql.CallableStatement)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 DBDef (org.dbflute.dbway.DBDef)1 DfProcedureExecutionMetaGettingFailureException (org.dbflute.exception.DfProcedureExecutionMetaGettingFailureException)1 DfSqlFileRunnerExecute (org.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerExecute)1 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)1 DfColumnMeta (org.dbflute.logic.jdbc.metadata.info.DfColumnMeta)1 DfProcedureColumnMeta (org.dbflute.logic.jdbc.metadata.info.DfProcedureColumnMeta)1 DfProcedureColumnType (org.dbflute.logic.jdbc.metadata.info.DfProcedureColumnMeta.DfProcedureColumnType)1 DfProcedureNotParamResultMeta (org.dbflute.logic.jdbc.metadata.info.DfProcedureNotParamResultMeta)1 DfProcedureSynonymMeta (org.dbflute.logic.jdbc.metadata.info.DfProcedureSynonymMeta)1 DfProcedureNativeTranslatorOracle (org.dbflute.logic.jdbc.metadata.procedure.DfProcedureNativeTranslatorOracle)1 DfProcedureSynonymExtractor (org.dbflute.logic.jdbc.metadata.synonym.DfProcedureSynonymExtractor)1