diff --git a/src/main/java/org/apache/ibatis/session/Configuration.java b/src/main/java/org/apache/ibatis/session/Configuration.java index 7c53ccac507..db86def2263 100644 --- a/src/main/java/org/apache/ibatis/session/Configuration.java +++ b/src/main/java/org/apache/ibatis/session/Configuration.java @@ -784,8 +784,10 @@ protected void buildAllStatements() { } if (!incompleteStatements.isEmpty()) { synchronized (incompleteStatements) { - // This always throws a BuilderException. - incompleteStatements.iterator().next().parseStatementNode(); + incompleteStatements.removeIf(x -> { + x.parseStatementNode(); + return true; + }); } } if (!incompleteMethods.isEmpty()) { diff --git a/src/test/java/org/apache/ibatis/submitted/resolution/CreateDB.sql b/src/test/java/org/apache/ibatis/submitted/resolution/CreateDB.sql new file mode 100644 index 00000000000..f035d197d0f --- /dev/null +++ b/src/test/java/org/apache/ibatis/submitted/resolution/CreateDB.sql @@ -0,0 +1,26 @@ +-- +-- Copyright 2009-2018 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. +-- + +drop table users if exists; + +create table users ( + id int, + name varchar(20) +); + +insert into users (id, name) values +(1, 'User1'), +(2, 'User2'); diff --git a/src/test/java/org/apache/ibatis/submitted/resolution/User.java b/src/test/java/org/apache/ibatis/submitted/resolution/User.java new file mode 100644 index 00000000000..2f362170757 --- /dev/null +++ b/src/test/java/org/apache/ibatis/submitted/resolution/User.java @@ -0,0 +1,40 @@ +/** + * Copyright 2009-2018 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.apache.ibatis.submitted.resolution; + +import java.io.Serializable; + +public class User implements Serializable { + private static final long serialVersionUID = 1L; + private Integer id; + private String name; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/src/test/java/org/apache/ibatis/submitted/resolution/cachereffromxml/CacheRefFromXmlTest.java b/src/test/java/org/apache/ibatis/submitted/resolution/cachereffromxml/CacheRefFromXmlTest.java new file mode 100644 index 00000000000..5471eb7bc1e --- /dev/null +++ b/src/test/java/org/apache/ibatis/submitted/resolution/cachereffromxml/CacheRefFromXmlTest.java @@ -0,0 +1,60 @@ +/** + * Copyright 2009-2018 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.apache.ibatis.submitted.resolution.cachereffromxml; + +import java.io.Reader; + +import org.apache.ibatis.BaseDataTest; +import org.apache.ibatis.io.Resources; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.ibatis.session.SqlSessionFactoryBuilder; +import org.apache.ibatis.submitted.resolution.User; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class CacheRefFromXmlTest { + + private static SqlSessionFactory sqlSessionFactory; + + @BeforeClass + public static void setUp() throws Exception { + // create an SqlSessionFactory + try (Reader reader = Resources + .getResourceAsReader("org/apache/ibatis/submitted/resolution/cachereffromxml/mybatis-config.xml")) { + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + } + + // populate in-memory database + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/resolution/CreateDB.sql"); + } + + @Test + public void shouldGetAUser() { + SqlSession sqlSession = sqlSessionFactory.openSession(); + try { + UserMapper mapper = sqlSession.getMapper(UserMapper.class); + User user = mapper.getUser(1); + Assert.assertEquals(Integer.valueOf(1), user.getId()); + Assert.assertEquals("User1", user.getName()); + } finally { + sqlSession.close(); + } + } + +} diff --git a/src/test/java/org/apache/ibatis/submitted/resolution/cachereffromxml/UserMapper.java b/src/test/java/org/apache/ibatis/submitted/resolution/cachereffromxml/UserMapper.java new file mode 100644 index 00000000000..1869483138e --- /dev/null +++ b/src/test/java/org/apache/ibatis/submitted/resolution/cachereffromxml/UserMapper.java @@ -0,0 +1,24 @@ +/** + * Copyright 2009-2018 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.apache.ibatis.submitted.resolution.cachereffromxml; + +import org.apache.ibatis.annotations.CacheNamespace; +import org.apache.ibatis.submitted.resolution.User; + +@CacheNamespace +public interface UserMapper { + User getUser(Integer id); +} diff --git a/src/test/java/org/apache/ibatis/submitted/resolution/cachereffromxml/UserMapper.xml b/src/test/java/org/apache/ibatis/submitted/resolution/cachereffromxml/UserMapper.xml new file mode 100644 index 00000000000..301a8dd03fe --- /dev/null +++ b/src/test/java/org/apache/ibatis/submitted/resolution/cachereffromxml/UserMapper.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + diff --git a/src/test/java/org/apache/ibatis/submitted/resolution/cachereffromxml/mybatis-config.xml b/src/test/java/org/apache/ibatis/submitted/resolution/cachereffromxml/mybatis-config.xml new file mode 100644 index 00000000000..74a96392a28 --- /dev/null +++ b/src/test/java/org/apache/ibatis/submitted/resolution/cachereffromxml/mybatis-config.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + +