├── .mvn ├── jvm.config ├── maven.config ├── wrapper │ └── maven-wrapper.properties ├── extensions.xml └── settings.xml ├── .gitattributes ├── renovate.json ├── .gitignore ├── LICENSE_HEADER ├── src ├── test │ ├── resources │ │ ├── org │ │ │ └── mybatis │ │ │ │ └── guice │ │ │ │ ├── datasource │ │ │ │ └── builtin │ │ │ │ │ └── JndiDataSourceProviderTest.properties │ │ │ │ ├── jta │ │ │ │ ├── shutdowndb.sql │ │ │ │ └── setupdb.sql │ │ │ │ ├── sample │ │ │ │ ├── db │ │ │ │ │ ├── database-schema.sql │ │ │ │ │ └── database-test-data.sql │ │ │ │ ├── mybatis-config.xml │ │ │ │ └── mapper │ │ │ │ │ └── UserMapper.xml │ │ │ │ ├── objectfactory │ │ │ │ ├── objectfactory.xml │ │ │ │ └── objectwrapperfactory.xml │ │ │ │ ├── nestedtx │ │ │ │ └── setupdb.sql │ │ │ │ └── configuration │ │ │ │ └── ErrorMapper.xml │ │ └── mybatis-package-config.xml │ └── java │ │ └── org │ │ └── mybatis │ │ └── guice │ │ ├── resolver │ │ ├── alias │ │ │ ├── User.java │ │ │ └── Address.java │ │ ├── mapper │ │ │ ├── FirstMapper.java │ │ │ └── SecondMapper.java │ │ ├── interceptor │ │ │ ├── FirstInterceptor.java │ │ │ └── SecondInterceptor.java │ │ └── typehandler │ │ │ └── AddressTypeHandler.java │ │ ├── generictypehandler │ │ ├── InjectedObject.java │ │ ├── SubCustomObject.java │ │ └── CustomObject.java │ │ ├── configuration │ │ ├── ErrorMapper.java │ │ └── settings │ │ │ ├── CacheEnabledConfigurationSettingTest.java │ │ │ ├── UseColumnLabelConfigurationSettingTest.java │ │ │ ├── UseGeneratedKeysConfigurationSettingTest.java │ │ │ ├── CallSettersOnNullsConfigurationSettingTest.java │ │ │ ├── LazyLoadingEnabledConfigurationSettingTest.java │ │ │ ├── AggressiveLazyLoadingConfigurationSettingTest.java │ │ │ ├── DefaultStatementTimeoutConfigurationSettingTest.java │ │ │ ├── MapUnderscoreToCamelCaseConfigurationSettingTest.java │ │ │ ├── MultipleResultSetsEnabledConfigurationSettingTest.java │ │ │ ├── LocalCacheScopeConfigurationSettingTest.java │ │ │ └── DefaultScriptingLanguageTypeConfigurationSettingTest.java │ │ ├── scripting │ │ └── CustomLanguageDriver.java │ │ ├── jta │ │ ├── JtaService.java │ │ ├── JtaRollbackException.java │ │ ├── TableRow.java │ │ ├── JtaMapper.java │ │ ├── CustomXaResourceProvider.java │ │ ├── simple │ │ │ ├── Name.java │ │ │ ├── Schema2Service.java │ │ │ ├── Schema1Mapper.java │ │ │ ├── Schema2Mapper.java │ │ │ └── Schema1Service.java │ │ ├── JtaService1Impl.java │ │ └── JtaService2Impl.java │ │ ├── objectfactory │ │ ├── CustomObject.java │ │ ├── CustomObjectWrapperFactory.java │ │ └── CustomObjectFactory.java │ │ ├── Counter.java │ │ ├── sample │ │ ├── dao │ │ │ ├── UserDao.java │ │ │ └── UserDaoImpl.java │ │ ├── mapper │ │ │ └── UserMapper.java │ │ ├── service │ │ │ ├── FooService.java │ │ │ ├── FooServiceDaoImpl.java │ │ │ └── FooServiceMapperImpl.java │ │ └── domain │ │ │ └── User.java │ │ ├── customconfiguration │ │ ├── MyConfiguration.java │ │ └── MyConfigurationProvider.java │ │ ├── CustomException.java │ │ ├── nestedtx │ │ ├── TableRow.java │ │ └── NestedTxMapper.java │ │ ├── customsqlsessionfactory │ │ ├── MySqlSessionFactory.java │ │ └── MySqlSessionFactoryProvider.java │ │ ├── ContactMapper.java │ │ ├── multidstest │ │ ├── MockInitialContextFactory.java │ │ ├── Schema1Service.java │ │ ├── Schema2Service.java │ │ ├── Schema1Mapper.java │ │ ├── Schema2Mapper.java │ │ └── MockContext.java │ │ ├── XMLAlternateEnvironmentMyBatisModuleTestCaseTest.java │ │ ├── XMLGuiceTestExtension.java │ │ ├── XMLGuicePackageTestExtension.java │ │ ├── XMLAlternateEnvironmentGuiceTestExtension.java │ │ ├── AddressConverter.java │ │ ├── CountUpdateInterceptor.java │ │ ├── session │ │ ├── SqlSessionFactoryProviderTest.java │ │ └── SqlSessionManagerProviderTest.java │ │ ├── Address.java │ │ ├── mappers │ │ └── MapperProviderTest.java │ │ ├── CustomType.java │ │ └── environment │ │ └── EnvironmentProviderTest.java ├── main │ └── java │ │ └── org │ │ └── mybatis │ │ └── guice │ │ ├── binder │ │ ├── package-info.java │ │ ├── AliasBinder.java │ │ └── TypeHandlerBinder.java │ │ ├── provision │ │ ├── package-info.java │ │ └── KeyMatcher.java │ │ ├── datasource │ │ ├── c3p0 │ │ │ └── package-info.java │ │ ├── druid │ │ │ └── package-info.java │ │ ├── dbcp │ │ │ ├── package-info.java │ │ │ ├── PerUserMaxIdle.java │ │ │ ├── PerUserMaxTotal.java │ │ │ ├── PerUserMaxWaitMillis.java │ │ │ ├── PerUserDefaultReadOnly.java │ │ │ ├── PerUserDefaultAutoCommit.java │ │ │ └── PerUserDefaultTransactionIsolation.java │ │ ├── builtin │ │ │ └── package-info.java │ │ ├── hikaricp │ │ │ └── package-info.java │ │ └── helper │ │ │ ├── package-info.java │ │ │ └── KeyResolver.java │ │ ├── package-info.java │ │ ├── transactional │ │ ├── package-info.java │ │ ├── TransactionAttributeStrategy.java │ │ ├── NeverTransactionAttributeStrategy.java │ │ ├── MandatoryTransactionAttributeStrategy.java │ │ ├── RequiredTransactionAttributeStrategy.java │ │ ├── SupportsTransactionAttributeStrategy.java │ │ ├── RequiresNewTransactionAttributeStrategy.java │ │ ├── XASqlSessionManagerProvider.java │ │ ├── MyBatisXAException.java │ │ └── Isolation.java │ │ ├── environment │ │ ├── package-info.java │ │ └── EnvironmentProvider.java │ │ ├── configuration │ │ ├── package-info.java │ │ ├── settings │ │ │ ├── ConfigurationSetting.java │ │ │ ├── ConfigurationSettings.java │ │ │ ├── MapperConfigurationSetting.java │ │ │ ├── CacheEnabledConfigurationSetting.java │ │ │ ├── UseColumnLabelConfigurationSetting.java │ │ │ ├── UseGeneratedKeysConfigurationSetting.java │ │ │ ├── CallSettersOnNullsConfigurationSetting.java │ │ │ ├── LazyLoadingEnabledConfigurationSetting.java │ │ │ ├── AliasConfigurationSetting.java │ │ │ ├── AggressiveLazyLoadingConfigurationSetting.java │ │ │ ├── DefaultExecutorTypeConfigurationSetting.java │ │ │ ├── DefaultStatementTimeoutConfigurationSetting.java │ │ │ ├── LocalCacheScopeConfigurationSetting.java │ │ │ ├── MapUnderscoreToCamelCaseConfigurationSetting.java │ │ │ ├── AutoMappingBehaviorConfigurationSetting.java │ │ │ ├── MultipleResultSetsEnabledConfigurationSetting.java │ │ │ ├── DefaultScriptingLanguageTypeConfigurationSetting.java │ │ │ ├── TypeHandlerConfigurationSettingProvider.java │ │ │ ├── ObjectFactoryConfigurationSetting.java │ │ │ ├── InterceptorConfigurationSettingProvider.java │ │ │ └── ObjectWrapperFactoryConfigurationSetting.java │ │ └── ConfigurationSettingListener.java │ │ ├── session │ │ ├── package-info.java │ │ └── SqlSessionManagerProvider.java │ │ └── mappers │ │ ├── package-info.java │ │ └── MapperProvider.java └── site │ └── site.xml ├── format.xml ├── .github └── workflows │ ├── sonatype.yaml │ ├── ci.yaml │ ├── site.yaml │ ├── codeql.yaml │ ├── sonar.yaml │ └── coveralls.yaml ├── README.md └── NOTICE /.mvn/jvm.config: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set default behaviour, in case users don't have core.autocrlf set. 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.mvn/maven.config: -------------------------------------------------------------------------------- 1 | -Daether.checksums.algorithms=SHA-512,SHA-256,SHA-1,MD5 2 | -Daether.connector.smartChecksums=false 3 | --no-transfer-progress 4 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:recommended" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /*.iml 2 | /*.ipr 3 | /*.iws 4 | /.idea 5 | /.classpath 6 | /.project 7 | /.settings 8 | /mybatis-guice_TEST.log 9 | /mybatis-guice_TEST.properties 10 | /mybatis-guice_TEST.script 11 | /nb* 12 | /target 13 | /derby.log 14 | .mvn/wrapper/maven-wrapper.jar 15 | release.properties 16 | pom.xml.releaseBackup 17 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionType=source 2 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.12/apache-maven-3.9.12-bin.zip 3 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.4/maven-wrapper-3.3.4.jar 4 | wrapperVersion=3.3.4 5 | -------------------------------------------------------------------------------- /LICENSE_HEADER: -------------------------------------------------------------------------------- 1 | Copyright ${license.git.copyrightYears} the original author or authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | https://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/guice/datasource/builtin/JndiDataSourceProviderTest.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2009-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 | property_true=true 18 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/binder/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | * The MyBatis module EDSL. 18 | */ 19 | package org.mybatis.guice.binder; 20 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/resolver/alias/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.resolver.alias; 17 | 18 | public class User { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /format.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/resolver/alias/Address.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.resolver.alias; 17 | 18 | public class Address { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/provision/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2025 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 | * Contains the guice provisions. 18 | */ 19 | package org.mybatis.guice.provision; 20 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/resolver/mapper/FirstMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.resolver.mapper; 17 | 18 | public interface FirstMapper { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/generictypehandler/InjectedObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.generictypehandler; 17 | 18 | public class InjectedObject { 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/resolver/mapper/SecondMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.resolver.mapper; 17 | 18 | public interface SecondMapper { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/guice/jta/shutdowndb.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright 2009-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 | -- drop table table1; 18 | -- drop table table2; 19 | 20 | delete from table1; 21 | delete from table2; 22 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/datasource/c3p0/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | * Contains c3p0 Data Source provider. 18 | */ 19 | package org.mybatis.guice.datasource.c3p0; 20 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/datasource/druid/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | * Contains c3p0 Data Source provider. 18 | */ 19 | package org.mybatis.guice.datasource.druid; 20 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | * Contains core classes to build the MyBatis stuff through Google Guice. 18 | */ 19 | package org.mybatis.guice; 20 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/datasource/dbcp/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2025 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 | * Contains Apache commons-dbcp2 Data Source providers. 18 | */ 19 | package org.mybatis.guice.datasource.dbcp; 20 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/configuration/ErrorMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration; 17 | 18 | public interface ErrorMapper { 19 | public int selectCount(); 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/generictypehandler/SubCustomObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.generictypehandler; 17 | 18 | public class SubCustomObject extends CustomObject { 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/transactional/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | * Contains classes to mark and handle transactional methods. 18 | */ 19 | package org.mybatis.guice.transactional; 20 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/environment/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | * Contains core classes to build the myBatis Environment through google-guice. 18 | */ 19 | package org.mybatis.guice.environment; 20 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | * Contains core classes to build the iBatis Configuration through google-guice. 18 | */ 19 | package org.mybatis.guice.configuration; 20 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/session/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | * Defines Google Guice's providers for {@code SqlSessionFactory} and {@code SqlSessionManager}. 18 | */ 19 | package org.mybatis.guice.session; 20 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/mappers/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | * Contains the Provider and utility class to auto-bind requested mappers in the Google Guice binder. 18 | */ 19 | package org.mybatis.guice.mappers; 20 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/datasource/builtin/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | * Contains core classes to build the myBatis DataSource implementations through google-guice. 18 | */ 19 | package org.mybatis.guice.datasource.builtin; 20 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/datasource/hikaricp/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | * Contains core classes to build the HikariCP DataSource implementations through google-guice. 18 | */ 19 | package org.mybatis.guice.datasource.hikaricp; 20 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/transactional/TransactionAttributeStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.transactional; 17 | 18 | public interface TransactionAttributeStrategy { 19 | TransactionAttribute getTransactionAttribute(); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/datasource/helper/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | * Contains helper classes to build and bind JDBC.driver and JDBC.url properties. 18 | */ 19 | package org.mybatis.guice.datasource.helper; 20 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/guice/sample/db/database-schema.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright 2009-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 | drop table if exists users; 18 | create table users ( 19 | id varchar(80) not null, 20 | name varchar(80) not null, 21 | constraint pk_user primary key (id) 22 | ); 23 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/scripting/CustomLanguageDriver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.scripting; 17 | 18 | import org.apache.ibatis.scripting.defaults.RawLanguageDriver; 19 | 20 | public class CustomLanguageDriver extends RawLanguageDriver { 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/jta/JtaService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.jta; 17 | 18 | import java.util.List; 19 | 20 | public interface JtaService { 21 | int insertTable(TableRow row); 22 | 23 | List selectAllTable(); 24 | 25 | String getName(); 26 | } 27 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/guice/sample/db/database-test-data.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright 2009-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 | insert into users VALUES ( 'u1', 'Pocoyo' ); 18 | insert into users VALUES ( 'u2', 'Pato' ); 19 | insert into users VALUES ( 'u3', 'Eli' ); 20 | insert into users VALUES ( 'u4', 'Valentina' ); 21 | -------------------------------------------------------------------------------- /.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | fr.jcgay.maven 22 | maven-profiler 23 | 3.3 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/objectfactory/CustomObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.objectfactory; 17 | 18 | import java.io.Serializable; 19 | 20 | public class CustomObject implements Serializable { 21 | private static final long serialVersionUID = 7391016546082689721L; 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/jta/JtaRollbackException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.jta; 17 | 18 | public class JtaRollbackException extends Exception { 19 | private static final long serialVersionUID = -4005752017823397888L; 20 | 21 | public JtaRollbackException() { 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/ConfigurationSetting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import org.apache.ibatis.session.Configuration; 19 | 20 | public interface ConfigurationSetting { 21 | public void applyConfigurationSetting(Configuration configuration); 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/generictypehandler/CustomObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.generictypehandler; 17 | 18 | public class CustomObject { 19 | private String name; 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/Counter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice; 17 | 18 | public class Counter { 19 | 20 | private int count; 21 | 22 | public void increment() { 23 | count++; 24 | } 25 | 26 | public void reset() { 27 | count = 0; 28 | } 29 | 30 | public int getCount() { 31 | return count; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/sample/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.sample.dao; 17 | 18 | import org.mybatis.guice.sample.domain.User; 19 | 20 | /** 21 | * A org.mybatis.guice sample mapper. 22 | */ 23 | public interface UserDao { 24 | 25 | User getUser(String userId); 26 | 27 | public void brokenInsert(User user); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/sample/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.sample.mapper; 17 | 18 | import org.mybatis.guice.sample.domain.User; 19 | 20 | /** 21 | * A org.mybatis.guice sample mapper. 22 | */ 23 | public interface UserMapper { 24 | 25 | User getUser(String userId); 26 | 27 | void brokenAdd(User user); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/transactional/NeverTransactionAttributeStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.transactional; 17 | 18 | public class NeverTransactionAttributeStrategy implements TransactionAttributeStrategy { 19 | @Override 20 | public TransactionAttribute getTransactionAttribute() { 21 | return TransactionAttribute.NEVER; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/transactional/MandatoryTransactionAttributeStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.transactional; 17 | 18 | public class MandatoryTransactionAttributeStrategy implements TransactionAttributeStrategy { 19 | @Override 20 | public TransactionAttribute getTransactionAttribute() { 21 | return TransactionAttribute.MANDATORY; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/transactional/RequiredTransactionAttributeStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.transactional; 17 | 18 | public class RequiredTransactionAttributeStrategy implements TransactionAttributeStrategy { 19 | @Override 20 | public TransactionAttribute getTransactionAttribute() { 21 | return TransactionAttribute.REQUIRED; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/transactional/SupportsTransactionAttributeStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.transactional; 17 | 18 | public class SupportsTransactionAttributeStrategy implements TransactionAttributeStrategy { 19 | @Override 20 | public TransactionAttribute getTransactionAttribute() { 21 | return TransactionAttribute.SUPPORTS; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/transactional/RequiresNewTransactionAttributeStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.transactional; 17 | 18 | public class RequiresNewTransactionAttributeStrategy implements TransactionAttributeStrategy { 19 | @Override 20 | public TransactionAttribute getTransactionAttribute() { 21 | return TransactionAttribute.REQUIRESNEW; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/guice/objectfactory/objectfactory.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/customconfiguration/MyConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.customconfiguration; 17 | 18 | import org.apache.ibatis.mapping.Environment; 19 | import org.apache.ibatis.session.Configuration; 20 | 21 | public class MyConfiguration extends Configuration { 22 | 23 | public MyConfiguration(Environment environment) { 24 | super(environment); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/CustomException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice; 17 | 18 | public final class CustomException extends Exception { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | public CustomException(Throwable cause) { 23 | super(cause); 24 | } 25 | 26 | public CustomException(String message, Throwable cause) { 27 | super(message, cause); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /.github/workflows/sonatype.yaml: -------------------------------------------------------------------------------- 1 | name: Sonatype 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | permissions: read-all 9 | 10 | concurrency: 11 | group: ${{ github.workflow }}-${{ github.ref }} 12 | cancel-in-progress: true 13 | 14 | jobs: 15 | build: 16 | if: github.repository_owner == 'mybatis' && ! contains(toJSON(github.event.head_commit.message), '[maven-release-plugin]') 17 | runs-on: ubuntu-latest 18 | timeout-minutes: 30 19 | steps: 20 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 21 | - name: Setup Java 22 | uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5 23 | with: 24 | cache: maven 25 | distribution: temurin 26 | java-version: 25 27 | - name: Deploy to Sonatype 28 | run: ./mvnw deploy --batch-mode --no-transfer-progress --settings ./.mvn/settings.xml --show-version -Dlicense.skip=true -DskipTests 29 | env: 30 | CI_DEPLOY_USERNAME: ${{ secrets.CI_DEPLOY_USERNAME }} 31 | CI_DEPLOY_PASSWORD: ${{ secrets.CI_DEPLOY_PASSWORD }} 32 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/guice/jta/setupdb.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright 2009-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 | --drop table if exists table1; 18 | --drop table if exists table2; 19 | 20 | create table table1 ( 21 | id integer not null, 22 | name varchar(80) not null, 23 | constraint pk_table1 primary key (id) 24 | ); 25 | 26 | create table table2 ( 27 | id integer not null, 28 | name varchar(80) not null, 29 | constraint pk_table2 primary key (id) 30 | ); 31 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/guice/nestedtx/setupdb.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright 2009-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 | drop table if exists table1; 18 | drop table if exists table2; 19 | 20 | create table table1 ( 21 | id integer not null, 22 | name varchar(80) not null, 23 | constraint pk_table1 primary key (id) 24 | ); 25 | 26 | create table table2 ( 27 | id integer not null, 28 | name varchar(80) not null, 29 | constraint pk_table2 primary key (id) 30 | ); 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | MyBatis Guice Module 2 | ==================== 3 | 4 | [![Java CI](https://github.com/mybatis/guice/actions/workflows/ci.yaml/badge.svg)](https://github.com/mybatis/guice/actions/workflows/ci.yaml) 5 | [![Coverage Status](https://coveralls.io/repos/mybatis/guice/badge.svg?branch=master&service=github)](https://coveralls.io/github/mybatis/guice?branch=master) 6 | [![Maven central](https://maven-badges.herokuapp.com/maven-central/org.mybatis/mybatis-guice/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.mybatis/mybatis-guice) 7 | [![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/https/oss.sonatype.org/org.mybatis/mybatis-guice.svg)](https://oss.sonatype.org/content/repositories/snapshots/org/mybatis/mybatis-guice/) 8 | [![License](https://img.shields.io/:license-apache-brightgreen.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) 9 | 10 | ![mybatis-guice](https://mybatis.org/images/mybatis-logo.png) 11 | 12 | The MyBatis Guice module is easy-to-use Google Guice bridge for MyBatis sql mapping framework. 13 | 14 | Essentials 15 | ---------- 16 | 17 | * [See the docs](https://mybatis.org/guice/) 18 | 19 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/binder/AliasBinder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.binder; 17 | 18 | /** 19 | * Allows bind a {@code Class} to an already defined type alias. 20 | */ 21 | public interface AliasBinder { 22 | 23 | /** 24 | * Binds a {@code Class} to an already defined type alias. 25 | * 26 | * @param type 27 | * The {@code Class} has to be bound to the alias 28 | */ 29 | void to(Class type); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/jta/TableRow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.jta; 17 | 18 | public class TableRow { 19 | private int id; 20 | private String name; 21 | 22 | public int getId() { 23 | return id; 24 | } 25 | 26 | public void setId(int id) { 27 | this.id = id; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/jta/JtaMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.jta; 17 | 18 | import java.util.List; 19 | 20 | import org.apache.ibatis.annotations.Insert; 21 | import org.apache.ibatis.annotations.Select; 22 | 23 | public interface JtaMapper { 24 | 25 | @Insert({ "insert into table1 (id, name) values (#{id}, #{name})" }) 26 | int insertTable(TableRow row); 27 | 28 | @Select({ "select * from table1" }) 29 | List selectAllTable(); 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/nestedtx/TableRow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.nestedtx; 17 | 18 | public class TableRow { 19 | private int id; 20 | private String name; 21 | 22 | public int getId() { 23 | return id; 24 | } 25 | 26 | public void setId(int id) { 27 | this.id = id; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: [workflow_dispatch, push, pull_request] 4 | 5 | permissions: read-all 6 | 7 | concurrency: 8 | group: ${{ github.workflow }}-${{ github.ref }} 9 | cancel-in-progress: true 10 | 11 | jobs: 12 | test: 13 | runs-on: ${{ matrix.os }} 14 | timeout-minutes: 30 15 | strategy: 16 | matrix: 17 | cache: [maven] 18 | distribution: [temurin] 19 | java: [21, 25, 26-ea] 20 | os: [macos-latest, ubuntu-latest, windows-latest] 21 | fail-fast: false 22 | max-parallel: 6 23 | name: Test JDK ${{ matrix.java }}, ${{ matrix.os }} 24 | 25 | steps: 26 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 27 | - name: Setup Java ${{ matrix.java }} ${{ matrix.distribution }} 28 | uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5 29 | with: 30 | cache: ${{ matrix.cache }} 31 | distribution: ${{ matrix.distribution }} 32 | java-version: ${{ matrix.java }} 33 | - name: Test with Maven 34 | run: ./mvnw test --batch-mode --no-transfer-progress --show-version -D"license.skip=true" 35 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/objectfactory/CustomObjectWrapperFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.objectfactory; 17 | 18 | import jakarta.inject.Inject; 19 | 20 | import org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory; 21 | 22 | public class CustomObjectWrapperFactory extends DefaultObjectWrapperFactory { 23 | @Inject 24 | private CustomObject customObject; 25 | 26 | public CustomObject getCustomObject() { 27 | return customObject; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/sample/service/FooService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.sample.service; 17 | 18 | import org.mybatis.guice.sample.domain.User; 19 | 20 | /** 21 | * FooService acts as a business service. 22 | *

23 | * All calls to any method of FooService are transactional. 24 | */ 25 | public interface FooService { 26 | 27 | User doSomeBusinessStuff(String userId); 28 | 29 | void brokenInsert(User user); 30 | 31 | void brokenInsert2(User user); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/guice/objectfactory/objectwrapperfactory.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/customsqlsessionfactory/MySqlSessionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.customsqlsessionfactory; 17 | 18 | import jakarta.inject.Inject; 19 | 20 | import org.apache.ibatis.session.Configuration; 21 | import org.apache.ibatis.session.defaults.DefaultSqlSessionFactory; 22 | 23 | public class MySqlSessionFactory extends DefaultSqlSessionFactory { 24 | @Inject 25 | public MySqlSessionFactory(Configuration configuration) { 26 | super(configuration); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/ContactMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice; 17 | 18 | import java.util.List; 19 | 20 | public interface ContactMapper { 21 | 22 | void brokenAdd(Contact contact); 23 | 24 | void add(Contact contact); 25 | 26 | void update(Contact contact); 27 | 28 | void delete(Integer id); 29 | 30 | Contact getById(Integer id); 31 | 32 | Contact getByIdWithTypeHandler(Integer id); 33 | 34 | List selectAll(); 35 | 36 | List selectAllWithDatabaseId(); 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/objectfactory/CustomObjectFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.objectfactory; 17 | 18 | import jakarta.inject.Inject; 19 | 20 | import org.apache.ibatis.reflection.factory.DefaultObjectFactory; 21 | 22 | public class CustomObjectFactory extends DefaultObjectFactory { 23 | private static final long serialVersionUID = 7195913612693620013L; 24 | @Inject 25 | private CustomObject customObject; 26 | 27 | public CustomObject getCustomObject() { 28 | return customObject; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/multidstest/MockInitialContextFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.multidstest; 17 | 18 | import java.util.Hashtable; 19 | 20 | import javax.naming.Context; 21 | import javax.naming.NamingException; 22 | import javax.naming.spi.InitialContextFactory; 23 | 24 | public class MockInitialContextFactory implements InitialContextFactory { 25 | 26 | @Override 27 | public Context getInitialContext(Hashtable environment) throws NamingException { 28 | return new MockContext(false); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/guice/configuration/ErrorMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 29 | 30 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/datasource/dbcp/PerUserMaxIdle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.datasource.dbcp; 17 | 18 | import com.google.inject.BindingAnnotation; 19 | 20 | import java.lang.annotation.Documented; 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | @BindingAnnotation 27 | @Documented 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target(ElementType.PARAMETER) 30 | public @interface PerUserMaxIdle { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/datasource/dbcp/PerUserMaxTotal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.datasource.dbcp; 17 | 18 | import com.google.inject.BindingAnnotation; 19 | 20 | import java.lang.annotation.Documented; 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | @BindingAnnotation 27 | @Documented 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target(ElementType.PARAMETER) 30 | public @interface PerUserMaxTotal { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/datasource/dbcp/PerUserMaxWaitMillis.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.datasource.dbcp; 17 | 18 | import com.google.inject.BindingAnnotation; 19 | 20 | import java.lang.annotation.Documented; 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | @BindingAnnotation 27 | @Documented 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target(ElementType.PARAMETER) 30 | public @interface PerUserMaxWaitMillis { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/datasource/dbcp/PerUserDefaultReadOnly.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.datasource.dbcp; 17 | 18 | import com.google.inject.BindingAnnotation; 19 | 20 | import java.lang.annotation.Documented; 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | @BindingAnnotation 27 | @Documented 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target(ElementType.PARAMETER) 30 | public @interface PerUserDefaultReadOnly { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/datasource/dbcp/PerUserDefaultAutoCommit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.datasource.dbcp; 17 | 18 | import com.google.inject.BindingAnnotation; 19 | 20 | import java.lang.annotation.Documented; 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | @BindingAnnotation 27 | @Documented 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target(ElementType.PARAMETER) 30 | public @interface PerUserDefaultAutoCommit { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/transactional/XASqlSessionManagerProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.transactional; 17 | 18 | import jakarta.inject.Inject; 19 | import jakarta.inject.Provider; 20 | 21 | import javax.transaction.xa.XAResource; 22 | 23 | import org.apache.ibatis.session.SqlSessionManager; 24 | 25 | public class XASqlSessionManagerProvider implements Provider { 26 | @Inject 27 | private SqlSessionManager sqlSessionManager; 28 | 29 | @Override 30 | public XAResource get() { 31 | return new XASqlSessionManager(sqlSessionManager); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/jta/CustomXaResourceProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.jta; 17 | 18 | import javax.transaction.xa.XAResource; 19 | 20 | import org.mybatis.guice.transactional.XASqlSessionManagerProvider; 21 | 22 | public class CustomXaResourceProvider extends XASqlSessionManagerProvider { 23 | private static boolean providerCalled = false; 24 | 25 | @Override 26 | public XAResource get() { 27 | providerCalled = true; 28 | return super.get(); 29 | } 30 | 31 | public static boolean isProviderCalled() { 32 | return providerCalled; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/ConfigurationSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import com.google.inject.BindingAnnotation; 19 | 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 | * Marker for ConfigurationSetting interfaces. 27 | */ 28 | @BindingAnnotation 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(ElementType.FIELD) 31 | public @interface ConfigurationSettings { 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/datasource/dbcp/PerUserDefaultTransactionIsolation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.datasource.dbcp; 17 | 18 | import com.google.inject.BindingAnnotation; 19 | 20 | import java.lang.annotation.Documented; 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | @BindingAnnotation 27 | @Documented 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target(ElementType.PARAMETER) 30 | public @interface PerUserDefaultTransactionIsolation { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/ConfigurationSettingListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration; 17 | 18 | import org.mybatis.guice.configuration.settings.ConfigurationSetting; 19 | import org.mybatis.guice.configuration.settings.MapperConfigurationSetting; 20 | 21 | /** 22 | * Allows configuration settings to be applied to configuration. 23 | */ 24 | public interface ConfigurationSettingListener { 25 | void addConfigurationSetting(ConfigurationSetting configurationSetting); 26 | 27 | void addMapperConfigurationSetting(MapperConfigurationSetting mapperConfigurationSetting); 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/jta/simple/Name.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.jta.simple; 17 | 18 | public class Name { 19 | private int id; 20 | private String name; 21 | 22 | public Name() { 23 | super(); 24 | } 25 | 26 | public Name(int id, String name) { 27 | this.id = id; 28 | this.name = name; 29 | } 30 | 31 | public int getId() { 32 | return id; 33 | } 34 | 35 | public void setId(int id) { 36 | this.id = id; 37 | } 38 | 39 | public String getName() { 40 | return name; 41 | } 42 | 43 | public void setName(String name) { 44 | this.name = name; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /.github/workflows/site.yaml: -------------------------------------------------------------------------------- 1 | name: Site 2 | 3 | on: 4 | push: 5 | branches: 6 | - site 7 | 8 | permissions: 9 | contents: write 10 | 11 | concurrency: 12 | group: ${{ github.workflow }}-${{ github.ref }} 13 | cancel-in-progress: true 14 | 15 | jobs: 16 | build: 17 | if: github.repository_owner == 'mybatis' && ! contains(toJSON(github.event.head_commit.message), '[maven-release-plugin]') 18 | runs-on: ubuntu-latest 19 | timeout-minutes: 60 20 | steps: 21 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 22 | - name: Setup Java 23 | uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5 24 | with: 25 | cache: maven 26 | distribution: temurin 27 | java-version: 25 28 | - name: Build site 29 | run: ./mvnw site site:stage --batch-mode --no-transfer-progress --settings ./.mvn/settings.xml --show-version -Dlicense.skip=true -DskipTests 30 | env: 31 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 32 | NVD_API_KEY: ${{ secrets.NVD_API_KEY }} 33 | - name: Deploy Site to gh-pages 34 | uses: JamesIves/github-pages-deploy-action@9d877eea73427180ae43cf98e8914934fe157a1a # v4 35 | with: 36 | branch: gh-pages 37 | folder: target/staging 38 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/multidstest/Schema1Service.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.multidstest; 17 | 18 | import jakarta.inject.Inject; 19 | 20 | import org.mybatis.guice.transactional.Transactional; 21 | 22 | public class Schema1Service { 23 | @Inject 24 | private Schema1Mapper mapper; 25 | 26 | @Transactional 27 | public void createSchema1() { 28 | mapper.createSchema1Step1(); 29 | mapper.createSchema1Step2(); 30 | mapper.createSchema1Step3(); 31 | } 32 | 33 | @Transactional 34 | public Integer getNextValueFromSchema1() { 35 | return mapper.getNextValueFromSchema1(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/multidstest/Schema2Service.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.multidstest; 17 | 18 | import jakarta.inject.Inject; 19 | 20 | import org.mybatis.guice.transactional.Transactional; 21 | 22 | public class Schema2Service { 23 | @Inject 24 | private Schema2Mapper mapper; 25 | 26 | @Transactional 27 | public void createSchema2() { 28 | mapper.createSchema2Step1(); 29 | mapper.createSchema2Step2(); 30 | mapper.createSchema2Step3(); 31 | } 32 | 33 | @Transactional 34 | public Integer getNextValueFromSchema2() { 35 | return mapper.getNextValueFromSchema2(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/MapperConfigurationSetting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import org.apache.ibatis.session.Configuration; 19 | 20 | public final class MapperConfigurationSetting { 21 | 22 | private final Class mapperClass; 23 | 24 | public MapperConfigurationSetting(Class mapperClass) { 25 | this.mapperClass = mapperClass; 26 | } 27 | 28 | public void applyConfigurationSetting(Configuration configuration) { 29 | if (!configuration.hasMapper(mapperClass)) { 30 | configuration.addMapper(mapperClass); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/resolver/interceptor/FirstInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.resolver.interceptor; 17 | 18 | import java.util.Properties; 19 | 20 | import org.apache.ibatis.plugin.Interceptor; 21 | import org.apache.ibatis.plugin.Invocation; 22 | 23 | public class FirstInterceptor implements Interceptor { 24 | @Override 25 | public Object intercept(Invocation invocation) throws Throwable { 26 | return null; 27 | } 28 | 29 | @Override 30 | public Object plugin(Object target) { 31 | return null; 32 | } 33 | 34 | @Override 35 | public void setProperties(Properties properties) { 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/resolver/interceptor/SecondInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.resolver.interceptor; 17 | 18 | import java.util.Properties; 19 | 20 | import org.apache.ibatis.plugin.Interceptor; 21 | import org.apache.ibatis.plugin.Invocation; 22 | 23 | public class SecondInterceptor implements Interceptor { 24 | @Override 25 | public Object intercept(Invocation invocation) throws Throwable { 26 | return null; 27 | } 28 | 29 | @Override 30 | public Object plugin(Object target) { 31 | return null; 32 | } 33 | 34 | @Override 35 | public void setProperties(Properties properties) { 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yaml: -------------------------------------------------------------------------------- 1 | name: "CodeQL" 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | schedule: 9 | - cron: '43 10 * * 2' 10 | 11 | concurrency: 12 | group: ${{ github.workflow }}-${{ github.ref }} 13 | cancel-in-progress: true 14 | 15 | jobs: 16 | analyze: 17 | name: Analyze 18 | runs-on: 'ubuntu-latest' 19 | timeout-minutes: 30 20 | permissions: 21 | actions: read 22 | contents: read 23 | security-events: write 24 | 25 | steps: 26 | - name: Checkout 27 | uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 28 | 29 | - name: Setup Java 30 | uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5 31 | with: 32 | cache: maven 33 | distribution: 'temurin' 34 | java-version: 25 35 | 36 | - name: Initialize CodeQL 37 | uses: github/codeql-action/init@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4 38 | with: 39 | queries: +security-and-quality 40 | 41 | - name: Autobuild 42 | uses: github/codeql-action/autobuild@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4 43 | 44 | - name: Perform CodeQL Analysis 45 | uses: github/codeql-action/analyze@5d4e8d1aca955e8d8589aabd499c5cae939e33c7 # v4 46 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/CacheEnabledConfigurationSetting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import org.apache.ibatis.session.Configuration; 19 | 20 | public class CacheEnabledConfigurationSetting implements ConfigurationSetting { 21 | 22 | private final boolean useCacheEnabled; 23 | 24 | public CacheEnabledConfigurationSetting(final boolean useCacheEnabled) { 25 | this.useCacheEnabled = useCacheEnabled; 26 | } 27 | 28 | @Override 29 | public void applyConfigurationSetting(Configuration configuration) { 30 | configuration.setCacheEnabled(useCacheEnabled); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/UseColumnLabelConfigurationSetting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import org.apache.ibatis.session.Configuration; 19 | 20 | public class UseColumnLabelConfigurationSetting implements ConfigurationSetting { 21 | 22 | private final boolean useColumnLabel; 23 | 24 | public UseColumnLabelConfigurationSetting(final boolean useColumnLabel) { 25 | this.useColumnLabel = useColumnLabel; 26 | } 27 | 28 | @Override 29 | public void applyConfigurationSetting(Configuration configuration) { 30 | configuration.setUseColumnLabel(useColumnLabel); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/UseGeneratedKeysConfigurationSetting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import org.apache.ibatis.session.Configuration; 19 | 20 | public class UseGeneratedKeysConfigurationSetting implements ConfigurationSetting { 21 | 22 | private final boolean useGeneratedKeys; 23 | 24 | public UseGeneratedKeysConfigurationSetting(final boolean useGeneratedKeys) { 25 | this.useGeneratedKeys = useGeneratedKeys; 26 | } 27 | 28 | @Override 29 | public void applyConfigurationSetting(Configuration configuration) { 30 | configuration.setUseGeneratedKeys(useGeneratedKeys); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/guice/sample/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/multidstest/Schema1Mapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.multidstest; 17 | 18 | import org.apache.ibatis.annotations.Select; 19 | import org.apache.ibatis.annotations.Update; 20 | 21 | public interface Schema1Mapper { 22 | 23 | @Update({ "drop schema schema1 if exists cascade;" }) 24 | int createSchema1Step1(); 25 | 26 | @Update({ "create schema schema1;" }) 27 | int createSchema1Step2(); 28 | 29 | @Update({ "CREATE SEQUENCE schema1.test_sequence AS INTEGER START WITH 100 INCREMENT BY 1;" }) 30 | int createSchema1Step3(); 31 | 32 | @Select({ "call next value for schema1.test_sequence" }) 33 | Integer getNextValueFromSchema1(); 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/multidstest/Schema2Mapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.multidstest; 17 | 18 | import org.apache.ibatis.annotations.Select; 19 | import org.apache.ibatis.annotations.Update; 20 | 21 | public interface Schema2Mapper { 22 | 23 | @Update({ "drop schema schema2 if exists cascade;" }) 24 | int createSchema2Step1(); 25 | 26 | @Update({ "create schema schema2;" }) 27 | int createSchema2Step2(); 28 | 29 | @Update({ "CREATE SEQUENCE schema2.test_sequence AS INTEGER START WITH 200 INCREMENT BY 1;" }) 30 | int createSchema2Step3(); 31 | 32 | @Select({ "call next value for schema2.test_sequence" }) 33 | Integer getNextValueFromSchema2(); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/CallSettersOnNullsConfigurationSetting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import org.apache.ibatis.session.Configuration; 19 | 20 | public class CallSettersOnNullsConfigurationSetting implements ConfigurationSetting { 21 | 22 | private final boolean callSettersOnNulls; 23 | 24 | public CallSettersOnNullsConfigurationSetting(final boolean callSettersOnNulls) { 25 | this.callSettersOnNulls = callSettersOnNulls; 26 | } 27 | 28 | @Override 29 | public void applyConfigurationSetting(Configuration configuration) { 30 | configuration.setCallSettersOnNulls(callSettersOnNulls); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/LazyLoadingEnabledConfigurationSetting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import org.apache.ibatis.session.Configuration; 19 | 20 | public class LazyLoadingEnabledConfigurationSetting implements ConfigurationSetting { 21 | 22 | private final boolean lazyLoadingEnabled; 23 | 24 | public LazyLoadingEnabledConfigurationSetting(final boolean lazyLoadingEnabled) { 25 | this.lazyLoadingEnabled = lazyLoadingEnabled; 26 | } 27 | 28 | @Override 29 | public void applyConfigurationSetting(Configuration configuration) { 30 | configuration.setLazyLoadingEnabled(lazyLoadingEnabled); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/provision/KeyMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2025 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 | package org.mybatis.guice.provision; 17 | 18 | import com.google.inject.Binding; 19 | import com.google.inject.Key; 20 | import com.google.inject.matcher.Matcher; 21 | 22 | public final class KeyMatcher implements Matcher> { 23 | private final Key key; 24 | 25 | KeyMatcher(Key key) { 26 | this.key = key; 27 | } 28 | 29 | @Override 30 | public boolean matches(Binding t) { 31 | return key.getTypeLiteral().getRawType().isAssignableFrom(t.getKey().getTypeLiteral().getRawType()); 32 | } 33 | 34 | public static KeyMatcher create(Key key) { 35 | return new KeyMatcher<>(key); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/nestedtx/NestedTxMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.nestedtx; 17 | 18 | import java.util.List; 19 | 20 | import org.apache.ibatis.annotations.Insert; 21 | import org.apache.ibatis.annotations.Select; 22 | 23 | public interface NestedTxMapper { 24 | 25 | @Insert({ "insert into table1 (id, name) values (#{id}, #{name})" }) 26 | int insertTable1(TableRow row); 27 | 28 | @Select({ "select * from table1" }) 29 | List selectAllTable1(); 30 | 31 | @Insert({ "insert into table2 (id, name) values (#{id}, #{name})" }) 32 | int insertTable2(TableRow row); 33 | 34 | @Select({ "select * from table2" }) 35 | List selectAllTable2(); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/AliasConfigurationSetting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import org.apache.ibatis.session.Configuration; 19 | 20 | public final class AliasConfigurationSetting implements ConfigurationSetting { 21 | 22 | private final String alias; 23 | private final Class clazz; 24 | 25 | public AliasConfigurationSetting(final String alias, final Class clazz) { 26 | this.alias = alias; 27 | this.clazz = clazz; 28 | } 29 | 30 | @Override 31 | public void applyConfigurationSetting(Configuration configuration) { 32 | configuration.getTypeAliasRegistry().registerAlias(alias, clazz); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/customconfiguration/MyConfigurationProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2025 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 | package org.mybatis.guice.customconfiguration; 17 | 18 | import jakarta.inject.Inject; 19 | 20 | import org.apache.ibatis.mapping.Environment; 21 | import org.apache.ibatis.session.Configuration; 22 | import org.mybatis.guice.configuration.ConfigurationProvider; 23 | 24 | public class MyConfigurationProvider extends ConfigurationProvider { 25 | 26 | @Inject 27 | public MyConfigurationProvider(Environment environment) { 28 | super(environment); 29 | } 30 | 31 | @Override 32 | protected Configuration newConfiguration(Environment environment) { 33 | return new MyConfiguration(environment); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/AggressiveLazyLoadingConfigurationSetting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import org.apache.ibatis.session.Configuration; 19 | 20 | public class AggressiveLazyLoadingConfigurationSetting implements ConfigurationSetting { 21 | 22 | private final boolean aggressiveLazyLoading; 23 | 24 | public AggressiveLazyLoadingConfigurationSetting(final boolean aggressiveLazyLoading) { 25 | this.aggressiveLazyLoading = aggressiveLazyLoading; 26 | } 27 | 28 | @Override 29 | public void applyConfigurationSetting(Configuration configuration) { 30 | configuration.setAggressiveLazyLoading(aggressiveLazyLoading); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/DefaultExecutorTypeConfigurationSetting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import org.apache.ibatis.session.Configuration; 19 | import org.apache.ibatis.session.ExecutorType; 20 | 21 | public class DefaultExecutorTypeConfigurationSetting implements ConfigurationSetting { 22 | 23 | private final ExecutorType executorType; 24 | 25 | public DefaultExecutorTypeConfigurationSetting(final ExecutorType executorType) { 26 | this.executorType = executorType; 27 | } 28 | 29 | @Override 30 | public void applyConfigurationSetting(Configuration configuration) { 31 | configuration.setDefaultExecutorType(executorType); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/DefaultStatementTimeoutConfigurationSetting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import org.apache.ibatis.session.Configuration; 19 | 20 | public class DefaultStatementTimeoutConfigurationSetting implements ConfigurationSetting { 21 | 22 | private final Integer defaultStatementTimeout; 23 | 24 | public DefaultStatementTimeoutConfigurationSetting(Integer defaultStatementTimeout) { 25 | this.defaultStatementTimeout = defaultStatementTimeout; 26 | } 27 | 28 | @Override 29 | public void applyConfigurationSetting(Configuration configuration) { 30 | configuration.setDefaultStatementTimeout(defaultStatementTimeout); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/XMLAlternateEnvironmentMyBatisModuleTestCaseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice; 17 | 18 | import jakarta.inject.Inject; 19 | 20 | import org.apache.ibatis.session.SqlSessionFactory; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | 24 | @ExtendWith(XMLAlternateEnvironmentGuiceTestExtension.class) 25 | final class XMLAlternateEnvironmentMyBatisModuleTestCaseTest extends AbstractMyBatisModuleTestCase { 26 | 27 | @Inject 28 | private SqlSessionFactory sqlSessionFactory; 29 | 30 | @Test 31 | void testEnvironmentId() throws Exception { 32 | assert "test2".equals(sqlSessionFactory.getConfiguration().getEnvironment().getId()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/LocalCacheScopeConfigurationSetting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import org.apache.ibatis.session.Configuration; 19 | import org.apache.ibatis.session.LocalCacheScope; 20 | 21 | public class LocalCacheScopeConfigurationSetting implements ConfigurationSetting { 22 | 23 | private final LocalCacheScope localCacheScope; 24 | 25 | public LocalCacheScopeConfigurationSetting(final LocalCacheScope localCacheScope) { 26 | this.localCacheScope = localCacheScope; 27 | } 28 | 29 | @Override 30 | public void applyConfigurationSetting(Configuration configuration) { 31 | configuration.setLocalCacheScope(localCacheScope); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/MapUnderscoreToCamelCaseConfigurationSetting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import org.apache.ibatis.session.Configuration; 19 | 20 | public class MapUnderscoreToCamelCaseConfigurationSetting implements ConfigurationSetting { 21 | 22 | private final boolean mapUnderscoreToCamelCase; 23 | 24 | public MapUnderscoreToCamelCaseConfigurationSetting(final boolean mapUnderscoreToCamelCase) { 25 | this.mapUnderscoreToCamelCase = mapUnderscoreToCamelCase; 26 | } 27 | 28 | @Override 29 | public void applyConfigurationSetting(Configuration configuration) { 30 | configuration.setMapUnderscoreToCamelCase(mapUnderscoreToCamelCase); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/sample/domain/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.sample.domain; 17 | 18 | /** 19 | * A simple bean that holds User info. 20 | */ 21 | public class User { 22 | 23 | private String id; 24 | 25 | private String name; 26 | 27 | public String getId() { 28 | return this.id; 29 | } 30 | 31 | public void setId(String id) { 32 | this.id = id; 33 | } 34 | 35 | public String getName() { 36 | return this.name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return new StringBuilder().append("{").append(this.id).append(", ").append(this.name).append("}").toString(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/customsqlsessionfactory/MySqlSessionFactoryProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.customsqlsessionfactory; 17 | 18 | import jakarta.inject.Inject; 19 | import jakarta.inject.Provider; 20 | 21 | import org.apache.ibatis.session.Configuration; 22 | import org.apache.ibatis.session.SqlSessionFactory; 23 | 24 | public class MySqlSessionFactoryProvider implements Provider { 25 | private final Configuration configuration; 26 | 27 | @Inject 28 | public MySqlSessionFactoryProvider(final Configuration configuration) { 29 | this.configuration = configuration; 30 | } 31 | 32 | @Override 33 | public SqlSessionFactory get() { 34 | return new MySqlSessionFactory(configuration); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/jta/simple/Schema2Service.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.jta.simple; 17 | 18 | import jakarta.inject.Inject; 19 | 20 | import java.util.List; 21 | 22 | import org.mybatis.guice.transactional.Transactional; 23 | 24 | public class Schema2Service { 25 | @Inject 26 | private Schema2Mapper mapper; 27 | 28 | @Transactional 29 | public void createSchema2() { 30 | mapper.createSchema2Step1(); 31 | mapper.createSchema2Step2(); 32 | mapper.createSchema2Step3(); 33 | } 34 | 35 | @Transactional 36 | public List getAllNames() { 37 | return mapper.getAllNames(); 38 | } 39 | 40 | @Transactional 41 | public int insertName(Name name) { 42 | return mapper.insertName(name); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/resources/org/mybatis/guice/sample/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 26 | 27 | INSERT INTO 28 | contact (id, 29 | name 30 | ) 31 | VALUES ( 32 | #{name} 33 | ) 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/multidstest/MockContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.multidstest; 17 | 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | 21 | import javax.naming.InitialContext; 22 | import javax.naming.NamingException; 23 | 24 | public class MockContext extends InitialContext { 25 | 26 | private static Map bindings = new HashMap(); 27 | 28 | public MockContext(boolean lazy) throws NamingException { 29 | super(lazy); 30 | } 31 | 32 | @Override 33 | public Object lookup(String name) throws NamingException { 34 | return bindings.get(name); 35 | } 36 | 37 | @Override 38 | public void bind(String name, Object obj) throws NamingException { 39 | bindings.put(name, obj); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/AutoMappingBehaviorConfigurationSetting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import org.apache.ibatis.session.AutoMappingBehavior; 19 | import org.apache.ibatis.session.Configuration; 20 | 21 | public class AutoMappingBehaviorConfigurationSetting implements ConfigurationSetting { 22 | 23 | private final AutoMappingBehavior autoMappingBehavior; 24 | 25 | public AutoMappingBehaviorConfigurationSetting(final AutoMappingBehavior autoMappingBehavior) { 26 | this.autoMappingBehavior = autoMappingBehavior; 27 | } 28 | 29 | @Override 30 | public void applyConfigurationSetting(Configuration configuration) { 31 | configuration.setAutoMappingBehavior(autoMappingBehavior); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/MultipleResultSetsEnabledConfigurationSetting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2025 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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import org.apache.ibatis.session.Configuration; 19 | 20 | /** 21 | * @deprecated This option has no effect. 22 | */ 23 | @Deprecated 24 | public class MultipleResultSetsEnabledConfigurationSetting implements ConfigurationSetting { 25 | 26 | private final boolean multipleResultSetsEnabled; 27 | 28 | public MultipleResultSetsEnabledConfigurationSetting(final boolean multipleResultSetsEnabled) { 29 | this.multipleResultSetsEnabled = multipleResultSetsEnabled; 30 | } 31 | 32 | @Override 33 | public void applyConfigurationSetting(Configuration configuration) { 34 | configuration.setMultipleResultSetsEnabled(multipleResultSetsEnabled); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/sample/dao/UserDaoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.sample.dao; 17 | 18 | import jakarta.inject.Inject; 19 | 20 | import org.apache.ibatis.session.SqlSession; 21 | import org.mybatis.guice.sample.domain.User; 22 | 23 | public class UserDaoImpl implements UserDao { 24 | 25 | private SqlSession sqlSession; 26 | 27 | @Inject 28 | public void setSqlSession(SqlSession sqlSession) { 29 | this.sqlSession = sqlSession; 30 | } 31 | 32 | @Override 33 | public User getUser(String userId) { 34 | return (User) this.sqlSession.selectOne("org.mybatis.guice.sample.mapper.UserMapper.getUser", userId); 35 | } 36 | 37 | @Override 38 | public void brokenInsert(User user) { 39 | this.sqlSession.insert("org.mybatis.guice.sample.mapper.UserMapper.brokenAdd", user); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/jta/simple/Schema1Mapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.jta.simple; 17 | 18 | import java.util.List; 19 | 20 | import org.apache.ibatis.annotations.Insert; 21 | import org.apache.ibatis.annotations.Select; 22 | import org.apache.ibatis.annotations.Update; 23 | 24 | public interface Schema1Mapper { 25 | 26 | @Update({ "drop schema schema1 if exists cascade;" }) 27 | int createSchema1Step1(); 28 | 29 | @Update({ "create schema schema1;" }) 30 | int createSchema1Step2(); 31 | 32 | @Update({ "create table schema1.name (id int not null, name varchar(50) not null);" }) 33 | int createSchema1Step3(); 34 | 35 | @Select({ "select id, name from schema1.name order by id" }) 36 | List getAllNames(); 37 | 38 | @Insert({ "insert into schema1.name (id, name) values (#{id}, #{name})" }) 39 | int insertName(Name name); 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/jta/simple/Schema2Mapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.jta.simple; 17 | 18 | import java.util.List; 19 | 20 | import org.apache.ibatis.annotations.Insert; 21 | import org.apache.ibatis.annotations.Select; 22 | import org.apache.ibatis.annotations.Update; 23 | 24 | public interface Schema2Mapper { 25 | 26 | @Update({ "drop schema schema2 if exists cascade;" }) 27 | int createSchema2Step1(); 28 | 29 | @Update({ "create schema schema2;" }) 30 | int createSchema2Step2(); 31 | 32 | @Update({ "create table schema2.name (id int not null, name varchar(50) not null);" }) 33 | int createSchema2Step3(); 34 | 35 | @Select({ "select id, name from schema2.name order by id" }) 36 | List getAllNames(); 37 | 38 | @Insert({ "insert into schema2.name (id, name) values (#{id}, #{name})" }) 39 | int insertName(Name name); 40 | } 41 | -------------------------------------------------------------------------------- /.github/workflows/sonar.yaml: -------------------------------------------------------------------------------- 1 | name: SonarCloud 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | permissions: read-all 9 | 10 | concurrency: 11 | group: ${{ github.workflow }}-${{ github.ref }} 12 | cancel-in-progress: true 13 | 14 | env: 15 | SONAR_ORGANIZATION: mybatis 16 | SONAR_PROJECT_KEY: guice 17 | 18 | jobs: 19 | build: 20 | if: github.repository_owner == 'mybatis' 21 | runs-on: ubuntu-latest 22 | timeout-minutes: 30 23 | steps: 24 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 25 | with: 26 | # Disabling shallow clone is recommended for improving relevancy of reporting 27 | fetch-depth: 0 28 | - name: Setup Java 29 | uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5 30 | with: 31 | cache: maven 32 | distribution: temurin 33 | java-version: 25 34 | - name: Set SONAR_SCANNER_JAVA_OPTS 35 | run: echo "SONAR_SCANNER_JAVA_OPTS=-Xmx512m" >> ${GITHUB_ENV} 36 | - name: Analyze with SonarCloud 37 | run: ./mvnw verify jacoco:report sonar:sonar --batch-mode --no-transfer-progress --show-version -Dlicense.skip=true -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=${{ env.SONAR_ORGANIZATION }} -Dsonar.projectKey=${{ env.SONAR_ORGANIZATION }}_${{ env.SONAR_PROJECT_KEY }} -Dsonar.scanner.skipJreProvisioning=true -Dsonar.token=${{ env.SONAR_TOKEN }} 38 | env: 39 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 40 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 41 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/XMLGuiceTestExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice; 17 | 18 | import com.google.inject.Module; 19 | 20 | import java.sql.SQLException; 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | import java.util.Properties; 24 | 25 | public final class XMLGuiceTestExtension extends AbstractGuiceTestExtension { 26 | 27 | public XMLGuiceTestExtension() throws SQLException { 28 | super(); 29 | } 30 | 31 | @Override 32 | protected List createMyBatisModule() { 33 | List modules = new ArrayList(2); 34 | modules.add(new XMLMyBatisModule() { 35 | 36 | @Override 37 | protected void initialize() { 38 | } 39 | 40 | }); 41 | return modules; 42 | } 43 | 44 | @Override 45 | protected Properties createTestProperties() { 46 | return new Properties(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/DefaultScriptingLanguageTypeConfigurationSetting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import org.apache.ibatis.scripting.LanguageDriver; 19 | import org.apache.ibatis.session.Configuration; 20 | 21 | public class DefaultScriptingLanguageTypeConfigurationSetting implements ConfigurationSetting { 22 | 23 | private final Class defaultScriptingLanguageType; 24 | 25 | public DefaultScriptingLanguageTypeConfigurationSetting( 26 | Class defaultScriptingLanguageType) { 27 | this.defaultScriptingLanguageType = defaultScriptingLanguageType; 28 | } 29 | 30 | @Override 31 | public void applyConfigurationSetting(Configuration configuration) { 32 | configuration.setDefaultScriptingLanguage(defaultScriptingLanguageType); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /.github/workflows/coveralls.yaml: -------------------------------------------------------------------------------- 1 | name: Coveralls 2 | 3 | on: [push, pull_request] 4 | 5 | permissions: read-all 6 | 7 | concurrency: 8 | group: ${{ github.workflow }}-${{ github.ref }} 9 | cancel-in-progress: true 10 | 11 | jobs: 12 | coveralls: 13 | if: github.repository_owner == 'mybatis' 14 | runs-on: ubuntu-latest 15 | timeout-minutes: 30 16 | steps: 17 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 18 | - name: Setup Java 19 | uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5 20 | with: 21 | cache: maven 22 | distribution: temurin 23 | java-version: 25 24 | - name: Run the build 25 | run: ./mvnw test --batch-mode --no-transfer-progress --quiet --show-version -Dlicense.skip=true 26 | - name: Report Coverage to Coveralls for Pull Requests 27 | if: github.event_name == 'pull_request' 28 | run: ./mvnw generate-sources jacoco:report coveralls:report --batch-mode --no-transfer-progress -DpullRequest=${{ env.PR_NUMBER }} -DrepoToken=${{ env.GITHUB_TOKEN }} -DserviceName=github 29 | env: 30 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 31 | PR_NUMBER: ${{ github.event.number }} 32 | - name: Report Coverage to Coveralls for General Push 33 | if: github.event_name == 'push' 34 | run: ./mvnw generate-sources jacoco:report coveralls:report --batch-mode --no-transfer-progress -DrepoToken=${{ env.GITHUB_TOKEN }} -DserviceName=github 35 | env: 36 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 37 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | MyBatis-Guice 2 | Copyright 2010-2023 3 | 4 | This product includes software developed by 5 | The MyBatis Team (http://www.mybatis.org/). 6 | 7 | iBATIS 8 | This product includes software developed by 9 | The Apache Software Foundation (http://www.apache.org/). 10 | 11 | Copyright 2010 The Apache Software Foundation 12 | 13 | Licensed under the Apache License, Version 2.0 (the "License"); 14 | you may not use this file except in compliance with the License. 15 | You may obtain a copy of the License at 16 | 17 | http://www.apache.org/licenses/LICENSE-2.0 18 | 19 | Unless required by applicable law or agreed to in writing, software 20 | distributed under the License is distributed on an "AS IS" BASIS, 21 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | See the License for the specific language governing permissions and 23 | limitations under the License. 24 | 25 | Google Guice 26 | Copyright 2010 The Apache Software Foundation 27 | 28 | Licensed under the Apache License, Version 2.0 (the "License"); 29 | you may not use this file except in compliance with the License. 30 | You may obtain a copy of the License at 31 | 32 | http://www.apache.org/licenses/LICENSE-2.0 33 | 34 | Unless required by applicable law or agreed to in writing, software 35 | distributed under the License is distributed on an "AS IS" BASIS, 36 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 37 | See the License for the specific language governing permissions and 38 | limitations under the License. 39 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/XMLGuicePackageTestExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice; 17 | 18 | import com.google.inject.Module; 19 | 20 | import java.sql.SQLException; 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | import java.util.Properties; 24 | 25 | public final class XMLGuicePackageTestExtension extends AbstractGuiceTestExtension { 26 | 27 | public XMLGuicePackageTestExtension() throws SQLException { 28 | super(); 29 | } 30 | 31 | @Override 32 | protected List createMyBatisModule() { 33 | List modules = new ArrayList(2); 34 | modules.add(new XMLMyBatisModule() { 35 | 36 | @Override 37 | protected void initialize() { 38 | setClassPathResource("mybatis-package-config.xml"); 39 | } 40 | 41 | }); 42 | return modules; 43 | } 44 | 45 | @Override 46 | protected Properties createTestProperties() { 47 | return new Properties(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/TypeHandlerConfigurationSettingProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2025 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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import com.google.inject.Injector; 19 | import com.google.inject.Key; 20 | 21 | import jakarta.inject.Inject; 22 | import jakarta.inject.Provider; 23 | 24 | import org.apache.ibatis.type.TypeHandler; 25 | 26 | public final class TypeHandlerConfigurationSettingProvider implements Provider { 27 | @Inject 28 | private Injector injector; 29 | 30 | private final Key> key; 31 | 32 | public TypeHandlerConfigurationSettingProvider(final Key> key) { 33 | this.key = key; 34 | } 35 | 36 | @Override 37 | public ConfigurationSetting get() { 38 | final TypeHandler handlerInstance = injector.getInstance(key); 39 | return configuration -> configuration.getTypeHandlerRegistry().register(handlerInstance); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/jta/simple/Schema1Service.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.jta.simple; 17 | 18 | import jakarta.inject.Inject; 19 | 20 | import java.util.List; 21 | 22 | import org.mybatis.guice.transactional.Transactional; 23 | import org.mybatis.guice.transactional.Transactional.TxType; 24 | 25 | public class Schema1Service { 26 | @Inject 27 | private Schema1Mapper mapper; 28 | 29 | @Transactional 30 | public void createSchema1() { 31 | mapper.createSchema1Step1(); 32 | mapper.createSchema1Step2(); 33 | mapper.createSchema1Step3(); 34 | } 35 | 36 | @Transactional 37 | public List getAllNames() { 38 | return mapper.getAllNames(); 39 | } 40 | 41 | @Transactional 42 | public int insertName(Name name) { 43 | return mapper.insertName(name); 44 | } 45 | 46 | @Transactional(TxType.REQUIRES_NEW) 47 | public int insertNameWithNewTransaction(Name name) { 48 | return mapper.insertName(name); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/XMLAlternateEnvironmentGuiceTestExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice; 17 | 18 | import com.google.inject.Module; 19 | 20 | import java.sql.SQLException; 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | import java.util.Properties; 24 | 25 | public final class XMLAlternateEnvironmentGuiceTestExtension extends AbstractGuiceTestExtension { 26 | 27 | public XMLAlternateEnvironmentGuiceTestExtension() throws SQLException { 28 | super(); 29 | } 30 | 31 | @Override 32 | protected List createMyBatisModule() { 33 | List modules = new ArrayList(2); 34 | modules.add(new XMLMyBatisModule() { 35 | 36 | @Override 37 | protected void initialize() { 38 | setEnvironmentId("test2"); 39 | } 40 | 41 | }); 42 | return modules; 43 | } 44 | 45 | @Override 46 | protected Properties createTestProperties() { 47 | return new Properties(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/transactional/MyBatisXAException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.transactional; 17 | 18 | import javax.transaction.xa.XAException; 19 | 20 | public class MyBatisXAException extends XAException { 21 | private static final long serialVersionUID = -7280133560046132709L; 22 | 23 | /** 24 | * Instantiates a new my batis XA exception. 25 | * 26 | * @param message 27 | * the message 28 | * @param errorCode 29 | * the error code 30 | */ 31 | public MyBatisXAException(String message, int errorCode) { 32 | super(message); 33 | this.errorCode = errorCode; 34 | } 35 | 36 | /** 37 | * Instantiates a new my batis XA exception. 38 | * 39 | * @param message 40 | * the message 41 | * @param errorCode 42 | * the error code 43 | * @param t 44 | * the t 45 | */ 46 | public MyBatisXAException(String message, int errorCode, Throwable t) { 47 | super(message); 48 | this.errorCode = errorCode; 49 | initCause(t); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/AddressConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice; 17 | 18 | import java.text.ParseException; 19 | import java.util.regex.Matcher; 20 | import java.util.regex.Pattern; 21 | 22 | public class AddressConverter { 23 | 24 | public Address convert(String input) throws ParseException { 25 | Pattern pattern = Pattern.compile("(\\d+)\\s([\\w\\s]+)"); 26 | Matcher matcher = pattern.matcher(input); 27 | if (matcher.matches()) { 28 | Address address = new Address(); 29 | address.setNumber(Integer.valueOf(matcher.group(1))); 30 | address.setStreet(matcher.group(2)); 31 | return address; 32 | } else { 33 | throw new ParseException("Address did not match expected pattern: " + pattern.pattern(), 0); 34 | } 35 | } 36 | 37 | public String convert(Address address) { 38 | StringBuilder builder = new StringBuilder(); 39 | builder.append(address.getNumber().toString()); 40 | builder.append(" "); 41 | builder.append(address.getStreet()); 42 | return builder.toString(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/ObjectFactoryConfigurationSetting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2025 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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import com.google.inject.Injector; 19 | 20 | import jakarta.inject.Inject; 21 | import jakarta.inject.Provider; 22 | 23 | import org.apache.ibatis.reflection.factory.ObjectFactory; 24 | 25 | public class ObjectFactoryConfigurationSetting implements Provider { 26 | 27 | @Inject 28 | private Injector injector; 29 | 30 | private final Class objectFactoryType; 31 | 32 | public ObjectFactoryConfigurationSetting(Class objectFactoryType) { 33 | this.objectFactoryType = objectFactoryType; 34 | } 35 | 36 | public void setInjector(final Injector injector) { 37 | this.injector = injector; 38 | } 39 | 40 | @Override 41 | public ConfigurationSetting get() { 42 | final ObjectFactory objectFactory = injector.getInstance(objectFactoryType); 43 | return configuration -> configuration.setObjectFactory(objectFactory); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/jta/JtaService1Impl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.jta; 17 | 18 | import jakarta.inject.Inject; 19 | 20 | import java.util.List; 21 | 22 | import org.apache.ibatis.logging.Log; 23 | import org.apache.ibatis.logging.LogFactory; 24 | import org.apache.ibatis.session.SqlSessionFactory; 25 | import org.mybatis.guice.transactional.Transactional; 26 | 27 | public class JtaService1Impl { 28 | private final Log log = LogFactory.getLog(getClass()); 29 | 30 | @Inject 31 | JtaMapper mapper; 32 | @Inject 33 | SqlSessionFactory factory; 34 | 35 | public JtaService1Impl() { 36 | } 37 | 38 | @Transactional 39 | public int insertTable(TableRow row) { 40 | log.debug(getName() + " insertTable"); 41 | return mapper.insertTable(row); 42 | } 43 | 44 | @Transactional 45 | public List selectAllTable() { 46 | log.debug(getName() + " selectAllTable"); 47 | return mapper.selectAllTable(); 48 | } 49 | 50 | public String getName() { 51 | return factory.getConfiguration().getEnvironment().getId(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/jta/JtaService2Impl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.jta; 17 | 18 | import jakarta.inject.Inject; 19 | 20 | import java.util.List; 21 | 22 | import org.apache.ibatis.logging.Log; 23 | import org.apache.ibatis.logging.LogFactory; 24 | import org.apache.ibatis.session.SqlSessionFactory; 25 | import org.mybatis.guice.transactional.Transactional; 26 | 27 | public class JtaService2Impl { 28 | private final Log log = LogFactory.getLog(getClass()); 29 | 30 | @Inject 31 | JtaMapper mapper; 32 | @Inject 33 | SqlSessionFactory factory; 34 | 35 | public JtaService2Impl() { 36 | } 37 | 38 | @Transactional 39 | public int insertTable(TableRow row) { 40 | log.debug(getName() + " insertTable"); 41 | return mapper.insertTable(row); 42 | } 43 | 44 | @Transactional 45 | public List selectAllTable() { 46 | log.debug(getName() + " selectAllTable"); 47 | return mapper.selectAllTable(); 48 | } 49 | 50 | public String getName() { 51 | return factory.getConfiguration().getEnvironment().getId(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/resolver/typehandler/AddressTypeHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.resolver.typehandler; 17 | 18 | import java.sql.CallableStatement; 19 | import java.sql.PreparedStatement; 20 | import java.sql.ResultSet; 21 | import java.sql.SQLException; 22 | 23 | import org.apache.ibatis.type.BaseTypeHandler; 24 | import org.apache.ibatis.type.JdbcType; 25 | import org.mybatis.guice.resolver.alias.Address; 26 | 27 | public class AddressTypeHandler extends BaseTypeHandler

{ 28 | @Override 29 | public void setNonNullParameter(PreparedStatement ps, int i, Address parameter, JdbcType jdbcType) 30 | throws SQLException { 31 | } 32 | 33 | @Override 34 | public Address getNullableResult(ResultSet rs, String columnName) throws SQLException { 35 | return null; 36 | } 37 | 38 | @Override 39 | public Address getNullableResult(ResultSet rs, int columnIndex) throws SQLException { 40 | return null; 41 | } 42 | 43 | @Override 44 | public Address getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { 45 | return null; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/CountUpdateInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice; 17 | 18 | import jakarta.inject.Inject; 19 | 20 | import java.util.Properties; 21 | 22 | import org.apache.ibatis.executor.Executor; 23 | import org.apache.ibatis.mapping.MappedStatement; 24 | import org.apache.ibatis.plugin.Interceptor; 25 | import org.apache.ibatis.plugin.Intercepts; 26 | import org.apache.ibatis.plugin.Invocation; 27 | import org.apache.ibatis.plugin.Plugin; 28 | import org.apache.ibatis.plugin.Signature; 29 | 30 | @Intercepts({ @Signature(type = Executor.class, method = "update", args = { MappedStatement.class, Object.class }) }) 31 | public class CountUpdateInterceptor implements Interceptor { 32 | 33 | @Inject 34 | private Counter counter; 35 | 36 | @Override 37 | public Object intercept(Invocation invocation) throws Throwable { 38 | counter.increment(); 39 | return invocation.proceed(); 40 | } 41 | 42 | @Override 43 | public Object plugin(Object target) { 44 | return Plugin.wrap(target, this); 45 | } 46 | 47 | @Override 48 | public void setProperties(Properties properties) { 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/configuration/settings/CacheEnabledConfigurationSettingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import static org.mockito.Mockito.verify; 19 | 20 | import org.apache.ibatis.session.Configuration; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | import org.mockito.Mock; 24 | import org.mockito.junit.jupiter.MockitoExtension; 25 | 26 | @ExtendWith(MockitoExtension.class) 27 | class CacheEnabledConfigurationSettingTest { 28 | @Mock 29 | private Configuration configuration; 30 | 31 | @Test 32 | void applyConfigurationSetting_True() { 33 | CacheEnabledConfigurationSetting setting = new CacheEnabledConfigurationSetting(true); 34 | setting.applyConfigurationSetting(configuration); 35 | verify(configuration).setCacheEnabled(true); 36 | } 37 | 38 | @Test 39 | void applyConfigurationSetting_False() { 40 | CacheEnabledConfigurationSetting setting = new CacheEnabledConfigurationSetting(false); 41 | setting.applyConfigurationSetting(configuration); 42 | verify(configuration).setCacheEnabled(false); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/configuration/settings/UseColumnLabelConfigurationSettingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import static org.mockito.Mockito.verify; 19 | 20 | import org.apache.ibatis.session.Configuration; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | import org.mockito.Mock; 24 | import org.mockito.junit.jupiter.MockitoExtension; 25 | 26 | @ExtendWith(MockitoExtension.class) 27 | class UseColumnLabelConfigurationSettingTest { 28 | @Mock 29 | private Configuration configuration; 30 | 31 | @Test 32 | void applyConfigurationSetting_True() { 33 | UseColumnLabelConfigurationSetting setting = new UseColumnLabelConfigurationSetting(true); 34 | setting.applyConfigurationSetting(configuration); 35 | verify(configuration).setUseColumnLabel(true); 36 | } 37 | 38 | @Test 39 | void applyConfigurationSetting_False() { 40 | UseColumnLabelConfigurationSetting setting = new UseColumnLabelConfigurationSetting(false); 41 | setting.applyConfigurationSetting(configuration); 42 | verify(configuration).setUseColumnLabel(false); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/InterceptorConfigurationSettingProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import com.google.inject.Injector; 19 | 20 | import jakarta.inject.Inject; 21 | import jakarta.inject.Provider; 22 | 23 | import org.apache.ibatis.plugin.Interceptor; 24 | import org.apache.ibatis.session.Configuration; 25 | 26 | public final class InterceptorConfigurationSettingProvider implements Provider { 27 | 28 | @Inject 29 | private Injector injector; 30 | 31 | private final Class interceptorClass; 32 | 33 | public InterceptorConfigurationSettingProvider(final Class interceptorClass) { 34 | this.interceptorClass = interceptorClass; 35 | } 36 | 37 | @Override 38 | public ConfigurationSetting get() { 39 | final Interceptor interceptor = injector.getInstance(interceptorClass); 40 | return new ConfigurationSetting() { 41 | @Override 42 | public void applyConfigurationSetting(Configuration configuration) { 43 | configuration.addInterceptor(interceptor); 44 | } 45 | }; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/configuration/settings/ObjectWrapperFactoryConfigurationSetting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2025 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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import com.google.inject.Injector; 19 | 20 | import jakarta.inject.Inject; 21 | import jakarta.inject.Provider; 22 | 23 | import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory; 24 | 25 | public class ObjectWrapperFactoryConfigurationSetting implements Provider { 26 | 27 | @Inject 28 | private Injector injector; 29 | private final Class objectWrapperFactoryType; 30 | 31 | public ObjectWrapperFactoryConfigurationSetting(Class objectWrapperFactoryType) { 32 | this.objectWrapperFactoryType = objectWrapperFactoryType; 33 | } 34 | 35 | public void setInjector(final Injector injector) { 36 | this.injector = injector; 37 | } 38 | 39 | @Override 40 | public ConfigurationSetting get() { 41 | final ObjectWrapperFactory objectWrapperFactory = injector.getInstance(objectWrapperFactoryType); 42 | return configuration -> configuration.setObjectWrapperFactory(objectWrapperFactory); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/configuration/settings/UseGeneratedKeysConfigurationSettingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import static org.mockito.Mockito.verify; 19 | 20 | import org.apache.ibatis.session.Configuration; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | import org.mockito.Mock; 24 | import org.mockito.junit.jupiter.MockitoExtension; 25 | 26 | @ExtendWith(MockitoExtension.class) 27 | class UseGeneratedKeysConfigurationSettingTest { 28 | @Mock 29 | private Configuration configuration; 30 | 31 | @Test 32 | void applyConfigurationSetting_True() { 33 | UseGeneratedKeysConfigurationSetting setting = new UseGeneratedKeysConfigurationSetting(true); 34 | setting.applyConfigurationSetting(configuration); 35 | verify(configuration).setUseGeneratedKeys(true); 36 | } 37 | 38 | @Test 39 | void applyConfigurationSetting_False() { 40 | UseGeneratedKeysConfigurationSetting setting = new UseGeneratedKeysConfigurationSetting(false); 41 | setting.applyConfigurationSetting(configuration); 42 | verify(configuration).setUseGeneratedKeys(false); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/configuration/settings/CallSettersOnNullsConfigurationSettingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import static org.mockito.Mockito.verify; 19 | 20 | import org.apache.ibatis.session.Configuration; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | import org.mockito.Mock; 24 | import org.mockito.junit.jupiter.MockitoExtension; 25 | 26 | @ExtendWith(MockitoExtension.class) 27 | class CallSettersOnNullsConfigurationSettingTest { 28 | @Mock 29 | private Configuration configuration; 30 | 31 | @Test 32 | void applyConfigurationSetting_True() { 33 | CallSettersOnNullsConfigurationSetting setting = new CallSettersOnNullsConfigurationSetting(true); 34 | setting.applyConfigurationSetting(configuration); 35 | verify(configuration).setCallSettersOnNulls(true); 36 | } 37 | 38 | @Test 39 | void applyConfigurationSetting_False() { 40 | CallSettersOnNullsConfigurationSetting setting = new CallSettersOnNullsConfigurationSetting(false); 41 | setting.applyConfigurationSetting(configuration); 42 | verify(configuration).setCallSettersOnNulls(false); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/configuration/settings/LazyLoadingEnabledConfigurationSettingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import static org.mockito.Mockito.verify; 19 | 20 | import org.apache.ibatis.session.Configuration; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | import org.mockito.Mock; 24 | import org.mockito.junit.jupiter.MockitoExtension; 25 | 26 | @ExtendWith(MockitoExtension.class) 27 | class LazyLoadingEnabledConfigurationSettingTest { 28 | @Mock 29 | private Configuration configuration; 30 | 31 | @Test 32 | void applyConfigurationSetting_True() { 33 | LazyLoadingEnabledConfigurationSetting setting = new LazyLoadingEnabledConfigurationSetting(true); 34 | setting.applyConfigurationSetting(configuration); 35 | verify(configuration).setLazyLoadingEnabled(true); 36 | } 37 | 38 | @Test 39 | void applyConfigurationSetting_False() { 40 | LazyLoadingEnabledConfigurationSetting setting = new LazyLoadingEnabledConfigurationSetting(false); 41 | setting.applyConfigurationSetting(configuration); 42 | verify(configuration).setLazyLoadingEnabled(false); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/transactional/Isolation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.transactional; 17 | 18 | import org.apache.ibatis.session.TransactionIsolationLevel; 19 | 20 | /** 21 | * Enum of isolation levels. This enum exists because Java annotations do not support null default values - so we need 22 | * to add the DEFAULT level which means - do not specify an isolation level. 23 | * 24 | * @author Jeff Butler 25 | * 26 | * @since 3.1 27 | */ 28 | public enum Isolation { 29 | 30 | DEFAULT(null), 31 | 32 | NONE(TransactionIsolationLevel.NONE), 33 | 34 | READ_COMMITTED(TransactionIsolationLevel.READ_COMMITTED), 35 | 36 | READ_UNCOMMITTED(TransactionIsolationLevel.READ_UNCOMMITTED), 37 | 38 | REPEATABLE_READ(TransactionIsolationLevel.REPEATABLE_READ), 39 | 40 | SERIALIZABLE(TransactionIsolationLevel.SERIALIZABLE); 41 | 42 | private final TransactionIsolationLevel transactionIsolationLevel; 43 | 44 | private Isolation(TransactionIsolationLevel transactionIsolationLevel) { 45 | this.transactionIsolationLevel = transactionIsolationLevel; 46 | } 47 | 48 | public TransactionIsolationLevel getTransactionIsolationLevel() { 49 | return transactionIsolationLevel; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/configuration/settings/AggressiveLazyLoadingConfigurationSettingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import static org.mockito.Mockito.verify; 19 | 20 | import org.apache.ibatis.session.Configuration; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | import org.mockito.Mock; 24 | import org.mockito.junit.jupiter.MockitoExtension; 25 | 26 | @ExtendWith(MockitoExtension.class) 27 | class AggressiveLazyLoadingConfigurationSettingTest { 28 | @Mock 29 | private Configuration configuration; 30 | 31 | @Test 32 | void applyConfigurationSetting_True() { 33 | AggressiveLazyLoadingConfigurationSetting setting = new AggressiveLazyLoadingConfigurationSetting(true); 34 | setting.applyConfigurationSetting(configuration); 35 | verify(configuration).setAggressiveLazyLoading(true); 36 | } 37 | 38 | @Test 39 | void applyConfigurationSetting_False() { 40 | AggressiveLazyLoadingConfigurationSetting setting = new AggressiveLazyLoadingConfigurationSetting(false); 41 | setting.applyConfigurationSetting(configuration); 42 | verify(configuration).setAggressiveLazyLoading(false); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/configuration/settings/DefaultStatementTimeoutConfigurationSettingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import static org.mockito.Mockito.verify; 19 | 20 | import org.apache.ibatis.session.Configuration; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | import org.mockito.Mock; 24 | import org.mockito.junit.jupiter.MockitoExtension; 25 | 26 | @ExtendWith(MockitoExtension.class) 27 | class DefaultStatementTimeoutConfigurationSettingTest { 28 | @Mock 29 | private Configuration configuration; 30 | 31 | @Test 32 | void applyConfigurationSetting_20() { 33 | DefaultStatementTimeoutConfigurationSetting setting = new DefaultStatementTimeoutConfigurationSetting(20); 34 | setting.applyConfigurationSetting(configuration); 35 | verify(configuration).setDefaultStatementTimeout(20); 36 | } 37 | 38 | @Test 39 | void applyConfigurationSetting_100() { 40 | DefaultStatementTimeoutConfigurationSetting setting = new DefaultStatementTimeoutConfigurationSetting(100); 41 | setting.applyConfigurationSetting(configuration); 42 | verify(configuration).setDefaultStatementTimeout(100); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /.mvn/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | 24 | 25 | central 26 | ${env.CI_DEPLOY_USERNAME} 27 | ${env.CI_DEPLOY_PASSWORD} 28 | 29 | 30 | 31 | 32 | gh-pages-scm 33 | 34 | branch 35 | gh-pages 36 | 37 | 38 | 39 | 40 | 41 | github 42 | ${env.GITHUB_TOKEN} 43 | 44 | 45 | 46 | 47 | nvd 48 | ${env.NVD_API_KEY} 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/configuration/settings/MapUnderscoreToCamelCaseConfigurationSettingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import static org.mockito.Mockito.verify; 19 | 20 | import org.apache.ibatis.session.Configuration; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | import org.mockito.Mock; 24 | import org.mockito.junit.jupiter.MockitoExtension; 25 | 26 | @ExtendWith(MockitoExtension.class) 27 | class MapUnderscoreToCamelCaseConfigurationSettingTest { 28 | @Mock 29 | private Configuration configuration; 30 | 31 | @Test 32 | void applyConfigurationSetting_True() { 33 | MapUnderscoreToCamelCaseConfigurationSetting setting = new MapUnderscoreToCamelCaseConfigurationSetting(true); 34 | setting.applyConfigurationSetting(configuration); 35 | verify(configuration).setMapUnderscoreToCamelCase(true); 36 | } 37 | 38 | @Test 39 | void applyConfigurationSetting_False() { 40 | MapUnderscoreToCamelCaseConfigurationSetting setting = new MapUnderscoreToCamelCaseConfigurationSetting(false); 41 | setting.applyConfigurationSetting(configuration); 42 | verify(configuration).setMapUnderscoreToCamelCase(false); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/session/SqlSessionFactoryProviderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.session; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | import static org.junit.jupiter.api.Assertions.assertNotNull; 20 | 21 | import org.apache.ibatis.session.Configuration; 22 | import org.apache.ibatis.session.SqlSessionFactory; 23 | import org.junit.jupiter.api.BeforeEach; 24 | import org.junit.jupiter.api.Test; 25 | import org.junit.jupiter.api.extension.ExtendWith; 26 | import org.mockito.Mock; 27 | import org.mockito.junit.jupiter.MockitoExtension; 28 | 29 | @ExtendWith(MockitoExtension.class) 30 | class SqlSessionFactoryProviderTest { 31 | private SqlSessionFactoryProvider sqlSessionFactoryProvider; 32 | @Mock 33 | private Configuration configuration; 34 | 35 | @BeforeEach 36 | void beforeTest() { 37 | sqlSessionFactoryProvider = new SqlSessionFactoryProvider(); 38 | sqlSessionFactoryProvider.createNewSqlSessionFactory(configuration); 39 | } 40 | 41 | @Test 42 | void get() { 43 | SqlSessionFactory sqlSessionFactory = sqlSessionFactoryProvider.get(); 44 | 45 | assertNotNull(sqlSessionFactory); 46 | assertEquals(configuration, sqlSessionFactory.getConfiguration()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/session/SqlSessionManagerProviderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.session; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertNotNull; 19 | import static org.mockito.Mockito.verify; 20 | 21 | import org.apache.ibatis.session.SqlSessionFactory; 22 | import org.apache.ibatis.session.SqlSessionManager; 23 | import org.junit.jupiter.api.BeforeEach; 24 | import org.junit.jupiter.api.Test; 25 | import org.junit.jupiter.api.extension.ExtendWith; 26 | import org.mockito.Mock; 27 | import org.mockito.junit.jupiter.MockitoExtension; 28 | 29 | @ExtendWith(MockitoExtension.class) 30 | class SqlSessionManagerProviderTest { 31 | private SqlSessionManagerProvider sqlSessionManagerProvider; 32 | @Mock 33 | private SqlSessionFactory sqlSessionFactory; 34 | 35 | @BeforeEach 36 | void beforeTest() { 37 | sqlSessionManagerProvider = new SqlSessionManagerProvider(); 38 | sqlSessionManagerProvider.createNewSqlSessionManager(sqlSessionFactory); 39 | } 40 | 41 | @Test 42 | void get() { 43 | SqlSessionManager sqlSessionManager = sqlSessionManagerProvider.get(); 44 | 45 | assertNotNull(sqlSessionManager); 46 | sqlSessionManager.openSession(); 47 | verify(sqlSessionFactory).openSession(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/resources/mybatis-package-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/configuration/settings/MultipleResultSetsEnabledConfigurationSettingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2025 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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import static org.mockito.Mockito.verify; 19 | 20 | import org.apache.ibatis.session.Configuration; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | import org.mockito.Mock; 24 | import org.mockito.junit.jupiter.MockitoExtension; 25 | 26 | @Deprecated 27 | @ExtendWith(MockitoExtension.class) 28 | class MultipleResultSetsEnabledConfigurationSettingTest { 29 | @Mock 30 | private Configuration configuration; 31 | 32 | @Test 33 | void applyConfigurationSetting_True() { 34 | MultipleResultSetsEnabledConfigurationSetting setting = new MultipleResultSetsEnabledConfigurationSetting(true); 35 | setting.applyConfigurationSetting(configuration); 36 | verify(configuration).setMultipleResultSetsEnabled(true); 37 | } 38 | 39 | @Test 40 | void applyConfigurationSetting_False() { 41 | MultipleResultSetsEnabledConfigurationSetting setting = new MultipleResultSetsEnabledConfigurationSetting(false); 42 | setting.applyConfigurationSetting(configuration); 43 | verify(configuration).setMultipleResultSetsEnabled(false); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/Address.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice; 17 | 18 | public class Address { 19 | 20 | private Integer number; 21 | 22 | private String street; 23 | 24 | public String getStreet() { 25 | return street; 26 | } 27 | 28 | public void setStreet(String street) { 29 | this.street = street; 30 | } 31 | 32 | public Integer getNumber() { 33 | return number; 34 | } 35 | 36 | public void setNumber(Integer number) { 37 | this.number = number; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | StringBuilder builder = new StringBuilder(); 43 | builder.append(String.valueOf(number)); 44 | builder.append(" "); 45 | builder.append(street); 46 | return builder.toString(); 47 | } 48 | 49 | @Override 50 | public int hashCode() { 51 | return 2034997181 + number.hashCode() + street.hashCode(); 52 | } 53 | 54 | @Override 55 | public boolean equals(Object obj) { 56 | if (this == obj) { 57 | return true; 58 | } 59 | if (obj instanceof Address) { 60 | Address other = (Address) obj; 61 | boolean equals = this.number.equals(other.number); 62 | equals &= this.street.equals(other.street); 63 | return equals; 64 | } 65 | return false; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/configuration/settings/LocalCacheScopeConfigurationSettingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import static org.mockito.Mockito.verify; 19 | 20 | import org.apache.ibatis.session.Configuration; 21 | import org.apache.ibatis.session.LocalCacheScope; 22 | import org.junit.jupiter.api.Test; 23 | import org.junit.jupiter.api.extension.ExtendWith; 24 | import org.mockito.Mock; 25 | import org.mockito.junit.jupiter.MockitoExtension; 26 | 27 | @ExtendWith(MockitoExtension.class) 28 | class LocalCacheScopeConfigurationSettingTest { 29 | @Mock 30 | private Configuration configuration; 31 | 32 | @Test 33 | void applyConfigurationSetting_Session() { 34 | LocalCacheScopeConfigurationSetting setting = new LocalCacheScopeConfigurationSetting(LocalCacheScope.SESSION); 35 | setting.applyConfigurationSetting(configuration); 36 | verify(configuration).setLocalCacheScope(LocalCacheScope.SESSION); 37 | } 38 | 39 | @Test 40 | void applyConfigurationSetting_Statement() { 41 | LocalCacheScopeConfigurationSetting setting = new LocalCacheScopeConfigurationSetting(LocalCacheScope.STATEMENT); 42 | setting.applyConfigurationSetting(configuration); 43 | verify(configuration).setLocalCacheScope(LocalCacheScope.STATEMENT); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/datasource/helper/KeyResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.datasource.helper; 17 | 18 | import static com.google.inject.name.Names.named; 19 | 20 | import com.google.inject.Injector; 21 | import com.google.inject.Key; 22 | 23 | import jakarta.inject.Inject; 24 | import jakarta.inject.Provider; 25 | 26 | final class KeyResolver implements Provider { 27 | 28 | private final Key key; 29 | 30 | private final String defaultValue; 31 | 32 | private final String toString; 33 | 34 | @Inject 35 | private Injector injector; 36 | 37 | public KeyResolver(final String key, final String defaultValue) { 38 | this.key = Key.get(String.class, named(key)); 39 | this.defaultValue = defaultValue; 40 | toString = "${" + key + "}"; 41 | } 42 | 43 | public void setInjector(Injector injector) { 44 | this.injector = injector; 45 | } 46 | 47 | /** 48 | * {@inheritDoc} 49 | */ 50 | @Override 51 | public String get() { 52 | try { 53 | return injector.getInstance(key); 54 | } catch (Throwable e) { 55 | if (defaultValue != null) { 56 | return defaultValue; 57 | } 58 | return toString; 59 | } 60 | } 61 | 62 | @Override 63 | public String toString() { 64 | return toString; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/mappers/MapperProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.mappers; 17 | 18 | import jakarta.inject.Inject; 19 | import jakarta.inject.Provider; 20 | 21 | import java.util.Objects; 22 | 23 | import org.apache.ibatis.session.SqlSessionManager; 24 | 25 | /** 26 | * A generic MyBatis mapper provider. 27 | */ 28 | public final class MapperProvider implements Provider { 29 | 30 | private final Class mapperType; 31 | 32 | @Inject 33 | private SqlSessionManager sqlSessionManager; 34 | 35 | public MapperProvider(Class mapperType) { 36 | this.mapperType = mapperType; 37 | } 38 | 39 | public void setSqlSessionManager(SqlSessionManager sqlSessionManager) { 40 | this.sqlSessionManager = sqlSessionManager; 41 | } 42 | 43 | @Override 44 | public T get() { 45 | return this.sqlSessionManager.getMapper(mapperType); 46 | } 47 | 48 | @Override 49 | public int hashCode() { 50 | return Objects.hashCode(this.mapperType); 51 | } 52 | 53 | @Override 54 | public boolean equals(Object obj) { 55 | if (obj == null) { 56 | return false; 57 | } 58 | if (this.getClass() != obj.getClass()) { 59 | return false; 60 | } 61 | MapperProvider other = (MapperProvider) obj; 62 | return Objects.equals(this.mapperType, other.mapperType); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/mappers/MapperProviderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.mappers; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertNotNull; 19 | import static org.mockito.Mockito.verify; 20 | import static org.mockito.Mockito.when; 21 | 22 | import org.apache.ibatis.session.SqlSessionManager; 23 | import org.junit.jupiter.api.BeforeEach; 24 | import org.junit.jupiter.api.Test; 25 | import org.junit.jupiter.api.extension.ExtendWith; 26 | import org.mockito.Mock; 27 | import org.mockito.junit.jupiter.MockitoExtension; 28 | 29 | @ExtendWith(MockitoExtension.class) 30 | class MapperProviderTest { 31 | private MapperProvider mapperProvider; 32 | @Mock 33 | private SqlSessionManager sqlSessionManager; 34 | private TestMapper mapper; 35 | 36 | @BeforeEach 37 | void beforeTest() { 38 | mapperProvider = new MapperProvider(TestMapper.class); 39 | mapperProvider.setSqlSessionManager(sqlSessionManager); 40 | mapper = new TestMapper(); 41 | when(sqlSessionManager.getMapper(TestMapper.class)).thenReturn(mapper); 42 | } 43 | 44 | @Test 45 | void get() { 46 | TestMapper mapper = mapperProvider.get(); 47 | assertNotNull(mapper); 48 | verify(sqlSessionManager).getMapper(TestMapper.class); 49 | } 50 | 51 | private static class TestMapper { 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/environment/EnvironmentProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.environment; 17 | 18 | import jakarta.inject.Inject; 19 | import jakarta.inject.Named; 20 | import jakarta.inject.Provider; 21 | import jakarta.inject.Singleton; 22 | 23 | import javax.sql.DataSource; 24 | 25 | import org.apache.ibatis.mapping.Environment; 26 | import org.apache.ibatis.transaction.TransactionFactory; 27 | 28 | /** 29 | * Provides the myBatis Environment. 30 | */ 31 | @Singleton 32 | public final class EnvironmentProvider implements Provider { 33 | 34 | /** 35 | * The environment id. 36 | */ 37 | @Inject 38 | @Named("mybatis.environment.id") 39 | private String id; 40 | 41 | @Inject 42 | private TransactionFactory transactionFactory; 43 | 44 | @Inject 45 | private DataSource dataSource; 46 | 47 | public void setId(String id) { 48 | this.id = id; 49 | } 50 | 51 | public void setTransactionFactory(TransactionFactory transactionFactory) { 52 | this.transactionFactory = transactionFactory; 53 | } 54 | 55 | public void setDataSource(DataSource dataSource) { 56 | this.dataSource = dataSource; 57 | } 58 | 59 | /** 60 | * {@inheritDoc} 61 | */ 62 | @Override 63 | public Environment get() { 64 | return new Environment(id, transactionFactory, dataSource); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/session/SqlSessionManagerProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.session; 17 | 18 | import static org.apache.ibatis.session.SqlSessionManager.newInstance; 19 | 20 | import jakarta.inject.Inject; 21 | import jakarta.inject.Provider; 22 | import jakarta.inject.Singleton; 23 | 24 | import org.apache.ibatis.session.SqlSessionFactory; 25 | import org.apache.ibatis.session.SqlSessionManager; 26 | 27 | @Singleton 28 | public final class SqlSessionManagerProvider implements Provider { 29 | 30 | private SqlSessionManager sqlSessionManager; 31 | 32 | /** 33 | * @since 1.0.1 34 | */ 35 | public SqlSessionManagerProvider() { 36 | // do nothing 37 | } 38 | 39 | @Deprecated 40 | public SqlSessionManagerProvider(SqlSessionFactory sqlSessionFactory) { 41 | this.sqlSessionManager = newInstance(sqlSessionFactory); 42 | } 43 | 44 | /** 45 | * Creates the new sql session manager. 46 | * 47 | * @param sqlSessionFactory 48 | * the sql session factory 49 | * 50 | * @since 1.0.1 51 | */ 52 | @Inject 53 | public void createNewSqlSessionManager(SqlSessionFactory sqlSessionFactory) { 54 | this.sqlSessionManager = newInstance(sqlSessionFactory); 55 | } 56 | 57 | @Override 58 | public SqlSessionManager get() { 59 | return sqlSessionManager; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/sample/service/FooServiceDaoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.sample.service; 17 | 18 | import jakarta.inject.Inject; 19 | 20 | import org.mybatis.guice.CustomException; 21 | import org.mybatis.guice.sample.dao.UserDao; 22 | import org.mybatis.guice.sample.domain.User; 23 | import org.mybatis.guice.transactional.Isolation; 24 | import org.mybatis.guice.transactional.Transactional; 25 | 26 | /** 27 | * Impl of the FooService. 28 | *

29 | * FooService simply receives a userId and uses a mapper/dao to get a record from the database. 30 | */ 31 | @Transactional(rethrowExceptionsAs = CustomException.class) 32 | public class FooServiceDaoImpl implements FooService { 33 | 34 | private UserDao userDao; 35 | 36 | @Inject 37 | public void setUserDao(UserDao userDao) { 38 | this.userDao = userDao; 39 | } 40 | 41 | @Override 42 | @Transactional(isolation = Isolation.SERIALIZABLE) 43 | public User doSomeBusinessStuff(String userId) { 44 | return this.userDao.getUser(userId); 45 | } 46 | 47 | @Override 48 | @Transactional(isolation = Isolation.SERIALIZABLE, rethrowExceptionsAs = IllegalArgumentException.class) 49 | public void brokenInsert(User user) { 50 | this.userDao.brokenInsert(user); 51 | } 52 | 53 | @Override 54 | public void brokenInsert2(User user) { 55 | this.userDao.brokenInsert(user); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/CustomType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2025 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 | package org.mybatis.guice; 17 | 18 | public class CustomType { 19 | 20 | private Long value; 21 | 22 | public CustomType() { 23 | } 24 | 25 | public CustomType(long currentTimeMillis) { 26 | setValue(currentTimeMillis); 27 | } 28 | 29 | /** 30 | * @return the value 31 | */ 32 | public Long getValue() { 33 | return value; 34 | } 35 | 36 | /** 37 | * @param value 38 | * the value to set 39 | */ 40 | public void setValue(Long value) { 41 | this.value = value; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return value != null ? value.toString() : null; 47 | } 48 | 49 | @Override 50 | public int hashCode() { 51 | final int prime = 31; 52 | int result = 1; 53 | result = prime * result + ((value == null) ? 0 : value.hashCode()); 54 | return result; 55 | } 56 | 57 | @Override 58 | public boolean equals(Object obj) { 59 | if (this == obj) 60 | return true; 61 | if (obj == null) 62 | return false; 63 | if (getClass() != obj.getClass()) 64 | return false; 65 | CustomType other = (CustomType) obj; 66 | if (value == null) { 67 | if (other.value != null) 68 | return false; 69 | } else if (Math.abs(value - other.value) > 5) 70 | return false; 71 | return true; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/sample/service/FooServiceMapperImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2023 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 | package org.mybatis.guice.sample.service; 17 | 18 | import jakarta.inject.Inject; 19 | 20 | import org.mybatis.guice.CustomException; 21 | import org.mybatis.guice.sample.domain.User; 22 | import org.mybatis.guice.sample.mapper.UserMapper; 23 | import org.mybatis.guice.transactional.Isolation; 24 | import org.mybatis.guice.transactional.Transactional; 25 | 26 | /** 27 | * Impl of the FooService. 28 | *

29 | * FooService simply receives a userId and uses a mapper/dao to get a record from the database. 30 | */ 31 | @Transactional(isolation = Isolation.SERIALIZABLE, rethrowExceptionsAs = CustomException.class) 32 | public class FooServiceMapperImpl implements FooService { 33 | 34 | private UserMapper userMapper; 35 | 36 | @Inject 37 | public void setUserMapper(UserMapper userMapper) { 38 | this.userMapper = userMapper; 39 | } 40 | 41 | @Override 42 | public User doSomeBusinessStuff(String userId) { 43 | return this.userMapper.getUser(userId); 44 | } 45 | 46 | @Override 47 | @Transactional(isolation = Isolation.SERIALIZABLE, rethrowExceptionsAs = IllegalArgumentException.class) 48 | public void brokenInsert(User user) { 49 | this.userMapper.brokenAdd(user); 50 | } 51 | 52 | @Override 53 | public void brokenInsert2(User user) { 54 | this.userMapper.brokenAdd(user); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/mybatis/guice/binder/TypeHandlerBinder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.binder; 17 | 18 | import com.google.inject.TypeLiteral; 19 | 20 | import org.apache.ibatis.type.TypeHandler; 21 | 22 | /** 23 | * Bind the given {@code TypeHandler} to an already defined type. 24 | */ 25 | public interface TypeHandlerBinder { 26 | 27 | /** 28 | * Bind the given {@code TypeHandler} to an already defined type. 29 | * 30 | * @param handler 31 | * The {@code TypeHandler} has to be bound 32 | */ 33 | void with(Class> handler); 34 | 35 | /** 36 | * Bind the given {@code TypeHandler} to an already defined type. 37 | * 38 | * @param handler 39 | * The {@code TypeHandler} has to be bound 40 | */ 41 | void with(TypeLiteral> handler); 42 | 43 | /** 44 | * Bind the given {@code TypeHandler} to an already defined type. 45 | * 46 | * @param handler 47 | * The {@code TypeHandler} has to be bound 48 | */ 49 | void withProvidedTypeHandler(Class> handler); 50 | 51 | /** 52 | * Bind the given {@code TypeHandler} to an already defined type. 53 | * 54 | * @param handler 55 | * The {@code TypeHandler} has to be bound 56 | */ 57 | void withProvidedTypeHandler(TypeLiteral> handler); 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/environment/EnvironmentProviderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.environment; 17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; 19 | 20 | import javax.sql.DataSource; 21 | 22 | import org.apache.ibatis.mapping.Environment; 23 | import org.apache.ibatis.transaction.TransactionFactory; 24 | import org.junit.jupiter.api.BeforeEach; 25 | import org.junit.jupiter.api.Test; 26 | import org.junit.jupiter.api.extension.ExtendWith; 27 | import org.mockito.Mock; 28 | import org.mockito.junit.jupiter.MockitoExtension; 29 | 30 | @ExtendWith(MockitoExtension.class) 31 | class EnvironmentProviderTest { 32 | private EnvironmentProvider environmentProvider; 33 | private String id; 34 | @Mock 35 | private DataSource dataSource; 36 | @Mock 37 | private TransactionFactory transactionFactory; 38 | 39 | @BeforeEach 40 | void beforeTest() { 41 | environmentProvider = new EnvironmentProvider(); 42 | id = "test environment"; 43 | environmentProvider.setId(id); 44 | environmentProvider.setDataSource(dataSource); 45 | environmentProvider.setTransactionFactory(transactionFactory); 46 | } 47 | 48 | @Test 49 | void get() { 50 | Environment environment = environmentProvider.get(); 51 | assertEquals(id, environment.getId()); 52 | assertEquals(dataSource, environment.getDataSource()); 53 | assertEquals(transactionFactory, environment.getTransactionFactory()); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/mybatis/guice/configuration/settings/DefaultScriptingLanguageTypeConfigurationSettingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-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 | package org.mybatis.guice.configuration.settings; 17 | 18 | import static org.mockito.Mockito.verify; 19 | 20 | import org.apache.ibatis.scripting.defaults.RawLanguageDriver; 21 | import org.apache.ibatis.scripting.xmltags.XMLLanguageDriver; 22 | import org.apache.ibatis.session.Configuration; 23 | import org.junit.jupiter.api.Test; 24 | import org.junit.jupiter.api.extension.ExtendWith; 25 | import org.mockito.Mock; 26 | import org.mockito.junit.jupiter.MockitoExtension; 27 | 28 | @ExtendWith(MockitoExtension.class) 29 | class DefaultScriptingLanguageTypeConfigurationSettingTest { 30 | @Mock 31 | private Configuration configuration; 32 | 33 | @Test 34 | void applyConfigurationSetting_Raw() { 35 | DefaultScriptingLanguageTypeConfigurationSetting setting = new DefaultScriptingLanguageTypeConfigurationSetting( 36 | RawLanguageDriver.class); 37 | setting.applyConfigurationSetting(configuration); 38 | verify(configuration).setDefaultScriptingLanguage(RawLanguageDriver.class); 39 | } 40 | 41 | @Test 42 | void applyConfigurationSetting_Xml() { 43 | DefaultScriptingLanguageTypeConfigurationSetting setting = new DefaultScriptingLanguageTypeConfigurationSetting( 44 | XMLLanguageDriver.class); 45 | setting.applyConfigurationSetting(configuration); 46 | verify(configuration).setDefaultScriptingLanguage(XMLLanguageDriver.class); 47 | } 48 | } 49 | --------------------------------------------------------------------------------