Author: cbegin Date: Mon Jul 27 02:28:46 2009 New Revision: 798012 URL: http://svn.apache.org/viewvc?rev=798012&view=rev Log: renamed "prefix" element to "trim"
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/TrimSqlNode.java - copied, changed from r795577, ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/PrefixSqlNode.java Removed: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/PrefixSqlNode.java Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/XMLStatementBuilder.java ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/SetSqlNode.java ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/WhereSqlNode.java ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/ibatis-3-mapper.dtd ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/builder/AuthorMapper.xml ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/builder/PostMapper.xml ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/builder/xml/dynamic/DynamicSqlSourceTest.java ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/session/SqlSessionTest.java ibatis/trunk/java/ibatis-3/version.properties Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/XMLStatementBuilder.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/XMLStatementBuilder.java?rev=798012&r1=798011&r2=798012&view=diff ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/XMLStatementBuilder.java (original) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/XMLStatementBuilder.java Mon Jul 27 02:28:46 2009 @@ -87,7 +87,7 @@ private Map<String, NodeHandler> nodeHandlers = new HashMap<String, NodeHandler>() { { put("include", new IncludeNodeHandler()); - put("prefix", new PrefixHandler()); + put("trim", new TrimHandler()); put("where", new WhereHandler()); put("set", new SetHandler()); put("foreach", new ForEachHandler()); @@ -162,14 +162,14 @@ } } - private class PrefixHandler implements NodeHandler { + private class TrimHandler implements NodeHandler { public void handleNode(XNode nodeToHandle, List<SqlNode> targetContents) { List<SqlNode> contents = parseDynamicTags(nodeToHandle); MixedSqlNode mixedSqlNode = new MixedSqlNode(contents); String with = nodeToHandle.getStringAttribute("with"); String overrides = nodeToHandle.getStringAttribute("overrides"); - PrefixSqlNode prefix = new PrefixSqlNode(mixedSqlNode, with, overrides); - targetContents.add(prefix); + TrimSqlNode trim = new TrimSqlNode(mixedSqlNode, with, overrides); + targetContents.add(trim); } } Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/SetSqlNode.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/SetSqlNode.java?rev=798012&r1=798011&r2=798012&view=diff ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/SetSqlNode.java (original) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/SetSqlNode.java Mon Jul 27 02:28:46 2009 @@ -1,6 +1,6 @@ package org.apache.ibatis.builder.xml.dynamic; -public class SetSqlNode extends PrefixSqlNode { +public class SetSqlNode extends TrimSqlNode { public SetSqlNode(SqlNode contents) { super(contents, "SET", ","); Copied: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/TrimSqlNode.java (from r795577, ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/PrefixSqlNode.java) URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/TrimSqlNode.java?p2=ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/TrimSqlNode.java&p1=ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/PrefixSqlNode.java&r1=795577&r2=798012&rev=798012&view=diff ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/PrefixSqlNode.java (original) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/TrimSqlNode.java Mon Jul 27 02:28:46 2009 @@ -2,13 +2,13 @@ import java.util.*; -public class PrefixSqlNode implements SqlNode { +public class TrimSqlNode implements SqlNode { private SqlNode contents; private String stringToPrefixWith; private List<String> stringsToOverride = new ArrayList<String>(); - public PrefixSqlNode(SqlNode contents, String with, String overrides) { + public TrimSqlNode(SqlNode contents, String with, String overrides) { this.contents = contents; this.stringToPrefixWith = with; this.stringsToOverride = parseOverrides(overrides); Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/WhereSqlNode.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/WhereSqlNode.java?rev=798012&r1=798011&r2=798012&view=diff ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/WhereSqlNode.java (original) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/dynamic/WhereSqlNode.java Mon Jul 27 02:28:46 2009 @@ -1,6 +1,6 @@ package org.apache.ibatis.builder.xml.dynamic; -public class WhereSqlNode extends PrefixSqlNode{ +public class WhereSqlNode extends TrimSqlNode { public WhereSqlNode(SqlNode contents) { super(contents, "WHERE", "AND |OR "); Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/ibatis-3-mapper.dtd URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/ibatis-3-mapper.dtd?rev=798012&r1=798011&r2=798012&view=diff ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/ibatis-3-mapper.dtd (original) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/builder/xml/ibatis-3-mapper.dtd Mon Jul 27 02:28:46 2009 @@ -130,7 +130,7 @@ type CDATA #REQUIRED > -<!ELEMENT select (#PCDATA | include | prefix | where | set | foreach | choose | if)*> +<!ELEMENT select (#PCDATA | include | trim | where | set | foreach | choose | if)*> <!ATTLIST select id CDATA #REQUIRED parameterMap CDATA #IMPLIED @@ -145,7 +145,7 @@ useCache (true|false) #IMPLIED > -<!ELEMENT insert (#PCDATA | selectKey | include | prefix | where | set | foreach | choose | if)*> +<!ELEMENT insert (#PCDATA | selectKey | include | trim | where | set | foreach | choose | if)*> <!ATTLIST insert id CDATA #REQUIRED parameterMap CDATA #IMPLIED @@ -157,7 +157,7 @@ useGeneratedKeys (true|false) #IMPLIED > -<!ELEMENT selectKey (#PCDATA | include | prefix | where | set | foreach | choose | if)*> +<!ELEMENT selectKey (#PCDATA | include | trim | where | set | foreach | choose | if)*> <!ATTLIST selectKey resultType CDATA #IMPLIED statementType (STATEMENT|PREPARED|CALLABLE) #IMPLIED @@ -165,7 +165,7 @@ order (BEFORE|AFTER) #IMPLIED > -<!ELEMENT update (#PCDATA | include | prefix | where | set | foreach | choose | if)*> +<!ELEMENT update (#PCDATA | include | trim | where | set | foreach | choose | if)*> <!ATTLIST update id CDATA #REQUIRED parameterMap CDATA #IMPLIED @@ -175,7 +175,7 @@ statementType (STATEMENT|PREPARED|CALLABLE) #IMPLIED > -<!ELEMENT delete (#PCDATA | include | prefix | where | set | foreach | choose | if)*> +<!ELEMENT delete (#PCDATA | include | trim | where | set | foreach | choose | if)*> <!ATTLIST delete id CDATA #REQUIRED parameterMap CDATA #IMPLIED @@ -192,20 +192,20 @@ refid CDATA #REQUIRED > -<!ELEMENT sql (#PCDATA | include | prefix | where | set | foreach | choose | if)*> +<!ELEMENT sql (#PCDATA | include | trim | where | set | foreach | choose | if)*> <!ATTLIST sql id CDATA #REQUIRED > -<!ELEMENT prefix (#PCDATA | include | prefix | where | set | foreach | choose | if)*> -<!ATTLIST prefix +<!ELEMENT trim (#PCDATA | include | trim | where | set | foreach | choose | if)*> +<!ATTLIST trim with CDATA #IMPLIED overrides CDATA #IMPLIED > -<!ELEMENT where (#PCDATA | include | prefix | where | set | foreach | choose | if)*> -<!ELEMENT set (#PCDATA | include | prefix | where | set | foreach | choose | if)*> +<!ELEMENT where (#PCDATA | include | trim | where | set | foreach | choose | if)*> +<!ELEMENT set (#PCDATA | include | trim | where | set | foreach | choose | if)*> -<!ELEMENT foreach (#PCDATA | include | prefix | where | set | foreach | choose | if)*> +<!ELEMENT foreach (#PCDATA | include | trim | where | set | foreach | choose | if)*> <!ATTLIST foreach collection CDATA #REQUIRED item CDATA #IMPLIED @@ -216,13 +216,13 @@ > <!ELEMENT choose (when* , otherwise?)> -<!ELEMENT when (#PCDATA | include | prefix | where | set | foreach | choose | if)*> +<!ELEMENT when (#PCDATA | include | trim | where | set | foreach | choose | if)*> <!ATTLIST when test CDATA #REQUIRED > -<!ELEMENT otherwise (#PCDATA | include | prefix | where | set | foreach | choose | if)*> +<!ELEMENT otherwise (#PCDATA | include | trim | where | set | foreach | choose | if)*> -<!ELEMENT if (#PCDATA | include | prefix | where | set | foreach | choose | if)*> +<!ELEMENT if (#PCDATA | include | trim | where | set | foreach | choose | if)*> <!ATTLIST if test CDATA #REQUIRED > Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/builder/AuthorMapper.xml URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/builder/AuthorMapper.xml?rev=798012&r1=798011&r2=798012&view=diff ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/builder/AuthorMapper.xml (original) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/builder/AuthorMapper.xml Mon Jul 27 02:28:46 2009 @@ -74,4 +74,18 @@ delete from Author where id = #{id} </delete> + + <update id="updateAuthorIfNecessary" + parameterType="domain.blog.Author"> + update Author + <set> + <if test="username != null">username=#{username},</if> + <if test="password != null">password=#{password},</if> + <if test="email != null">email=#{email},</if> + <if test="bio != null">bio=#{bio}</if> + </set> + where id=#{id} + </update> + + </mapper> \ No newline at end of file Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/builder/PostMapper.xml URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/builder/PostMapper.xml?rev=798012&r1=798011&r2=798012&view=diff ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/builder/PostMapper.xml (original) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/builder/PostMapper.xml Mon Jul 27 02:28:46 2009 @@ -22,21 +22,11 @@ AND id IN <foreach item="item_id" index="index" open="(" close=")" separator="," collection="ids">#{ids[${index}]}</foreach> </if> - <prefix with="AND"> + <trim with="AND"> <include refid="byBlogId"/> - </prefix> + </trim> </otherwise> </choose> </where> - </select> - <!-- - P.id as post_id, - P.blog_id as post_blog_id, - P.author_id as post_author_id, - P.created_on as post_created_on, - P.section as post_section, - P.subject as post_subject, - P.draft as draft, - P.body as post_body - --> + </select> </mapper> \ No newline at end of file Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/builder/xml/dynamic/DynamicSqlSourceTest.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/builder/xml/dynamic/DynamicSqlSourceTest.java?rev=798012&r1=798011&r2=798012&view=diff ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/builder/xml/dynamic/DynamicSqlSourceTest.java (original) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/builder/xml/dynamic/DynamicSqlSourceTest.java Mon Jul 27 02:28:46 2009 @@ -100,7 +100,7 @@ } @Test - public void shouldPrefixWHEREInsteadOfANDForFirstCondition() throws Exception { + public void shouldTrimWHEREInsteadOfANDForFirstCondition() throws Exception { final String expected = "SELECT * FROM BLOG WHERE ID = ?"; DynamicSqlSource source = createDynamicSqlSource( new TextSqlNode("SELECT * FROM BLOG"), @@ -115,7 +115,7 @@ } @Test - public void shouldPrefixWHEREInsteadOfORForSecondCondition() throws Exception { + public void shouldTrimWHEREInsteadOfORForSecondCondition() throws Exception { final String expected = "SELECT * FROM BLOG WHERE NAME = ?"; DynamicSqlSource source = createDynamicSqlSource( new TextSqlNode("SELECT * FROM BLOG"), @@ -130,7 +130,7 @@ } @Test - public void shouldPrefixWHEREInsteadOfANDForBothConditions() throws Exception { + public void shouldTrimWHEREInsteadOfANDForBothConditions() throws Exception { final String expected = "SELECT * FROM BLOG WHERE ID = ? OR NAME = ?"; DynamicSqlSource source = createDynamicSqlSource( new TextSqlNode("SELECT * FROM BLOG"), @@ -145,7 +145,7 @@ } @Test - public void shouldPrefixNoWhereClause() throws Exception { + public void shouldTrimNoWhereClause() throws Exception { final String expected = "SELECT * FROM BLOG"; DynamicSqlSource source = createDynamicSqlSource( new TextSqlNode("SELECT * FROM BLOG"), @@ -160,7 +160,7 @@ } @Test - public void shouldPrefixSETInsteadOfCOMMAForBothConditions() throws Exception { + public void shouldTrimSETInsteadOfCOMMAForBothConditions() throws Exception { final String expected = "UPDATE BLOG SET ID = ? , NAME = ?"; DynamicSqlSource source = createDynamicSqlSource( new TextSqlNode("UPDATE BLOG"), @@ -175,7 +175,7 @@ } @Test - public void shouldPrefixNoSetClause() throws Exception { + public void shouldTrimNoSetClause() throws Exception { final String expected = "UPDATE BLOG"; DynamicSqlSource source = createDynamicSqlSource( new TextSqlNode("UPDATE BLOG"), Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/session/SqlSessionTest.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/session/SqlSessionTest.java?rev=798012&r1=798011&r2=798012&view=diff ============================================================================== --- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/session/SqlSessionTest.java (original) +++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/session/SqlSessionTest.java Mon Jul 27 02:28:46 2009 @@ -151,6 +151,32 @@ } } + @Test @Ignore + public void shouldUpdateAuthorIfNecessary() throws Exception { + SqlSession session = sqlMapper.openSession(); + Author original; + Author updated; + try { + original = (Author) session.selectOne("domain.blog.mappers.AuthorMapper.selectAuthor", 101); + original.setEmail("n...@email.com"); + original.setBio(null); + session.update("domain.blog.mappers.AuthorMapper.updateAuthorIfNecessary", original); + + updated = (Author) session.selectOne("domain.blog.mappers.AuthorMapper.selectAuthor", 101); + assertEquals(original.getEmail(), updated.getEmail()); + session.commit(); + } finally { + session.close(); + } + try { + session = sqlMapper.openSession(); + updated = (Author) session.selectOne("domain.blog.mappers.AuthorMapper.selectAuthor", 101); + assertEquals(original.getEmail(), updated.getEmail()); + } finally { + session.close(); + } + } + @Test public void shouldDeleteAuthor() throws Exception { SqlSession session = sqlMapper.openSession(); Modified: ibatis/trunk/java/ibatis-3/version.properties URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/version.properties?rev=798012&r1=798011&r2=798012&view=diff ============================================================================== --- ibatis/trunk/java/ibatis-3/version.properties (original) +++ ibatis/trunk/java/ibatis-3/version.properties Mon Jul 27 02:28:46 2009 @@ -1,5 +1,5 @@ #Build version info -#Wed Jul 01 00:03:12 MDT 2009 +#Sun Jul 19 11:25:50 MDT 2009 version=3.0.0 -buildDate=2009/07/01 00\:03 -buildNum=185 +buildDate=2009/07/19 11\:25 +buildNum=187