-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#noissue] Refactor mybatis configuration
- Loading branch information
Showing
41 changed files
with
664 additions
and
218 deletions.
There are no files selected for viewing
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
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 @@ | ||
# pinpoint-commons-mybatis |
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,97 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2019 NAVER Corp. | ||
~ | ||
~ 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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.navercorp.pinpoint</groupId> | ||
<artifactId>pinpoint</artifactId> | ||
<version>2.6.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>pinpoint-commons-mybatis</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<jdk.version>11</jdk.version> | ||
<jdk.home>${env.JAVA_11_HOME}</jdk.home> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.navercorp.pinpoint</groupId> | ||
<artifactId>pinpoint-annotations</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.navercorp.pinpoint</groupId> | ||
<artifactId>pinpoint-commons</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.mybatis</groupId> | ||
<artifactId>mybatis</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
</dependency> | ||
|
||
|
||
<!-- Logging dependencies --> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-slf4j-impl</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-jcl</artifactId> | ||
<version>${log4j2.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-autoconfigure</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-jdbc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
44 changes: 44 additions & 0 deletions
44
...s/src/main/java/com/navercorp/pinpoint/mybatis/DefaultMyBatisConfigurationCustomizer.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,44 @@ | ||
/* | ||
* Copyright 2023 NAVER Corp. | ||
* | ||
* 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 com.navercorp.pinpoint.mybatis; | ||
|
||
import org.apache.ibatis.session.Configuration; | ||
import org.apache.ibatis.session.ExecutorType; | ||
|
||
public class DefaultMyBatisConfigurationCustomizer implements MyBatisConfigurationCustomizer { | ||
|
||
@Override | ||
public void customize(Configuration config) { | ||
config.setCacheEnabled(true); | ||
|
||
// lazy loading | ||
config.setLazyLoadingEnabled(true); | ||
config.setAggressiveLazyLoading(true); | ||
|
||
config.setUseGeneratedKeys(true); | ||
|
||
// don't need "REUSE" because preparedStatements are cached at dbcp | ||
config.setDefaultExecutorType(ExecutorType.SIMPLE); | ||
|
||
// defaultQueryTimeout. unit is second | ||
config.setDefaultStatementTimeout(5); | ||
|
||
// underscore mapping of DB table | ||
config.setMapUnderscoreToCamelCase(true); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
commons-mybatis/src/main/java/com/navercorp/pinpoint/mybatis/MyBatisConfiguration.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,35 @@ | ||
/* | ||
* Copyright 2023 NAVER Corp. | ||
* | ||
* 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 com.navercorp.pinpoint.mybatis; | ||
|
||
import com.navercorp.pinpoint.mybatis.plugin.BindingLogPlugin; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class MyBatisConfiguration { | ||
@Bean | ||
public MyBatisConfigurationCustomizer myBatisConfigurationCustomizer() { | ||
return new DefaultMyBatisConfigurationCustomizer(); | ||
} | ||
|
||
@Bean | ||
public BindingLogPlugin bindingLogPlugin() { | ||
return new BindingLogPlugin(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...-mybatis/src/main/java/com/navercorp/pinpoint/mybatis/MyBatisConfigurationCustomizer.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,24 @@ | ||
/* | ||
* Copyright 2023 NAVER Corp. | ||
* | ||
* 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 com.navercorp.pinpoint.mybatis; | ||
|
||
import org.apache.ibatis.session.Configuration; | ||
|
||
public interface MyBatisConfigurationCustomizer { | ||
void customize(Configuration config); | ||
} |
27 changes: 27 additions & 0 deletions
27
commons-mybatis/src/main/java/com/navercorp/pinpoint/mybatis/MyBatisRegistryHandler.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,27 @@ | ||
/* | ||
* Copyright 2023 NAVER Corp. | ||
* | ||
* 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 com.navercorp.pinpoint.mybatis; | ||
|
||
import org.apache.ibatis.type.TypeAliasRegistry; | ||
import org.apache.ibatis.type.TypeHandlerRegistry; | ||
|
||
public interface MyBatisRegistryHandler { | ||
void registerTypeAlias(TypeAliasRegistry typeAliasRegistry); | ||
|
||
void registerTypeHandler(TypeHandlerRegistry typeHandlerRegistry); | ||
} |
46 changes: 46 additions & 0 deletions
46
...ons-mybatis/src/main/java/com/navercorp/pinpoint/mybatis/MyBatisRegistryHandlerChain.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,46 @@ | ||
/* | ||
* Copyright 2023 NAVER Corp. | ||
* | ||
* 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 com.navercorp.pinpoint.mybatis; | ||
|
||
import org.apache.ibatis.type.TypeAliasRegistry; | ||
import org.apache.ibatis.type.TypeHandlerRegistry; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class MyBatisRegistryHandlerChain implements MyBatisRegistryHandler { | ||
private final List<? extends MyBatisRegistryHandler> handlers; | ||
|
||
public MyBatisRegistryHandlerChain(List<? extends MyBatisRegistryHandler> handlers) { | ||
this.handlers = Objects.requireNonNull(handlers, "handlers"); | ||
} | ||
|
||
@Override | ||
public void registerTypeAlias(TypeAliasRegistry typeAliasRegistry) { | ||
for (MyBatisRegistryHandler handler : handlers) { | ||
handler.registerTypeAlias(typeAliasRegistry); | ||
} | ||
} | ||
|
||
@Override | ||
public void registerTypeHandler(TypeHandlerRegistry typeHandlerRegistry) { | ||
for (MyBatisRegistryHandler handler : handlers) { | ||
handler.registerTypeHandler(typeHandlerRegistry); | ||
} | ||
} | ||
} |
7 changes: 4 additions & 3 deletions
7
...oint/web/dao/ibatis/BindLogFormatter.java → ...oint/mybatis/plugin/BindLogFormatter.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
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
Oops, something went wrong.