-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fjn
committed
Jul 28, 2021
1 parent
6d9fdb9
commit bd497d2
Showing
4 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
Binary file modified
BIN
+0 Bytes
(100%)
sqlhelper-examples/sqlhelper-examples-db/src/main/resources/test.h2.db
Binary file not shown.
36 changes: 36 additions & 0 deletions
36
...atis/src/main/java/com/jn/sqlhelper/examples/mybatis/config/MybatisInterceptorConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2021 the original author or authors. | ||
* | ||
* Licensed under the Apache, 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.gnu.org/licenses/lgpl-2.0.html | ||
* | ||
* 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 com.jn.sqlhelper.examples.mybatis.config; | ||
|
||
import com.jn.sqlhelper.examples.mybatis.plugins.Interceptor0; | ||
import com.jn.sqlhelper.examples.mybatis.plugins.Interceptor1; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.annotation.Order; | ||
|
||
@Configuration | ||
public class MybatisInterceptorConfig { | ||
@Bean | ||
@Order(Integer.MAX_VALUE) | ||
public Interceptor0 interceptor0(){ | ||
return new Interceptor0(); | ||
} | ||
|
||
@Bean | ||
@Order(Integer.MIN_VALUE) | ||
public Interceptor1 interceptor1(){ | ||
return new Interceptor1(); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...service-mybatis/src/main/java/com/jn/sqlhelper/examples/mybatis/plugins/Interceptor0.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2021 the original author or authors. | ||
* | ||
* Licensed under the Apache, 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.gnu.org/licenses/lgpl-2.0.html | ||
* | ||
* 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 com.jn.sqlhelper.examples.mybatis.plugins; | ||
|
||
import org.apache.ibatis.cache.CacheKey; | ||
import org.apache.ibatis.executor.Executor; | ||
import org.apache.ibatis.mapping.BoundSql; | ||
import org.apache.ibatis.mapping.MappedStatement; | ||
import org.apache.ibatis.plugin.*; | ||
import org.apache.ibatis.session.ResultHandler; | ||
import org.apache.ibatis.session.RowBounds; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Properties; | ||
|
||
@Intercepts({ | ||
@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class}), | ||
@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}), | ||
@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class}), | ||
@Signature(type = Executor.class, method = "queryCursor", args = {MappedStatement.class, Object.class, RowBounds.class}), | ||
@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class}) | ||
}) | ||
public class Interceptor0 implements Interceptor { | ||
private static final Logger logger = LoggerFactory.getLogger(Interceptor0.class); | ||
@Override | ||
public Object intercept(Invocation invocation) throws Throwable { | ||
logger.info("------------------Interceptor0 start---------------"); | ||
Object obj = invocation.proceed(); | ||
logger.info("------------------Interceptor0 end---------------"); | ||
return obj; | ||
} | ||
|
||
@Override | ||
public Object plugin(Object target) { | ||
if (target instanceof Executor) { | ||
return Plugin.wrap(target, this); | ||
} | ||
return target; | ||
} | ||
|
||
@Override | ||
public void setProperties(Properties properties) { | ||
|
||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...service-mybatis/src/main/java/com/jn/sqlhelper/examples/mybatis/plugins/Interceptor1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2021 the original author or authors. | ||
* | ||
* Licensed under the Apache, 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.gnu.org/licenses/lgpl-2.0.html | ||
* | ||
* 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 com.jn.sqlhelper.examples.mybatis.plugins; | ||
|
||
import org.apache.ibatis.cache.CacheKey; | ||
import org.apache.ibatis.executor.Executor; | ||
import org.apache.ibatis.mapping.BoundSql; | ||
import org.apache.ibatis.mapping.MappedStatement; | ||
import org.apache.ibatis.plugin.*; | ||
import org.apache.ibatis.session.ResultHandler; | ||
import org.apache.ibatis.session.RowBounds; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Properties; | ||
|
||
@Intercepts({ | ||
@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class}), | ||
@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}), | ||
@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class}), | ||
@Signature(type = Executor.class, method = "queryCursor", args = {MappedStatement.class, Object.class, RowBounds.class}), | ||
@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class}) | ||
}) | ||
public class Interceptor1 implements Interceptor { | ||
private static final Logger logger = LoggerFactory.getLogger(Interceptor1.class); | ||
@Override | ||
public Object intercept(Invocation invocation) throws Throwable { | ||
logger.info("------------------Interceptor1 start---------------"); | ||
Object obj = invocation.proceed(); | ||
logger.info("------------------Interceptor1 end---------------"); | ||
return obj; | ||
} | ||
|
||
@Override | ||
public Object plugin(Object target) { | ||
if (target instanceof Executor) { | ||
return Plugin.wrap(target, this); | ||
} | ||
return target; | ||
} | ||
|
||
@Override | ||
public void setProperties(Properties properties) { | ||
|
||
} | ||
} |