ibatis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbe...@apache.org
Subject svn commit: r748384 - in /ibatis/trunk/java/ibatis-3/ibatis-3-core/src: main/java/org/apache/ibatis/binding/ main/java/org/apache/ibatis/parser/ test/java/org/apache/ibatis/binding/ test/java/org/apache/ibatis/parser/
Date Fri, 27 Feb 2009 03:52:02 GMT
Author: cbegin
Date: Fri Feb 27 03:52:01 2009
New Revision: 748384

URL: http://svn.apache.org/viewvc?rev=748384&view=rev
Log:
In the middle of correcting constructor mapping support

Modified:
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperAnnotationParser.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parser/MapperConfigurator.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/parser/AuthorMapper.xml

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperAnnotationParser.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperAnnotationParser.java?rev=748384&r1=748383&r2=748384&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperAnnotationParser.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperAnnotationParser.java
Fri Feb 27 03:52:01 2009
@@ -1,7 +1,10 @@
 package org.apache.ibatis.binding;
 
 import static org.apache.ibatis.annotations.Annotations.*;
-import org.apache.ibatis.mapping.*;
+import org.apache.ibatis.mapping.Configuration;
+import org.apache.ibatis.mapping.ResultFlag;
+import org.apache.ibatis.mapping.ResultSetType;
+import org.apache.ibatis.mapping.StatementType;
 import org.apache.ibatis.parser.MapperConfigurator;
 import org.apache.ibatis.type.JdbcType;
 
@@ -29,7 +32,6 @@
     parseCacheRef();
     Method[] methods = type.getMethods();
     for (Method method : methods) {
-      parseConstructor(method);
       parseResults(method);
       parseStatement(method);
     }
@@ -50,48 +52,13 @@
   }
 
   private void parseResults(Method method) {
-    Results results = method.getAnnotation(Results.class);
-    if (results != null) {
-      String resultMapId = type.getName() + "." + method.getName();
-      configurator.resultMapStart(resultMapId,getReturnType(method),null);
-      for (Result result : results.value()) {
-        ArrayList<ResultFlag> flags = new ArrayList<ResultFlag>();
-        if (result.id()) flags.add(ResultFlag.ID);
-        configurator.resultMapping(
-            result.property(),
-            result.column(),
-            result.javaType() == void.class ? null : result.javaType(),
-            result.jdbcType() == JdbcType.UNDEFINED ? null : result.jdbcType(),
-            null,
-            null,
-            result.typeHandler() == void.class ? null : result.typeHandler(),
-            flags);
-      }
-      configurator.resultMapEnd();
-      hasResults = true;
-    }
-  }
-
-  public void parseConstructor(Method method) {
     ConstructorArgs args = method.getAnnotation(ConstructorArgs.class);
-    if (args != null) {
+    Results results = method.getAnnotation(Results.class);
+    if (results != null || args != null) {
       String resultMapId = type.getName() + "." + method.getName();
-      configurator.resultMapStart(resultMapId,getReturnType(method),null);
-      for (Arg arg : args.value()) {
-        ArrayList<ResultFlag> flags = new ArrayList<ResultFlag>();
-        flags.add(ResultFlag.CONSTRUCTOR);
-        if (arg.id()) flags.add(ResultFlag.ID);
-        configurator.resultMapping(
-            null,
-            arg.column(),
-            arg.javaType() == void.class ? null : arg.javaType(),
-            arg.jdbcType() == JdbcType.UNDEFINED ? null : arg.jdbcType(),
-            null,
-            null,
-            arg.typeHandler() == void.class ? null : arg.typeHandler(),
-            flags);      }
-      configurator.resultMapEnd();
-      hasResults = true;
+      configurator.resultMapStart(resultMapId, getReturnType(method), null);
+      applyConstructorArgs(args);
+      applyResults(results);
     }
   }
 
@@ -184,5 +151,43 @@
     return null;
   }
 
+  private void applyResults(Results results) {
+    if (results != null) {
+      for (Result result : results.value()) {
+        ArrayList<ResultFlag> flags = new ArrayList<ResultFlag>();
+        if (result.id()) flags.add(ResultFlag.ID);
+        configurator.resultMapping(
+            result.property(),
+            result.column(),
+            result.javaType() == void.class ? null : result.javaType(),
+            result.jdbcType() == JdbcType.UNDEFINED ? null : result.jdbcType(),
+            null,
+            null,
+            result.typeHandler() == void.class ? null : result.typeHandler(),
+            flags);
+      }
+      hasResults = true;
+    }
+  }
+
+  private void applyConstructorArgs(ConstructorArgs args) {
+    if (args != null) {
+      for (Arg arg : args.value()) {
+        ArrayList<ResultFlag> flags = new ArrayList<ResultFlag>();
+        flags.add(ResultFlag.CONSTRUCTOR);
+        if (arg.id()) flags.add(ResultFlag.ID);
+        configurator.resultMapping(
+            null,
+            arg.column(),
+            arg.javaType() == void.class ? null : arg.javaType(),
+            arg.jdbcType() == JdbcType.UNDEFINED ? null : arg.jdbcType(),
+            null,
+            null,
+            arg.typeHandler() == void.class ? null : arg.typeHandler(),
+            flags);
+      }
+      hasResults = true;
+    }
+  }
 
 }

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parser/MapperConfigurator.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parser/MapperConfigurator.java?rev=748384&r1=748383&r2=748384&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parser/MapperConfigurator.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parser/MapperConfigurator.java
Fri Feb 27 03:52:01 2009
@@ -332,7 +332,7 @@
   }
 
   private Class resolveResultJavaType(Class resultType, String property, Class javaType)
{
-    if (javaType == null) {
+    if (javaType == null && property != null) {
       MetaClass metaResultType = MetaClass.forClass(resultType);
       javaType = metaResultType.getSetterType(property);
     }

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=748384&r1=748383&r2=748384&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 03:52:01 2009
@@ -5,11 +5,11 @@
 
 public interface BoundAuthorMapper {
 
-//  @ConstructorArgs({
-//      @Arg(column = "AUTHOR_ID")
-//      })
+  @ConstructorArgs({
+      @Arg(column = "AUTHOR_ID",javaType = int.class)
+      })
   @Results({
-    @Result(property="id",column = "AUTHOR_ID"),
+//    @Result(property="id",column = "AUTHOR_ID"),
       @Result(property = "username",column = "AUTHOR_USERNAME"),
       @Result(property = "password",column = "AUTHOR_PASSWORD"),
       @Result(property = "email",column = "AUTHOR_EMAIL"),

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=748384&r1=748383&r2=748384&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 03:52:01 2009
@@ -22,12 +22,12 @@
 
   <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"/>
+      <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"/>
     </constructor>
   </resultMap>
 



Mime
View raw message