Search in sources :

Example 6 with ExecutorException

use of org.apache.ibatis.executor.ExecutorException in project mybatis-3 by mybatis.

the class DefaultResultSetHandler method combineKeys.

private CacheKey combineKeys(CacheKey rowKey, CacheKey parentRowKey) {
    if (rowKey.getUpdateCount() > 1 && parentRowKey.getUpdateCount() > 1) {
        CacheKey combinedKey;
        try {
            combinedKey = rowKey.clone();
        } catch (CloneNotSupportedException e) {
            throw new ExecutorException("Error cloning cache key.  Cause: " + e, e);
        }
        combinedKey.update(parentRowKey);
        return combinedKey;
    }
    return CacheKey.NULL_CACHE_KEY;
}
Also used : ExecutorException(org.apache.ibatis.executor.ExecutorException) CacheKey(org.apache.ibatis.cache.CacheKey)

Example 7 with ExecutorException

use of org.apache.ibatis.executor.ExecutorException in project mybatis-3 by mybatis.

the class ResultLoader method newExecutor.

private Executor newExecutor() {
    final Environment environment = configuration.getEnvironment();
    if (environment == null) {
        throw new ExecutorException("ResultLoader could not load lazily.  Environment was not configured.");
    }
    final DataSource ds = environment.getDataSource();
    if (ds == null) {
        throw new ExecutorException("ResultLoader could not load lazily.  DataSource was not configured.");
    }
    final TransactionFactory transactionFactory = environment.getTransactionFactory();
    final Transaction tx = transactionFactory.newTransaction(ds, null, false);
    return configuration.newExecutor(tx, ExecutorType.SIMPLE);
}
Also used : ExecutorException(org.apache.ibatis.executor.ExecutorException) Transaction(org.apache.ibatis.transaction.Transaction) TransactionFactory(org.apache.ibatis.transaction.TransactionFactory) Environment(org.apache.ibatis.mapping.Environment) DataSource(javax.sql.DataSource)

Example 8 with ExecutorException

use of org.apache.ibatis.executor.ExecutorException in project mybatis-3 by mybatis.

the class JavassistProxyFactory method crateProxy.

static Object crateProxy(Class<?> type, MethodHandler callback, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
    ProxyFactory enhancer = new ProxyFactory();
    enhancer.setSuperclass(type);
    try {
        type.getDeclaredMethod(WRITE_REPLACE_METHOD);
        // ObjectOutputStream will call writeReplace of objects returned by writeReplace
        if (log.isDebugEnabled()) {
            log.debug(WRITE_REPLACE_METHOD + " method was found on bean " + type + ", make sure it returns this");
        }
    } catch (NoSuchMethodException e) {
        enhancer.setInterfaces(new Class[] { WriteReplaceInterface.class });
    } catch (SecurityException e) {
    // nothing to do here
    }
    Object enhanced;
    Class<?>[] typesArray = constructorArgTypes.toArray(new Class[constructorArgTypes.size()]);
    Object[] valuesArray = constructorArgs.toArray(new Object[constructorArgs.size()]);
    try {
        enhanced = enhancer.create(typesArray, valuesArray);
    } catch (Exception e) {
        throw new ExecutorException("Error creating lazy proxy.  Cause: " + e, e);
    }
    ((Proxy) enhanced).setHandler(callback);
    return enhanced;
}
Also used : Proxy(javassist.util.proxy.Proxy) AbstractEnhancedDeserializationProxy(org.apache.ibatis.executor.loader.AbstractEnhancedDeserializationProxy) ExecutorException(org.apache.ibatis.executor.ExecutorException) ProxyFactory(javassist.util.proxy.ProxyFactory) WriteReplaceInterface(org.apache.ibatis.executor.loader.WriteReplaceInterface) ExecutorException(org.apache.ibatis.executor.ExecutorException)

Example 9 with ExecutorException

use of org.apache.ibatis.executor.ExecutorException in project mybatis-3 by mybatis.

the class BaseStatementHandler method prepare.

@Override
public Statement prepare(Connection connection, Integer transactionTimeout) throws SQLException {
    ErrorContext.instance().sql(boundSql.getSql());
    Statement statement = null;
    try {
        statement = instantiateStatement(connection);
        setStatementTimeout(statement, transactionTimeout);
        setFetchSize(statement);
        return statement;
    } catch (SQLException e) {
        closeStatement(statement);
        throw e;
    } catch (Exception e) {
        closeStatement(statement);
        throw new ExecutorException("Error preparing statement.  Cause: " + e, e);
    }
}
Also used : ExecutorException(org.apache.ibatis.executor.ExecutorException) SQLException(java.sql.SQLException) MappedStatement(org.apache.ibatis.mapping.MappedStatement) Statement(java.sql.Statement) ExecutorException(org.apache.ibatis.executor.ExecutorException) SQLException(java.sql.SQLException)

Example 10 with ExecutorException

use of org.apache.ibatis.executor.ExecutorException in project mybatis-3 by mybatis.

the class DefaultResultSetHandler method instantiateCollectionPropertyIfAppropriate.

private Object instantiateCollectionPropertyIfAppropriate(ResultMapping resultMapping, MetaObject metaObject) {
    final String propertyName = resultMapping.getProperty();
    Object propertyValue = metaObject.getValue(propertyName);
    if (propertyValue == null) {
        Class<?> type = resultMapping.getJavaType();
        if (type == null) {
            type = metaObject.getSetterType(propertyName);
        }
        try {
            if (objectFactory.isCollection(type)) {
                propertyValue = objectFactory.create(type);
                metaObject.setValue(propertyName, propertyValue);
                return propertyValue;
            }
        } catch (Exception e) {
            throw new ExecutorException("Error instantiating collection property for result '" + resultMapping.getProperty() + "'.  Cause: " + e, e);
        }
    } else if (objectFactory.isCollection(propertyValue.getClass())) {
        return propertyValue;
    }
    return null;
}
Also used : ExecutorException(org.apache.ibatis.executor.ExecutorException) MetaObject(org.apache.ibatis.reflection.MetaObject) SQLException(java.sql.SQLException) ResultMapException(org.apache.ibatis.executor.result.ResultMapException) ExecutorException(org.apache.ibatis.executor.ExecutorException)

Aggregations

ExecutorException (org.apache.ibatis.executor.ExecutorException)15 MetaObject (org.apache.ibatis.reflection.MetaObject)7 SQLException (java.sql.SQLException)6 ResultMapping (org.apache.ibatis.mapping.ResultMapping)5 TypeHandler (org.apache.ibatis.type.TypeHandler)4 CacheKey (org.apache.ibatis.cache.CacheKey)3 ResultMap (org.apache.ibatis.mapping.ResultMap)3 ResultSet (java.sql.ResultSet)2 ResultMapException (org.apache.ibatis.executor.result.ResultMapException)2 MappedStatement (org.apache.ibatis.mapping.MappedStatement)2 Configuration (org.apache.ibatis.session.Configuration)2 ResultSetMetaData (java.sql.ResultSetMetaData)1 Statement (java.sql.Statement)1 Proxy (javassist.util.proxy.Proxy)1 ProxyFactory (javassist.util.proxy.ProxyFactory)1 DataSource (javax.sql.DataSource)1 DefaultCursor (org.apache.ibatis.cursor.defaults.DefaultCursor)1 Executor (org.apache.ibatis.executor.Executor)1 AbstractEnhancedDeserializationProxy (org.apache.ibatis.executor.loader.AbstractEnhancedDeserializationProxy)1 WriteReplaceInterface (org.apache.ibatis.executor.loader.WriteReplaceInterface)1