Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2014-2015 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  * either express or implied. See the License for the specific language
  * governing permissions and limitations under the License.
  */
 package org.dbflute.bhv.core;
 
 import java.util.List;
 import java.util.Map;
 
The invoker of behavior command.
 public interface methods are as follows:
   o clearExecutionCache();
   o isExecutionCacheEmpty();
   o getExecutionCacheSize();
   o injectComponentProperty(BehaviorCommandComponentSetup behaviorCommand);
   o invoke(BehaviorCommand behaviorCommand);
   o createOutsideSqlBasicExecutor(String tableDbName);
   o createBehaviorExceptionThrower();
   o getSequenceCacheHandler();
 

Author(s):
jflute
 
 public class BehaviorCommandInvoker {
 
     // ===================================================================================
     //                                                                           Attribute
     //                                                                           =========
     // -----------------------------------------------------
     //                                      Injection Target
     //                                      ----------------
     protected InvokerAssistant _invokerAssistant;
 
     // -----------------------------------------------------
     //                                       Execution Cache
     //                                       ---------------
     
The map of SQL execution. (dispose target, synchronized manually as transaction)
 
     protected final Map<StringSqlExecution_executionMap = newConcurrentHashMap();

    
The lock object to synchronize the execution map for transaction. (NotNull)
 
     protected final Object _executionCacheLock = new Object();
 
     // -----------------------------------------------------
     //                                    Disposable Process
     //                                    ------------------
     protected final DisposableProcess _disposableProcess = new DisposableProcess() {
         public void dispose() {
             clearExecutionCache();
         }
    };
    // ===================================================================================
    //                                                                         Constructor
    //                                                                         ===========
    public BehaviorCommandInvoker() {
    }
    // ===================================================================================
    //                                                                     Execution Cache
    //                                                                     ===============
    public void clearExecutionCache() {
        // basically should be called only for special case (e.g. HotDeploy)
        synchronized () {
            .clear();
        }
    }
    public boolean isExecutionCacheEmpty() {
        return .isEmpty();
    }
    public int getExecutionCacheSize() {
        return .size();
    }
    // ===================================================================================
    //                                                                      Command Set up
    //                                                                      ==============
    
Inject the properties of component to the command of behavior. {Public Interface}

Parameters:
behaviorCommand The command of behavior. (NotNull)
    public void injectComponentProperty(BehaviorCommandComponentSetup behaviorCommand) {
        assertInvokerAssistant();
        behaviorCommand.setDBMetaProvider(.assistDBMetaProvider());
        behaviorCommand.setDataSource(.assistDataSource());
        behaviorCommand.setSqlFileEncoding(getSqlFileEncoding());
    }
    protected String getSqlFileEncoding() {
        assertInvokerAssistant();
        return .assistSqlFileEncoding();
    }
    // ===================================================================================
    //                                                                      Command Invoke
    //                                                                      ==============
    
Invoke the command of behavior. {Public Interface} This method is an entry point!

Parameters:
<RESULT> The type of result.
behaviorCommand The command of behavior. (NotNull)
Returns:
The result object. (NullAllowed)
    public <RESULT> RESULT invoke(BehaviorCommand<RESULT> behaviorCommand) {
        RuntimeException cause = null;
        RESULT result = null;
        try {
            final ResourceContext parentContext = getParentContext();
            initializeContext();
            setupResourceContext(behaviorCommandparentContext);
            processBeforeHook(behaviorCommand);
            result = dispatchInvoking(behaviorCommand);
        } catch (RuntimeException e) {
            cause = e;
        } finally {
            processFinallyHook(behaviorCommandcause);
            closeContext();
        }
        if (cause != null) {
            throw cause;
        } else {
            return result;
        }
    }
    protected <RESULT> void setupResourceContext(BehaviorCommand<RESULT> behaviorCommandResourceContext parentContext) {
        assertInvokerAssistant();
        final ResourceContext resourceContext = new ResourceContext();
        resourceContext.setParentContext(parentContext); // not null only when recursive call
        resourceContext.setBehaviorCommand(behaviorCommand);
        resourceContext.setCurrentDBDef(.assistCurrentDBDef());
        resourceContext.setDBMetaProvider(.assistDBMetaProvider());
        ResourceContext.setResourceContextOnThread(resourceContext);
    }
    protected <RESULT> void processBeforeHook(BehaviorCommand<RESULT> behaviorCommand) {
        if (!CallbackContext.isExistBehaviorCommandHookOnThread()) {
            return;
        }
        final BehaviorCommandHook hook = CallbackContext.getCallbackContextOnThread().getBehaviorCommandHook();
        hook.hookBefore(behaviorCommand);
    }
    protected <RESULT> void processFinallyHook(BehaviorCommand<RESULT> behaviorCommandRuntimeException cause) {
        if (!CallbackContext.isExistBehaviorCommandHookOnThread()) {
            return;
        }
        final BehaviorCommandHook hook = CallbackContext.getCallbackContextOnThread().getBehaviorCommandHook();
        hook.hookFinally(behaviorCommandcause);
    }

    

Parameters:
<RESULT> The type of result.
behaviorCommand The command of behavior. (NotNull)
Returns:
The result object. (NullAllowed)
    protected <RESULT> RESULT dispatchInvoking(BehaviorCommand<RESULT> behaviorCommand) {
        final boolean logEnabled = isLogEnabled();
        // - - - - - - - - - - - - -
        // Initialize SQL Execution
        // - - - - - - - - - - - - -
        if (behaviorCommand.isInitializeOnly()) {
            initializeSqlExecution(behaviorCommand);
            return null// The end! (Initialize Only)
        }
        behaviorCommand.beforeGettingSqlExecution();
        SqlExecution execution = findSqlExecution(behaviorCommand);
        // - - - - - - - - - - -
        // Execute SQL Execution
        // - - - - - - - - - - -
        final SqlResultHandler sqlResultHander = getSqlResultHander();
        final boolean hasSqlResultHandler = sqlResultHander != null;
        final long before = deriveCommandBeforeAfterTimeIfNeeds(logEnabledhasSqlResultHandler);
        Long after = null;
        Object ret = null;
        RuntimeException cause = null;
        try {
            final Object[] args = behaviorCommand.getSqlExecutionArgument();
            ret = executeSql(executionargs);
            final Class<?> retType = behaviorCommand.getCommandReturnType();
            assertRetType(retTyperet);
            after = deriveCommandBeforeAfterTimeIfNeeds(logEnabledhasSqlResultHandler);
            if (logEnabled) {
                logResult(behaviorCommandretTyperetbeforeafter);
            }
            ret = convertReturnValueIfNeeds(retretType);
        } catch (RuntimeException e) {
            try {
                handleExecutionException(e); // always throw
            } catch (RuntimeException handled) {
                cause = handled;
                throw handled;
            }
        } finally {
            behaviorCommand.afterExecuting();
            // - - - - - - - - - - - -
            // Call the handler back!
            // - - - - - - - - - - - -
            if (hasSqlResultHandler) {
                callbackSqlResultHanler(behaviorCommandsqlResultHanderretbeforeaftercause);
            }
        }
        // - - - - - - - - -
        // Cast and Return!
        // - - - - - - - - -
        @SuppressWarnings("unchecked")
        final RESULT result = (RESULT) ret;
        return result;
    }
    protected long deriveCommandBeforeAfterTimeIfNeeds(boolean logEnabledboolean hasSqlResultHandler) {
        long time = 0;
        if (logEnabled || hasSqlResultHandler) {
            time = systemTime();
        }
        return time;
    }
    protected long systemTime() {
        return DBFluteSystem.currentTimeMillis(); // for calculating performance
    }
    protected Object convertReturnValueIfNeeds(Object retClass<?> retType) {
        if (retType.isPrimitive()) {
            return convertPrimitiveWrapper(retretType);
        } else if (Number.class.isAssignableFrom(retType)) {
            return convertNumber(retretType);
        }
        return ret;
    }
    protected void handleExecutionException(RuntimeException cause) {
        if (cause instanceof SQLFailureException) {
            throw cause;
        }
        final SQLExceptionDigger digger = getSQLExceptionDigger();
        final SQLException sqlEx = digger.digUp(cause);
        if (sqlEx != null) {
            handleSQLException(sqlEx);
        } else {
            throw cause;
        }
    }
    protected void handleSQLException(SQLException e) {
        final SQLExceptionResource resource = new SQLExceptionResource();
        ResourceContext.createSQLExceptionHandler().handleSQLException(eresource);
    }
    protected <RESULT> void callbackSqlResultHanler(BehaviorCommand<RESULT> behaviorCommandSqlResultHandler sqlResultHanderObject ret,
            Long commandBeforeLong commandAfterRuntimeException cause) {
        final SqlLogInfo sqlLogInfo = getResultSqlLogInfo(behaviorCommand);
        final Long sqlBefore = InternalMapContext.getSqlBeforeTimeMillis();
        final Long sqlAfter = InternalMapContext.getSqlAfterTimeMillis();
        final ExecutionTimeInfo timeInfo = new ExecutionTimeInfo(commandBeforecommandAftersqlBeforesqlAfter);
        final SqlResultInfo info = new SqlResultInfo(behaviorCommandretsqlLogInfotimeInfocause);
        sqlResultHander.handle(info);
    }
    protected <RESULT> SqlLogInfo getResultSqlLogInfo(BehaviorCommand<RESULT> behaviorCommand) {
        final SqlLogInfo sqlLogInfo = InternalMapContext.getResultSqlLogInfo();
        if (sqlLogInfo != null) {
            return sqlLogInfo;
        }
        return new SqlLogInfo(behaviorCommandnullnew Object[] {}, new Class<?>[] {}, new SqlLogInfo.SqlLogDisplaySqlBuilder() {
            public String build(String executedSqlObject[] bindArgsClass<?>[] bindArgTypes) {
                return null;
            }
        }); // as dummy
    }
    // ===================================================================================
    //                                                                       SQL Execution
    //                                                                       =============
    protected <RESULT> SqlExecution findSqlExecution(final BehaviorCommand<RESULT> behaviorCommand) {
        final boolean logEnabled = isLogEnabled();
        SqlExecution execution = null;
        try {
            final String key = behaviorCommand.buildSqlExecutionKey();
            execution = getSqlExecution(key);
            if (execution == null) {
                long beforeCmd = 0;
                if (logEnabled) {
                    beforeCmd = systemTime();
                }
                SqlExecutionCreator creator = behaviorCommand.createSqlExecutionCreator();
                execution = getOrCreateSqlExecution(keycreator);
                if (logEnabled) {
                    final long afterCmd = systemTime();
                    if (beforeCmd != afterCmd) {
                        logSqlExecution(behaviorCommandexecutionbeforeCmdafterCmd);
                    }
                }
            }
            return execution;
        } finally {
            if (logEnabled) {
                logInvocation(behaviorCommandfalse);
            }
            readyInvokePath(behaviorCommand);
        }
    }
    protected <RESULT> void initializeSqlExecution(BehaviorCommand<RESULT> behaviorCommand) {
        final String key = behaviorCommand.buildSqlExecutionKey();
        final SqlExecutionCreator creator = behaviorCommand.createSqlExecutionCreator();
        final SqlExecution execution = getSqlExecution(key);
        if (execution != null) {
            return// already initialized
        }
        getOrCreateSqlExecution(keycreator); // initialize
    }

    
Get SQL-execution if it exists.

Parameters:
key The key of SQL execution. (NotNull)
Returns:
The SQL execution that may be created then. (NullAllowed)
    protected SqlExecution getSqlExecution(String key) {
        return .get(key);
    }

    
Get SQL-execution that may be created if it does not exist.

Parameters:
key The key of SQL-execution. (NotNull)
executionCreator The creator of SQL-execution. (NotNull)
Returns:
The SQL-execution that may be created then. (NotNull)
    protected SqlExecution getOrCreateSqlExecution(String keySqlExecutionCreator executionCreator) {
        SqlExecution execution = null;
        synchronized () {
            execution = getSqlExecution(key);
            if (execution != null) {
                // previous thread might have initialized
                // or reading might failed by same-time writing
                return execution;
            }
            if (isLogEnabled()) {
                log("...Initializing sqlExecution for the key '" + key + "'");
            }
            execution = executionCreator.createSqlExecution();
            assertCreatorReturnExecution(keyexecutionCreatorexecution);
            .put(keyexecution);
        }
        toBeDisposable(); // for HotDeploy
        return execution;
    }
    protected void assertCreatorReturnExecution(String keySqlExecutionCreator executionCreatorSqlExecution execution) {
        if (execution == null) {
            String msg = "sqlExecutionCreator.createSqlCommand() should not return null:";
            msg = msg + " sqlExecutionCreator=" + executionCreator + " key=" + key;
            throw new IllegalStateException(msg);
        }
    }
    protected Object executeSql(SqlExecution executionObject[] args) {
        return execution.execute(args);
    }
    // ===================================================================================
    //                                                                      Log SqlCommand
    //                                                                      ==============
    protected <RESULT> void logSqlExecution(BehaviorCommand<RESULT> behaviorCommandSqlExecution executionlong beforeCmdlong afterCmd) {
        final String view = DfTraceViewUtil.convertToPerformanceView(afterCmd - beforeCmd);
        log("SqlExecution Initialization Cost: [" + view + "]");
    }
    // ===================================================================================
    //                                                                      Log Invocation
    //                                                                      ==============
    protected <RESULT> void logInvocation(BehaviorCommand<RESULT> behaviorCommandboolean saveOnly) {
        final StackTraceElement[] stackTrace = new Exception().getStackTrace();
        final BehaviorInvokeNameResult behaviorInvokeNameResult = extractBehaviorInvoke(behaviorCommandstackTrace);
        saveBehaviorInvokeName(behaviorInvokeNameResult);
        final BehaviorInvokePathResult invokePathResult = buildInvokePath(behaviorCommandstackTracebehaviorInvokeNameResult);
        if (invokePathResult != null) {
            saveClientInvokeName(invokePathResult);
            saveByPassInvokeName(invokePathResult);
            saveInvokePath(invokePathResult);
        }
        if (saveOnly) { // e.g. log level is INFO and invocation path ready
            return;
        }
        final String expNoMethodSuffix = behaviorInvokeNameResult.getInvocationExpNoMethodSuffix();
        final String equalBorder = buildFitBorder("""="expNoMethodSuffixfalse);
        final String frameBase = "/=====================================================";
        final String spaceBase = "                                                      ";
        log(frameBase + equalBorder + "==");
        log(spaceBase + behaviorInvokeNameResult.getInvocationExp());
        log(spaceBase + equalBorder + "=/");
        if (invokePathResult != null) {
            final String invokePath = invokePathResult.getInvokePath();
            if (Srl.is_NotNull_and_NotTrimmedEmpty(invokePath)) { // just in case
                log(invokePath);
            }
        }
        if (behaviorCommand.isOutsideSql() && !behaviorCommand.isProcedure()) {
            final OutsideSqlContext outsideSqlContext = getOutsideSqlContext();
            if (outsideSqlContext != null) {
                log("path: " + behaviorCommand.getOutsideSqlPath());
                log("option: " + behaviorCommand.getOutsideSqlOption());
            }
        }
    }
    // -----------------------------------------------------
    //                                Extract BehaviorInvoke
    //                                ----------------------
    protected <RESULT> BehaviorInvokeNameResult extractBehaviorInvoke(BehaviorCommand<RESULT> behaviorCommand,
            StackTraceElement[] stackTrace) {
        final DBMeta dbmeta = ResourceContext.provideDBMeta(behaviorCommand.getTableDbName());
        if (dbmeta == null) { // basically no way, only direct invoking
            return createUnknownInvokeNameResult();
        }
        Class<?> outsideSqlResultType = null;
        boolean outsideSqlAutoPaging = false;
        if (behaviorCommand.isOutsideSql()) {
            final OutsideSqlContext outsideSqlContext = getOutsideSqlContext();
            outsideSqlResultType = outsideSqlContext.getResultType();
            outsideSqlAutoPaging = outsideSqlContext.isAutoPagingLogging();
        }
        final BehaviorInvokeNameExtractor extractor = createBehaviorInvokeNameExtractor(dbmetaoutsideSqlResultTypeoutsideSqlAutoPaging);
        return extractor.extractBehaviorInvoke(stackTrace);
    }
    protected BehaviorInvokeNameResult createUnknownInvokeNameResult() { // basically no way
        final String unknownKeyword;
        if (OutsideSqlContext.isExistOutsideSqlContextOnThread()) { // e.g. OutsideSql engine use
            final OutsideSqlContext context = OutsideSqlContext.getOutsideSqlContextOnThread();
            unknownKeyword = context.getTableDbName();
        } else {
            unknownKeyword = "Unknown";
        }
        final String expNoMethodSuffix = unknownKeyword + ".invoke";
        return new BehaviorInvokeNameResult(expNoMethodSuffix + "()"expNoMethodSuffixnullnull);
    }
    protected BehaviorInvokeNameExtractor createBehaviorInvokeNameExtractor(final DBMeta dbmetaClass<?> outsideSqlResultType,
            boolean outsideSqlAutoPaging) {
        return new BehaviorInvokeNameExtractor(dbmetaoutsideSqlResultTypeoutsideSqlAutoPaging);
    }
    // -----------------------------------------------------
    //                                 Invocation Adjustment
    //                                 ---------------------
    protected String buildFitBorder(String prefixString elementString lengthTargetStringboolean space) {
        final int length = space ? lengthTargetString.length() / 2 : lengthTargetString.length();
        final StringBuffer sb = new StringBuffer();
        sb.append(prefix);
        for (int i = 0; i < lengthi++) {
            sb.append(element);
            if (space) {
                sb.append(" ");
            }
        }
        if (space) {
            sb.append(element);
        }
        return sb.toString();
    }
    // -----------------------------------------------------
    //                                      Build InvokePath
    //                                      ----------------
    protected <RESULT> BehaviorInvokePathResult buildInvokePath(BehaviorCommand<RESULT> behaviorCommandStackTraceElement[] stackTrace,
            BehaviorInvokeNameResult behaviorInvokeNameResult) {
        final String[] clientNames = .assistClientInvokeNames();
        final String[] byPassNames = .assistByPassInvokeNames();
        final BehaviorInvokePathBuilder invokePathBuilder = new BehaviorInvokePathBuilder(clientNamesbyPassNames);
        return invokePathBuilder.buildInvokePath(stackTracebehaviorInvokeNameResult);
    }
    // -----------------------------------------------------
    //                                       Save Invocation
    //                                       ---------------
    // basically for error message
    protected void saveBehaviorInvokeName(BehaviorInvokeNameResult behaviorInvokeNameResult) {
        final String behaviorInvokeName = behaviorInvokeNameResult.getInvocationExp();
        InternalMapContext.setBehaviorInvokeName(behaviorInvokeName);
    }
    protected void saveClientInvokeName(BehaviorInvokePathResult invokePathResult) {
        final String clientInvokeName = invokePathResult != null ? invokePathResult.getClientInvokeName() : null;
        if (clientInvokeName != null && clientInvokeName.trim().length() > 0) {
            InternalMapContext.setClientInvokeName(clientInvokeName);
        }
    }
    protected void saveByPassInvokeName(BehaviorInvokePathResult invokePathResult) {
        final String byPassInvokeName = invokePathResult != null ? invokePathResult.getByPassInvokeName() : null;
        if (byPassInvokeName != null && byPassInvokeName.trim().length() > 0) {
            InternalMapContext.setByPassInvokeName(byPassInvokeName);
        }
    }
    protected void saveInvokePath(BehaviorInvokePathResult invokePathResult) {
        final BehaviorInvokeNameResult behaviorInvokeNameResult = invokePathResult.getBehaviorInvokeNameResult();
        final String invokePath = invokePathResult.getInvokePath();
        final String callerExp = behaviorInvokeNameResult.getInvocationExp();
        final String omitMark = .;
        InternalMapContext.setSavedInvokePath(Srl.substringLastFront(invokePathomitMark) + callerExp);
    }
    // ===================================================================================
    //                                                                          Log Result
    //                                                                          ==========
    protected <RESULT> void logResult(BehaviorCommand<RESULT> behaviorCommandClass<?> retTypeObject retlong beforelong after) {
        final BehaviorResultBuilder behaviorResultBuilder = createBehaviorResultBuilder();
        final String resultExp = behaviorResultBuilder.buildResultExp(retTyperetbeforeafter);
        log(resultExp);
        log(" ");
    }
        return new BehaviorResultBuilder();
    }
    // ===================================================================================
    //                                                                    InvokePath Ready
    //                                                                    ================
    protected <RESULT> void readyInvokePath(final BehaviorCommand<RESULT> behaviorCommand) {
        // basically for exception message and SQL string filter
        InternalMapContext.setInvokePathProvider(new InvokePathProvider() {
            public String provide() { // lazily
                final String invokePath = InternalMapContext.getSavedInvokePath();
                if (invokePath != null) {
                    return invokePath;
                }
                logInvocation(behaviorCommandtrue); // save only
                return InternalMapContext.getSavedInvokePath();
            }
        });
    }
    // ===================================================================================
    //                                                                      Context Helper
    //                                                                      ==============
    protected ResourceContext getParentContext() {
        if (isRecursiveInvoking()) {
            return ResourceContext.getResourceContextOnThread();
        }
        return null;
    }
    protected void initializeContext() {
        if (isRecursiveInvoking()) {
            saveAllContextOnThread();
        }
        clearAllCurrentContext();
    }
    protected boolean isRecursiveInvoking() { // should be called before initialization
        return ResourceContext.isExistResourceContextOnThread();
    }
    protected void closeContext() {
        if (FetchAssistContext.isExistFetchNarrowingBeanOnThread()) {
            // /- - - - - - - - - - - - - - - - - - - - - - - - - - - -
            // Because there is possible that fetch narrowing has been
            // ignored for manualPaging of outsideSql.
            // - - - - - - - - - -/
            final FetchNarrowingBean fnbean = FetchAssistContext.getFetchNarrowingBeanOnThread();
            fnbean.xenableIgnoredFetchNarrowing();
        }
        clearAllCurrentContext();
    }
    protected void saveAllContextOnThread() {
        ContextStack.saveAllContextOnThread();
    }
    protected void restoreAllContextOnThreadIfExists() {
        ContextStack.restoreAllContextOnThreadIfExists();
    }
    protected void clearAllCurrentContext() {
        ContextStack.clearAllCurrentContext();
    }
        if (!OutsideSqlContext.isExistOutsideSqlContextOnThread()) {
            return null;
        }
        return OutsideSqlContext.getOutsideSqlContextOnThread();
    }
    protected SqlResultHandler getSqlResultHander() {
        if (!CallbackContext.isExistCallbackContextOnThread()) {
            return null;
        }
        return CallbackContext.getCallbackContextOnThread().getSqlResultHandler();
    }
    // ===================================================================================
    //                                                                  Execute Status Log
    //                                                                  ==================
    protected void log(String msg) {
        XLog.log(msg);
    }
    protected boolean isLogEnabled() {
        return XLog.isLogEnabled();
    }
    // ===================================================================================
    //                                                                             Dispose
    //                                                                             =======
    protected void toBeDisposable() {
        assertInvokerAssistant();
    }
    // ===================================================================================
    //                                                                   Relation Optional
    //                                                                   =================
    
Get the factory of relation optional.

Returns:
The factory assisted by invoker assistant. (NotNull)
    }
    // ===================================================================================
    //                                                                          OutsideSql
    //                                                                          ==========
    

Parameters:
<BEHAVIOR> The type of behavior.
tableDbName The DB name of table. (NotNull)
Returns:
The new-created all facade executor of outside SQL. (NotNull)
    public <BEHAVIOR> OutsideSqlAllFacadeExecutor<BEHAVIOR> createOutsideSqlAllFacadeExecutor(String tableDbName) {
        final DBDef dbdef = .assistCurrentDBDef();
        final OutsideSqlOption option = .assistFirstOutsideSqlOption(tableDbName); // might be null
        return factory.createAllFacade(factory.createBasic(thistableDbNamedbdefoption));
    }
    // ===================================================================================
    //                                                                 SQLException Digger
    //                                                                 ===================
    
Get the digger of SQLException.

Returns:
The digger assisted by invoker assistant. (NotNull)
    }
    // ===================================================================================
    //                                                                      Sequence Cache
    //                                                                      ==============
    
Get the handler of sequence cache.

Returns:
The handler assisted by invoker assistant. (NotNull)
    }
    // ===================================================================================
    //                                                                   Exception Thrower
    //                                                                   =================
    
Get the thrower of behavior exception.

Returns:
The thrower of assisted by invoker assistant. (NotNull)
    }
    // ===================================================================================
    //                                                                      Convert Helper
    //                                                                      ==============
    protected Object convertPrimitiveWrapper(Object retClass<?> retType) {
        return DfTypeUtil.toWrapper(retretType);
    }
    protected Object convertNumber(Object retClass<?> retType) {
        return DfTypeUtil.toNumber(retretType);
    }
    // ===================================================================================
    //                                                                       Assert Helper
    //                                                                       =============
    protected void assertRetType(Class<?> retTypeObject ret) {
        if (List.class.isAssignableFrom(retType)) {
            if (ret != null && !(ret instanceof List<?>)) {
                String msg = "The retType is difference from actual return: ";
                msg = msg + "retType=" + retType + " ret.getClass()=" + ret.getClass() + " ref=" + ret;
                throw new IllegalStateException(msg);
            }
        } else if (Entity.class.isAssignableFrom(retType)) {
            if (ret != null && !(ret instanceof Entity)) {
                String msg = "The retType is difference from actual return: ";
                msg = msg + "retType=" + retType + " ret.getClass()=" + ret.getClass() + " ref=" + ret;
                throw new IllegalStateException(msg);
            }
        }
    }
    protected void assertInvokerAssistant() {
        if ( == null) {
            String msg = "The attribute 'invokerAssistant' should not be null!";
            throw new IllegalStateException(msg);
        }
    }
    // ===================================================================================
    //                                                                      General Helper
    //                                                                      ==============
    protected <KEY, VALUE> ConcurrentHashMap<KEY, VALUE> newConcurrentHashMap() {
        return new ConcurrentHashMap<KEY, VALUE>();
    }
    protected String ln() {
        return DBFluteSystem.ln();
    }
    // ===================================================================================
    //                                                                            Accessor
    //                                                                            ========
    public void setInvokerAssistant(InvokerAssistant invokerAssistant) {
         = invokerAssistant;
    }
New to GrepCode? Check out our FAQ X