diff --git a/.travis.yml b/.travis.yml index 18b5d53..61998f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,10 +6,10 @@ jdk: - oraclejdk8 script: - # build using mybatis latest version + # build using mybatis latest released version - ./mvnw clean verify - # build using mybatis 3.4.x line - - ./mvnw clean verify -Dmybatis.version=3.4.6 + # test using mybatis 3.4.x line + - ./mvnw test -Dmybatis.version=3.4.6 # build using mybatis 3.5.x snapshot - ./mvnw clean verify -Dmybatis.version=3.5.2-SNAPSHOT diff --git a/pom.xml b/pom.xml index 33ab245..1ba5bfe 100644 --- a/pom.xml +++ b/pom.xml @@ -117,6 +117,18 @@ + + + + maven-surefire-plugin + + + ${mybatis.version} + + + + + org.asciidoctor diff --git a/src/main/asciidoc/user-guide.adoc b/src/main/asciidoc/user-guide.adoc index 1ae0c93..6f5e43a 100644 --- a/src/main/asciidoc/user-guide.adoc +++ b/src/main/asciidoc/user-guide.adoc @@ -963,6 +963,71 @@ using <>. AND firstName LIKE #{patternFirstName} ESCAPE '\' ---- +== Support classes + +We provides useful classes for supporting development. + +=== TemplateFilePathProvider + +The `TemplateFilePathProvider` is SQL provider class that return the SQL template file path(Available since 1.0.1). +This class use with SQL provider annotation(`@InsertProvider`, `@UpdateProvider`, `@DeleteProvider` and `@SelectProvider`}) as follow: + +[NOTE] +==== +**This class required to use on MyBatis 3.5.1+.** +==== + +.Usage: + +[source, java] +---- +package com.example.mapper; + +public interface BaseMapper { + + @Options(useGeneratedKeys = true, keyProperty = "id") + @InsertProvider(type = TemplateFilePathProvider.class) + void insert(T entity); + + @UpdateProvider(type = TemplateFilePathProvider.class) + void update(T entity); + + @DeleteProvider(type = TemplateFilePathProvider.class) + void delete(T entity); + + @SelectProvider(type = TemplateFilePathProvider.class) + T findById(Integer id); + +} +---- + +[source, java] +---- +package com.example.mapper; + +public interface NameMapper extends BaseMapper { + + @SelectProvider(type = TemplateFilePathProvider.class) + List findByCondition(NameCondition condition); + +} +---- + +By default implementation, a template file path resolve following format and priority order. +If does not match all, it throw an exception that indicate not found a template file. + +* `com/example/mapper/NameMapper-{methodName}-{databaseId}.sql` +* `com/example/mapper/NameMapper-{methodName}.sql` + + (fallback using default database) +* `com/example/mapper/BaseMapper-{methodName}-{databaseId}.sql` + + (fallback using declaring class of mapper method) +* `com/example/mapper/BaseMapper-{methodName}.sql` + + (fallback using declaring class of mapper method and default database) + +If you want to customize the template file path format(e.g. `com/example/mapper/NameMapper/{methodName}-{databaseId}.sql`), +please specify a custom implementation of the `TemplateFilePathGenerator` +using `TemplateFilePathProvider#setCustomTemplateFilePathGenerator` method **before initialize the MyBatis module**. + == Cautions for usage diff --git a/src/main/java/org/mybatis/scripting/thymeleaf/support/TemplateFilePathProvider.java b/src/main/java/org/mybatis/scripting/thymeleaf/support/TemplateFilePathProvider.java new file mode 100644 index 0000000..c01890f --- /dev/null +++ b/src/main/java/org/mybatis/scripting/thymeleaf/support/TemplateFilePathProvider.java @@ -0,0 +1,174 @@ +/** + * Copyright 2018-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mybatis.scripting.thymeleaf.support; + +import java.io.IOException; +import java.lang.reflect.Method; +import java.util.Optional; + +import org.apache.ibatis.builder.annotation.ProviderContext; +import org.apache.ibatis.io.Resources; + +/** + * The SQL provider class that return the SQL template file path.
+ * IMPORTANT: This class required to use with mybatis 3.5.1+ and need to use with SQL provider annotation (such + * as {@link org.apache.ibatis.annotations.SelectProvider} as follow:
+ *
+ * + *
+ * package com.example.mapper;
+ *
+ * public interface BaseMapper<T> {
+ *
+ *   @Options(useGeneratedKeys = true, keyProperty = "id")
+ *   @InsertProvider(type = TemplateFilePathProvider.class)
+ *   void insert(T entity);
+ *
+ *   @UpdateProvider(type = TemplateFilePathProvider.class)
+ *   void update(T entity);
+ *
+ *   @DeleteProvider(type = TemplateFilePathProvider.class)
+ *   void delete(T entity);
+ *
+ *   @SelectProvider(type = TemplateFilePathProvider.class)
+ *   T findById(Integer id);
+ *
+ * }
+ * 
+ * + *
+ * package com.example.mapper;
+ *
+ * public interface NameMapper extends BaseMapper {
+ *
+ *   @SelectProvider(type = TemplateFilePathProvider.class)
+ *   List<Name> findByConditions(NameConditions conditions);
+ *
+ * }
+ * 
+ * + * @author Kazuki Shimizu + * @version 1.0.1 + */ +public class TemplateFilePathProvider { + + private static TemplateFilePathGenerator generator = TemplateFilePathProvider::generatePath; + + /** + * Set custom implementation for {@link TemplateFilePathGenerator}. + * + * @param customGenerator + * a instance for generating a template file path + */ + public static void setCustomTemplateFilePathGenerator(TemplateFilePathGenerator customGenerator) { + generator = Optional.ofNullable(customGenerator).orElse(TemplateFilePathProvider::generatePath); + } + + /** + * Provide an SQL scripting string(template file path). + * + *
+ * By default implementation, a template file path resolve following format and priority order. If does not match all, + * it throw an exception that indicate not found a template file. + *
    + *
  • com/example/mapper/NameMapper-{methodName}-{databaseId}.sql
  • + *
  • com/example/mapper/NameMapper-{methodName}.sql (fallback using default database)
  • + *
  • com/example/mapper/BaseMapper-{methodName}-{databaseId}.sql (fallback using declaring class of method)
  • + *
  • com/example/mapper/BaseMapper-{methodName}.sql (fallback using declaring class of method and default + * database)
  • + *
+ *
+ * If you want to customize path format, please call the + * {@link #setCustomTemplateFilePathGenerator(TemplateFilePathGenerator)} on application initialize phase. + * + * @param context + * a context of SQL provider + * @return an SQL scripting string(template file path) + */ + public static String provideSql(ProviderContext context) { + return providePath(context.getMapperType(), context.getMapperMethod(), context.getDatabaseId()); + } + + static String providePath(Class mapperType, Method mapperMethod, String databaseId) { + boolean fallbackDeclaringClass = mapperType != mapperMethod.getDeclaringClass(); + boolean fallbackDatabase = databaseId != null; + String path = generator.generatePath(mapperType, mapperMethod, databaseId); + if (exists(path)) { + return path; + } + if (fallbackDatabase) { + path = generator.generatePath(mapperType, mapperMethod, null); + if (exists(path)) { + return path; + } + } + if (fallbackDeclaringClass) { + path = generator.generatePath(mapperMethod.getDeclaringClass(), mapperMethod, databaseId); + if (exists(path)) { + return path; + } + } + if (fallbackDatabase) { + path = generator.generatePath(mapperMethod.getDeclaringClass(), mapperMethod, null); + if (exists(path)) { + return path; + } + } + throw new IllegalStateException("The SQL template file not found. mapperType:[" + mapperType + "] mapperMethod:[" + + mapperMethod + "] databaseId:[" + databaseId + "]"); + } + + private static String generatePath(Class type, Method method, String databaseId) { + StringBuilder path = new StringBuilder(); + path.append(type.getName().replace('.', '/')); + path.append("-").append(method.getName()); + if (databaseId != null) { + path.append("-").append(databaseId); + } + path.append(".sql"); + return path.toString(); + } + + private static boolean exists(String path) { + try { + return Resources.getResourceAsFile(path).exists(); + } catch (IOException e) { + return false; + } + } + + /** + * The interface that implements a function for generating template file path. + */ + @FunctionalInterface + public interface TemplateFilePathGenerator { + + /** + * Generate a template file path. + * + * @param type + * mapper interface type that specified provider (or declaring interface type of mapper method) + * @param method + * a mapper method that specified provider + * @param databaseId + * a database id that provided from {@link org.apache.ibatis.mapping.DatabaseIdProvider} + * @return a template file path + */ + String generatePath(Class type, Method method, String databaseId); + + } + +} diff --git a/src/main/java/org/mybatis/scripting/thymeleaf/support/package-info.java b/src/main/java/org/mybatis/scripting/thymeleaf/support/package-info.java new file mode 100644 index 0000000..f1675e6 --- /dev/null +++ b/src/main/java/org/mybatis/scripting/thymeleaf/support/package-info.java @@ -0,0 +1,19 @@ +/** + * Copyright 2018-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * The package that holds classes for supports development. + */ +package org.mybatis.scripting.thymeleaf.support; \ No newline at end of file diff --git a/src/test/java/org/mybatis/scripting/thymeleaf/integrationtest/TemplateFilePathProviderBasedMapperTest.java b/src/test/java/org/mybatis/scripting/thymeleaf/integrationtest/TemplateFilePathProviderBasedMapperTest.java new file mode 100644 index 0000000..8188b13 --- /dev/null +++ b/src/test/java/org/mybatis/scripting/thymeleaf/integrationtest/TemplateFilePathProviderBasedMapperTest.java @@ -0,0 +1,123 @@ +/** + * Copyright 2018-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mybatis.scripting.thymeleaf.integrationtest; + +import java.io.Reader; +import java.sql.Connection; + +import org.apache.ibatis.io.Resources; +import org.apache.ibatis.jdbc.ScriptRunner; +import org.apache.ibatis.mapping.Environment; +import org.apache.ibatis.session.Configuration; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.ibatis.session.SqlSessionFactoryBuilder; +import org.apache.ibatis.transaction.TransactionFactory; +import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; +import org.hsqldb.jdbc.JDBCDataSource; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledIfSystemProperty; +import org.mybatis.scripting.thymeleaf.ThymeleafLanguageDriver; +import org.mybatis.scripting.thymeleaf.integrationtest.domain.Name; +import org.mybatis.scripting.thymeleaf.integrationtest.mapper.TemplateFilePathProviderBasedMapper; + +@DisabledIfSystemProperty(named = "mybatis.version", matches = "3\\.4\\..*|3\\.5\\.0") +class TemplateFilePathProviderBasedMapperTest { + private static SqlSessionFactory sqlSessionFactory; + + @BeforeAll + static void setUp() throws Exception { + Class.forName("org.hsqldb.jdbcDriver"); + JDBCDataSource dataSource = new JDBCDataSource(); + dataSource.setUrl("jdbc:hsqldb:mem:db1"); + dataSource.setUser("sa"); + dataSource.setPassword(""); + + try (Connection conn = dataSource.getConnection()) { + try (Reader reader = Resources.getResourceAsReader("create-db.sql")) { + ScriptRunner runner = new ScriptRunner(conn); + runner.setLogWriter(null); + runner.setErrorLogWriter(null); + runner.runScript(reader); + conn.commit(); + } + } + + TransactionFactory transactionFactory = new JdbcTransactionFactory(); + Environment environment = new Environment("development", transactionFactory, dataSource); + + Configuration configuration = new Configuration(environment); + configuration.setMapUnderscoreToCamelCase(true); + configuration.setDefaultScriptingLanguage(ThymeleafLanguageDriver.class); + + configuration.addMapper(TemplateFilePathProviderBasedMapper.class); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); + } + + @Test + void testInsert() { + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { + TemplateFilePathProviderBasedMapper mapper = sqlSession.getMapper(TemplateFilePathProviderBasedMapper.class); + Name name = new Name(); + name.setFirstName("Thymeleaf"); + name.setLastName("MyBatis"); + mapper.insert(name); + + Name loadedName = mapper.findById(name.getId()); + Assertions.assertEquals(name.getFirstName(), loadedName.getFirstName()); + Assertions.assertEquals(name.getLastName(), loadedName.getLastName()); + } + } + + @Test + void testUpdate() { + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { + TemplateFilePathProviderBasedMapper mapper = sqlSession.getMapper(TemplateFilePathProviderBasedMapper.class); + Name name = new Name(); + name.setFirstName("Thymeleaf"); + name.setLastName("MyBatis"); + mapper.insert(name); + + Name updatingName = new Name(); + updatingName.setId(name.getId()); + updatingName.setFirstName("Thymeleaf3"); + mapper.update(updatingName); + + Name loadedName = mapper.findById(name.getId()); + Assertions.assertEquals(updatingName.getFirstName(), loadedName.getFirstName()); + Assertions.assertEquals(name.getLastName(), loadedName.getLastName()); + } + } + + @Test + void testDelete() { + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { + TemplateFilePathProviderBasedMapper mapper = sqlSession.getMapper(TemplateFilePathProviderBasedMapper.class); + Name name = new Name(); + name.setFirstName("Thymeleaf"); + name.setLastName("MyBatis"); + mapper.insert(name); + + mapper.delete(name); + + Name loadedName = mapper.findById(name.getId()); + Assertions.assertNull(loadedName); + } + } + +} diff --git a/src/test/java/org/mybatis/scripting/thymeleaf/integrationtest/mapper/TemplateFilePathProviderBasedMapper.java b/src/test/java/org/mybatis/scripting/thymeleaf/integrationtest/mapper/TemplateFilePathProviderBasedMapper.java new file mode 100644 index 0000000..112b733 --- /dev/null +++ b/src/test/java/org/mybatis/scripting/thymeleaf/integrationtest/mapper/TemplateFilePathProviderBasedMapper.java @@ -0,0 +1,41 @@ +/** + * Copyright 2018-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mybatis.scripting.thymeleaf.integrationtest.mapper; + +import org.apache.ibatis.annotations.DeleteProvider; +import org.apache.ibatis.annotations.InsertProvider; +import org.apache.ibatis.annotations.Options; +import org.apache.ibatis.annotations.SelectProvider; +import org.apache.ibatis.annotations.UpdateProvider; +import org.mybatis.scripting.thymeleaf.integrationtest.domain.Name; +import org.mybatis.scripting.thymeleaf.support.TemplateFilePathProvider; + +public interface TemplateFilePathProviderBasedMapper { + + @Options(useGeneratedKeys = true, keyProperty = "id") + @InsertProvider(type = TemplateFilePathProvider.class) + void insert(Name name); + + @UpdateProvider(type = TemplateFilePathProvider.class) + void update(Name name); + + @DeleteProvider(type = TemplateFilePathProvider.class) + void delete(Name name); + + @SelectProvider(type = TemplateFilePathProvider.class) + Name findById(Integer id); + +} diff --git a/src/test/java/org/mybatis/scripting/thymeleaf/support/BaseMapper.java b/src/test/java/org/mybatis/scripting/thymeleaf/support/BaseMapper.java new file mode 100644 index 0000000..6bd3e82 --- /dev/null +++ b/src/test/java/org/mybatis/scripting/thymeleaf/support/BaseMapper.java @@ -0,0 +1,26 @@ +/** + * Copyright 2018-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mybatis.scripting.thymeleaf.support; + +public interface BaseMapper { + void insert(T model); + + void update(T model); + + long count(); + + T selectOne(int id); +} diff --git a/src/test/java/org/mybatis/scripting/thymeleaf/support/TemplateFilePathProviderTest.java b/src/test/java/org/mybatis/scripting/thymeleaf/support/TemplateFilePathProviderTest.java new file mode 100644 index 0000000..8adb469 --- /dev/null +++ b/src/test/java/org/mybatis/scripting/thymeleaf/support/TemplateFilePathProviderTest.java @@ -0,0 +1,103 @@ +/** + * Copyright 2018-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mybatis.scripting.thymeleaf.support; + +import java.lang.reflect.Method; +import java.util.Arrays; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledIfSystemProperty; + +@DisabledIfSystemProperty(named = "mybatis.version", matches = "3\\.4\\..*|3\\.5\\.0") +class TemplateFilePathProviderTest { + + @BeforeEach + @AfterEach + void clean() { + TemplateFilePathProvider.setCustomTemplateFilePathGenerator(null); + } + + @Test + void withoutDatabaseId() { + String path = TemplateFilePathProvider.providePath(TestMapper.class, extractMethod(TestMapper.class, "update"), + null); + Assertions.assertEquals("org/mybatis/scripting/thymeleaf/support/TestMapper-update.sql", path); + } + + @Test + void withDatabaseId() { + String path = TemplateFilePathProvider.providePath(TestMapper.class, extractMethod(TestMapper.class, "update"), + "h2"); + Assertions.assertEquals("org/mybatis/scripting/thymeleaf/support/TestMapper-update-h2.sql", path); + } + + @Test + void fallbackWithDefaultDatabase() { + String path = TemplateFilePathProvider.providePath(TestMapper.class, extractMethod(TestMapper.class, "delete"), + "h2"); + Assertions.assertEquals("org/mybatis/scripting/thymeleaf/support/TestMapper-delete.sql", path); + } + + @Test + void fallbackDeclaringClassWithoutDatabaseId() { + String path = TemplateFilePathProvider.providePath(TestMapper.class, extractMethod(TestMapper.class, "insert"), + null); + Assertions.assertEquals("org/mybatis/scripting/thymeleaf/support/BaseMapper-insert.sql", path); + } + + @Test + void fallbackDeclaringClassWithDatabaseId() { + String path = TemplateFilePathProvider.providePath(TestMapper.class, extractMethod(TestMapper.class, "insert"), + "h2"); + Assertions.assertEquals("org/mybatis/scripting/thymeleaf/support/BaseMapper-insert-h2.sql", path); + } + + @Test + void fallbackDeclaringClassAndDefaultDatabase() { + String path = TemplateFilePathProvider.providePath(TestMapper.class, extractMethod(TestMapper.class, "count"), + "h2"); + Assertions.assertEquals("org/mybatis/scripting/thymeleaf/support/BaseMapper-count.sql", path); + } + + @Test + void notFoundSqlFile() { + IllegalStateException e = Assertions.assertThrows(IllegalStateException.class, () -> { + TemplateFilePathProvider.providePath(TestMapper.class, extractMethod(TestMapper.class, "selectOne"), "h2"); + }); + Assertions.assertEquals( + "The SQL template file not found. mapperType:[interface org.mybatis.scripting.thymeleaf.support.TestMapper] mapperMethod:[public abstract java.lang.Object org.mybatis.scripting.thymeleaf.support.BaseMapper.selectOne(int)] databaseId:[h2]", + e.getMessage()); + } + + @Test + void customTemplateFileGenerator() { + TemplateFilePathProvider.setCustomTemplateFilePathGenerator( + (type, method, databaseId) -> type.getName().replace('.', '/') + "_" + method.getName() + ".sql"); + String path = TemplateFilePathProvider.providePath(TestMapper.class, extractMethod(TestMapper.class, "selectOne"), + null); + Assertions.assertEquals("org/mybatis/scripting/thymeleaf/support/BaseMapper_selectOne.sql", path); + + } + + private Method extractMethod(Class type, String methodName) { + return Arrays.stream(type.getMethods()).filter(m -> m.getName().equals(methodName)).findFirst().orElseThrow( + () -> new IllegalArgumentException("The method not found. type:" + type + " methodName:" + methodName)); + } + +} diff --git a/src/test/java/org/mybatis/scripting/thymeleaf/support/TestMapper.java b/src/test/java/org/mybatis/scripting/thymeleaf/support/TestMapper.java new file mode 100644 index 0000000..66d62e1 --- /dev/null +++ b/src/test/java/org/mybatis/scripting/thymeleaf/support/TestMapper.java @@ -0,0 +1,22 @@ +/** + * Copyright 2018-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mybatis.scripting.thymeleaf.support; + +import org.mybatis.scripting.thymeleaf.integrationtest.domain.Name; + +interface TestMapper extends BaseMapper { + void delete(int id); +} diff --git a/src/test/resources/org/mybatis/scripting/thymeleaf/integrationtest/mapper/TemplateFilePathProviderBasedMapper-delete.sql b/src/test/resources/org/mybatis/scripting/thymeleaf/integrationtest/mapper/TemplateFilePathProviderBasedMapper-delete.sql new file mode 100644 index 0000000..652e80a --- /dev/null +++ b/src/test/resources/org/mybatis/scripting/thymeleaf/integrationtest/mapper/TemplateFilePathProviderBasedMapper-delete.sql @@ -0,0 +1,18 @@ +-- +-- Copyright 2018-2019 the original author or authors. +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +DELETE FROM names + WHERE id = /*[# mb:p="id,typeHandler=org.apache.ibatis.type.IntegerTypeHandler"]*/ 1 /*[/]*/ diff --git a/src/test/resources/org/mybatis/scripting/thymeleaf/integrationtest/mapper/TemplateFilePathProviderBasedMapper-findById.sql b/src/test/resources/org/mybatis/scripting/thymeleaf/integrationtest/mapper/TemplateFilePathProviderBasedMapper-findById.sql new file mode 100644 index 0000000..dc4d1d9 --- /dev/null +++ b/src/test/resources/org/mybatis/scripting/thymeleaf/integrationtest/mapper/TemplateFilePathProviderBasedMapper-findById.sql @@ -0,0 +1,18 @@ +-- +-- Copyright 2018-2019 the original author or authors. +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +SELECT * FROM names + /*[# th:insert="~{sql/NameMapper/findByIdWhere.sql}" /]*/ diff --git a/src/test/resources/org/mybatis/scripting/thymeleaf/integrationtest/mapper/TemplateFilePathProviderBasedMapper-insert.sql b/src/test/resources/org/mybatis/scripting/thymeleaf/integrationtest/mapper/TemplateFilePathProviderBasedMapper-insert.sql new file mode 100644 index 0000000..d4189f3 --- /dev/null +++ b/src/test/resources/org/mybatis/scripting/thymeleaf/integrationtest/mapper/TemplateFilePathProviderBasedMapper-insert.sql @@ -0,0 +1,18 @@ +-- +-- Copyright 2018-2019 the original author or authors. +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +INSERT INTO names (firstName, lastName) + VALUES (/*[# mb:p="firstName"]*/ 'Taro' /*[/]*/, /*[# mb:p="lastName"]*/ 'Yamada' /*[/]*/) diff --git a/src/test/resources/org/mybatis/scripting/thymeleaf/integrationtest/mapper/TemplateFilePathProviderBasedMapper-update.sql b/src/test/resources/org/mybatis/scripting/thymeleaf/integrationtest/mapper/TemplateFilePathProviderBasedMapper-update.sql new file mode 100644 index 0000000..b05d3a0 --- /dev/null +++ b/src/test/resources/org/mybatis/scripting/thymeleaf/integrationtest/mapper/TemplateFilePathProviderBasedMapper-update.sql @@ -0,0 +1,25 @@ +-- +-- Copyright 2018-2019 the original author or authors. +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +UPDATE names + SET id = id + /*[# th:if="${firstName} != null"]*/ + ,firstName = /*[# mb:p="firstName"]*/ 'Taro' /*[/]*/ + /*[/]*/ + /*[# th:if="${lastName} != null"]*/ + ,lastName = /*[# mb:p="lastName"]*/ 'Yamada' /*[/]*/ + /*[/]*/ + WHERE id = /*[# mb:p="id"]*/ 1 /*[/]*/ diff --git a/src/test/resources/org/mybatis/scripting/thymeleaf/support/BaseMapper-count.sql b/src/test/resources/org/mybatis/scripting/thymeleaf/support/BaseMapper-count.sql new file mode 100644 index 0000000..06a28d5 --- /dev/null +++ b/src/test/resources/org/mybatis/scripting/thymeleaf/support/BaseMapper-count.sql @@ -0,0 +1,16 @@ +-- +-- Copyright 2018-2019 the original author or authors. +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + diff --git a/src/test/resources/org/mybatis/scripting/thymeleaf/support/BaseMapper-insert-h2.sql b/src/test/resources/org/mybatis/scripting/thymeleaf/support/BaseMapper-insert-h2.sql new file mode 100644 index 0000000..06a28d5 --- /dev/null +++ b/src/test/resources/org/mybatis/scripting/thymeleaf/support/BaseMapper-insert-h2.sql @@ -0,0 +1,16 @@ +-- +-- Copyright 2018-2019 the original author or authors. +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + diff --git a/src/test/resources/org/mybatis/scripting/thymeleaf/support/BaseMapper-insert.sql b/src/test/resources/org/mybatis/scripting/thymeleaf/support/BaseMapper-insert.sql new file mode 100644 index 0000000..06a28d5 --- /dev/null +++ b/src/test/resources/org/mybatis/scripting/thymeleaf/support/BaseMapper-insert.sql @@ -0,0 +1,16 @@ +-- +-- Copyright 2018-2019 the original author or authors. +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + diff --git a/src/test/resources/org/mybatis/scripting/thymeleaf/support/BaseMapper_selectOne.sql b/src/test/resources/org/mybatis/scripting/thymeleaf/support/BaseMapper_selectOne.sql new file mode 100644 index 0000000..06a28d5 --- /dev/null +++ b/src/test/resources/org/mybatis/scripting/thymeleaf/support/BaseMapper_selectOne.sql @@ -0,0 +1,16 @@ +-- +-- Copyright 2018-2019 the original author or authors. +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + diff --git a/src/test/resources/org/mybatis/scripting/thymeleaf/support/TestMapper-delete.sql b/src/test/resources/org/mybatis/scripting/thymeleaf/support/TestMapper-delete.sql new file mode 100644 index 0000000..06a28d5 --- /dev/null +++ b/src/test/resources/org/mybatis/scripting/thymeleaf/support/TestMapper-delete.sql @@ -0,0 +1,16 @@ +-- +-- Copyright 2018-2019 the original author or authors. +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + diff --git a/src/test/resources/org/mybatis/scripting/thymeleaf/support/TestMapper-update-h2.sql b/src/test/resources/org/mybatis/scripting/thymeleaf/support/TestMapper-update-h2.sql new file mode 100644 index 0000000..06a28d5 --- /dev/null +++ b/src/test/resources/org/mybatis/scripting/thymeleaf/support/TestMapper-update-h2.sql @@ -0,0 +1,16 @@ +-- +-- Copyright 2018-2019 the original author or authors. +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + diff --git a/src/test/resources/org/mybatis/scripting/thymeleaf/support/TestMapper-update.sql b/src/test/resources/org/mybatis/scripting/thymeleaf/support/TestMapper-update.sql new file mode 100644 index 0000000..06a28d5 --- /dev/null +++ b/src/test/resources/org/mybatis/scripting/thymeleaf/support/TestMapper-update.sql @@ -0,0 +1,16 @@ +-- +-- Copyright 2018-2019 the original author or authors. +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +