You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by cb...@apache.org on 2008/12/30 06:31:22 UTC

svn commit: r730044 - in /ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java: domain/blog/ org/apache/ibatis/api/ org/apache/ibatis/parser/

Author: cbegin
Date: Mon Dec 29 21:31:20 2008
New Revision: 730044

URL: http://svn.apache.org/viewvc?rev=730044&view=rev
Log:
added constructor test

Added:
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/domain/blog/ImmutableAuthor.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/ExampleMapper.xml
Modified:
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/domain/blog/Author.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/api/SqlSessionTest.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/AuthorMapper.xml
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/BlogMapper.xml

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/domain/blog/Author.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/domain/blog/Author.java?rev=730044&r1=730043&r2=730044&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/domain/blog/Author.java (original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/domain/blog/Author.java Mon Dec 29 21:31:20 2008
@@ -1,109 +1,41 @@
 package domain.blog;
 
-import java.io.Serializable;
-
-public class Author implements Serializable {
-
-  private int id;
-  private String username;
-  private String password;
-  private String email;
-  private String bio;
-  private Section favouriteSection;
+public class Author extends ImmutableAuthor {
 
   public Author() {
+    super(-1, null, null, null, null, null);
   }
 
   public Author(int id, String username, String password, String email, String bio, Section section) {
-    this.id = id;
-    this.username = username;
-    this.password = password;
-    this.email = email;
-    this.bio = bio;
-    this.favouriteSection = section;
+    super(id, username, password, email, bio, section);
   }
 
   public Author(int id) {
-    this.id = id;
-  }
-
-  public int getId() {
-    return id;
+    super(id, null, null, null, null, null);
   }
 
   public void setId(int id) {
     this.id = id;
   }
 
-  public String getUsername() {
-    return username;
-  }
-
   public void setUsername(String username) {
     this.username = username;
   }
 
-  public String getPassword() {
-    return password;
-  }
-
   public void setPassword(String password) {
     this.password = password;
   }
 
-  public String getEmail() {
-    return email;
-  }
-
   public void setEmail(String email) {
     this.email = email;
   }
 
-  public String getBio() {
-    return bio;
-  }
-
   public void setBio(String bio) {
     this.bio = bio;
   }
 
-  public Section getFavouriteSection() {
-    return favouriteSection;
-  }
-
   public void setFavouriteSection(Section favouriteSection) {
     this.favouriteSection = favouriteSection;
   }
 
-  public boolean equals(Object o) {
-    if (this == o) return true;
-    if (!(o instanceof Author)) return false;
-
-    Author author = (Author) o;
-
-    if (id != author.id) return false;
-    if (bio != null ? !bio.equals(author.bio) : author.bio != null) return false;
-    if (email != null ? !email.equals(author.email) : author.email != null) return false;
-    if (password != null ? !password.equals(author.password) : author.password != null) return false;
-    if (username != null ? !username.equals(author.username) : author.username != null) return false;
-    if (favouriteSection != null ? !favouriteSection.equals(author.favouriteSection) : author.favouriteSection != null)
-      return false;
-
-    return true;
-  }
-
-  public int hashCode() {
-    int result;
-    result = id;
-    result = 31 * result + (username != null ? username.hashCode() : 0);
-    result = 31 * result + (password != null ? password.hashCode() : 0);
-    result = 31 * result + (email != null ? email.hashCode() : 0);
-    result = 31 * result + (bio != null ? bio.hashCode() : 0);
-    result = 31 * result + (favouriteSection != null ? favouriteSection.hashCode() : 0);
-    return result;
-  }
-
-  public String toString() {
-    return id + " " + username + " " + password + " " + email;
-  }
 }
\ No newline at end of file

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/domain/blog/ImmutableAuthor.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/domain/blog/ImmutableAuthor.java?rev=730044&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/domain/blog/ImmutableAuthor.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/domain/blog/ImmutableAuthor.java Mon Dec 29 21:31:20 2008
@@ -0,0 +1,77 @@
+package domain.blog;
+
+import java.io.Serializable;
+
+public class ImmutableAuthor implements Serializable {
+  protected int id;
+  protected String username;
+  protected String password;
+  protected String email;
+  protected String bio;
+  protected Section favouriteSection;
+
+  public ImmutableAuthor(int id, String username, String password, String email, String bio, Section section) {
+    this.id = id;
+    this.username = username;
+    this.password = password;
+    this.email = email;
+    this.bio = bio;
+    this.favouriteSection = section;
+  }
+
+  public int getId() {
+    return id;
+  }
+
+  public String getUsername() {
+    return username;
+  }
+
+  public String getPassword() {
+    return password;
+  }
+
+  public String getEmail() {
+    return email;
+  }
+
+  public String getBio() {
+    return bio;
+  }
+
+  public Section getFavouriteSection() {
+    return favouriteSection;
+  }
+
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof Author)) return false;
+
+    Author author = (Author) o;
+
+    if (id != author.id) return false;
+    if (bio != null ? !bio.equals(author.bio) : author.bio != null) return false;
+    if (email != null ? !email.equals(author.email) : author.email != null) return false;
+    if (password != null ? !password.equals(author.password) : author.password != null) return false;
+    if (username != null ? !username.equals(author.username) : author.username != null) return false;
+    if (favouriteSection != null ? !favouriteSection.equals(author.favouriteSection) : author.favouriteSection != null)
+      return false;
+
+    return true;
+  }
+
+  public int hashCode() {
+    int result;
+    result = id;
+    result = 31 * result + (username != null ? username.hashCode() : 0);
+    result = 31 * result + (password != null ? password.hashCode() : 0);
+    result = 31 * result + (email != null ? email.hashCode() : 0);
+    result = 31 * result + (bio != null ? bio.hashCode() : 0);
+    result = 31 * result + (favouriteSection != null ? favouriteSection.hashCode() : 0);
+    return result;
+  }
+
+  public String toString() {
+    return id + " " + username + " " + password + " " + email;
+  }
+}

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/api/SqlSessionTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/api/SqlSessionTest.java?rev=730044&r1=730043&r2=730044&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/api/SqlSessionTest.java (original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/api/SqlSessionTest.java Mon Dec 29 21:31:20 2008
@@ -9,6 +9,7 @@
 
 import domain.blog.Author;
 import domain.blog.Section;
+import domain.blog.ImmutableAuthor;
 
 public class SqlSessionTest extends BaseDataTest {
   private static SqlSessionFactory sqlMapper;
@@ -46,6 +47,19 @@
   }
 
   @Test
+  public void shouldSelectOneImmutableAuthor() throws Exception {
+    SqlSession session = sqlMapper.openSession();
+    try {
+      ImmutableAuthor author = (ImmutableAuthor) session.selectOne(
+          "com.domain.AuthorMapper.selectImmutableAuthor", new Author(101));
+      Assert.assertEquals(101, author.getId());
+      Assert.assertEquals(Section.NEWS, author.getFavouriteSection());
+    } finally {
+      session.close();
+    }
+  }
+
+  @Test
   public void shouldSelectOneAuthorWithInlineParams() throws Exception {
     SqlSession session = sqlMapper.openSession();
     try {

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/AuthorMapper.xml
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/AuthorMapper.xml?rev=730044&r1=730043&r2=730044&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/AuthorMapper.xml (original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/AuthorMapper.xml Mon Dec 29 21:31:20 2008
@@ -20,6 +20,17 @@
     <result property="favouriteSection" column="favourite_section" />
   </resultMap>
 
+  <resultMap id="selectImmutableAuthor" type="domain.blog.ImmutableAuthor">
+    <constructor>
+      <id column="id" property="id" />
+      <result property="username" column="username" />
+      <result property="password" column="password" />
+      <result property="email" column="email" />
+      <result property="bio" column="bio" />
+      <result property="favouriteSection" column="favourite_section" />
+    </constructor>
+  </resultMap>
+
   <select id="selectAllAuthors"
           resultType="domain.blog.Author">
     select * from author
@@ -32,6 +43,13 @@
     from author where id = ?
   </select>
 
+  <select id="selectImmutableAuthor"
+          parameterMap="selectAuthor"
+          resultMap="selectImmutableAuthor">
+    select id, username, password, email, bio, favourite_section
+    from author where id = ?
+  </select>
+
   <select id="selectAuthorWithInlineParams"
           parameterType="int"
           resultType="domain.blog.Author">

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/BlogMapper.xml
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/BlogMapper.xml?rev=730044&r1=730043&r2=730044&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/BlogMapper.xml (original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/BlogMapper.xml Mon Dec 29 21:31:20 2008
@@ -4,20 +4,7 @@
     PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
     "http://ibatis.apache.org/dtd/ibatis-mapper-3.dtd">
 
-<mapper namespace="com.domain.PersonMapper">
-
-  <cache-ref namespace=""/>
-
-  <cache type="PERPETUAL" eviction="LRU" flushInterval="3600000" size="1000" readOnly="false">
-    <property name="" value=""/>
-  </cache>
-  
-  <parameterMap id="" type="">
-    <parameter property="id" javaType="" jdbcType="" typeHandler=""
-           mode="IN" scale="" resultMap=""/>
-    <parameter property="dept" javaType="" jdbcType="" typeHandler=""
-           mode="IN" scale="" resultMap=""/>
-  </parameterMap>
+<mapper namespace="com.domain.BlogMapper">
 
   <resultMap id="" type="" extends="">
     <constructor>
@@ -26,10 +13,6 @@
     </constructor>
     <result property="" column="" javaType="" jdbcType="" typeHandler=""/>
     <collection property="" column="" javaType="" select="" resultMap=""/>
-    <discriminator column="" javaType="" jdbcType="">
-      <case value="" resultMap=""/>
-      <case value="" resultMap=""/>
-    </discriminator>
   </resultMap>
 
   <select id="selectAllPeople" useCache="true" flushCache="false" parameterType="" resultType="" resultMap="">
@@ -37,9 +20,4 @@
     ${opts.order,javaType="",jdbcType="",typeHandler="",mode="",scale="",resultMap=""}
   </select>
   
-  <select id="selectPersonInDept" parameterType="" resultType="" resultMap="">
-    select * from PERSON
-    where PERSON_ID = #param.id --or #{params.id}
-  </select>
-
 </mapper>
\ No newline at end of file

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/ExampleMapper.xml
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/ExampleMapper.xml?rev=730044&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/ExampleMapper.xml (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/ExampleMapper.xml Mon Dec 29 21:31:20 2008
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!DOCTYPE mapper
+    PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
+    "http://ibatis.apache.org/dtd/ibatis-mapper-3.dtd">
+
+<mapper namespace="com.domain.PersonMapper">
+
+  <cache-ref namespace=""/>
+
+  <cache type="PERPETUAL" eviction="LRU" flushInterval="3600000" size="1000" readOnly="false">
+    <property name="" value=""/>
+  </cache>
+
+  <parameterMap id="" type="">
+    <parameter property="id" javaType="" jdbcType="" typeHandler=""
+           mode="IN" scale="" resultMap=""/>
+    <parameter property="dept" javaType="" jdbcType="" typeHandler=""
+           mode="IN" scale="" resultMap=""/>
+  </parameterMap>
+
+  <resultMap id="" type="" extends="">
+    <constructor>
+      <id column="" javaType="" jdbcType="" typeHandler="" />
+      <result column="" javaType="" jdbcType="" typeHandler=""/>
+    </constructor>
+    <result property="" column="" javaType="" jdbcType="" typeHandler=""/>
+    <collection property="" column="" javaType="" select="" resultMap=""/>
+    <discriminator column="" javaType="" jdbcType="">
+      <case value="" resultMap=""/>
+      <case value="" resultMap=""/>
+    </discriminator>
+  </resultMap>
+
+  <select id="selectAllPeople" useCache="true" flushCache="false" parameterType="" resultType="" resultMap="">
+    select * from PERSON order by
+    ${opts.order,javaType="",jdbcType="",typeHandler="",mode="",scale="",resultMap=""}
+  </select>
+
+  <select id="selectPersonInDept" parameterType="" resultType="" resultMap="">
+    select * from PERSON
+    where PERSON_ID = #param.id --or #{params.id}
+  </select>
+
+</mapper>
\ No newline at end of file