Example usage for org.apache.ibatis.executor ExecutorException ExecutorException

List of usage examples for org.apache.ibatis.executor ExecutorException ExecutorException

Introduction

In this page you can find the example usage for org.apache.ibatis.executor ExecutorException ExecutorException.

Prototype

public ExecutorException(String message, Throwable cause) 

Source Link

Usage

From source file:com.hand.hap.mybatis.mapperhelper.MultipleJdbc3KeyGenerator.java

License:Open Source License

public void processBatch(MappedStatement ms, Statement stmt, Collection<Object> parameters) {
    ResultSet rs = null;/*  ww w. j av a2  s  . c  om*/
    try {
        rs = stmt.getGeneratedKeys();
        final Configuration configuration = ms.getConfiguration();
        final TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry();
        final String[] keyProperties = ms.getKeyProperties();
        final ResultSetMetaData rsmd = rs.getMetaData();
        TypeHandler<?>[] typeHandlers = null;
        if (keyProperties != null && rsmd.getColumnCount() >= keyProperties.length) {
            for (Object parameter : parameters) {
                // there should be one row for each statement (also one for each parameter)
                if (!rs.next()) {
                    break;
                }
                final MetaObject metaParam = configuration.newMetaObject(parameter);
                if (typeHandlers == null) {
                    typeHandlers = getTypeHandlers(typeHandlerRegistry, metaParam, keyProperties);
                }
                populateKeys(rs, metaParam, keyProperties, typeHandlers);
            }
        }
    } catch (Exception e) {
        throw new ExecutorException(
                "Error getting generated key or setting result to parameter object. Cause: " + e, e);
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (Exception e) {
                // ignore
            }
        }
    }
}

From source file:com.luxoft.mybatis.splitter.UpdateSplitterPlugin.java

License:Apache License

@Override
public Object plugin(Object target) {
    if (reusePreparedStatements && target instanceof BatchExecutor) {
        target = replaceBatchExecutor((BatchExecutor) target);
    }//from   w  ww. ja  v a 2s.co m
    if (reusePreparedStatements && target instanceof CachingExecutor) {
        try {
            Object delegate = cachingExecutorDelegate.get(target);
            if (delegate instanceof BatchExecutor) {
                cachingExecutorDelegate.set(target, replaceBatchExecutor((BatchExecutor) delegate));
            }
        } catch (IllegalAccessException e) {
            throw new ExecutorException(MSG_ERROR_ACCESSING_DELEGATE, e);
        }
    }
    return target instanceof Executor
            ? Plugin.wrap(target, new UpdateSplitterPlugin(splitter, skipEmptyStatements))
            : target;
}

From source file:com.luxoft.mybatis.splitter.UpdateSplitterPlugin.java

License:Apache License

private Object replaceBatchExecutor(BatchExecutor target) {
    try {/*from   w w w .ja v a2  s.co  m*/
        return new ReusingBatchExecutor((Configuration) executorConfiguration.get(target),
                target.getTransaction(), retainExecuteOrder, reuseBetweenFlushes);
    } catch (IllegalAccessException e) {
        throw new ExecutorException(MSG_ERROR_ACCESSING_CONFIGURATION, e);
    }
}

From source file:com.luxoft.mybatis.splitter.UpdateSplitterPlugin.java

License:Apache License

@Override
public void setProperties(Properties properties) {
    String property = properties.getProperty(SPLIT_EXPRESSION_PROPERTY);
    if (property != null) {
        splitter = new RegexpSplitter(property);
    }//w  w w. j a v  a 2  s  .co  m
    property = properties.getProperty(DELIMITER_PROPERTY);
    if (property != null) {
        splitter = new DelimiterSplitter(property);
    }
    skipEmptyStatements = getBooleanProperty(properties, SKIP_EMPTY_STATEMENTS_PROPERTY, skipEmptyStatements);
    retainExecuteOrder = getBooleanProperty(properties, RETAIN_EXECUTE_ORDER_PROPERTY, retainExecuteOrder);
    reusePreparedStatements = getBooleanProperty(properties, REUSE_PREPARED_STATEMENTS_PROPERTY,
            reusePreparedStatements);
    reuseBetweenFlushes = getBooleanProperty(properties, REUSE_BETWEEN_FLUSHES_PROPERTY, reuseBetweenFlushes);
    if (reusePreparedStatements) {
        try {
            executorConfiguration = BaseExecutor.class.getDeclaredField("configuration");
            executorConfiguration.setAccessible(true);
        } catch (Exception e) {
            throw new ExecutorException(MSG_ERROR_ACCESSING_CONFIGURATION, e);
        }
        try {
            cachingExecutorDelegate = CachingExecutor.class.getDeclaredField("delegate");
            cachingExecutorDelegate.setAccessible(true);
        } catch (Exception e) {
            throw new ExecutorException(MSG_ERROR_ACCESSING_DELEGATE, e);
        }
    }
}