|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package io.microsphere.mybatis.executor; |
| 18 | + |
| 19 | +import io.microsphere.mybatis.plugin.InterceptorContext; |
| 20 | +import org.apache.ibatis.cache.CacheKey; |
| 21 | +import org.apache.ibatis.cursor.Cursor; |
| 22 | +import org.apache.ibatis.executor.Executor; |
| 23 | +import org.apache.ibatis.mapping.BoundSql; |
| 24 | +import org.apache.ibatis.mapping.MappedStatement; |
| 25 | +import org.apache.ibatis.reflection.MetaObject; |
| 26 | +import org.apache.ibatis.session.ResultHandler; |
| 27 | +import org.apache.ibatis.session.RowBounds; |
| 28 | + |
| 29 | +import javax.annotation.Nullable; |
| 30 | +import java.sql.SQLException; |
| 31 | +import java.util.List; |
| 32 | + |
| 33 | +import static io.microsphere.mybatis.executor.ThrowingErrorExecutorFilter.throwsError; |
| 34 | + |
| 35 | +/** |
| 36 | + * {@link ExecutorInterceptor} class throws the errors. |
| 37 | + * |
| 38 | + * @author <a href="mailto:mercyblitz@gmail.com">Mercy<a/> |
| 39 | + * @see ExecutorInterceptor |
| 40 | + * @since 1.0.0 |
| 41 | + */ |
| 42 | +public class ThrowingErrorExecutorInterceptor implements ExecutorInterceptor { |
| 43 | + |
| 44 | + @Override |
| 45 | + public void beforeUpdate(InterceptorContext<Executor> context, MappedStatement ms, Object parameter) { |
| 46 | + throwsError(); |
| 47 | + ExecutorInterceptor.super.beforeUpdate(context, ms, parameter); |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public void afterUpdate(InterceptorContext<Executor> context, MappedStatement ms, Object parameter, @Nullable Integer result, @Nullable SQLException failure) { |
| 52 | + throwsError(); |
| 53 | + ExecutorInterceptor.super.afterUpdate(context, ms, parameter, result, failure); |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public void beforeQuery(InterceptorContext<Executor> context, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, @Nullable CacheKey cacheKey, @Nullable BoundSql boundSql) { |
| 58 | + throwsError(); |
| 59 | + ExecutorInterceptor.super.beforeQuery(context, ms, parameter, rowBounds, resultHandler, cacheKey, boundSql); |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public <E> void afterQuery(InterceptorContext<Executor> context, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, @Nullable CacheKey cacheKey, @Nullable BoundSql boundSql, @Nullable List<E> result, @Nullable SQLException failure) { |
| 64 | + throwsError(); |
| 65 | + ExecutorInterceptor.super.afterQuery(context, ms, parameter, rowBounds, resultHandler, cacheKey, boundSql, result, failure); |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public void beforeQueryCursor(InterceptorContext<Executor> context, MappedStatement ms, Object parameter, RowBounds rowBounds) { |
| 70 | + throwsError(); |
| 71 | + ExecutorInterceptor.super.beforeQueryCursor(context, ms, parameter, rowBounds); |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public <E> void afterQueryCursor(InterceptorContext<Executor> context, MappedStatement ms, Object parameter, RowBounds rowBounds, @Nullable Cursor<E> result, @Nullable SQLException failure) { |
| 76 | + throwsError(); |
| 77 | + ExecutorInterceptor.super.afterQueryCursor(context, ms, parameter, rowBounds, result, failure); |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + public void beforeCommit(InterceptorContext<Executor> context, boolean required) { |
| 82 | + throwsError(); |
| 83 | + ExecutorInterceptor.super.beforeCommit(context, required); |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public void afterCommit(InterceptorContext<Executor> context, boolean required, @Nullable SQLException failure) { |
| 88 | + throwsError(); |
| 89 | + ExecutorInterceptor.super.afterCommit(context, required, failure); |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + public void beforeRollback(InterceptorContext<Executor> context, boolean required) { |
| 94 | + throwsError(); |
| 95 | + ExecutorInterceptor.super.beforeRollback(context, required); |
| 96 | + } |
| 97 | + |
| 98 | + @Override |
| 99 | + public void afterRollback(InterceptorContext<Executor> context, boolean required, @Nullable SQLException failure) { |
| 100 | + throwsError(); |
| 101 | + ExecutorInterceptor.super.afterRollback(context, required, failure); |
| 102 | + } |
| 103 | + |
| 104 | + @Override |
| 105 | + public void beforeGetTransaction(InterceptorContext<Executor> context) { |
| 106 | + throwsError(); |
| 107 | + ExecutorInterceptor.super.beforeGetTransaction(context); |
| 108 | + } |
| 109 | + |
| 110 | + @Override |
| 111 | + public void afterGetTransaction(InterceptorContext<Executor> context, @Nullable Throwable failure) { |
| 112 | + throwsError(); |
| 113 | + ExecutorInterceptor.super.afterGetTransaction(context, failure); |
| 114 | + } |
| 115 | + |
| 116 | + @Override |
| 117 | + public void beforeCreateCacheKey(InterceptorContext<Executor> context, MappedStatement ms, Object parameter, RowBounds rowBounds, BoundSql boundSql) { |
| 118 | + throwsError(); |
| 119 | + ExecutorInterceptor.super.beforeCreateCacheKey(context, ms, parameter, rowBounds, boundSql); |
| 120 | + } |
| 121 | + |
| 122 | + @Override |
| 123 | + public void afterCreateCacheKey(InterceptorContext<Executor> context, MappedStatement ms, Object parameter, RowBounds rowBounds, BoundSql boundSql, @Nullable CacheKey key, @Nullable Throwable failure) { |
| 124 | + throwsError(); |
| 125 | + ExecutorInterceptor.super.afterCreateCacheKey(context, ms, parameter, rowBounds, boundSql, key, failure); |
| 126 | + } |
| 127 | + |
| 128 | + @Override |
| 129 | + public void beforeDeferLoad(InterceptorContext<Executor> context, MappedStatement ms, MetaObject resultObject, String property, CacheKey key, Class<?> targetType) { |
| 130 | + throwsError(); |
| 131 | + ExecutorInterceptor.super.beforeDeferLoad(context, ms, resultObject, property, key, targetType); |
| 132 | + } |
| 133 | + |
| 134 | + @Override |
| 135 | + public void afterDeferLoad(InterceptorContext<Executor> context, MappedStatement ms, MetaObject resultObject, String property, CacheKey key, Class<?> targetType, @Nullable Throwable failure) { |
| 136 | + throwsError(); |
| 137 | + ExecutorInterceptor.super.afterDeferLoad(context, ms, resultObject, property, key, targetType, failure); |
| 138 | + } |
| 139 | + |
| 140 | + @Override |
| 141 | + public void beforeClose(InterceptorContext<Executor> context, boolean forceRollback) { |
| 142 | + throwsError(); |
| 143 | + ExecutorInterceptor.super.beforeClose(context, forceRollback); |
| 144 | + } |
| 145 | + |
| 146 | + @Override |
| 147 | + public void afterClose(InterceptorContext<Executor> context, boolean forceRollback) { |
| 148 | + throwsError(); |
| 149 | + ExecutorInterceptor.super.afterClose(context, forceRollback); |
| 150 | + } |
| 151 | +} |
0 commit comments