ibatis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbe...@apache.org
Subject svn commit: r748391 - in /ibatis/trunk/java/ibatis-3/ibatis-3-core/src: main/java/org/apache/ibatis/executor/resultset/ main/java/org/apache/ibatis/parser/ main/java/org/apache/ibatis/reflection/ test/java/domain/blog/ test/java/org/apache/ibatis/bindi...
Date Fri, 27 Feb 2009 04:50:45 GMT
Author: cbegin
Date: Fri Feb 27 04:50:44 2009
New Revision: 748391

URL: http://svn.apache.org/viewvc?rev=748391&view=rev
Log:
Fixed constructor support.

Modified:
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parser/MapperParser.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parser/ibatis-mapper-3.dtd
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/reflection/DefaultObjectFactory.java
    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/domain/blog/ImmutableAuthor.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BindingTest.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BoundAuthorMapper.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/executor/ExecutorTestHelper.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/parser/AuthorMapper.xml

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java?rev=748391&r1=748390&r2=748391&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java
Fri Feb 27 04:50:44 2009
@@ -204,9 +204,9 @@
       List<Class> argTypes = new ArrayList<Class>();
       List<Object> argValues = new ArrayList<Object>();
       for (ResultMapping resultMapping : rm.getConstructorResultMappings()) {
-        processResult(rs, rm, resultMapping, null, constructorArgs);
+        Object value = processResult(rs, rm, resultMapping, null, constructorArgs);
         argTypes.add(resultMapping.getJavaType());
-        argValues.add(constructorArgs.get(resultMapping.getProperty()));
+        argValues.add(value);
       }
       resultObject = objectFactory.create(rm.getType(), argTypes, argValues);
     } else {
@@ -259,10 +259,11 @@
   private Object processSimpleResult(ResultSet rs, ResultMap rm, ResultMapping resultMapping,
Object resultObject) throws SQLException {
     MetaObject metaResultObject = MetaObject.forObject(resultObject);
     Object value = getPrimitiveResultMappingValue(rs, resultMapping);
-    if (typeHandlerRegistry.hasTypeHandler(rm.getType())) {
+    String property = resultMapping.getProperty();
+    if (typeHandlerRegistry.hasTypeHandler(rm.getType()) || property == null) {
       resultObject = value;
     } else if (value != null) {
-      metaResultObject.setValue(resultMapping.getProperty(), value);
+      metaResultObject.setValue(property, value);
     }
     foundValues.set(value != null || foundValues.get());
     return resultObject;

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parser/MapperParser.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parser/MapperParser.java?rev=748391&r1=748390&r2=748391&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parser/MapperParser.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parser/MapperParser.java
Fri Feb 27 04:50:44 2009
@@ -111,7 +111,7 @@
 
   //  <constructor>
   //    <id column="" javaType="" jdbcType="" typeHandler=""/>
-  @Nodelet("/mapper/resultMap/constructor/id")
+  @Nodelet("/mapper/resultMap/constructor/idArg")
   public void resultMapConstructorIdElement(NodeletContext context) throws Exception {
     buildResultMappingFromContext(context,
         new ArrayList<ResultFlag>() {
@@ -124,7 +124,7 @@
 
   //  <constructor>
   //    <result column="" javaType="" jdbcType="" typeHandler=""/>
-  @Nodelet("/mapper/resultMap/constructor/result")
+  @Nodelet("/mapper/resultMap/constructor/arg")
   public void resultMapConstructorResultElement(NodeletContext context) throws Exception
{
     buildResultMappingFromContext(context, new ArrayList<ResultFlag>() {
       {

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parser/ibatis-mapper-3.dtd
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parser/ibatis-mapper-3.dtd?rev=748391&r1=748390&r2=748391&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parser/ibatis-mapper-3.dtd
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parser/ibatis-mapper-3.dtd
Fri Feb 27 04:50:44 2009
@@ -44,7 +44,7 @@
 extends CDATA #IMPLIED
 >
 
-<!ELEMENT constructor (id*,result*)>
+<!ELEMENT constructor (idArg*,arg*)>
 
 <!ELEMENT id EMPTY>
 <!ATTLIST id
@@ -64,6 +64,22 @@
 typeHandler CDATA #IMPLIED
 >
 
+<!ELEMENT idArg EMPTY>
+<!ATTLIST idArg
+javaType CDATA #IMPLIED
+column CDATA #IMPLIED
+jdbcType CDATA #IMPLIED
+typeHandler CDATA #IMPLIED
+>
+
+<!ELEMENT arg EMPTY>
+<!ATTLIST arg
+javaType CDATA #IMPLIED
+column CDATA #IMPLIED
+jdbcType CDATA #IMPLIED
+typeHandler CDATA #IMPLIED
+>
+
 <!ELEMENT collection EMPTY>
 <!ATTLIST collection
 property CDATA #REQUIRED

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/reflection/DefaultObjectFactory.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/reflection/DefaultObjectFactory.java?rev=748391&r1=748390&r2=748391&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/reflection/DefaultObjectFactory.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/reflection/DefaultObjectFactory.java
Fri Feb 27 04:50:44 2009
@@ -35,7 +35,17 @@
         return constructor.newInstance(constructorArgs.toArray(new Object[constructorArgs.size()]));
       }
     } catch (Exception e) {
-      throw new ReflectionException("Error instantiating " + type + ". Cause: " + e, e);
+      StringBuilder argTypes = new StringBuilder();
+      for (Class argType : constructorArgTypes) {
+        argTypes.append(argType.getSimpleName());
+        argTypes.append(",");
+      }
+      StringBuilder argValues = new StringBuilder();
+      for (Object argValue : constructorArgs) {
+        argValues.append(String.valueOf(argValue));
+        argValues.append(",");
+      }
+      throw new ReflectionException("Error instantiating " + type + " with invalid types
(" + argTypes + ") or values ("+argValues+"). Cause: " + e, e);
     }
   }
 

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=748391&r1=748390&r2=748391&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 Fri Feb
27 04:50:44 2009
@@ -6,11 +6,11 @@
     super(-1, null, null, null, null, null);
   }
 
-  public Author(int id, String username, String password, String email, String bio, Section
section) {
+  public Author(Integer id, String username, String password, String email, String bio, Section
section) {
     super(id, username, password, email, bio, section);
   }
 
-  public Author(int id) {
+  public Author(Integer id) {
     super(id, null, null, null, null, null);
   }
 

Modified: 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=748391&r1=748390&r2=748391&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/domain/blog/ImmutableAuthor.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/domain/blog/ImmutableAuthor.java
Fri Feb 27 04:50:44 2009
@@ -10,7 +10,7 @@
   protected String bio;
   protected Section favouriteSection;
 
-  public ImmutableAuthor(int id, String username, String password, String email, String bio,
Section section) {
+  public ImmutableAuthor(Integer id, String username, String password, String email, String
bio, Section section) {
     this.id = id;
     this.username = username;
     this.password = password;

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BindingTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BindingTest.java?rev=748391&r1=748390&r2=748391&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BindingTest.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BindingTest.java
Fri Feb 27 04:50:44 2009
@@ -60,5 +60,21 @@
     }
   }
 
+  @Test
+  public void shouldSelectOneAuthorByConstructor() {
+    SqlSession session = sqlSessionFactory.openSession();
+    try {
+      BoundAuthorMapper mapper = session.getMapper(BoundAuthorMapper.class);
+      Author author = mapper.selectAuthorConstructor(101);
+      assertEquals(101,author.getId());
+      assertEquals("jim",author.getUsername());
+      assertEquals("********",author.getPassword());
+      assertEquals("jim@ibatis.apache.org",author.getEmail());
+      assertEquals("", author.getBio());
+    } finally {
+      session.close();
+    }
+  }
+
 
 }

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BoundAuthorMapper.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BoundAuthorMapper.java?rev=748391&r1=748390&r2=748391&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BoundAuthorMapper.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BoundAuthorMapper.java
Fri Feb 27 04:50:44 2009
@@ -1,19 +1,19 @@
 package org.apache.ibatis.binding;
 
-import static org.apache.ibatis.annotations.Annotations.*;
 import domain.blog.Author;
+import domain.blog.Section;
+import static org.apache.ibatis.annotations.Annotations.*;
 
 public interface BoundAuthorMapper {
 
   @ConstructorArgs({
-      @Arg(column = "AUTHOR_ID",javaType = int.class)
+    @Arg(column = "AUTHOR_ID", javaType = Integer.class)
       })
   @Results({
-//    @Result(property="id",column = "AUTHOR_ID"),
-      @Result(property = "username",column = "AUTHOR_USERNAME"),
-      @Result(property = "password",column = "AUTHOR_PASSWORD"),
-      @Result(property = "email",column = "AUTHOR_EMAIL"),
-      @Result(property = "bio",column = "AUTHOR_BIO")
+    @Result(property = "username", column = "AUTHOR_USERNAME"),
+    @Result(property = "password", column = "AUTHOR_PASSWORD"),
+    @Result(property = "email", column = "AUTHOR_EMAIL"),
+    @Result(property = "bio", column = "AUTHOR_BIO")
       })
   @Select({
       "SELECT ",
@@ -25,4 +25,24 @@
       "FROM AUTHOR WHERE ID = #{id}"})
   Author selectAuthor(int id);
 
+
+  @ConstructorArgs({
+    @Arg(column = "AUTHOR_ID", javaType = Integer.class),
+    @Arg(column = "AUTHOR_USERNAME", javaType = String.class),
+    @Arg(column = "AUTHOR_PASSWORD", javaType = String.class),
+    @Arg(column = "AUTHOR_EMAIL", javaType = String.class),
+    @Arg(column = "AUTHOR_BIO", javaType = String.class),
+    @Arg(column = "AUTHOR_SECTION", javaType = Section.class)
+      })
+  @Select({
+      "SELECT ",
+      "  ID as AUTHOR_ID,",
+      "  USERNAME as AUTHOR_USERNAME,",
+      "  PASSWORD as AUTHOR_PASSWORD,",
+      "  EMAIL as AUTHOR_EMAIL,",
+      "  BIO as AUTHOR_BIO," +
+      "  FAVOURITE_SECTION as AUTHOR_SECTION",
+      "FROM AUTHOR WHERE ID = #{id}"})
+  Author selectAuthorConstructor(int id);
+
 }

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/executor/ExecutorTestHelper.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/executor/ExecutorTestHelper.java?rev=748391&r1=748390&r2=748391&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/executor/ExecutorTestHelper.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/executor/ExecutorTestHelper.java
Fri Feb 27 04:50:44 2009
@@ -171,7 +171,7 @@
           {
             add(new ResultMap.Builder(config, "defaultResultMap", Author.class, new ArrayList<ResultMapping>()
{
               {
-                add(new ResultMapping.Builder(config, "id", "id", registry.getTypeHandler(int.class)).javaType(int.class).flags(new
ArrayList<ResultFlag>() {
+                add(new ResultMapping.Builder(config, null, "id", registry.getTypeHandler(Integer.class)).javaType(Integer.class).flags(new
ArrayList<ResultFlag>() {
                   {
                     add(ResultFlag.CONSTRUCTOR);
                   }

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=748391&r1=748390&r2=748391&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
Fri Feb 27 04:50:44 2009
@@ -22,12 +22,12 @@
 
   <resultMap id="selectImmutableAuthor" type="domain.blog.ImmutableAuthor">
     <constructor>
-      <id column="id" javaType="int"/>
-      <result column="username" javaType="string"/>
-      <result column="password" javaType="string"/>
-      <result column="email" javaType="string"/>
-      <result column="bio" javaType="string"/>
-      <result column="favourite_section" javaType="domain.blog.Section"/>
+      <idArg column="id" javaType="int"/>
+      <arg column="username" javaType="string"/>
+      <arg column="password" javaType="string"/>
+      <arg column="email" javaType="string"/>
+      <arg column="bio" javaType="string"/>
+      <arg column="favourite_section" javaType="domain.blog.Section"/>
     </constructor>
   </resultMap>
 



Mime
View raw message