Search in sources :

Example 6 with BehaviorCommandMeta

use of org.dbflute.bhv.core.BehaviorCommandMeta in project dbflute-core by dbflute.

the class TnProcedureCommand method doFilterExecutedSqlByCallbackFilter.

protected String doFilterExecutedSqlByCallbackFilter(String executedSql) {
    final SqlStringFilter sqlStringFilter = getSqlStringFilter();
    if (sqlStringFilter != null) {
        final BehaviorCommandMeta meta = ResourceContext.behaviorCommand();
        final String filteredSql = sqlStringFilter.filterProcedure(meta, executedSql);
        return filteredSql != null ? filteredSql : executedSql;
    }
    return executedSql;
}
Also used : SqlStringFilter(org.dbflute.hook.SqlStringFilter) BehaviorCommandMeta(org.dbflute.bhv.core.BehaviorCommandMeta)

Example 7 with BehaviorCommandMeta

use of org.dbflute.bhv.core.BehaviorCommandMeta in project lastaflute by lastaflute.

the class TransactionSavedRecentResult method prepareEntityUpdateKeyMap.

// ===================================================================================
// Entity Update
// =============
protected Map<String, Object> prepareEntityUpdateKeyMap(BehaviorCommandMeta meta) {
    // always can get if entity update
    final Entity entity = extractArgumentEntity(meta);
    if (entity == null) {
        // no way, just in case
        return Collections.emptyMap();
    }
    final DBMeta dbmeta = entity.asDBMeta();
    final Map<String, Object> keyMap;
    final Set<String> uniqueProps = entity.myuniqueDrivenProperties();
    if (!uniqueProps.isEmpty()) {
        final Map<String, Object> uniqueMap = uniqueProps.stream().map(prop -> {
            return dbmeta.findColumnInfo(prop);
        }).collect(Collectors.toMap(col -> col.getColumnDbName(), col -> col.read(entity)));
        keyMap = uniqueMap;
    } else if (dbmeta.hasPrimaryKey() && entity.hasPrimaryKeyValue()) {
        keyMap = dbmeta.extractPrimaryKeyMap(entity);
    } else {
        // no way if entity update, just in case
        keyMap = Collections.emptyMap();
    }
    return keyMap;
}
Also used : BehaviorCommandMeta(org.dbflute.bhv.core.BehaviorCommandMeta) DfCollectionUtil(org.dbflute.util.DfCollectionUtil) BehaviorCommand(org.dbflute.bhv.core.BehaviorCommand) Logger(org.slf4j.Logger) Entity(org.dbflute.Entity) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) DBMeta(org.dbflute.dbmeta.DBMeta) Collectors(java.util.stream.Collectors) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) Map(java.util.Map) Collections(java.util.Collections) Entity(org.dbflute.Entity) DBMeta(org.dbflute.dbmeta.DBMeta)

Example 8 with BehaviorCommandMeta

use of org.dbflute.bhv.core.BehaviorCommandMeta in project lastaflute by lastaflute.

the class RomanticTraceableSqlResultHandler method handle.

@Override
public void handle(SqlResultInfo info) {
    final RomanticTransaction tx = TransactionRomanticContext.getRomanticTransaction();
    if (tx != null) {
        // not saved because of internal object
        final BehaviorCommandMeta meta = info.getMeta();
        final String tableName = meta.getDBMeta().getTableDispName();
        final String command = meta.getCommandName();
        final ExecutionTimeInfo timeInfo = info.getExecutionTimeInfo();
        final Long beginMillis = timeInfo.getCommandBeforeTimeMillis();
        final Long endMillis = timeInfo.getCommandAfterTimeMillis();
        final Class<?> resultType = meta.getCommandReturnType();
        final Object resultValue = info.getResult();
        tx.registerRecentResult(tableName, command, beginMillis, endMillis, resultType, resultValue, meta);
    }
}
Also used : RomanticTransaction(org.lastaflute.db.jta.RomanticTransaction) ExecutionTimeInfo(org.dbflute.jdbc.ExecutionTimeInfo) BehaviorCommandMeta(org.dbflute.bhv.core.BehaviorCommandMeta)

Example 9 with BehaviorCommandMeta

use of org.dbflute.bhv.core.BehaviorCommandMeta in project dbflute-core by dbflute.

the class AbstractOutsideSqlExecution method doFilterExecutedSqlByCallbackFilter.

protected String doFilterExecutedSqlByCallbackFilter(String executedSql) {
    final SqlStringFilter sqlStringFilter = getSqlStringFilter();
    if (sqlStringFilter != null) {
        final BehaviorCommandMeta meta = ResourceContext.behaviorCommand();
        final String filteredSql = sqlStringFilter.filterOutsideSql(meta, executedSql);
        return filteredSql != null ? filteredSql : executedSql;
    }
    return executedSql;
}
Also used : SqlStringFilter(org.dbflute.hook.SqlStringFilter) BehaviorCommandMeta(org.dbflute.bhv.core.BehaviorCommandMeta)

Example 10 with BehaviorCommandMeta

use of org.dbflute.bhv.core.BehaviorCommandMeta in project dbflute-core by dbflute.

the class CallbackContextTest method setupThreeBehaviorCommandHook.

private void setupThreeBehaviorCommandHook(CallbackContext context) {
    setupTwoBehaviorCommandHook(context);
    context.setBehaviorCommandHook(new BehaviorCommandHook() {

        public void hookBefore(BehaviorCommandMeta meta) {
            markHere("thirdBefore");
        }

        public void hookFinally(BehaviorCommandMeta meta, RuntimeException cause) {
            markHere("thirdFinally");
        }
    });
}
Also used : BehaviorCommandHook(org.dbflute.bhv.core.BehaviorCommandHook) InheritableBehaviorCommandHook(org.dbflute.hook.CallbackContext.InheritableBehaviorCommandHook) BehaviorCommandMeta(org.dbflute.bhv.core.BehaviorCommandMeta)

Aggregations

BehaviorCommandMeta (org.dbflute.bhv.core.BehaviorCommandMeta)13 BehaviorCommandHook (org.dbflute.bhv.core.BehaviorCommandHook)6 SqlStringFilter (org.dbflute.hook.SqlStringFilter)5 InheritableBehaviorCommandHook (org.dbflute.hook.CallbackContext.InheritableBehaviorCommandHook)3 Collections (java.util.Collections)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Entity (org.dbflute.Entity)1 BehaviorCommand (org.dbflute.bhv.core.BehaviorCommand)1 DBMeta (org.dbflute.dbmeta.DBMeta)1 ExecutionTimeInfo (org.dbflute.jdbc.ExecutionTimeInfo)1 DfCollectionUtil (org.dbflute.util.DfCollectionUtil)1 RomanticTransaction (org.lastaflute.db.jta.RomanticTransaction)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1