diff --git a/src/test/java/mybatis-velocity.properties b/src/test/java/mybatis-velocity.properties index 1371add..e8e3956 100644 --- a/src/test/java/mybatis-velocity.properties +++ b/src/test/java/mybatis-velocity.properties @@ -1,2 +1,2 @@ -additional.context.attributes=trailingWildCardFormatter:org.mybatis.scripting.velocity.use.TrailingWildCardFormatter +additional.context.attributes=trailingWildCardFormatter:org.mybatis.scripting.velocity.use.TrailingWildCardFormatter,enumBinder:org.mybatis.scripting.velocity.use.EnumBinder userdirective=org.mybatis.scripting.velocity.use.CustomUserDirective \ No newline at end of file diff --git a/src/test/java/org/mybatis/scripting/velocity/use/EnumBinder.java b/src/test/java/org/mybatis/scripting/velocity/use/EnumBinder.java new file mode 100644 index 0000000..eaf8987 --- /dev/null +++ b/src/test/java/org/mybatis/scripting/velocity/use/EnumBinder.java @@ -0,0 +1,28 @@ +/* + * Copyright 2013 MyBatis.org. + * + * 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.velocity.use; + +/** + * + * @author mnesarco + */ +public class EnumBinder { + + public EnumWrapper bind(String className) throws ClassNotFoundException { + return new EnumWrapper(Class.forName(className)); + } + +} diff --git a/src/test/java/org/mybatis/scripting/velocity/use/EnumWrapper.java b/src/test/java/org/mybatis/scripting/velocity/use/EnumWrapper.java new file mode 100644 index 0000000..cc42d68 --- /dev/null +++ b/src/test/java/org/mybatis/scripting/velocity/use/EnumWrapper.java @@ -0,0 +1,38 @@ +/* + * Copyright 2013 MyBatis.org. + * + * 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.velocity.use; + +import java.util.HashMap; + +/** + * + * @author mnesarco + */ +public class EnumWrapper extends HashMap { + + public EnumWrapper(Class e) { + if (e.isEnum()) { + Object[] consts = e.getEnumConstants(); + for (int i = 0; i answer = sqlSession.selectList("org.mybatis.scripting.velocity.use.selectEnumBinding"); + assertEquals(3, answer.size()); + for (Name n : answer) { + assertEquals("Flintstone", n.getLastName()); + } + + } finally { + sqlSession.close(); + } + } + @Test public void testSelectNamesWithFormattedParamSafe() { SqlSession sqlSession = sqlSessionFactory.openSession(); diff --git a/src/test/java/org/mybatis/scripting/velocity/use/mapper.xml b/src/test/java/org/mybatis/scripting/velocity/use/mapper.xml index 68c9580..6da2f5b 100644 --- a/src/test/java/org/mybatis/scripting/velocity/use/mapper.xml +++ b/src/test/java/org/mybatis/scripting/velocity/use/mapper.xml @@ -107,4 +107,12 @@ VALUES (@{firstName}, @{lastName}) + + \ No newline at end of file