├── .editorconfig ├── .gitattributes ├── .github └── workflows │ ├── github-actions-cd.yml │ └── github-actions-ci.yml ├── .gitignore ├── LICENSE ├── README.md ├── README_zh.md ├── build.gradle ├── buildSrc ├── build.gradle ├── gradle.properties ├── settings.gradle └── src │ └── main │ └── java │ └── io │ └── easybest │ └── mybatis │ └── build │ ├── ConventionsPlugin.java │ ├── DeployedPlugin.java │ ├── JavaConventions.java │ ├── MavenPublishingConventions.java │ ├── MavenRepositoryPlugin.java │ ├── optional │ └── OptionalDependenciesPlugin.java │ └── toolchain │ ├── ToolchainExtension.java │ └── ToolchainPlugin.java ├── core ├── build.gradle └── src │ └── main │ └── java │ └── io │ └── easybest │ └── mybatis │ ├── annotation │ ├── DatabaseDefault.java │ ├── GetterOptional.java │ ├── JdbcType.java │ ├── LogicDelete.java │ └── TypeHandler.java │ └── domain │ ├── AbstractAuditable.java │ ├── AbstractPersistable.java │ ├── Audit.java │ ├── Id.java │ ├── Identifiable.java │ └── LongId.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── logo.png ├── main ├── build.gradle └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── easybest │ │ │ └── mybatis │ │ │ ├── auxiliary │ │ │ ├── SQLResult.java │ │ │ ├── Syntax.java │ │ │ └── Tuple.java │ │ │ ├── dialect │ │ │ ├── AbstractDialect.java │ │ │ ├── AbstractPaginationHandler.java │ │ │ ├── CUBRIDDialect.java │ │ │ ├── ClickHouseDialect.java │ │ │ ├── DB2400Dialect.java │ │ │ ├── DB2Dialect.java │ │ │ ├── DMDialect.java │ │ │ ├── DerbyDialect.java │ │ │ ├── Dialect.java │ │ │ ├── EnterpriseDBDialect.java │ │ │ ├── FirebirdDialect.java │ │ │ ├── H2Dialect.java │ │ │ ├── HANADialect.java │ │ │ ├── HerdDBDialect.java │ │ │ ├── HighGoDialect.java │ │ │ ├── HsqlDbDialect.java │ │ │ ├── ImpalaDialect.java │ │ │ ├── InformixDialect.java │ │ │ ├── Ingres10Dialect.java │ │ │ ├── Ingres9Dialect.java │ │ │ ├── IngresDialect.java │ │ │ ├── KingbaseDialect.java │ │ │ ├── MariaDBDialect.java │ │ │ ├── MySQLDialect.java │ │ │ ├── Oracle12cDialect.java │ │ │ ├── Oracle8iDialect.java │ │ │ ├── Oracle9iDialect.java │ │ │ ├── OscarDialect.java │ │ │ ├── PaginationHandler.java │ │ │ ├── PhoenixDialect.java │ │ │ ├── PolarDBDialect.java │ │ │ ├── PostgreSQLDialect.java │ │ │ ├── SQLServer2005Dialect.java │ │ │ ├── SQLServer2012Dialect.java │ │ │ ├── SQLiteDialect.java │ │ │ ├── SqlServerDialect.java │ │ │ ├── XuguDialect.java │ │ │ ├── internal │ │ │ │ ├── AliasConstantsHelper.java │ │ │ │ └── StringHelper.java │ │ │ └── pagination │ │ │ │ ├── FirstPaginationHandler.java │ │ │ │ ├── Oracle12PaginationHandler.java │ │ │ │ ├── SQLServer2005PaginationHandler.java │ │ │ │ ├── SQLServer2012PaginationHandler.java │ │ │ │ └── TopPaginationHandler.java │ │ │ ├── mapping │ │ │ ├── DefaultEntityManager.java │ │ │ ├── DerivedSqlIdentifier.java │ │ │ ├── EntityManager.java │ │ │ ├── MappingObjectFactory.java │ │ │ ├── MybatisAssociation.java │ │ │ ├── MybatisPersistentEntity.java │ │ │ ├── MybatisPersistentEntityImpl.java │ │ │ ├── MybatisPersistentProperty.java │ │ │ ├── MybatisPersistentPropertyImpl.java │ │ │ ├── NamingStrategy.java │ │ │ ├── PersistentPropertyPathExtension.java │ │ │ ├── TypeRegistry.java │ │ │ ├── handler │ │ │ │ ├── DateUnixTimestampTypeHandler.java │ │ │ │ ├── UUIDTypeHandler.java │ │ │ │ └── UnixTimestampDateTypeHandler.java │ │ │ ├── precompile │ │ │ │ ├── AbstractSegment.java │ │ │ │ ├── Bind.java │ │ │ │ ├── Choose.java │ │ │ │ ├── Column.java │ │ │ │ ├── Composite.java │ │ │ │ ├── Constant.java │ │ │ │ ├── Delete.java │ │ │ │ ├── Escape.java │ │ │ │ ├── Foreach.java │ │ │ │ ├── Fragment.java │ │ │ │ ├── Function.java │ │ │ │ ├── If.java │ │ │ │ ├── Include.java │ │ │ │ ├── Insert.java │ │ │ │ ├── Interpolation.java │ │ │ │ ├── MethodInvocation.java │ │ │ │ ├── MybatisAggregateRootPrecompile.java │ │ │ │ ├── MybatisMapperBuilder.java │ │ │ │ ├── MybatisMapperSnippet.java │ │ │ │ ├── MybatisSimpleMapperSnippet.java │ │ │ │ ├── MybatisStagingMapperSnippet.java │ │ │ │ ├── Page.java │ │ │ │ ├── Parameter.java │ │ │ │ ├── ParameterExpression.java │ │ │ │ ├── Placeholder.java │ │ │ │ ├── ResultMap.java │ │ │ │ ├── SQL.java │ │ │ │ ├── SafeVars.java │ │ │ │ ├── Segment.java │ │ │ │ ├── Select.java │ │ │ │ ├── Set.java │ │ │ │ ├── Sorting.java │ │ │ │ ├── SqlDefinition.java │ │ │ │ ├── StagingMappers.java │ │ │ │ ├── Table.java │ │ │ │ ├── Trim.java │ │ │ │ ├── Update.java │ │ │ │ └── Where.java │ │ │ └── sql │ │ │ │ ├── CompositeSqlIdentifier.java │ │ │ │ ├── DefaultIdentifierProcessing.java │ │ │ │ ├── DefaultSqlIdentifier.java │ │ │ │ ├── Identifier.java │ │ │ │ ├── IdentifierProcessing.java │ │ │ │ └── SqlIdentifier.java │ │ │ └── repository │ │ │ ├── BasicQuery.java │ │ │ ├── Fetch.java │ │ │ ├── FetchMode.java │ │ │ ├── Modifying.java │ │ │ ├── MybatisRepository.java │ │ │ ├── Query.java │ │ │ ├── QueryByCriteriaExecutor.java │ │ │ ├── QuerydslMybatisPredicateExecutor.java │ │ │ ├── ResultMap.java │ │ │ ├── ResultType.java │ │ │ ├── Temporal.java │ │ │ ├── config │ │ │ ├── DialectResolver.java │ │ │ ├── EnableMybatisAuditing.java │ │ │ ├── EnableMybatisRepositories.java │ │ │ ├── MybatisAuditingRegistrar.java │ │ │ ├── MybatisRepositoriesRegistrar.java │ │ │ ├── MybatisRepositoryConfigExtension.java │ │ │ └── MybatisRepositoryNameSpaceHandler.java │ │ │ ├── query │ │ │ ├── AbstractMybatisQuery.java │ │ │ ├── AbstractStringBasedMybatisQuery.java │ │ │ ├── DeclaredQuery.java │ │ │ ├── DefaultMybatisEntityMetadata.java │ │ │ ├── DefaultQueryEnhancer.java │ │ │ ├── EmptyDeclaredQuery.java │ │ │ ├── EscapeCharacter.java │ │ │ ├── ExpressionBasedStringQuery.java │ │ │ ├── IndicatingMybatisQuery.java │ │ │ ├── JSqlParserQueryEnhancer.java │ │ │ ├── JSqlParserUtils.java │ │ │ ├── MapperedMybatisQuery.java │ │ │ ├── MybatisEntityMetadata.java │ │ │ ├── MybatisParameters.java │ │ │ ├── MybatisParametersParameterAccessor.java │ │ │ ├── MybatisQueryExecution.java │ │ │ ├── MybatisQueryFactory.java │ │ │ ├── MybatisQueryIntendListener.java │ │ │ ├── MybatisQueryLookupStrategy.java │ │ │ ├── MybatisQueryMethod.java │ │ │ ├── MybatisResultConverters.java │ │ │ ├── ParameterMetadataProvider.java │ │ │ ├── PartTreeMybatisQuery.java │ │ │ ├── PartTreeQueryCreator.java │ │ │ ├── Procedure.java │ │ │ ├── QueryEnhancer.java │ │ │ ├── QueryEnhancerFactory.java │ │ │ ├── QueryUtils.java │ │ │ ├── StringQuery.java │ │ │ └── criteria │ │ │ │ ├── ColumnResult.java │ │ │ │ ├── Condition.java │ │ │ │ ├── Conditions.java │ │ │ │ ├── CriteriaQuery.java │ │ │ │ ├── DefaultCriteriaQuery.java │ │ │ │ ├── DefaultDeleteQuery.java │ │ │ │ ├── DefaultInsertQuery.java │ │ │ │ ├── DefaultUpdateQuery.java │ │ │ │ ├── DeleteQuery.java │ │ │ │ ├── FieldFunction.java │ │ │ │ ├── InsertQuery.java │ │ │ │ ├── LambdaCriteriaQuery.java │ │ │ │ ├── LambdaDeleteQuery.java │ │ │ │ ├── LambdaInsertQuery.java │ │ │ │ ├── LambdaUpdateQuery.java │ │ │ │ ├── LambdaUtils.java │ │ │ │ ├── Operator.java │ │ │ │ ├── ParamValue.java │ │ │ │ ├── ParamValueCallback.java │ │ │ │ ├── Predicate.java │ │ │ │ ├── PredicateResult.java │ │ │ │ ├── PredicateType.java │ │ │ │ ├── QueryUtils.java │ │ │ │ ├── SegmentResult.java │ │ │ │ ├── SelectRange.java │ │ │ │ ├── Sorting.java │ │ │ │ ├── UpdateQuery.java │ │ │ │ └── impl │ │ │ │ ├── ConditionsImpl.java │ │ │ │ ├── CriteriaQueryImpl.java │ │ │ │ ├── DeleteQueryImpl.java │ │ │ │ ├── InsertQueryImpl.java │ │ │ │ └── UpdateQueryImpl.java │ │ │ └── support │ │ │ ├── FetchableFluentQueryByExample.java │ │ │ ├── FluentQuerySupport.java │ │ │ ├── MybatisContext.java │ │ │ ├── MybatisEvaluationContextExtension.java │ │ │ ├── MybatisRepositoryFactory.java │ │ │ ├── MybatisRepositoryFactoryBean.java │ │ │ ├── Pageable.java │ │ │ ├── ResidentParameterName.java │ │ │ ├── ResidentStatementName.java │ │ │ ├── SimpleMybatisRepository.java │ │ │ └── SqlSessionRepositorySupport.java │ └── resources │ │ ├── META-INF │ │ ├── mybatis-3-mapper.dtd │ │ ├── spring.factories │ │ ├── spring.handlers │ │ ├── spring.schemas │ │ └── spring.tooling │ │ └── io │ │ └── easybest │ │ └── mybatis │ │ └── repository │ │ └── config │ │ └── spring-data-mybatis-2.0.xsd │ └── test │ ├── java │ └── io │ │ └── easybest │ │ └── mybatis │ │ ├── domain │ │ └── sample │ │ │ ├── Address.java │ │ │ ├── Role.java │ │ │ ├── SpecialUser.java │ │ │ └── User.java │ │ └── repository │ │ ├── UserRepositoryFinderTests.java │ │ ├── UserRepositoryTests.java │ │ └── sample │ │ ├── NameOnlyDto.java │ │ ├── RoleRepository.java │ │ ├── UserRepository.java │ │ ├── UserRepositoryCustom.java │ │ └── UserRepositoryImpl.java │ └── resources │ ├── META-INF │ └── mybatis-named-queries.properties │ ├── application-context.xml │ ├── config │ └── namespace-application-context.xml │ ├── infrastructure.xml │ ├── logback.xml │ ├── mapper │ └── user.xml │ └── scripts │ ├── h2-init.sql │ ├── hsqldb-init.sql │ ├── mysql-init.sql │ ├── oracle-init.sql │ ├── postgre-init.sql │ ├── sqlite-init.sql │ └── sqlserver-init.sql ├── settings.gradle ├── src ├── checkstyle │ ├── checkstyle-suppressions.xml │ ├── checkstyle.xml │ ├── header.txt │ └── import-control.xml ├── idea │ └── code-schema.xml └── nohttp │ ├── checkstyle.xml │ ├── suppressions.xml │ └── whitelist.lines └── starter ├── build.gradle └── src └── main ├── java └── io │ └── easybest │ └── mybatis │ └── autoconfigure │ ├── MybatisEntityManagerAutoConfiguration.java │ ├── MybatisRepositoriesAutoConfiguration.java │ ├── MybatisRepositoriesRegistrar.java │ └── SpringDataMybatisProperties.java └── resources └── META-INF └── spring.factories /.gitattributes: -------------------------------------------------------------------------------- 1 | # 2 | # https://help.github.com/articles/dealing-with-line-endings/ 3 | # 4 | # These are explicitly windows files and should use crlf 5 | *.bat text eol=crlf 6 | 7 | -------------------------------------------------------------------------------- /.github/workflows/github-actions-cd.yml: -------------------------------------------------------------------------------- 1 | name: Deploy 2 | on: 3 | push: 4 | branches: 5 | - main 6 | - dev 7 | # pull_request: 8 | # branches: 9 | # - main 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | name: 'Deploy to Maven Central' 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: 'Set up JDK 8' 17 | uses: actions/setup-java@v3 18 | with: 19 | java-version: '8' 20 | distribution: 'adopt' 21 | - name: Gradle Cache 22 | uses: actions/cache@v3 23 | with: 24 | path: | 25 | ~/.gradle/caches 26 | ~/.gradle/wrapper 27 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} 28 | restore-keys: | 29 | ${{ runner.os }}-gradle- 30 | - name: Build with Gradle 31 | run: ./gradlew build 32 | - name: Decode PGP 33 | run: | 34 | echo "${{secrets.SIGNING_SECRET_KEY_RING_FILE}}" > ~/.gradle/secring.gpg.b64 35 | base64 -d ~/.gradle/secring.gpg.b64 > ~/.gradle/secring.gpg 36 | - name: Publish 37 | run: ./gradlew publish -Psigning.keyId=${{secrets.SIGNING_KEY_ID}} -Psigning.password= -Psigning.secretKeyRingFile=$(echo ~/.gradle/secring.gpg) 38 | env: 39 | MAVEN_SNAPSHOTS_URL: ${{secrets.MAVEN_SNAPSHOTS_URL}} 40 | MAVEN_RELEASE_URL: ${{secrets.MAVEN_RELEASE_URL}} 41 | MAVEN_REPO_USER: ${{secrets.MAVEN_REPO_USER}} 42 | MAVEN_REPO_PASS: ${{secrets.MAVEN_REPO_PASS}} 43 | -------------------------------------------------------------------------------- /.github/workflows/github-actions-ci.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: [ push ] 3 | jobs: 4 | build: 5 | runs-on: ubuntu-latest 6 | strategy: 7 | matrix: 8 | java: [ 8, 11, 17 ] 9 | name: 'Build on Java ${{ matrix.java }}' 10 | steps: 11 | - uses: actions/checkout@v3 12 | - name: 'Set up JDK ${{ matrix.java }}' 13 | uses: actions/setup-java@v3 14 | with: 15 | java-version: '${{ matrix.java }}' 16 | distribution: 'adopt' 17 | - name: Gradle Cache 18 | uses: actions/cache@v3 19 | with: 20 | path: | 21 | ~/.gradle/caches 22 | ~/.gradle/wrapper 23 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} 24 | restore-keys: | 25 | ${{ runner.os }}-gradle- 26 | - name: Build with Gradle 27 | run: ./gradlew build 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *# 2 | *.iml 3 | *.ipr 4 | *.iws 5 | *.jar 6 | *.sw? 7 | *~ 8 | .#* 9 | .*.md.html 10 | .DS_Store 11 | .attach_pid* 12 | .classpath 13 | .factorypath 14 | .gradle 15 | .idea 16 | .metadata 17 | .project 18 | .recommenders 19 | .settings 20 | .springBeans 21 | .vscode 22 | /code 23 | MANIFEST.MF 24 | _site/ 25 | activemq-data 26 | bin 27 | build 28 | 29 | 30 | !/**/src/**/bin 31 | !/**/src/**/build 32 | !/gradle/wrapper/gradle-wrapper.jar 33 | build.log 34 | dependency-reduced-pom.xml 35 | dump.rdb 36 | interpolated*.xml 37 | lib/ 38 | manifest.yml 39 | out 40 | overridedb.* 41 | target 42 | transaction-logs 43 | .flattened-pom.xml 44 | secrets.yml 45 | .gradletasknamecache 46 | .sts4-cache 47 | /main/src/test/resources/check/ 48 | testcase.db 49 | 50 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id "org.jetbrains.kotlin.jvm" apply false 3 | id "io.spring.nohttp" version "0.0.10" 4 | } 5 | 6 | 7 | description = "${projectName} build" 8 | 9 | defaultTasks "build" 10 | 11 | ext { 12 | javaProjects = subprojects 13 | } 14 | 15 | nohttp { 16 | allowlistFile = project.file("src/nohttp/whitelist.lines") 17 | source.exclude "**/bin/**" 18 | source.exclude "**/build/**" 19 | source.exclude "**/out/**" 20 | source.exclude "**/target/**" 21 | source.exclude "**/frontend/**" 22 | } 23 | 24 | task build { 25 | dependsOn checkstyleNohttp 26 | } 27 | 28 | configure([rootProject] + javaProjects) { project -> 29 | group "${groupId}" 30 | 31 | repositories { 32 | mavenCentral() 33 | } 34 | 35 | configurations.all { 36 | resolutionStrategy { 37 | cacheChangingModulesFor 0, "seconds" 38 | cacheDynamicVersionsFor 0, "seconds" 39 | } 40 | } 41 | } 42 | 43 | 44 | configure(javaProjects) { project -> 45 | apply plugin: "java-library" 46 | apply plugin: "io.easybest.gradle.plugin.conventions" 47 | apply plugin: "io.easybest.gradle.plugin.deployed" 48 | apply plugin: "io.easybest.gradle.plugin.optional-dependencies" 49 | 50 | sourceCompatibility = 1.8 51 | targetCompatibility = 1.8 52 | 53 | java { 54 | toolchain { 55 | languageVersion = JavaLanguageVersion.of(8) 56 | } 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /buildSrc/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id "java-gradle-plugin" 3 | id "maven-publish" 4 | id "signing" 5 | } 6 | 7 | repositories { 8 | mavenCentral() 9 | gradlePluginPortal() 10 | maven { url "https://repo.spring.io/release" } 11 | } 12 | 13 | sourceCompatibility = 1.8 14 | targetCompatibility = 1.8 15 | 16 | dependencies { 17 | implementation("io.spring.javaformat:spring-javaformat-gradle-plugin:0.0.28") 18 | 19 | } 20 | 21 | gradlePlugin { 22 | plugins { 23 | conventionsPlugin { 24 | id = "io.easybest.gradle.plugin.conventions" 25 | implementationClass = "io.easybest.mybatis.build.ConventionsPlugin" 26 | } 27 | deployedPlugin { 28 | id = "io.easybest.gradle.plugin.deployed" 29 | implementationClass = "io.easybest.mybatis.build.DeployedPlugin" 30 | } 31 | optionalDependenciesPlugin { 32 | id = "io.easybest.gradle.plugin.optional-dependencies" 33 | implementationClass = "io.easybest.mybatis.build.optional.OptionalDependenciesPlugin" 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /buildSrc/gradle.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easybest/spring-data-mybatis/773d8494ea4a8b66c785e4eaaa0c0eb35e5c4199/buildSrc/gradle.properties -------------------------------------------------------------------------------- /buildSrc/settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | mavenCentral() 4 | gradlePluginPortal() 5 | } 6 | } -------------------------------------------------------------------------------- /buildSrc/src/main/java/io/easybest/mybatis/build/ConventionsPlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package io.easybest.mybatis.build; 19 | 20 | import org.gradle.api.Plugin; 21 | import org.gradle.api.Project; 22 | 23 | /** 24 | * . 25 | * 26 | * @author Jarvis Song 27 | */ 28 | public class ConventionsPlugin implements Plugin { 29 | @Override 30 | public void apply(Project project) { 31 | new JavaConventions().apply(project); 32 | new MavenPublishingConventions().apply(project); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /buildSrc/src/main/java/io/easybest/mybatis/build/toolchain/ToolchainExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package io.easybest.mybatis.build.toolchain; 19 | 20 | import org.gradle.api.Project; 21 | import org.gradle.api.provider.Property; 22 | import org.gradle.jvm.toolchain.JavaLanguageVersion; 23 | 24 | /** 25 | * DSL extension for {@link ToolchainPlugin}. 26 | * 27 | * @author Jarvis Song 28 | */ 29 | public class ToolchainExtension { 30 | 31 | private final Property maximumCompatibleJavaVersion; 32 | 33 | private final JavaLanguageVersion javaVersion; 34 | 35 | public ToolchainExtension(Project project) { 36 | this.maximumCompatibleJavaVersion = project.getObjects().property(JavaLanguageVersion.class); 37 | String toolchainVersion = (String) project.findProperty("toolchainVersion"); 38 | this.javaVersion = null != toolchainVersion ? JavaLanguageVersion.of(toolchainVersion) : null; 39 | } 40 | 41 | public Property getMaximumCompatibleJavaVersion() { 42 | return this.maximumCompatibleJavaVersion; 43 | } 44 | 45 | public JavaLanguageVersion getJavaVersion() { 46 | return this.javaVersion; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /core/build.gradle: -------------------------------------------------------------------------------- 1 | description "${projectName} core" 2 | 3 | dependencies { 4 | 5 | api("javax.persistence:javax.persistence-api:2.2") 6 | compileOnly("org.springframework.data:spring-data-commons:${springDataVersion}") 7 | compileOnly('com.google.code.findbugs:annotations:3.0.1') 8 | 9 | compileOnly("org.projectlombok:lombok:${lombokVersion}") 10 | annotationProcessor("org.projectlombok:lombok:${lombokVersion}") 11 | 12 | } 13 | 14 | repositories { 15 | mavenCentral() 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /core/src/main/java/io/easybest/mybatis/annotation/DatabaseDefault.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | import java.sql.Types; 24 | 25 | /** 26 | * Set to the database default value. version bigint default 0 not null 27 | * @author JARVIS SONG 28 | * @since 2.0.0 29 | * @see Types 30 | */ 31 | @Retention(RetentionPolicy.RUNTIME) 32 | @Target({ ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE }) 33 | public @interface DatabaseDefault { 34 | 35 | } 36 | -------------------------------------------------------------------------------- /core/src/main/java/io/easybest/mybatis/annotation/GetterOptional.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * . 26 | * 27 | * @author Jarvis Song 28 | */ 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(ElementType.FIELD) 31 | public @interface GetterOptional { 32 | 33 | } 34 | -------------------------------------------------------------------------------- /core/src/main/java/io/easybest/mybatis/annotation/JdbcType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | import java.sql.Types; 24 | 25 | /** 26 | * Specify the jdbc type of property. 27 | * @author JARVIS SONG 28 | * @since 2.0.0 29 | * @see Types 30 | */ 31 | @Retention(RetentionPolicy.RUNTIME) 32 | @Target({ ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE, ElementType.PARAMETER }) 33 | public @interface JdbcType { 34 | 35 | /** 36 | * Jdbc generic SQL Type. 37 | * @return sql type 38 | */ 39 | int value(); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /core/src/main/java/io/easybest/mybatis/annotation/LogicDelete.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * . 26 | * 27 | * @author Jarvis Song 28 | */ 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(ElementType.TYPE) 31 | public @interface LogicDelete { 32 | 33 | /** 34 | * Column name to tag the record was deleted or not. Only support int. 35 | *
36 | 	 * 1 - deleted
37 | 	 * 0 - none deleted
38 | 	 * 
39 | * @return column name 40 | */ 41 | String value() default "deleted"; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /core/src/main/java/io/easybest/mybatis/annotation/TypeHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Specify type handler for a property. 26 | * @author JARVIS SONG 27 | * @since 2.0.0 28 | */ 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target({ ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE, ElementType.PARAMETER }) 31 | public @interface TypeHandler { 32 | 33 | Class value(); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /core/src/main/java/io/easybest/mybatis/domain/Id.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.domain; 18 | 19 | import java.io.Serializable; 20 | 21 | import javax.persistence.GeneratedValue; 22 | import javax.persistence.GenerationType; 23 | import javax.persistence.MappedSuperclass; 24 | 25 | /** 26 | * . 27 | * 28 | * @author Jarvis Song 29 | * @param pk 30 | */ 31 | @MappedSuperclass 32 | public abstract class Id implements Identifiable { 33 | 34 | @GeneratedValue(strategy = GenerationType.AUTO) 35 | @javax.persistence.Id 36 | protected T id; 37 | 38 | public Id() { 39 | } 40 | 41 | public Id(T id) { 42 | this.id = id; 43 | } 44 | 45 | @Override 46 | public T getId() { 47 | return this.id; 48 | } 49 | 50 | public void setId(T id) { 51 | this.id = id; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /core/src/main/java/io/easybest/mybatis/domain/Identifiable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.domain; 18 | 19 | import java.io.Serializable; 20 | 21 | /** 22 | * Indicate an entity or aggregate identifiable. 23 | * 24 | * @author Jarvis Song 25 | * @param identifier type 26 | */ 27 | public interface Identifiable extends Serializable { 28 | 29 | ID getId(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /core/src/main/java/io/easybest/mybatis/domain/LongId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.domain; 18 | 19 | import javax.persistence.MappedSuperclass; 20 | 21 | import lombok.Data; 22 | import lombok.EqualsAndHashCode; 23 | import lombok.NoArgsConstructor; 24 | import lombok.ToString; 25 | 26 | /** 27 | * . 28 | * 29 | * @author Jarvis Song 30 | */ 31 | @Data 32 | @NoArgsConstructor 33 | @EqualsAndHashCode(callSuper = true) 34 | @ToString(callSuper = true) 35 | @MappedSuperclass 36 | public abstract class LongId extends Id { 37 | 38 | public LongId(Long id) { 39 | super(id); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | version=2.1.0-SNAPSHOT 2 | projectName=spring-data-mybatis 3 | groupId=io.easybest 4 | 5 | org.gradle.caching=true 6 | org.gradle.parallel=true 7 | org.gradle.jvmargs=-Xmx1g -Dfile.encoding=UTF-8 8 | 9 | kotlinVersion=1.6.21 10 | kotlin.stdlib.default.dependency=false 11 | 12 | springDataVersion=2.7.5 13 | springVersion=5.3.23 14 | springBootVersion=2.7.5 15 | lombokVersion=1.18.24 16 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easybest/spring-data-mybatis/773d8494ea4a8b66c785e4eaaa0c0eb35e5c4199/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/easybest/spring-data-mybatis/773d8494ea4a8b66c785e4eaaa0c0eb35e5c4199/logo.png -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/auxiliary/SQLResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.auxiliary; 18 | 19 | import java.io.Serializable; 20 | 21 | import lombok.AllArgsConstructor; 22 | import lombok.Builder; 23 | import lombok.Getter; 24 | import lombok.ToString; 25 | import lombok.experimental.SuperBuilder; 26 | 27 | /** 28 | * . 29 | * 30 | * @author Jarvis Song 31 | */ 32 | @Getter 33 | @AllArgsConstructor 34 | @SuperBuilder 35 | @ToString 36 | public class SQLResult implements Serializable { 37 | 38 | private static final long serialVersionUID = 1605358872060161377L; 39 | 40 | /** 41 | * Empty. 42 | */ 43 | public static final SQLResult EMPTY = SQLResult.builder().build(); 44 | 45 | /** 46 | * Params name. 47 | */ 48 | public static final String PARAM_NAME = "__SQLResult"; 49 | 50 | /** 51 | * Params name. 52 | */ 53 | public static final String PARAM_CONNECTOR_NAME = PARAM_NAME + ".connector"; 54 | 55 | /** 56 | * Params name. 57 | */ 58 | public static final String PARAM_CONDITION_NAME = PARAM_NAME + ".condition"; 59 | 60 | /** 61 | * Params name. 62 | */ 63 | public static final String PARAM_SORTING_NAME = PARAM_NAME + ".sorting"; 64 | 65 | @Builder.Default 66 | private String connector = ""; 67 | 68 | @Builder.Default 69 | private String condition = ""; 70 | 71 | @Builder.Default 72 | private String sorting = ""; 73 | 74 | } 75 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/auxiliary/Tuple.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.auxiliary; 18 | 19 | import lombok.AllArgsConstructor; 20 | import lombok.Data; 21 | 22 | /** 23 | * . 24 | * 25 | * @author Jarvis Song 26 | * @param first 27 | * @param second 28 | */ 29 | @Data 30 | @AllArgsConstructor 31 | public class Tuple { 32 | 33 | private T first; 34 | 35 | private S second; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/AbstractDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | /** 23 | * Base class for {@link Dialect} implementations. 24 | * 25 | * @author Jarvis Song 26 | */ 27 | public abstract class AbstractDialect implements Dialect { 28 | 29 | protected Map functions = new HashMap<>(); 30 | 31 | public AbstractDialect() { 32 | 33 | this.registerFunction("lower", "lower"); 34 | this.registerFunction("concat", "concat"); 35 | 36 | } 37 | 38 | @Override 39 | public String getFunction(String name) { 40 | return this.functions.get(name); 41 | } 42 | 43 | protected void registerFunction(String name, String fun) { 44 | this.functions.put(name, fun); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/AbstractPaginationHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import io.easybest.mybatis.mapping.precompile.Segment; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | */ 26 | public abstract class AbstractPaginationHandler implements PaginationHandler { 27 | 28 | protected AbstractPaginationHandler() { 29 | } 30 | 31 | @Override 32 | public String processSql(String sql, Segment offset, Segment fetchSize, Segment offsetEnd) { 33 | throw new UnsupportedOperationException("Paged queries not supported by " + this.getClass().getName()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/CUBRIDDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import javax.persistence.GenerationType; 20 | 21 | import io.easybest.mybatis.mapping.precompile.Segment; 22 | 23 | /** 24 | * . 25 | * 26 | * @author Jarvis Song 27 | */ 28 | public class CUBRIDDialect extends AbstractDialect { 29 | 30 | private static final AbstractPaginationHandler PAGINATION_HANDLER = new AbstractPaginationHandler() { 31 | @Override 32 | public String processSql(String sql, Segment offset, Segment fetchSize, Segment offsetEnd) { 33 | 34 | return sql + (null != offset ? ("LIMIT " + offset + ", " + fetchSize) : "LIMIT " + fetchSize); 35 | } 36 | }; 37 | 38 | @Override 39 | public PaginationHandler getPaginationHandler() { 40 | return PAGINATION_HANDLER; 41 | } 42 | 43 | @Override 44 | public String getSequenceNextValString(String sequenceName) { 45 | return "select " + sequenceName + ".next_value from table({1}) as T(X)"; 46 | } 47 | 48 | @Override 49 | public String getNativeIdentifierGeneratorStrategy() { 50 | return GenerationType.IDENTITY.name().toLowerCase(); 51 | } 52 | 53 | @Override 54 | public String getIdentitySelectString(String table, String column, int type) { 55 | return "select last_insert_id()"; 56 | } 57 | 58 | @Override 59 | public String getIdentityInsertString() { 60 | return "NULL"; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/ClickHouseDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | /** 20 | * . 21 | * 22 | * @author Jarvis Song 23 | */ 24 | public class ClickHouseDialect extends MySQLDialect { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/DB2400Dialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | /** 20 | * . 21 | * 22 | * @author Jarvis Song 23 | */ 24 | public class DB2400Dialect extends DB2Dialect { 25 | 26 | @Override 27 | public String getSequenceNextValString(String sequenceName) { 28 | return "values nextval for " + sequenceName; 29 | } 30 | 31 | @Override 32 | public String getIdentitySelectString(String table, String column, int type) { 33 | 34 | return "select identity_val_local() from sysibm.sysdummy1"; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/DMDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | /** 20 | * . 21 | * 22 | * @author Jarvis Song 23 | */ 24 | public class DMDialect extends Oracle12cDialect { 25 | 26 | @Override 27 | public String regexpLike(String column, String pattern) { 28 | 29 | return "REGEXP_LIKE(" + column + "," + pattern + ")"; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/Dialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import javax.persistence.GenerationType; 20 | 21 | import org.springframework.dao.InvalidDataAccessApiUsageException; 22 | import org.springframework.data.mapping.MappingException; 23 | 24 | import io.easybest.mybatis.mapping.sql.IdentifierProcessing; 25 | 26 | /** 27 | * . 28 | * 29 | * @author Jarvis Song 30 | */ 31 | public interface Dialect { 32 | 33 | PaginationHandler getPaginationHandler(); 34 | 35 | String getFunction(String name); 36 | 37 | default String escape(String character) { 38 | 39 | return String.format("ESCAPE %s", character); 40 | } 41 | 42 | default String regexpLike(String column, String pattern) { 43 | throw new InvalidDataAccessApiUsageException("Unsupported regexpLike"); 44 | } 45 | 46 | default IdentifierProcessing getIdentifierProcessing() { 47 | return IdentifierProcessing.ANSI; 48 | } 49 | 50 | default String getNativeIdentifierGeneratorStrategy() { 51 | return GenerationType.SEQUENCE.name().toLowerCase(); 52 | } 53 | 54 | default String getIdentitySelectString(String table, String column, int type) { 55 | throw new MappingException(this.getClass().getName() + " does not support identity select."); 56 | } 57 | 58 | default String getIdentityInsertString() { 59 | return null; 60 | } 61 | 62 | default String getSequenceNextValString(String sequenceName) { 63 | throw new MappingException(this.getClass().getName() + " does not support sequences"); 64 | } 65 | 66 | default String limitN(int n) { 67 | return ""; 68 | } 69 | 70 | default boolean supportsBoolean() { 71 | return true; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/EnterpriseDBDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | /** 20 | * . 21 | * 22 | * @author Jarvis Song 23 | */ 24 | public class EnterpriseDBDialect extends PostgreSQLDialect { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/FirebirdDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import io.easybest.mybatis.mapping.precompile.Segment; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | */ 26 | public class FirebirdDialect extends AbstractDialect { 27 | 28 | private static final AbstractPaginationHandler PAGINATION_HANDLER = new AbstractPaginationHandler() { 29 | @Override 30 | public String processSql(String sql, Segment offset, Segment fetchSize, Segment offsetEnd) { 31 | 32 | return sql + (null != offset ? (" FIRST " + fetchSize + " SKIP " + offset) : " FIRST " + fetchSize); 33 | } 34 | }; 35 | 36 | @Override 37 | public PaginationHandler getPaginationHandler() { 38 | return PAGINATION_HANDLER; 39 | } 40 | 41 | @Override 42 | public String getSequenceNextValString(String sequenceName) { 43 | return "select " + "gen_id( " + sequenceName + ", 1 )" + " from rdb$database"; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/H2Dialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import static javax.persistence.GenerationType.SEQUENCE; 20 | 21 | /** 22 | * A {@link Dialect} for MySQL. 23 | * 24 | * @author Jarvis Song 25 | */ 26 | public class H2Dialect extends HsqlDbDialect { 27 | 28 | public H2Dialect() { 29 | 30 | super(); 31 | 32 | } 33 | 34 | @Override 35 | public String getIdentitySelectString(String table, String column, int type) { 36 | return "CALL IDENTITY()"; 37 | } 38 | 39 | @Override 40 | public String getIdentityInsertString() { 41 | return "null"; 42 | } 43 | 44 | @Override 45 | public String getSequenceNextValString(String sequenceName) { 46 | return "call next value for " + sequenceName; 47 | } 48 | 49 | @Override 50 | public String getNativeIdentifierGeneratorStrategy() { 51 | return SEQUENCE.name().toLowerCase(); 52 | } 53 | 54 | @Override 55 | public String regexpLike(String column, String pattern) { 56 | return "REGEXP_LIKE(" + column + "," + pattern + ")"; 57 | } 58 | 59 | @Override 60 | public String limitN(int n) { 61 | return "LIMIT " + n; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/HANADialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import javax.persistence.GenerationType; 20 | 21 | import io.easybest.mybatis.mapping.precompile.Segment; 22 | 23 | /** 24 | * . 25 | * 26 | * @author Jarvis Song 27 | */ 28 | public class HANADialect extends AbstractDialect { 29 | 30 | private static final AbstractPaginationHandler PAGINATION_HANDLER = new AbstractPaginationHandler() { 31 | @Override 32 | public String processSql(String sql, Segment offset, Segment fetchSize, Segment offsetEnd) { 33 | 34 | return sql + (null != offset ? ("LIMIT " + fetchSize + " OFFSET " + offset) : ("LIMIT " + fetchSize)); 35 | } 36 | }; 37 | 38 | @Override 39 | public PaginationHandler getPaginationHandler() { 40 | return PAGINATION_HANDLER; 41 | } 42 | 43 | @Override 44 | public String getSequenceNextValString(String sequenceName) { 45 | return String.format("select %s.nextval from sys.dummy", sequenceName); 46 | } 47 | 48 | @Override 49 | public String getNativeIdentifierGeneratorStrategy() { 50 | return GenerationType.IDENTITY.name().toLowerCase(); 51 | } 52 | 53 | @Override 54 | public String getIdentitySelectString(String table, String column, int type) { 55 | return "select current_identity_value() from " + table; 56 | } 57 | 58 | @Override 59 | public String limitN(int n) { 60 | return "LIMIT " + n; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/HerdDBDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import javax.persistence.GenerationType; 20 | 21 | import io.easybest.mybatis.mapping.precompile.Segment; 22 | 23 | /** 24 | * . 25 | * 26 | * @author Jarvis Song 27 | */ 28 | public class HerdDBDialect extends AbstractDialect { 29 | 30 | private static final PaginationHandler PAGINATION_HANDLER = new AbstractPaginationHandler() { 31 | 32 | @Override 33 | public String processSql(String sql, Segment offset, Segment fetchSize, Segment offsetEnd) { 34 | 35 | final boolean hasOffset = null != offset; 36 | 37 | return sql + (hasOffset ? (" LIMIT " + offset + "," + fetchSize) : (" LIMIT " + fetchSize)); 38 | } 39 | }; 40 | 41 | @Override 42 | public PaginationHandler getPaginationHandler() { 43 | return PAGINATION_HANDLER; 44 | } 45 | 46 | @Override 47 | public String getNativeIdentifierGeneratorStrategy() { 48 | return GenerationType.SEQUENCE.name().toLowerCase(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/HighGoDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | /** 20 | * . 21 | * 22 | * @author Jarvis Song 23 | */ 24 | public class HighGoDialect extends PostgreSQLDialect { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/HsqlDbDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import io.easybest.mybatis.mapping.precompile.Segment; 20 | 21 | import static javax.persistence.GenerationType.SEQUENCE; 22 | 23 | /** 24 | * A {@link Dialect} for HsqlDb. 25 | * 26 | * @author Jarvis Song 27 | */ 28 | public class HsqlDbDialect extends AbstractDialect { 29 | 30 | private static final AbstractPaginationHandler PAGINATION_HANDLER = new AbstractPaginationHandler() { 31 | 32 | @Override 33 | public String processSql(String sql, Segment offset, Segment fetchSize, Segment offsetEnd) { 34 | 35 | final boolean hasOffset = null != offset; 36 | 37 | return sql + (hasOffset ? (" LIMIT " + fetchSize + " OFFSET " + offset) : (" LIMIT " + fetchSize)); 38 | } 39 | }; 40 | 41 | public HsqlDbDialect() { 42 | 43 | super(); 44 | } 45 | 46 | @Override 47 | public String getIdentitySelectString(String table, String column, int type) { 48 | return "CALL IDENTITY()"; 49 | } 50 | 51 | @Override 52 | public String getSequenceNextValString(String sequenceName) { 53 | return "CALL NEXT VALUE FOR " + sequenceName; 54 | } 55 | 56 | @Override 57 | public PaginationHandler getPaginationHandler() { 58 | return PAGINATION_HANDLER; 59 | } 60 | 61 | @Override 62 | public String getNativeIdentifierGeneratorStrategy() { 63 | return SEQUENCE.name().toLowerCase(); 64 | } 65 | 66 | @Override 67 | public String regexpLike(String column, String pattern) { 68 | return "REGEXP_MATCHES(" + column + "," + pattern + ")"; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/ImpalaDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | /** 20 | * . 21 | * 22 | * @author Jarvis Song 23 | */ 24 | public class ImpalaDialect extends HsqlDbDialect { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/InformixDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import io.easybest.mybatis.mapping.precompile.Segment; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | */ 26 | public class InformixDialect extends AbstractDialect { 27 | 28 | private static final AbstractPaginationHandler PAGINATION_HANDLER = new AbstractPaginationHandler() { 29 | 30 | @Override 31 | public String processSql(String sql, Segment offset, Segment fetchSize, Segment offsetEnd) { 32 | 33 | final boolean hasOffset = null != offset; 34 | 35 | StringBuilder builder = new StringBuilder(); 36 | builder.append("SELECT "); 37 | if (hasOffset) { 38 | builder.append(" SKIP ").append(offsetEnd); 39 | } 40 | if (null != fetchSize) { 41 | builder.append(" FIRST ").append(fetchSize); 42 | } 43 | builder.append(" * FROM ( "); 44 | builder.append(sql); 45 | builder.append(" ) row_"); 46 | 47 | return builder.toString(); 48 | } 49 | }; 50 | 51 | @Override 52 | public PaginationHandler getPaginationHandler() { 53 | 54 | return PAGINATION_HANDLER; 55 | } 56 | 57 | @Override 58 | public String getSequenceNextValString(String sequenceName) { 59 | return "SELECT " + sequenceName + ".NEXTVAL"; 60 | } 61 | 62 | @Override 63 | public String regexpLike(String column, String pattern) { 64 | return "regex_match(" + column + "," + pattern + ")"; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/Ingres10Dialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import javax.persistence.GenerationType; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | */ 26 | public class Ingres10Dialect extends Ingres9Dialect { 27 | 28 | @Override 29 | public String getNativeIdentifierGeneratorStrategy() { 30 | return GenerationType.IDENTITY.name().toLowerCase(); 31 | } 32 | 33 | @Override 34 | public String getIdentityInsertString() { 35 | return "default"; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/Ingres9Dialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import io.easybest.mybatis.mapping.precompile.Segment; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | */ 26 | public class Ingres9Dialect extends IngresDialect { 27 | 28 | private static final PaginationHandler PAGINATION_HANDLER = new AbstractPaginationHandler() { 29 | @Override 30 | public String processSql(String sql, Segment offset, Segment fetchSize, Segment offsetEnd) { 31 | final String soff = " offset " + offset; 32 | final String slim = " fetch first " + fetchSize + " rows only"; 33 | final StringBuilder sb = new StringBuilder(sql.length() + soff.length() + slim.length()).append(sql); 34 | if (null != offset) { 35 | sb.append(soff); 36 | } 37 | if (null != fetchSize) { 38 | sb.append(slim); 39 | } 40 | return sb.toString(); 41 | } 42 | }; 43 | 44 | @Override 45 | public PaginationHandler getPaginationHandler() { 46 | return PAGINATION_HANDLER; 47 | } 48 | 49 | @Override 50 | public String getIdentitySelectString(String table, String column, int type) { 51 | return "select last_identity()"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/IngresDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import io.easybest.mybatis.dialect.pagination.FirstPaginationHandler; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | */ 26 | public class IngresDialect extends AbstractDialect { 27 | 28 | @Override 29 | public PaginationHandler getPaginationHandler() { 30 | return FirstPaginationHandler.INSTANCE; 31 | } 32 | 33 | @Override 34 | public String getSequenceNextValString(String sequenceName) { 35 | return "select nextval for " + sequenceName; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/KingbaseDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | /** 20 | * . 21 | * 22 | * @author Jarvis Song 23 | */ 24 | public class KingbaseDialect extends PostgreSQLDialect { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/MariaDBDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | /** 20 | * . 21 | * 22 | * @author Jarvis Song 23 | */ 24 | public class MariaDBDialect extends MySQLDialect { 25 | 26 | public MariaDBDialect() { 27 | 28 | super(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/Oracle12cDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import io.easybest.mybatis.dialect.pagination.Oracle12PaginationHandler; 20 | 21 | import static javax.persistence.GenerationType.SEQUENCE; 22 | 23 | /** 24 | * . 25 | * 26 | * @author Jarvis Song 27 | */ 28 | public class Oracle12cDialect extends Oracle9iDialect { 29 | 30 | @Override 31 | public PaginationHandler getPaginationHandler() { 32 | return Oracle12PaginationHandler.INSTANCE; 33 | } 34 | 35 | @Override 36 | public String getNativeIdentifierGeneratorStrategy() { 37 | return SEQUENCE.name().toLowerCase(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/OscarDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | /** 20 | * . 21 | * 22 | * @author Jarvis Song 23 | */ 24 | public class OscarDialect extends HsqlDbDialect { 25 | 26 | @Override 27 | public String getSequenceNextValString(String sequenceName) { 28 | return "select nextval('" + sequenceName + "')"; 29 | } 30 | 31 | @Override 32 | public String getIdentitySelectString(String table, String column, int type) { 33 | return super.getIdentitySelectString(table, column, type); 34 | } 35 | 36 | @Override 37 | public String getNativeIdentifierGeneratorStrategy() { 38 | return "select last_insert_id()"; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/PaginationHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import io.easybest.mybatis.mapping.precompile.Segment; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | */ 26 | public interface PaginationHandler { 27 | 28 | String processSql(String sql, Segment offset, Segment fetchSize, Segment offsetEnd); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/PhoenixDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | /** 20 | * . 21 | * 22 | * @author Jarvis Song 23 | */ 24 | public class PhoenixDialect extends HsqlDbDialect { 25 | 26 | @Override 27 | public String getSequenceNextValString(String sequenceName) { 28 | return "SELECT NEXT VALUE FOR " + sequenceName; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/PolarDBDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | /** 20 | * . 21 | * 22 | * @author Jarvis Song 23 | */ 24 | public class PolarDBDialect extends Oracle12cDialect { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/PostgreSQLDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import io.easybest.mybatis.mapping.precompile.Segment; 20 | 21 | import static javax.persistence.GenerationType.SEQUENCE; 22 | 23 | /** 24 | * . 25 | * 26 | * @author Jarvis Song 27 | */ 28 | public class PostgreSQLDialect extends AbstractDialect { 29 | 30 | private static final AbstractPaginationHandler PAGINATION_HANDLER = new AbstractPaginationHandler() { 31 | 32 | @Override 33 | public String processSql(String sql, Segment offset, Segment fetchSize, Segment offsetEnd) { 34 | 35 | final boolean hasOffset = null != offset; 36 | 37 | return sql + (hasOffset ? (" LIMIT " + fetchSize + " OFFSET " + offset) : (" LIMIT " + fetchSize)); 38 | 39 | } 40 | }; 41 | 42 | @Override 43 | public PaginationHandler getPaginationHandler() { 44 | return PAGINATION_HANDLER; 45 | } 46 | 47 | @Override 48 | public String getNativeIdentifierGeneratorStrategy() { 49 | 50 | return SEQUENCE.name().toLowerCase(); 51 | } 52 | 53 | @Override 54 | public String getIdentitySelectString(String table, String column, int type) { 55 | return "select currval('" + table + '_' + column + "_seq')"; 56 | } 57 | 58 | @Override 59 | public String getSequenceNextValString(String sequenceName) { 60 | return "NEXTVAL ('" + sequenceName + "')"; 61 | } 62 | 63 | @Override 64 | public String limitN(int n) { 65 | return "LIMIT " + n; 66 | } 67 | 68 | @Override 69 | public String regexpLike(String column, String pattern) { 70 | return column + " ~ " + pattern; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/SQLServer2005Dialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import io.easybest.mybatis.dialect.pagination.SQLServer2005PaginationHandler; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | */ 26 | public class SQLServer2005Dialect extends SqlServerDialect { 27 | 28 | @Override 29 | public PaginationHandler getPaginationHandler() { 30 | return new SQLServer2005PaginationHandler(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/SQLServer2012Dialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import io.easybest.mybatis.dialect.pagination.SQLServer2012PaginationHandler; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | */ 26 | public class SQLServer2012Dialect extends SqlServerDialect { 27 | 28 | @Override 29 | public PaginationHandler getPaginationHandler() { 30 | return new SQLServer2012PaginationHandler(); 31 | } 32 | 33 | @Override 34 | public String getSequenceNextValString(String sequenceName) { 35 | return "select next value for " + sequenceName; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/SQLiteDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import javax.persistence.GenerationType; 20 | 21 | import io.easybest.mybatis.mapping.precompile.Segment; 22 | 23 | /** 24 | * . 25 | * 26 | * @author Jarvis Song 27 | */ 28 | public class SQLiteDialect extends AbstractDialect { 29 | 30 | private static final AbstractPaginationHandler PAGINATION_HANDLER = new AbstractPaginationHandler() { 31 | 32 | @Override 33 | public String processSql(String sql, Segment offset, Segment fetchSize, Segment offsetEnd) { 34 | final boolean hasOffset = null != offset; 35 | 36 | return sql + (hasOffset ? (" LIMIT " + fetchSize + " OFFSET " + offset) : (" LIMIT " + fetchSize)); 37 | } 38 | }; 39 | 40 | @Override 41 | public PaginationHandler getPaginationHandler() { 42 | return PAGINATION_HANDLER; 43 | } 44 | 45 | @Override 46 | public String getNativeIdentifierGeneratorStrategy() { 47 | return GenerationType.IDENTITY.name().toLowerCase(); 48 | } 49 | 50 | @Override 51 | public String getIdentitySelectString(String table, String column, int type) { 52 | return "select last_insert_rowid()"; 53 | } 54 | 55 | @Override 56 | public String regexpLike(String column, String pattern) { 57 | return column + " regexp " + pattern; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/SqlServerDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | import javax.persistence.GenerationType; 20 | 21 | import io.easybest.mybatis.dialect.pagination.TopPaginationHandler; 22 | 23 | /** 24 | * . 25 | * 26 | * @author Jarvis Song 27 | */ 28 | public class SqlServerDialect extends AbstractDialect { 29 | 30 | private final PaginationHandler paginationHandler; 31 | 32 | public SqlServerDialect() { 33 | 34 | this.paginationHandler = new TopPaginationHandler(); 35 | } 36 | 37 | @Override 38 | public PaginationHandler getPaginationHandler() { 39 | return this.paginationHandler; 40 | } 41 | 42 | @Override 43 | public String getNativeIdentifierGeneratorStrategy() { 44 | return GenerationType.IDENTITY.name().toLowerCase(); 45 | } 46 | 47 | @Override 48 | public String getIdentitySelectString(String table, String column, int type) { 49 | return "select @@identity"; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/XuguDialect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect; 18 | 19 | /** 20 | * . 21 | * 22 | * @author Jarvis Song 23 | */ 24 | public class XuguDialect extends Oracle12cDialect { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/internal/AliasConstantsHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect.internal; 18 | 19 | /** 20 | * . 21 | * 22 | * @author Jarvis Song 23 | */ 24 | public class AliasConstantsHelper { 25 | 26 | private static final int MAX_POOL_SIZE = 40; 27 | 28 | private static final String[] pool = initPool(MAX_POOL_SIZE); 29 | 30 | public static String get(final int i) { 31 | if (i < MAX_POOL_SIZE && i >= 0) { 32 | return pool[i]; 33 | } 34 | else { 35 | return internalAlias(i); 36 | } 37 | } 38 | 39 | private static String[] initPool(final int maxPoolSize) { 40 | String[] pool = new String[maxPoolSize]; 41 | for (int i = 0; i < maxPoolSize; i++) { 42 | pool[i] = internalAlias(i); 43 | } 44 | return pool; 45 | } 46 | 47 | private static String internalAlias(final int i) { 48 | return Integer.toString(i) + '_'; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/pagination/FirstPaginationHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect.pagination; 18 | 19 | import io.easybest.mybatis.dialect.AbstractPaginationHandler; 20 | import io.easybest.mybatis.mapping.precompile.Segment; 21 | 22 | /** 23 | * . 24 | * 25 | * @author Jarvis Song 26 | */ 27 | public class FirstPaginationHandler extends AbstractPaginationHandler { 28 | 29 | /** 30 | * Singleton. 31 | */ 32 | public static final FirstPaginationHandler INSTANCE = new FirstPaginationHandler(); 33 | 34 | @Override 35 | public String processSql(String sql, Segment offset, Segment fetchSize, Segment offsetEnd) { 36 | 37 | return new StringBuilder(sql.length() + 16).append(sql) 38 | .insert(sql.toLowerCase().indexOf("select") + 6, " first " + fetchSize).toString(); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/dialect/pagination/TopPaginationHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.dialect.pagination; 18 | 19 | import java.util.Locale; 20 | 21 | import io.easybest.mybatis.dialect.AbstractPaginationHandler; 22 | import io.easybest.mybatis.mapping.precompile.Segment; 23 | 24 | /** 25 | * . 26 | * 27 | * @author Jarvis Song 28 | */ 29 | public class TopPaginationHandler extends AbstractPaginationHandler { 30 | 31 | @Override 32 | public String processSql(String sql, Segment offset, Segment fetchSize, Segment offsetEnd) { 33 | 34 | if (null != offset) { 35 | throw new UnsupportedOperationException("Offset is not supported."); 36 | } 37 | 38 | final int selectIndex = sql.toLowerCase(Locale.ROOT).indexOf("select"); 39 | final int selectDistinctIndex = sql.toLowerCase(Locale.ROOT).indexOf("select distinct"); 40 | final int insertionPoint = selectIndex + (selectDistinctIndex == selectIndex ? 15 : 6); 41 | 42 | StringBuilder sb = new StringBuilder(sql.length() + 8).append(sql); 43 | 44 | sb.insert(insertionPoint, " TOP " + fetchSize + " "); 45 | 46 | return sb.toString(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/EntityManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping; 18 | 19 | import org.mybatis.spring.SqlSessionTemplate; 20 | import org.springframework.data.mapping.context.MappingContext; 21 | import org.springframework.lang.Nullable; 22 | 23 | import io.easybest.mybatis.dialect.Dialect; 24 | import io.easybest.mybatis.repository.query.EscapeCharacter; 25 | 26 | /** 27 | * . 28 | * 29 | * @author Jarvis Song 30 | */ 31 | public interface EntityManager extends MappingContext, MybatisPersistentPropertyImpl> { 32 | 33 | SqlSessionTemplate getSqlSessionTemplate(); 34 | 35 | Dialect getDialect(); 36 | 37 | @Nullable 38 | String getNamedQuery(String name); 39 | 40 | EscapeCharacter getEscapeCharacter(); 41 | 42 | @Nullable 43 | String getUniformTablePrefix(); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/MybatisPersistentEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping; 18 | 19 | import java.util.Optional; 20 | 21 | import org.springframework.data.mapping.model.MutablePersistentEntity; 22 | 23 | import io.easybest.mybatis.mapping.sql.SqlIdentifier; 24 | 25 | /** 26 | * . 27 | * 28 | * @author Jarvis Song 29 | * @param entity type 30 | */ 31 | public interface MybatisPersistentEntity extends MutablePersistentEntity { 32 | 33 | SqlIdentifier getTableName(); 34 | 35 | String getEntityName(); 36 | 37 | boolean isCompositeId(); 38 | 39 | Optional getLogicDeleteColumn(); 40 | 41 | /** 42 | * Check whether the entity has associated attributes. 43 | * @return result 44 | */ 45 | boolean isBasic(); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/MybatisPersistentProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping; 18 | 19 | import org.apache.ibatis.type.JdbcType; 20 | import org.apache.ibatis.type.TypeHandler; 21 | import org.springframework.data.mapping.PersistentProperty; 22 | 23 | import io.easybest.mybatis.mapping.sql.SqlIdentifier; 24 | 25 | /** 26 | * . 27 | * 28 | * @author Jarvis Song 29 | */ 30 | public interface MybatisPersistentProperty extends PersistentProperty { 31 | 32 | boolean isEmbeddable(); 33 | 34 | boolean isDatabaseDefaultValue(); 35 | 36 | SqlIdentifier getColumnName(); 37 | 38 | JdbcType getJdbcType(); 39 | 40 | String getJavaType(); 41 | 42 | Class> getTypeHandler(); 43 | 44 | boolean isGetterOptional(); 45 | 46 | @Override 47 | MybatisPersistentEntity getOwner(); 48 | 49 | default SqlIdentifier getRequiredColumnName() { 50 | 51 | SqlIdentifier columnName = this.getColumnName(); 52 | if (null == columnName) { 53 | throw new IllegalArgumentException( 54 | String.format("No column name available for persistent property %s", this)); 55 | } 56 | return columnName; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/NamingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping; 18 | 19 | import org.springframework.data.util.ParsingUtils; 20 | import org.springframework.util.Assert; 21 | 22 | /** 23 | * . 24 | * 25 | * @author Jarvis Song 26 | */ 27 | public interface NamingStrategy { 28 | 29 | /** 30 | * Default instance. 31 | */ 32 | NamingStrategy UNDERSCORE = new NamingStrategy() { 33 | }; 34 | 35 | /** 36 | * As is naming strategy. 37 | */ 38 | NamingStrategy AS_IS = new NamingStrategy() { 39 | @Override 40 | public String getColumnName(MybatisPersistentProperty property) { 41 | return property.getName(); 42 | } 43 | }; 44 | 45 | default String getColumnName(MybatisPersistentProperty property) { 46 | 47 | Assert.notNull(property, "Property must not be null."); 48 | 49 | return ParsingUtils.reconcatenateCamelCase(property.getName(), "_"); 50 | 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/handler/UUIDTypeHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping.handler; 18 | 19 | import java.sql.CallableStatement; 20 | import java.sql.PreparedStatement; 21 | import java.sql.ResultSet; 22 | import java.sql.SQLException; 23 | import java.util.UUID; 24 | 25 | import org.apache.ibatis.type.BaseTypeHandler; 26 | import org.apache.ibatis.type.JdbcType; 27 | 28 | /** 29 | * . 30 | * 31 | * @author Jarvis Song 32 | */ 33 | public class UUIDTypeHandler extends BaseTypeHandler { 34 | 35 | @Override 36 | public void setNonNullParameter(PreparedStatement ps, int i, UUID parameter, JdbcType jdbcType) 37 | throws SQLException { 38 | ps.setString(i, parameter.toString()); 39 | } 40 | 41 | @Override 42 | public UUID getNullableResult(ResultSet rs, String columnName) throws SQLException { 43 | String uuid = rs.getString(columnName); 44 | if (null == uuid) { 45 | return null; 46 | } 47 | return UUID.fromString(uuid); 48 | } 49 | 50 | @Override 51 | public UUID getNullableResult(ResultSet rs, int columnIndex) throws SQLException { 52 | String uuid = rs.getString(columnIndex); 53 | if (null == uuid) { 54 | return null; 55 | } 56 | return UUID.fromString(uuid); 57 | } 58 | 59 | @Override 60 | public UUID getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { 61 | String uuid = cs.getString(columnIndex); 62 | if (null == uuid) { 63 | return null; 64 | } 65 | return UUID.fromString(uuid); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/handler/UnixTimestampDateTypeHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping.handler; 18 | 19 | import java.sql.CallableStatement; 20 | import java.sql.PreparedStatement; 21 | import java.sql.ResultSet; 22 | import java.sql.SQLException; 23 | import java.sql.Timestamp; 24 | 25 | import org.apache.ibatis.type.BaseTypeHandler; 26 | import org.apache.ibatis.type.JdbcType; 27 | 28 | /** 29 | * Date to unix time stamp type handler. 30 | * 31 | * @author JARVIS SONG 32 | * @since 2.0.0 33 | */ 34 | public class UnixTimestampDateTypeHandler extends BaseTypeHandler { 35 | 36 | @Override 37 | public void setNonNullParameter(PreparedStatement ps, int i, Long parameter, JdbcType jdbcType) 38 | throws SQLException { 39 | ps.setTimestamp(i, new Timestamp(parameter)); 40 | } 41 | 42 | @Override 43 | public Long getNullableResult(ResultSet rs, String columnName) throws SQLException { 44 | Timestamp timestamp = rs.getTimestamp(columnName); 45 | if (null == timestamp) { 46 | return null; 47 | } 48 | return timestamp.getTime(); 49 | } 50 | 51 | @Override 52 | public Long getNullableResult(ResultSet rs, int columnIndex) throws SQLException { 53 | Timestamp timestamp = rs.getTimestamp(columnIndex); 54 | if (null == timestamp) { 55 | return null; 56 | } 57 | return timestamp.getTime(); 58 | } 59 | 60 | @Override 61 | public Long getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { 62 | Timestamp timestamp = cs.getTimestamp(columnIndex); 63 | if (null == timestamp) { 64 | return null; 65 | } 66 | return timestamp.getTime(); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/precompile/AbstractSegment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping.precompile; 18 | 19 | import java.util.List; 20 | import java.util.Objects; 21 | import java.util.stream.Collectors; 22 | 23 | import lombok.Getter; 24 | import org.springframework.util.CollectionUtils; 25 | 26 | /** 27 | * . 28 | * 29 | * @author Jarvis Song 30 | */ 31 | @Getter 32 | public abstract class AbstractSegment implements Segment { 33 | 34 | private static final String BLANK = ""; 35 | 36 | protected List contents; 37 | 38 | @Override 39 | public String toString() { 40 | return ""; 41 | } 42 | 43 | protected String content() { 44 | 45 | if (CollectionUtils.isEmpty(this.contents)) { 46 | return BLANK; 47 | } 48 | 49 | return this.contents.stream().filter(Objects::nonNull).map(Segment::toString).collect(Collectors.joining(" ")); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/precompile/Bind.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping.precompile; 18 | 19 | import java.util.List; 20 | 21 | import lombok.Getter; 22 | 23 | /** 24 | * . 25 | * 26 | * @author Jarvis Song 27 | */ 28 | @Getter 29 | public class Bind extends AbstractSegment { 30 | 31 | private String name; 32 | 33 | private String value; 34 | 35 | public static Builder builder() { 36 | return new Builder(); 37 | } 38 | 39 | public static Bind of(String name, String value) { 40 | return Bind.builder().name(name).value(value).build(); 41 | } 42 | 43 | public static Bind of(String name, Segment value) { 44 | return Bind.builder().name(name).value(value.toString()).build(); 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | 50 | return ""; 51 | } 52 | 53 | public static class Builder { 54 | 55 | private List contents; 56 | 57 | private String name; 58 | 59 | private String value; 60 | 61 | public Bind build() { 62 | 63 | Bind bind = new Bind(); 64 | bind.contents = this.contents; 65 | bind.name = this.name; 66 | bind.value = this.value; 67 | return bind; 68 | } 69 | 70 | public Builder contents(final List contents) { 71 | this.contents = contents; 72 | return this; 73 | } 74 | 75 | public Builder name(final String name) { 76 | this.name = name; 77 | return this; 78 | } 79 | 80 | public Builder value(final String value) { 81 | this.value = value; 82 | return this; 83 | } 84 | 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/precompile/Composite.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping.precompile; 18 | 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | import lombok.Getter; 23 | 24 | /** 25 | * . 26 | * 27 | * @author Jarvis Song 28 | */ 29 | @Getter 30 | public class Composite extends AbstractSegment { 31 | 32 | public static Composite of(Segment... segments) { 33 | return Composite.builder().contents(Arrays.asList(segments)).build(); 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return this.content(); 39 | } 40 | 41 | public static Builder builder() { 42 | return new Builder(); 43 | } 44 | 45 | public static class Builder { 46 | 47 | protected List contents; 48 | 49 | public Composite build() { 50 | 51 | Composite instance = new Composite(); 52 | instance.contents = this.contents; 53 | 54 | return instance; 55 | } 56 | 57 | public Builder contents(final List contents) { 58 | this.contents = contents; 59 | return this; 60 | } 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/precompile/Constant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping.precompile; 18 | 19 | import lombok.Getter; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | */ 26 | @Getter 27 | public class Constant implements Segment { 28 | 29 | private final String value; 30 | 31 | public static Constant of(String value) { 32 | return new Constant(value); 33 | } 34 | 35 | public Constant(String value) { 36 | this.value = value; 37 | } 38 | 39 | /** 40 | * Comma. 41 | */ 42 | public static final Constant COMMA = new Constant(","); 43 | 44 | /** 45 | * Equals. 46 | */ 47 | public static final Constant EQUALS = new Constant("="); 48 | 49 | @Override 50 | public String toString() { 51 | return this.value; 52 | } 53 | 54 | public static Builder builder() { 55 | return new Builder(); 56 | } 57 | 58 | public static class Builder { 59 | 60 | private String value; 61 | 62 | public Constant build() { 63 | 64 | return new Constant(this.value); 65 | } 66 | 67 | public Builder value(final String value) { 68 | this.value = value; 69 | return this; 70 | } 71 | 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/precompile/Escape.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping.precompile; 18 | 19 | import lombok.Getter; 20 | 21 | import io.easybest.mybatis.dialect.Dialect; 22 | 23 | /** 24 | * . 25 | * 26 | * @author Jarvis Song 27 | */ 28 | @Getter 29 | public class Escape implements Segment { 30 | 31 | private Dialect dialect; 32 | 33 | public static Escape of(Dialect dialect) { 34 | 35 | return Escape.builder().dialect(dialect).build(); 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | 41 | return this.dialect.escape(Parameter.of("entityManager.escapeCharacter.escapeCharacter").toString()); 42 | } 43 | 44 | public static Builder builder() { 45 | return new Builder(); 46 | } 47 | 48 | public static class Builder { 49 | 50 | private Dialect dialect; 51 | 52 | public Escape build() { 53 | 54 | Escape instance = new Escape(); 55 | instance.dialect = this.dialect; 56 | 57 | return instance; 58 | } 59 | 60 | public Builder dialect(final Dialect dialect) { 61 | this.dialect = dialect; 62 | return this; 63 | } 64 | 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/precompile/If.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping.precompile; 18 | 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | import lombok.Getter; 23 | 24 | /** 25 | * . 26 | * 27 | * @author Jarvis Song 28 | */ 29 | @Getter 30 | public class If extends AbstractSegment { 31 | 32 | private String test; 33 | 34 | public static If of(String test, Segment... segments) { 35 | return If.builder().test(test).contents(Arrays.asList(segments)).build(); 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | 41 | return "" + this.content() + ""; 42 | } 43 | 44 | public static Builder builder() { 45 | return new Builder(); 46 | } 47 | 48 | public static class Builder { 49 | 50 | protected List contents; 51 | 52 | private String test; 53 | 54 | public If build() { 55 | 56 | If instance = new If(); 57 | instance.test = this.test; 58 | 59 | return instance; 60 | } 61 | 62 | public Builder contents(final List contents) { 63 | this.contents = contents; 64 | return this; 65 | } 66 | 67 | public Builder test(final String test) { 68 | this.test = test; 69 | return this; 70 | } 71 | 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/precompile/Include.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping.precompile; 18 | 19 | import lombok.AllArgsConstructor; 20 | import lombok.Getter; 21 | import lombok.NoArgsConstructor; 22 | 23 | import io.easybest.mybatis.repository.support.ResidentStatementName; 24 | 25 | /** 26 | * . 27 | * 28 | * @author Jarvis Song 29 | */ 30 | @Getter 31 | @NoArgsConstructor 32 | @AllArgsConstructor 33 | public class Include implements Segment { 34 | 35 | /** 36 | * Table name. 37 | */ 38 | public static Include TABLE_NAME = Include.of(ResidentStatementName.TABLE_NAME); 39 | 40 | /** 41 | * Pure table name. 42 | */ 43 | public static Include TABLE_NAME_PURE = Include.of(ResidentStatementName.TABLE_NAME_PURE); 44 | 45 | /** 46 | * Column list. 47 | */ 48 | public static Include COLUMN_LIST = Include.of(ResidentStatementName.COLUMN_LIST); 49 | 50 | /** 51 | * Column list. 52 | */ 53 | public static Include COLUMN_LIST_PURE = Include.of(ResidentStatementName.COLUMN_LIST_PURE); 54 | 55 | /** 56 | * COLUMN_LIST_USING_TYPE. 57 | */ 58 | public static Include COLUMN_LIST_USING_TYPE = Include.of(ResidentStatementName.COLUMN_LIST_USING_TYPE); 59 | 60 | private String id; 61 | 62 | public static Include of(String id) { 63 | return new Include(id); 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return ""; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/precompile/Interpolation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping.precompile; 18 | 19 | import java.util.List; 20 | 21 | import lombok.Getter; 22 | 23 | /** 24 | * . 25 | * 26 | * @author Jarvis Song 27 | */ 28 | @Getter 29 | public class Interpolation extends AbstractSegment { 30 | 31 | private String property; 32 | 33 | public static Interpolation of(String property) { 34 | return Interpolation.builder().property(property).build(); 35 | } 36 | 37 | public static Interpolation of(Segment property) { 38 | return Interpolation.builder().property(property.toString()).build(); 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | 44 | return "${" + this.property + "}"; 45 | } 46 | 47 | public static Builder builder() { 48 | return new Builder(); 49 | } 50 | 51 | public static class Builder { 52 | 53 | protected List contents; 54 | 55 | private String property; 56 | 57 | public Interpolation build() { 58 | 59 | Interpolation instance = new Interpolation(); 60 | instance.contents = this.contents; 61 | instance.property = this.property; 62 | 63 | return instance; 64 | } 65 | 66 | public Builder contents(final List contents) { 67 | this.contents = contents; 68 | return this; 69 | } 70 | 71 | public Builder property(final String property) { 72 | this.property = property; 73 | return this; 74 | } 75 | 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/precompile/MybatisMapperSnippet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping.precompile; 18 | 19 | /** 20 | * . 21 | * 22 | * @author Jarvis Song 23 | */ 24 | public abstract class MybatisMapperSnippet { 25 | 26 | /** 27 | * SEQ_MYBATIS. 28 | */ 29 | public static final String DEFAULT_SEQUENCE_NAME = "SEQ_MYBATIS"; 30 | 31 | /** 32 | * MYBATIS_DEFAULT_PARAMETER_NAME. 33 | */ 34 | public static final String MYBATIS_DEFAULT_PARAMETER_NAME = "_parameter"; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/precompile/MybatisStagingMapperSnippet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping.precompile; 18 | 19 | import io.easybest.mybatis.mapping.EntityManager; 20 | import io.easybest.mybatis.mapping.MybatisAssociation; 21 | 22 | /** 23 | * . 24 | * 25 | * @author Jarvis Song 26 | */ 27 | public class MybatisStagingMapperSnippet extends MybatisMapperSnippet { 28 | 29 | private final EntityManager entityManager; 30 | 31 | private final MybatisAssociation association; 32 | 33 | public MybatisStagingMapperSnippet(EntityManager entityManager, MybatisAssociation association) { 34 | 35 | this.entityManager = entityManager; 36 | this.association = association; 37 | } 38 | 39 | public String getNamespace() { 40 | 41 | return null; 42 | } 43 | 44 | public SqlDefinition select() { 45 | 46 | if (!this.association.isToMany()) { 47 | return null; 48 | } 49 | 50 | return null; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/precompile/ParameterExpression.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping.precompile; 18 | 19 | import lombok.Getter; 20 | import lombok.NoArgsConstructor; 21 | import lombok.ToString; 22 | 23 | /** 24 | * . 25 | * 26 | * @author Jarvis Song 27 | * @param type 28 | */ 29 | @Getter 30 | @NoArgsConstructor 31 | @ToString 32 | public class ParameterExpression { 33 | 34 | private String name; 35 | 36 | private Class javaType; 37 | 38 | public ParameterExpression(String name, Class javaType) { 39 | this.name = name; 40 | this.javaType = javaType; 41 | } 42 | 43 | public ParameterExpression(Class javaType) { 44 | this.javaType = javaType; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/precompile/Segment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping.precompile; 18 | 19 | /** 20 | * . 21 | * 22 | * @author Jarvis Song 23 | */ 24 | public interface Segment { 25 | 26 | @Override 27 | String toString(); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/precompile/Set.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping.precompile; 18 | 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | import lombok.Getter; 23 | 24 | /** 25 | * . 26 | * 27 | * @author Jarvis Song 28 | */ 29 | @Getter 30 | public class Set extends AbstractSegment { 31 | 32 | public static Builder builder() { 33 | return new Builder(); 34 | } 35 | 36 | public static Set of(Segment... segments) { 37 | return Set.builder().contents(Arrays.asList(segments)).build(); 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | 43 | return "" + this.content() + ""; 44 | } 45 | 46 | public static class Builder { 47 | 48 | private List contents; 49 | 50 | public Set build() { 51 | 52 | Set instance = new Set(); 53 | instance.contents = this.contents; 54 | 55 | return instance; 56 | } 57 | 58 | public Builder contents(final List contents) { 59 | this.contents = contents; 60 | return this; 61 | } 62 | 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/precompile/SqlDefinition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping.precompile; 18 | 19 | import java.util.List; 20 | 21 | import lombok.Getter; 22 | 23 | import io.easybest.mybatis.repository.support.MybatisContext; 24 | 25 | /** 26 | * . 27 | * 28 | * @author Jarvis Song 29 | */ 30 | @Getter 31 | public abstract class SqlDefinition extends AbstractSegment { 32 | 33 | protected String id; 34 | 35 | protected String databaseId; 36 | 37 | protected List derived; 38 | 39 | protected String parameterType = MybatisContext.class.getSimpleName(); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/precompile/StagingMappers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping.precompile; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | import io.easybest.mybatis.mapping.MybatisAssociation; 23 | 24 | /** 25 | * . 26 | * 27 | * @author Jarvis Song 28 | */ 29 | public class StagingMappers { 30 | 31 | private List associations = new ArrayList<>(); 32 | 33 | public void addAssociation(MybatisAssociation association) { 34 | this.associations.add(association); 35 | } 36 | 37 | public List getAssociations() { 38 | return this.associations; 39 | } 40 | 41 | public void complete() { 42 | this.associations = null; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/precompile/Where.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping.precompile; 18 | 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | import lombok.Getter; 23 | 24 | /** 25 | * . 26 | * 27 | * @author Jarvis Song 28 | */ 29 | @Getter 30 | public class Where extends AbstractSegment { 31 | 32 | public static Where of(Segment... segments) { 33 | return Where.builder().contents(Arrays.asList(segments)).build(); 34 | } 35 | 36 | public static Builder builder() { 37 | return new Builder(); 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | 43 | return "" + this.content() + ""; 44 | } 45 | 46 | public static class Builder { 47 | 48 | private List contents; 49 | 50 | public Where build() { 51 | 52 | Where where = new Where(); 53 | where.contents = this.contents; 54 | return where; 55 | 56 | } 57 | 58 | public Builder contents(final List contents) { 59 | this.contents = contents; 60 | return this; 61 | } 62 | 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/mapping/sql/DefaultIdentifierProcessing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.mapping.sql; 18 | 19 | /** 20 | * . 21 | * 22 | * @author Jarvis Song 23 | */ 24 | class DefaultIdentifierProcessing implements IdentifierProcessing { 25 | 26 | private final Quoting quoting; 27 | 28 | private final LetterCasing letterCasing; 29 | 30 | public DefaultIdentifierProcessing(Quoting quoting, LetterCasing letterCasing) { 31 | this.quoting = quoting; 32 | this.letterCasing = letterCasing; 33 | } 34 | 35 | @Override 36 | public String quote(String identifier) { 37 | return this.quoting.apply(identifier); 38 | } 39 | 40 | @Override 41 | public String standardizeLetterCase(String identifier) { 42 | return this.letterCasing.apply(identifier); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/BasicQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Annotation to declare basic query without any association on repository methods. 27 | * 28 | * @author Jarvis Song 29 | * @since 2.0.0 30 | */ 31 | @Retention(RetentionPolicy.RUNTIME) 32 | @Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) 33 | @Documented 34 | public @interface BasicQuery { 35 | 36 | } 37 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/Fetch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * . 26 | * 27 | * @author Jarvis Song 28 | */ 29 | @Target({ ElementType.METHOD, ElementType.FIELD }) 30 | @Retention(RetentionPolicy.RUNTIME) 31 | public @interface Fetch { 32 | 33 | FetchMode value(); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/FetchMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository; 18 | 19 | /** 20 | * Fetch options on associations. 21 | * 22 | * @author Jarvis Song 23 | */ 24 | public enum FetchMode { 25 | 26 | /** 27 | * Use a secondary select for each individual entity, collection, or join load. 28 | */ 29 | SELECT, 30 | /** 31 | * Use an outer join to load the related entities, collections or joins. 32 | */ 33 | JOIN, 34 | /** 35 | * Available for collections only. When accessing a non-initialized collection, this 36 | * fetch mode will trigger loading all elements of all collections of the same role 37 | * for all owners associated with the persistence context using a single secondary 38 | * select. 39 | */ 40 | SUBSELECT 41 | 42 | } 43 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/Modifying.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | import org.apache.ibatis.mapping.SqlCommandType; 26 | 27 | /** 28 | *

29 | * Indicates a query method should be considered as modifying query as that changes the 30 | * way it needs to be executed. This annotation is only considered if used on query 31 | * methods defined through a {@link Query} annotation). It's not applied on custom 32 | * implementation methods or queries derived from the method name as they already have 33 | * control over the underlying data access APIs or specify if they are modifying by their 34 | * name. 35 | *

36 | *

37 | * Queries that require a `@Modifying` annotation include {@code INSERT}, {@code UPDATE}, 38 | * {@code DELETE}, and DDL statements. 39 | *

40 | * 41 | * @author Jarvis Song 42 | * @since 2.0.0 43 | * @see Query 44 | */ 45 | @Retention(RetentionPolicy.RUNTIME) 46 | @Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) 47 | @Documented 48 | public @interface Modifying { 49 | 50 | /** 51 | * select, insert, update, delete. 52 | * @return modify type 53 | */ 54 | SqlCommandType value() default SqlCommandType.SELECT; 55 | 56 | } 57 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/QueryByCriteriaExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository; 18 | 19 | import java.util.List; 20 | import java.util.Optional; 21 | 22 | import io.easybest.mybatis.repository.query.criteria.CriteriaQuery; 23 | 24 | /** 25 | * . 26 | * 27 | * @author Jarvis Song 28 | * @param domain type 29 | */ 30 | public interface QueryByCriteriaExecutor { 31 | 32 | Optional findOne(CriteriaQuery criteria); 33 | 34 | List findAll(CriteriaQuery criteria); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/ResultMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | import io.easybest.mybatis.repository.support.ResidentStatementName; 26 | 27 | /** 28 | * Which resultMap will be used in the query. 29 | * @author Jarvis Song 30 | * @since 2.0.0 31 | */ 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) 34 | @Documented 35 | public @interface ResultMap { 36 | 37 | String value() default ResidentStatementName.RESULT_MAP; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/ResultType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Which resultType will be used in the query. 27 | * @author Jarvis Song 28 | * @since 2.0.0 29 | */ 30 | @Retention(RetentionPolicy.RUNTIME) 31 | @Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) 32 | @Documented 33 | public @interface ResultType { 34 | 35 | Class value() default Void.class; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/Temporal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | import java.util.Date; 25 | 26 | import javax.persistence.TemporalType; 27 | 28 | /** 29 | * Annotation to declare an appropriate {@code TemporalType} on query method parameters. 30 | * Note that this annotation can only be used on parameters of type {@link Date}. 31 | * 32 | * @author JARVIS SONG 33 | * @since 2.0.0 34 | */ 35 | @Retention(RetentionPolicy.RUNTIME) 36 | @Target(ElementType.PARAMETER) 37 | @Documented 38 | public @interface Temporal { 39 | 40 | TemporalType value() default TemporalType.DATE; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/config/MybatisAuditingRegistrar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.config; 18 | 19 | import java.lang.annotation.Annotation; 20 | 21 | import org.springframework.beans.factory.config.BeanDefinition; 22 | import org.springframework.beans.factory.support.BeanDefinitionRegistry; 23 | import org.springframework.data.auditing.config.AuditingBeanDefinitionRegistrarSupport; 24 | 25 | /** 26 | * . 27 | * 28 | * @author Jarvis Song 29 | */ 30 | class MybatisAuditingRegistrar extends AuditingBeanDefinitionRegistrarSupport { 31 | 32 | @Override 33 | protected Class getAnnotation() { 34 | return EnableMybatisAuditing.class; 35 | } 36 | 37 | @Override 38 | protected void registerAuditListenerBeanDefinition(BeanDefinition auditingHandlerDefinition, 39 | BeanDefinitionRegistry registry) { 40 | 41 | } 42 | 43 | @Override 44 | protected String getAuditingHandlerBeanName() { 45 | return null; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/config/MybatisRepositoriesRegistrar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.config; 18 | 19 | import java.lang.annotation.Annotation; 20 | 21 | import org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport; 22 | import org.springframework.data.repository.config.RepositoryConfigurationExtension; 23 | 24 | /** 25 | * {@link org.springframework.context.annotation.ImportBeanDefinitionRegistrar} to enable 26 | * {@link EnableMybatisRepositories} annotation. 27 | * 28 | * @author Jarvis Song 29 | */ 30 | class MybatisRepositoriesRegistrar extends RepositoryBeanDefinitionRegistrarSupport { 31 | 32 | @Override 33 | protected Class getAnnotation() { 34 | return EnableMybatisRepositories.class; 35 | } 36 | 37 | @Override 38 | protected RepositoryConfigurationExtension getExtension() { 39 | return new MybatisRepositoryConfigExtension(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/config/MybatisRepositoryNameSpaceHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.config; 18 | 19 | import org.springframework.beans.factory.xml.NamespaceHandlerSupport; 20 | import org.springframework.data.repository.config.RepositoryBeanDefinitionParser; 21 | import org.springframework.data.repository.config.RepositoryConfigurationExtension; 22 | 23 | /** 24 | * . 25 | * 26 | * @author Jarvis Song 27 | */ 28 | public class MybatisRepositoryNameSpaceHandler extends NamespaceHandlerSupport { 29 | 30 | @Override 31 | public void init() { 32 | 33 | RepositoryConfigurationExtension extension = new MybatisRepositoryConfigExtension(); 34 | RepositoryBeanDefinitionParser repositoryBeanDefinitionParser = new RepositoryBeanDefinitionParser(extension); 35 | 36 | this.registerBeanDefinitionParser("repositories", repositoryBeanDefinitionParser); 37 | // TODO register auditing parser 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/DeclaredQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query; 18 | 19 | import java.util.List; 20 | 21 | import org.springframework.lang.Nullable; 22 | import org.springframework.util.ObjectUtils; 23 | 24 | import io.easybest.mybatis.repository.query.StringQuery.ParameterBinding; 25 | 26 | /** 27 | * . 28 | * 29 | * @author Jarvis Song 30 | */ 31 | public interface DeclaredQuery { 32 | 33 | static DeclaredQuery of(@Nullable String query) { 34 | return ObjectUtils.isEmpty(query) ? EmptyDeclaredQuery.EMPTY_QUERY : new StringQuery(query); 35 | } 36 | 37 | boolean hasNamedParameter(); 38 | 39 | String getQueryString(); 40 | 41 | @Nullable 42 | String getAlias(); 43 | 44 | boolean hasConstructorExpression(); 45 | 46 | boolean isDefaultProjection(); 47 | 48 | List getParameterBindings(); 49 | 50 | DeclaredQuery deriveCountQuery(@Nullable String countQuery, @Nullable String countQueryProjection); 51 | 52 | default boolean usesPaging() { 53 | return false; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/DefaultMybatisEntityMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query; 18 | 19 | import org.springframework.util.Assert; 20 | 21 | import io.easybest.mybatis.mapping.MybatisPersistentEntity; 22 | 23 | /** 24 | * . 25 | * 26 | * @author Jarvis Song 27 | * @param domain type 28 | */ 29 | public class DefaultMybatisEntityMetadata implements MybatisEntityMetadata { 30 | 31 | private final MybatisPersistentEntity entity; 32 | 33 | public DefaultMybatisEntityMetadata(MybatisPersistentEntity entity) { 34 | 35 | Assert.notNull(entity, "entity must not be null!"); 36 | this.entity = entity; 37 | 38 | } 39 | 40 | @Override 41 | public String getEntityName() { 42 | 43 | return this.entity.getEntityName(); 44 | } 45 | 46 | @Override 47 | public String getTableName() { 48 | 49 | return this.entity.getTableName().getReference(); 50 | } 51 | 52 | @Override 53 | public Class getJavaType() { 54 | return this.entity.getType(); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/DefaultQueryEnhancer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query; 18 | 19 | import java.util.Set; 20 | 21 | import org.springframework.data.domain.Sort; 22 | 23 | /** 24 | * . 25 | * 26 | * @author Jarvis Song 27 | */ 28 | public class DefaultQueryEnhancer implements QueryEnhancer { 29 | 30 | private final DeclaredQuery query; 31 | 32 | public DefaultQueryEnhancer(DeclaredQuery query) { 33 | this.query = query; 34 | } 35 | 36 | @Override 37 | public String applySorting(Sort sort, String alias) { 38 | return QueryUtils.applySorting(this.getQuery().getQueryString(), sort, alias); 39 | } 40 | 41 | @Override 42 | public String detectAlias() { 43 | return QueryUtils.detectAlias(this.query.getQueryString()); 44 | } 45 | 46 | @Override 47 | public String createCountQueryFor(String countProjection) { 48 | return QueryUtils.createCountQueryFor(this.query.getQueryString(), countProjection); 49 | } 50 | 51 | @Override 52 | public String getProjection() { 53 | return QueryUtils.getProjection(this.query.getQueryString()); 54 | } 55 | 56 | @Override 57 | public Set getJoinAliases() { 58 | return QueryUtils.getOuterJoinAliases(this.query.getQueryString()); 59 | } 60 | 61 | @Override 62 | public DeclaredQuery getQuery() { 63 | return this.query; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/EmptyDeclaredQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query; 18 | 19 | import java.util.List; 20 | 21 | import org.springframework.util.Assert; 22 | 23 | /** 24 | * . 25 | * 26 | * @author Jarvis Song 27 | */ 28 | class EmptyDeclaredQuery implements DeclaredQuery { 29 | 30 | static final DeclaredQuery EMPTY_QUERY = new EmptyDeclaredQuery(); 31 | 32 | @Override 33 | public boolean hasNamedParameter() { 34 | return false; 35 | } 36 | 37 | @Override 38 | public String getQueryString() { 39 | return ""; 40 | } 41 | 42 | @Override 43 | public String getAlias() { 44 | return null; 45 | } 46 | 47 | @Override 48 | public boolean hasConstructorExpression() { 49 | return false; 50 | } 51 | 52 | @Override 53 | public boolean isDefaultProjection() { 54 | return false; 55 | } 56 | 57 | @Override 58 | public List getParameterBindings() { 59 | return null; 60 | } 61 | 62 | @Override 63 | public DeclaredQuery deriveCountQuery(String countQuery, String countQueryProjection) { 64 | 65 | Assert.hasText(countQuery, "CountQuery must not be empty!"); 66 | 67 | return DeclaredQuery.of(countQuery); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/IndicatingMybatisQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query; 18 | 19 | import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider; 20 | import org.springframework.expression.spel.standard.SpelExpressionParser; 21 | 22 | import io.easybest.mybatis.mapping.EntityManager; 23 | 24 | /** 25 | * . 26 | * 27 | * @author Jarvis Song 28 | */ 29 | public class IndicatingMybatisQuery extends AbstractStringBasedMybatisQuery { 30 | 31 | public IndicatingMybatisQuery(EntityManager entityManager, SpelExpressionParser parser, 32 | QueryMethodEvaluationContextProvider evaluationContextProvider, MybatisQueryMethod method, 33 | String queryString, String countQueryString) { 34 | 35 | super(entityManager, parser, evaluationContextProvider, method, queryString, countQueryString); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/MapperedMybatisQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query; 18 | 19 | import io.easybest.mybatis.mapping.EntityManager; 20 | import io.easybest.mybatis.mapping.precompile.SqlDefinition; 21 | 22 | /** 23 | * . 24 | * 25 | * @author Jarvis Song 26 | */ 27 | final class MapperedMybatisQuery extends AbstractMybatisQuery { 28 | 29 | public MapperedMybatisQuery(EntityManager entityManager, MybatisQueryMethod method) { 30 | super(entityManager, method); 31 | } 32 | 33 | @Override 34 | protected SqlDefinition doCreateSqlDefinition() { 35 | return null; 36 | } 37 | 38 | public String getStatementName() { 39 | return this.method.getAnnotationStringValue("statement", this.method.getName()); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/MybatisEntityMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query; 18 | 19 | import org.springframework.data.repository.core.EntityMetadata; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | * @param domain type 26 | */ 27 | public interface MybatisEntityMetadata extends EntityMetadata { 28 | 29 | String getEntityName(); 30 | 31 | String getTableName(); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/MybatisParametersParameterAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query; 18 | 19 | import org.springframework.data.repository.query.Parameter; 20 | import org.springframework.data.repository.query.Parameters; 21 | import org.springframework.data.repository.query.ParametersParameterAccessor; 22 | import org.springframework.lang.Nullable; 23 | 24 | /** 25 | * . 26 | * 27 | * @author Jarvis Song 28 | */ 29 | public class MybatisParametersParameterAccessor extends ParametersParameterAccessor { 30 | 31 | /** 32 | * Creates a new {@link ParametersParameterAccessor}. 33 | * @param parameters must not be {@literal null}. 34 | * @param values must not be {@literal null}. 35 | */ 36 | public MybatisParametersParameterAccessor(Parameters parameters, Object[] values) { 37 | super(parameters, values); 38 | } 39 | 40 | @Nullable 41 | public T getValue(Parameter parameter) { 42 | return super.getValue(parameter.getIndex()); 43 | } 44 | 45 | @Override 46 | protected Object[] getValues() { 47 | return super.getValues(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/MybatisQueryIntendListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query; 18 | 19 | import org.springframework.data.mapping.MappingException; 20 | import org.springframework.data.repository.core.support.QueryCreationListener; 21 | import org.springframework.data.repository.query.RepositoryQuery; 22 | import org.springframework.lang.NonNull; 23 | 24 | import io.easybest.mybatis.mapping.precompile.MybatisAggregateRootPrecompile; 25 | 26 | /** 27 | * . 28 | * 29 | * @author Jarvis Song 30 | */ 31 | public enum MybatisQueryIntendListener implements QueryCreationListener { 32 | 33 | /** 34 | * Singleton instance. 35 | */ 36 | INSTANCE; 37 | 38 | @Override 39 | public void onCreation(@NonNull RepositoryQuery query) { 40 | 41 | if (query instanceof IndicatingMybatisQuery) { 42 | MybatisAggregateRootPrecompile.compile((IndicatingMybatisQuery) query); 43 | return; 44 | } 45 | 46 | if (query instanceof PartTreeMybatisQuery) { 47 | MybatisAggregateRootPrecompile.compile((PartTreeMybatisQuery) query); 48 | return; 49 | } 50 | 51 | if (query instanceof MapperedMybatisQuery) { 52 | // don't have to do anything 53 | return; 54 | } 55 | 56 | throw new MappingException("Unsupported query " + query.getClass() + ", " + query.getQueryMethod()); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/Procedure.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Annotation to declare JPA 2.1 stored procedure mappings directly on repository methods. 26 | * 27 | * @author Thomas Darimont 28 | * @author Oliver Gierke 29 | * @author Christoph Strobl 30 | * @author Gabriel Basilio 31 | */ 32 | @Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) 33 | @Retention(RetentionPolicy.RUNTIME) 34 | public @interface Procedure { 35 | 36 | String value() default ""; 37 | 38 | String procedureName() default ""; 39 | 40 | String name() default ""; 41 | 42 | String outputParameterName() default ""; 43 | 44 | boolean refCursor() default false; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/QueryEnhancer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query; 18 | 19 | import java.util.Set; 20 | 21 | import org.springframework.data.domain.Sort; 22 | import org.springframework.lang.Nullable; 23 | 24 | /** 25 | * . 26 | * 27 | * @author Jarvis Song 28 | */ 29 | public interface QueryEnhancer { 30 | 31 | default String applySorting(Sort sort) { 32 | 33 | return this.applySorting(sort, this.detectAlias()); 34 | } 35 | 36 | String applySorting(Sort sort, @Nullable String alias); 37 | 38 | @Nullable 39 | String detectAlias(); 40 | 41 | default String createCountQueryFor() { 42 | return this.createCountQueryFor(null); 43 | } 44 | 45 | String createCountQueryFor(@Nullable String countProjection); 46 | 47 | default boolean hasConstructorExpression() { 48 | return QueryUtils.hasConstructorExpression(this.getQuery().getQueryString()); 49 | } 50 | 51 | String getProjection(); 52 | 53 | Set getJoinAliases(); 54 | 55 | DeclaredQuery getQuery(); 56 | 57 | } 58 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/criteria/ColumnResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query.criteria; 18 | 19 | import java.io.Serializable; 20 | import java.util.Set; 21 | 22 | import lombok.AllArgsConstructor; 23 | import lombok.Data; 24 | import lombok.NoArgsConstructor; 25 | 26 | import io.easybest.mybatis.mapping.precompile.Column; 27 | 28 | /** 29 | * . 30 | * 31 | * @author Jarvis Song 32 | */ 33 | @Data 34 | @AllArgsConstructor 35 | @NoArgsConstructor 36 | public class ColumnResult implements Serializable { 37 | 38 | private Column column; 39 | 40 | private Set connectors; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/criteria/CriteriaQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query.criteria; 18 | 19 | import org.springframework.data.domain.Example; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | * @param domain type 26 | * @param return type 27 | * @param field type 28 | * @param value type 29 | */ 30 | public interface CriteriaQuery extends SelectRange, Conditions, Sorting { 31 | 32 | static LambdaCriteriaQuery lambda(Class domainClass) { 33 | 34 | return new LambdaCriteriaQuery<>(domainClass); 35 | } 36 | 37 | static DefaultCriteriaQuery create(Class domainClass) { 38 | return new DefaultCriteriaQuery<>(domainClass); 39 | } 40 | 41 | R distinct(); 42 | 43 | R paging(); 44 | 45 | R unpaged(); 46 | 47 | R example(Example example); 48 | 49 | R exampling(); 50 | 51 | R binding(); 52 | 53 | R parameterType(String parameterType); 54 | 55 | R resultType(String resultType); 56 | 57 | R resultMap(String resultMap); 58 | 59 | } 60 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/criteria/DefaultCriteriaQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query.criteria; 18 | 19 | import io.easybest.mybatis.repository.query.criteria.impl.CriteriaQueryImpl; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | * @param domain type 26 | * @param value type 27 | */ 28 | public class DefaultCriteriaQuery extends CriteriaQueryImpl, String, V> { 29 | 30 | public DefaultCriteriaQuery(Class domainClass) { 31 | super(domainClass); 32 | } 33 | 34 | @Override 35 | protected Conditions, String, V> createConditionsInstance() { 36 | return new DefaultCriteriaQuery<>(this.domainClass); 37 | } 38 | 39 | @Override 40 | protected DefaultCriteriaQuery getReturns() { 41 | return this; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/criteria/DefaultDeleteQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query.criteria; 18 | 19 | import io.easybest.mybatis.repository.query.criteria.impl.DeleteQueryImpl; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | * @param domain type 26 | * @param value type 27 | */ 28 | public class DefaultDeleteQuery extends DeleteQueryImpl, String, V> { 29 | 30 | public DefaultDeleteQuery(Class domainClass) { 31 | super(domainClass); 32 | } 33 | 34 | @Override 35 | protected Conditions, String, V> createConditionsInstance() { 36 | return new DefaultDeleteQuery<>(this.domainClass); 37 | } 38 | 39 | @Override 40 | protected DefaultDeleteQuery getReturns() { 41 | return this; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/criteria/DefaultInsertQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query.criteria; 18 | 19 | import io.easybest.mybatis.repository.query.criteria.impl.InsertQueryImpl; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | * @param domain type 26 | * @param value type 27 | */ 28 | public class DefaultInsertQuery extends InsertQueryImpl, String, V> { 29 | 30 | public DefaultInsertQuery(Class domainClass) { 31 | super(domainClass); 32 | } 33 | 34 | @Override 35 | protected DefaultInsertQuery getReturns() { 36 | return this; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/criteria/DefaultUpdateQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query.criteria; 18 | 19 | import io.easybest.mybatis.repository.query.criteria.impl.UpdateQueryImpl; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | * @param domain type 26 | * @param value type 27 | */ 28 | public class DefaultUpdateQuery extends UpdateQueryImpl, String, V> { 29 | 30 | public DefaultUpdateQuery(Class domainClass) { 31 | super(domainClass); 32 | } 33 | 34 | @Override 35 | protected Conditions, String, V> createConditionsInstance() { 36 | return new DefaultUpdateQuery<>(this.domainClass); 37 | } 38 | 39 | @Override 40 | protected DefaultUpdateQuery getReturns() { 41 | return this; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/criteria/DeleteQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query.criteria; 18 | 19 | /** 20 | * . 21 | * 22 | * @author Jarvis Song 23 | * @param return type 24 | * @param field type 25 | * @param value type 26 | */ 27 | public interface DeleteQuery { 28 | 29 | static LambdaDeleteQuery lambda(Class domainClass) { 30 | 31 | return new LambdaDeleteQuery<>(domainClass); 32 | } 33 | 34 | static DefaultDeleteQuery create(Class domainClass) { 35 | return new DefaultDeleteQuery<>(domainClass); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/criteria/FieldFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query.criteria; 18 | 19 | import java.io.Serializable; 20 | import java.util.function.Function; 21 | 22 | /** 23 | * . 24 | * 25 | * @author Jarvis Song 26 | * @param domain type 27 | * @param return type 28 | */ 29 | @FunctionalInterface 30 | public interface FieldFunction extends Function, Serializable { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/criteria/InsertQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query.criteria; 18 | 19 | import io.easybest.mybatis.mapping.precompile.Column; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | * @param return type 26 | * @param field type 27 | * @param value type 28 | */ 29 | public interface InsertQuery { 30 | 31 | static LambdaInsertQuery lambda(Class domainClass) { 32 | 33 | return new LambdaInsertQuery<>(domainClass); 34 | } 35 | 36 | static DefaultInsertQuery create(Class domainClass) { 37 | return new DefaultInsertQuery<>(domainClass); 38 | } 39 | 40 | R set(F field, V value); 41 | 42 | R set(Column column, V value); 43 | 44 | @SuppressWarnings("unchecked") 45 | R customSet(String columnPart, String valuePart, V... values); 46 | 47 | R selective(); 48 | 49 | R selectKey(); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/criteria/LambdaCriteriaQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query.criteria; 18 | 19 | import io.easybest.mybatis.repository.query.criteria.impl.CriteriaQueryImpl; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | * @param domain type 26 | * @param value type 27 | */ 28 | public class LambdaCriteriaQuery extends CriteriaQueryImpl, FieldFunction, V> { 29 | 30 | public LambdaCriteriaQuery(Class domainClass) { 31 | super(domainClass); 32 | } 33 | 34 | @Override 35 | protected Conditions, FieldFunction, V> createConditionsInstance() { 36 | return new LambdaCriteriaQuery<>(this.domainClass); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/criteria/LambdaDeleteQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query.criteria; 18 | 19 | import io.easybest.mybatis.repository.query.criteria.impl.DeleteQueryImpl; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | * @param domain type 26 | * @param value type 27 | */ 28 | public class LambdaDeleteQuery extends DeleteQueryImpl, FieldFunction, V> { 29 | 30 | public LambdaDeleteQuery(Class domainClass) { 31 | super(domainClass); 32 | } 33 | 34 | @Override 35 | protected Conditions, FieldFunction, V> createConditionsInstance() { 36 | return new LambdaDeleteQuery<>(this.domainClass); 37 | } 38 | 39 | @Override 40 | protected LambdaDeleteQuery getReturns() { 41 | return this; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/criteria/LambdaInsertQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query.criteria; 18 | 19 | import io.easybest.mybatis.repository.query.criteria.impl.InsertQueryImpl; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | * @param domain type 26 | * @param value type 27 | */ 28 | public class LambdaInsertQuery extends InsertQueryImpl, FieldFunction, V> { 29 | 30 | public LambdaInsertQuery(Class domainClass) { 31 | super(domainClass); 32 | } 33 | 34 | @Override 35 | protected LambdaInsertQuery getReturns() { 36 | return this; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/criteria/LambdaUpdateQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query.criteria; 18 | 19 | import io.easybest.mybatis.repository.query.criteria.impl.UpdateQueryImpl; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | * @param domain type 26 | * @param value type 27 | */ 28 | public class LambdaUpdateQuery extends UpdateQueryImpl, FieldFunction, V> { 29 | 30 | public LambdaUpdateQuery(Class domainClass) { 31 | super(domainClass); 32 | } 33 | 34 | @Override 35 | protected Conditions, FieldFunction, V> createConditionsInstance() { 36 | return new LambdaUpdateQuery<>(this.domainClass); 37 | } 38 | 39 | @Override 40 | protected LambdaUpdateQuery getReturns() { 41 | return this; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/criteria/Operator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query.criteria; 18 | 19 | /** 20 | * . 21 | * 22 | * @author Jarvis Song 23 | */ 24 | public enum Operator { 25 | 26 | /** 27 | * AND. 28 | */ 29 | AND, 30 | /** 31 | * OR. 32 | */ 33 | OR; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/criteria/ParamValueCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query.criteria; 18 | 19 | import java.util.function.Function; 20 | 21 | import io.easybest.mybatis.mapping.precompile.Parameter; 22 | 23 | /** 24 | * . 25 | * 26 | * @author Jarvis Song 27 | */ 28 | @FunctionalInterface 29 | public interface ParamValueCallback extends Function { 30 | 31 | } 32 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/criteria/SegmentResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query.criteria; 18 | 19 | import java.io.Serializable; 20 | import java.util.LinkedHashSet; 21 | import java.util.LinkedList; 22 | import java.util.List; 23 | import java.util.Set; 24 | 25 | import lombok.AllArgsConstructor; 26 | import lombok.Data; 27 | import lombok.NoArgsConstructor; 28 | 29 | import io.easybest.mybatis.mapping.precompile.Segment; 30 | 31 | /** 32 | * . 33 | * 34 | * @author Jarvis Song 35 | */ 36 | @Data 37 | @AllArgsConstructor 38 | @NoArgsConstructor 39 | public class SegmentResult implements Serializable { 40 | 41 | private List segments; 42 | 43 | private Set connectors; 44 | 45 | public void add(Set connectors) { 46 | 47 | if (null == this.connectors) { 48 | this.connectors = new LinkedHashSet<>(); 49 | } 50 | 51 | this.connectors.addAll(connectors); 52 | } 53 | 54 | public void add(Segment segment) { 55 | if (null == this.segments) { 56 | this.segments = new LinkedList<>(); 57 | } 58 | this.segments.add(segment); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/criteria/SelectRange.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query.criteria; 18 | 19 | import io.easybest.mybatis.mapping.precompile.Column; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | * @param return type 26 | * @param field type 27 | */ 28 | public interface SelectRange { 29 | 30 | @SuppressWarnings("unchecked") 31 | R select(F... fields); 32 | 33 | @SuppressWarnings("unchecked") 34 | R exclude(F... fields); 35 | 36 | R selects(Column... columns); 37 | 38 | R selects(String selects); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/criteria/Sorting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query.criteria; 18 | 19 | import org.springframework.data.domain.Sort; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | * @param return type 26 | * @param field type 27 | */ 28 | public interface Sorting { 29 | 30 | @SuppressWarnings("unchecked") 31 | R orderBy(F... fields); 32 | 33 | @SuppressWarnings("unchecked") 34 | R orderBy(Sort.Direction direction, F... fields); 35 | 36 | R orderBy(Sort sort); 37 | 38 | R withSort(); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/query/criteria/UpdateQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.query.criteria; 18 | 19 | import io.easybest.mybatis.mapping.precompile.Column; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | * @param return type 26 | * @param field type 27 | * @param value type 28 | */ 29 | public interface UpdateQuery { 30 | 31 | static LambdaUpdateQuery lambda(Class domainClass) { 32 | 33 | return new LambdaUpdateQuery<>(domainClass); 34 | } 35 | 36 | static DefaultUpdateQuery create(Class domainClass) { 37 | return new DefaultUpdateQuery<>(domainClass); 38 | } 39 | 40 | R set(F field, V value); 41 | 42 | R set(Column column, V value); 43 | 44 | @SuppressWarnings("unchecked") 45 | R customSet(String sql, V... values); 46 | 47 | R selective(); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/support/MybatisEvaluationContextExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.support; 18 | 19 | import org.springframework.data.spel.spi.EvaluationContextExtension; 20 | 21 | import io.easybest.mybatis.repository.query.EscapeCharacter; 22 | 23 | /** 24 | * . 25 | * 26 | * @author Jarvis Song 27 | */ 28 | public class MybatisEvaluationContextExtension implements EvaluationContextExtension { 29 | 30 | private final MybatisRootObject root; 31 | 32 | public MybatisEvaluationContextExtension(char escapeCharacter) { 33 | 34 | this.root = MybatisRootObject.of(EscapeCharacter.of(escapeCharacter)); 35 | } 36 | 37 | @Override 38 | public String getExtensionId() { 39 | return "mybatis"; 40 | } 41 | 42 | @Override 43 | public Object getRootObject() { 44 | return this.root; 45 | } 46 | 47 | public static class MybatisRootObject { 48 | 49 | private final EscapeCharacter character; 50 | 51 | public MybatisRootObject(EscapeCharacter character) { 52 | this.character = character; 53 | } 54 | 55 | public static MybatisRootObject of(EscapeCharacter character) { 56 | return new MybatisRootObject(character); 57 | } 58 | 59 | public String escape(String source) { 60 | return this.character.escape(source); 61 | } 62 | 63 | public char escapeCharacter() { 64 | return this.character.getEscapeCharacter(); 65 | } 66 | 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /main/src/main/java/io/easybest/mybatis/repository/support/Pageable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.support; 18 | 19 | import java.io.Serializable; 20 | 21 | import lombok.Data; 22 | 23 | /** 24 | * . 25 | * 26 | * @author Jarvis Song 27 | */ 28 | @Data 29 | public class Pageable implements Serializable { 30 | 31 | private static final long serialVersionUID = -764308195468450433L; 32 | 33 | /** 34 | * Page Number. 35 | */ 36 | private int page; 37 | 38 | /** 39 | * Page Size. 40 | */ 41 | private int size; 42 | 43 | private long offset; 44 | 45 | private boolean unpaged = false; 46 | 47 | public Pageable(int page, int size) { 48 | 49 | this.page = page; 50 | this.size = size; 51 | this.offset = (long) page * size; 52 | } 53 | 54 | public Pageable(int page, int size, long offset) { 55 | this.page = page; 56 | this.size = size; 57 | this.offset = offset; 58 | } 59 | 60 | public static Pageable of(org.springframework.data.domain.Pageable pageable) { 61 | 62 | if (pageable.isUnpaged()) { 63 | Pageable p = new Pageable(-1, -1); 64 | p.setUnpaged(true); 65 | return p; 66 | } 67 | 68 | return new Pageable(pageable.getPageNumber(), pageable.getPageSize(), pageable.getOffset()); 69 | } 70 | 71 | public boolean isPaged() { 72 | return !this.unpaged; 73 | } 74 | 75 | public long getOffsetEnd() { 76 | return this.offset + this.size; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /main/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.data.repository.core.support.RepositoryFactorySupport=io.easybest.mybatis.repository.support.MybatisRepositoryFactory 2 | io.easybest.mybatis.repository.config.DialectResolver$MybatisDialectProvider=io.easybest.mybatis.repository.config.DialectResolver.DefaultDialectProvider 3 | -------------------------------------------------------------------------------- /main/src/main/resources/META-INF/spring.handlers: -------------------------------------------------------------------------------- 1 | http\://www.easybest.io/schema/mybatis=io.easybest.mybatis.repository.config.MybatisRepositoryNameSpaceHandler 2 | -------------------------------------------------------------------------------- /main/src/main/resources/META-INF/spring.schemas: -------------------------------------------------------------------------------- 1 | http\://www.easybest.io/schema/spring-data-mybatis-2.0.xsd=io/easybest/mybatis/repository/config/spring-data-mybatis-2.0.xsd 2 | http\://www.easybest.io/schema/spring-data-mybatis.xsd=io/easybest/mybatis/repository/config/spring-data-mybatis-2.0.xsd 3 | https\://www.easybest.io/schema/spring-data-mybatis-2.0.xsd=io/easybest/mybatis/repository/config/spring-data-mybatis-2.0.xsd 4 | https\://www.easybest.io/schema/spring-data-mybatis.xsd=io/easybest/mybatis/repository/config/spring-data-mybatis-2.0.xsd 5 | -------------------------------------------------------------------------------- /main/src/main/resources/META-INF/spring.tooling: -------------------------------------------------------------------------------- 1 | # Tooling related information for the MyBatis namespace 2 | http\://www.easybest.io/schema/mybatis@name=MyBatis Namespace 3 | http\://www.easybest.io/schema/mybatis@prefix=mybatis 4 | http\://www.easybest.io/schema/mybatis@icon=org/springframework/jdbc/config/spring-jdbc.gif 5 | -------------------------------------------------------------------------------- /main/src/main/resources/io/easybest/mybatis/repository/config/spring-data-mybatis-2.0.xsd: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /main/src/test/java/io/easybest/mybatis/domain/sample/Address.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.domain.sample; 18 | 19 | import javax.persistence.Embeddable; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Thomas Darimont 25 | */ 26 | @Embeddable 27 | public class Address { 28 | 29 | private String country; 30 | 31 | private String city; 32 | 33 | private String streetName; 34 | 35 | private String streetNo; 36 | 37 | public Address() { 38 | } 39 | 40 | public Address(String country, String city, String streetName, String streetNo) { 41 | this.country = country; 42 | this.city = city; 43 | this.streetName = streetName; 44 | this.streetNo = streetNo; 45 | } 46 | 47 | public String getCountry() { 48 | return this.country; 49 | } 50 | 51 | public String getCity() { 52 | return this.city; 53 | } 54 | 55 | public String getStreetName() { 56 | return this.streetName; 57 | } 58 | 59 | public String getStreetNo() { 60 | return this.streetNo; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /main/src/test/java/io/easybest/mybatis/domain/sample/Role.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.domain.sample; 18 | 19 | import java.util.Optional; 20 | 21 | import javax.persistence.Entity; 22 | import javax.persistence.GeneratedValue; 23 | import javax.persistence.Id; 24 | 25 | import io.easybest.mybatis.annotation.GetterOptional; 26 | 27 | /** 28 | * Sample domain class representing roles. Mapped with XML. 29 | * 30 | * @author Oliver Gierke 31 | * @author Thomas Darimont 32 | */ 33 | @Entity 34 | public class Role { 35 | 36 | private static final String PREFIX = "ROLE_"; 37 | 38 | @Id 39 | @GeneratedValue 40 | private Integer id; 41 | 42 | @GetterOptional 43 | private String name; 44 | 45 | public Role() { 46 | } 47 | 48 | public Role(final String name) { 49 | this.name = name; 50 | } 51 | 52 | public Integer getId() { 53 | 54 | return this.id; 55 | } 56 | 57 | public Optional getName() { 58 | return Optional.ofNullable(this.name); 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | 64 | return PREFIX + this.name; 65 | } 66 | 67 | public boolean isNew() { 68 | 69 | return this.id == null; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /main/src/test/java/io/easybest/mybatis/domain/sample/SpecialUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.domain.sample; 18 | 19 | import javax.persistence.Entity; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | */ 26 | @Entity 27 | public class SpecialUser extends User { 28 | 29 | } 30 | -------------------------------------------------------------------------------- /main/src/test/java/io/easybest/mybatis/repository/sample/NameOnlyDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.sample; 18 | 19 | /** 20 | * . 21 | * 22 | * @author Jarvis Song 23 | */ 24 | class NameOnlyDto { 25 | 26 | private String firstname; 27 | 28 | private String lastname; 29 | 30 | public NameOnlyDto(String firstname, String lastname) { 31 | this.firstname = firstname; 32 | this.lastname = lastname; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /main/src/test/java/io/easybest/mybatis/repository/sample/RoleRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.sample; 18 | 19 | import io.easybest.mybatis.domain.sample.Role; 20 | import io.easybest.mybatis.repository.MybatisRepository; 21 | 22 | /** 23 | * . 24 | * 25 | * @author Jarvis Song 26 | */ 27 | public interface RoleRepository extends MybatisRepository { 28 | 29 | } 30 | -------------------------------------------------------------------------------- /main/src/test/java/io/easybest/mybatis/repository/sample/UserRepositoryCustom.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.sample; 18 | 19 | import io.easybest.mybatis.domain.sample.User; 20 | 21 | /** 22 | * . 23 | * 24 | * @author Jarvis Song 25 | */ 26 | public interface UserRepositoryCustom { 27 | 28 | void findByOverrridingMethod(); 29 | 30 | void someCustomMethod(User user); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /main/src/test/java/io/easybest/mybatis/repository/sample/UserRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.repository.sample; 18 | 19 | import lombok.extern.slf4j.Slf4j; 20 | import org.mybatis.spring.SqlSessionTemplate; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | 23 | import io.easybest.mybatis.domain.sample.User; 24 | 25 | /** 26 | * . 27 | * 28 | * @author Jarvis Song 29 | */ 30 | @Slf4j 31 | public class UserRepositoryImpl implements UserRepositoryCustom { 32 | 33 | @Autowired 34 | public UserRepositoryImpl(SqlSessionTemplate sqlSessionTemplate) { 35 | } 36 | 37 | @Override 38 | public void findByOverrridingMethod() { 39 | log.debug("A method overriding a finder was invoked!"); 40 | } 41 | 42 | @Override 43 | public void someCustomMethod(User user) { 44 | log.debug("Some custom method was invoked!"); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /main/src/test/resources/META-INF/mybatis-named-queries.properties: -------------------------------------------------------------------------------- 1 | User.findByLastname=SELECT * FROM SD_User u WHERE u.lastname = ?1 2 | User.findBySpringDataNamedQuery=select u from #{#tableName} u where u.lastname=?1 3 | -------------------------------------------------------------------------------- /main/src/test/resources/application-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /main/src/test/resources/config/namespace-application-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /main/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d %5p [%t] %40.40c:%4L - %m%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /main/src/test/resources/mapper/user.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /main/src/test/resources/scripts/mysql-init.sql: -------------------------------------------------------------------------------- 1 | drop table if exists ROLE; 2 | drop table if exists SD_User; 3 | drop table if exists SD_User_ROLE; 4 | drop table if exists SD_User_SD_User; 5 | drop table if exists User_attributes; 6 | 7 | create table ROLE 8 | ( 9 | id integer not null auto_increment, 10 | name varchar(255), 11 | primary key (id) 12 | ); 13 | 14 | create table SD_User 15 | ( 16 | id integer not null auto_increment, 17 | active boolean not null, 18 | city varchar(255), 19 | country varchar(255), 20 | streetName varchar(255), 21 | streetNo varchar(255), 22 | age integer not null, 23 | binaryData blob(255), 24 | createdAt datetime, 25 | dateOfBirth date, 26 | emailAddress varchar(255) not null, 27 | firstname varchar(255) binary, 28 | lastname varchar(255) binary, 29 | manager_id integer, 30 | version bigint default 0 not null, 31 | deleted int default 0 not null, 32 | DTYPE varchar(31) null, 33 | primary key (id), 34 | unique key (emailAddress) 35 | ); 36 | create table SD_User_ROLE 37 | ( 38 | User_id integer not null, 39 | roles_id integer not null, 40 | primary key (User_id, roles_id) 41 | ); 42 | create table SD_User_SD_User 43 | ( 44 | User_id integer not null, 45 | colleagues_id integer not null, 46 | primary key (User_id, colleagues_id) 47 | ); 48 | 49 | create table User_attributes 50 | ( 51 | User_id integer not null, 52 | attributes varchar(255) 53 | ); 54 | 55 | -------------------------------------------------------------------------------- /main/src/test/resources/scripts/oracle-init.sql: -------------------------------------------------------------------------------- 1 | drop table ROLE; 2 | drop table SD_User; 3 | drop table SD_User_ROLE; 4 | drop table SD_User_SD_User; 5 | drop table User_attributes; 6 | 7 | drop sequence SEQ_MYBATIS; 8 | 9 | create sequence SEQ_MYBATIS start with 1 increment by 1; 10 | 11 | 12 | create table ROLE 13 | ( 14 | id number(11) not null, 15 | name varchar(255), 16 | primary key (id) 17 | ); 18 | 19 | create table SD_User 20 | ( 21 | id number(11) not null, 22 | active number(1) not null, 23 | city varchar(255), 24 | country varchar(255), 25 | streetName varchar(255), 26 | streetNo varchar(255), 27 | age integer not null, 28 | binaryData blob, 29 | createdAt timestamp, 30 | dateOfBirth date, 31 | emailAddress varchar(255) not null, 32 | firstname varchar(255), 33 | lastname varchar(255), 34 | manager_id integer, 35 | version number(19) default 0 not null, 36 | deleted int default 0 not null, 37 | DTYPE varchar(31) null, 38 | primary key (id) 39 | ); 40 | create table SD_User_ROLE 41 | ( 42 | User_id number(11) not null, 43 | roles_id number(11) not null, 44 | primary key (User_id, roles_id) 45 | ); 46 | create table SD_User_SD_User 47 | ( 48 | User_id number(11) not null, 49 | colleagues_id number(11) not null, 50 | primary key (User_id, colleagues_id) 51 | ); 52 | 53 | create table User_attributes 54 | ( 55 | User_id number(11) not null, 56 | attributes varchar(255) 57 | ); 58 | 59 | -------------------------------------------------------------------------------- /main/src/test/resources/scripts/postgre-init.sql: -------------------------------------------------------------------------------- 1 | drop table if exists ROLE; 2 | drop table if exists SD_User; 3 | drop table if exists SD_User_ROLE; 4 | drop table if exists SD_User_SD_User; 5 | drop table if exists User_attributes; 6 | 7 | create table ROLE 8 | ( 9 | id serial not null, 10 | name varchar(255), 11 | primary key (id) 12 | ); 13 | 14 | create table SD_User 15 | ( 16 | id serial not null, 17 | active boolean not null, 18 | city varchar(255), 19 | country varchar(255), 20 | streetName varchar(255), 21 | streetNo varchar(255), 22 | age integer not null, 23 | binaryData bytea, 24 | createdAt timestamp, 25 | dateOfBirth date, 26 | emailAddress varchar(255) not null, 27 | firstname varchar(255), 28 | lastname varchar(255), 29 | manager_id integer, 30 | version bigint default 0 not null, 31 | deleted int default 0 not null, 32 | DTYPE varchar(31) null, 33 | primary key (id) 34 | ); 35 | create table SD_User_ROLE 36 | ( 37 | User_id serial not null, 38 | roles_id serial not null, 39 | primary key (User_id, roles_id) 40 | ); 41 | create table SD_User_SD_User 42 | ( 43 | User_id serial not null, 44 | colleagues_id serial not null, 45 | primary key (User_id, colleagues_id) 46 | ); 47 | 48 | create table User_attributes 49 | ( 50 | User_id serial not null, 51 | attributes varchar(255) 52 | ); 53 | 54 | -------------------------------------------------------------------------------- /main/src/test/resources/scripts/sqlite-init.sql: -------------------------------------------------------------------------------- 1 | drop table if exists ROLE; 2 | drop table if exists SD_User; 3 | drop table if exists SD_User_ROLE; 4 | drop table if exists SD_User_SD_User; 5 | drop table if exists User_attributes; 6 | 7 | create table ROLE 8 | ( 9 | id integer not null primary key autoincrement, 10 | name varchar(255) 11 | ); 12 | 13 | create table SD_User 14 | ( 15 | id integer not null primary key autoincrement, 16 | active boolean not null, 17 | city varchar(255), 18 | country varchar(255), 19 | streetName varchar(255), 20 | streetNo varchar(255), 21 | age integer not null, 22 | binaryData blob, 23 | createdAt datetime, 24 | dateOfBirth date, 25 | emailAddress varchar(255) not null, 26 | firstname varchar(255), 27 | lastname varchar(255), 28 | manager_id integer, 29 | version bigint default 0 not null, 30 | deleted int default 0 not null, 31 | DTYPE varchar(31) null 32 | 33 | ); 34 | create table SD_User_ROLE 35 | ( 36 | User_id integer not null, 37 | roles_id integer not null, 38 | primary key (User_id, roles_id) 39 | ); 40 | create table SD_User_SD_User 41 | ( 42 | User_id integer not null, 43 | colleagues_id integer not null, 44 | primary key (User_id, colleagues_id) 45 | ); 46 | 47 | create table User_attributes 48 | ( 49 | User_id integer not null, 50 | attributes varchar(255) 51 | ); 52 | 53 | -------------------------------------------------------------------------------- /main/src/test/resources/scripts/sqlserver-init.sql: -------------------------------------------------------------------------------- 1 | drop table if exists ROLE; 2 | drop table if exists SD_User; 3 | drop table if exists SD_User_ROLE; 4 | drop table if exists SD_User_SD_User; 5 | drop table if exists User_attributes; 6 | 7 | create table ROLE 8 | ( 9 | id integer not null primary key identity, 10 | name varchar(255), 11 | primary key (id) 12 | ); 13 | 14 | create table SD_User 15 | ( 16 | id integer not null primary key identity, 17 | active bit not null, 18 | city varchar(255), 19 | country varchar(255), 20 | streetName varchar(255), 21 | streetNo varchar(255), 22 | age integer not null, 23 | binaryData binary, 24 | createdAt datetime, 25 | dateOfBirth date, 26 | emailAddress varchar(255) not null, 27 | firstname varchar(255), 28 | lastname varchar(255), 29 | manager_id integer, 30 | version bigint default 0 not null, 31 | deleted int default 0 not null, 32 | DTYPE varchar(31) null 33 | 34 | ); 35 | create table SD_User_ROLE 36 | ( 37 | User_id integer not null, 38 | roles_id integer not null, 39 | primary key (User_id, roles_id) 40 | ); 41 | create table SD_User_SD_User 42 | ( 43 | User_id integer not null, 44 | colleagues_id integer not null, 45 | primary key (User_id, colleagues_id) 46 | ); 47 | 48 | create table User_attributes 49 | ( 50 | User_id integer not null, 51 | attributes varchar(255) 52 | ); 53 | 54 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | mavenCentral() 4 | gradlePluginPortal() 5 | maven { 6 | url 'https://repo.spring.io/release' 7 | } 8 | } 9 | 10 | resolutionStrategy { 11 | eachPlugin { 12 | if (requested.id.id == "org.jetbrains.kotlin.jvm") { 13 | useVersion "${kotlinVersion}" 14 | } 15 | if (requested.id.id == "org.jetbrains.kotlin.plugin.spring") { 16 | useVersion "${kotlinVersion}" 17 | } 18 | } 19 | } 20 | } 21 | 22 | rootProject.name = 'spring-data-mybatis-build' 23 | 24 | include "core" 25 | include "main" 26 | include "starter" 27 | //include "processor" 28 | //include "querydsl" 29 | -------------------------------------------------------------------------------- /src/checkstyle/checkstyle-suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/checkstyle/header.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ -------------------------------------------------------------------------------- /src/checkstyle/import-control.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/nohttp/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/nohttp/suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/nohttp/whitelist.lines: -------------------------------------------------------------------------------- 1 | ^http://exslt.org/common.* 2 | ^http://ganglia.sourceforge.net.* 3 | ^http://hsqldb.org.* 4 | ^http://livereload.com/.* 5 | ^http://logback.qos.ch/manual/loggingSeparation.html 6 | ^http://schemas.xmlsoap.org/.* 7 | ^http://www.jdotsoft.com.* 8 | ^http://www.liquibase.org/xml/ns/dbchangelog/.* 9 | ^http://www.w3.org/2000/09/xmldsig.* 10 | ^http://www.easybest.io/schema/.* 11 | -------------------------------------------------------------------------------- /starter/build.gradle: -------------------------------------------------------------------------------- 1 | description "${projectName} starter" 2 | 3 | dependencies { 4 | 5 | api(project(":main")) 6 | 7 | api("org.springframework.boot:spring-boot-autoconfigure:${springBootVersion}") 8 | api("org.springframework.boot:spring-boot-starter-jdbc:${springBootVersion}") 9 | api('org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.2') 10 | 11 | annotationProcessor("org.springframework.boot:spring-boot-configuration-processor:${springBootVersion}") 12 | 13 | compileOnly("org.projectlombok:lombok:${lombokVersion}") 14 | annotationProcessor("org.projectlombok:lombok:${lombokVersion}") 15 | 16 | } 17 | 18 | repositories { 19 | mavenCentral() 20 | } 21 | -------------------------------------------------------------------------------- /starter/src/main/java/io/easybest/mybatis/autoconfigure/SpringDataMybatisProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.easybest.mybatis.autoconfigure; 18 | 19 | import lombok.Data; 20 | import org.springframework.boot.context.properties.ConfigurationProperties; 21 | 22 | /** 23 | * . 24 | * 25 | * @author Jarvis Song 26 | */ 27 | @ConfigurationProperties(SpringDataMybatisProperties.PREFIX) 28 | @Data 29 | public class SpringDataMybatisProperties { 30 | 31 | /** 32 | * Properties prefix. 33 | */ 34 | public static final String PREFIX = "spring.data.mybatis.repositories"; 35 | 36 | private boolean enabled; 37 | 38 | private String[] entityPackages; 39 | 40 | private NamingStrategyType namingStrategyType; 41 | 42 | private String uniformTablePrefix; 43 | 44 | public enum NamingStrategyType { 45 | 46 | /** 47 | * UNDERSCORE. 48 | */ 49 | UNDERSCORE, 50 | /** 51 | * AS_IS. 52 | */ 53 | AS_IS 54 | 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | # Auto Configure 2 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 3 | io.easybest.mybatis.autoconfigure.MybatisEntityManagerAutoConfiguration,\ 4 | io.easybest.mybatis.autoconfigure.MybatisRepositoriesAutoConfiguration 5 | --------------------------------------------------------------------------------