ibatis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbe...@apache.org
Subject svn commit: r748013 - in /ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis: annotations/Annotations.java binding/MapperAnnotationParser.java mapping/ResultMapping.java parser/MapperConfigurator.java
Date Thu, 26 Feb 2009 04:40:49 GMT
Author: cbegin
Date: Thu Feb 26 04:40:48 2009
New Revision: 748013

URL: http://svn.apache.org/viewvc?rev=748013&view=rev
Log:
Added @Results annotation support

Modified:
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/annotations/Annotations.java
    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/mapping/ResultMapping.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/parser/MapperConfigurator.java

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/annotations/Annotations.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/annotations/Annotations.java?rev=748013&r1=748012&r2=748013&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/annotations/Annotations.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/annotations/Annotations.java
Thu Feb 26 04:40:48 2009
@@ -21,9 +21,9 @@
   public static @interface Arg {
     boolean id() default false;
     String column() default "";
-    Class javaType() default Class.class;
+    Class javaType() default void.class;
     JdbcType jdbcType() default JdbcType.UNDEFINED;
-    Class typeHandler() default Class.class;
+    Class typeHandler() default void.class;
   }
 
   @Retention(RetentionPolicy.RUNTIME)
@@ -38,9 +38,9 @@
     boolean key() default false;
     String column() default "";
     String property() default "";
-    Class javaType() default Class.class;
+    Class javaType() default void.class;
     JdbcType jdbcType() default JdbcType.UNDEFINED;
-    Class typeHandler() default Class.class;
+    Class typeHandler() default void.class;
     String collectionSelect() default "";
     Results collectionResults() default @Results;
     String associationSelect() default "";

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=748013&r1=748012&r2=748013&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
Thu Feb 26 04:40:48 2009
@@ -3,16 +3,21 @@
 import static org.apache.ibatis.annotations.Annotations.*;
 import org.apache.ibatis.mapping.*;
 import org.apache.ibatis.parser.MapperConfigurator;
+import org.apache.ibatis.type.TypeHandler;
+import org.apache.ibatis.type.JdbcType;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.lang.reflect.TypeVariable;
-import java.lang.annotation.Annotation;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 
 public class MapperAnnotationParser {
 
   private MapperConfigurator configurator;
   private Class type;
+  private boolean hasResults;
 
   public MapperAnnotationParser(Configuration config, Class type) {
     String resource = type.getName().replace('.', '/') + ".java (best guess)";
@@ -22,24 +27,47 @@
 
   public void parse() {
     configurator.namespace(type.getName());
-    parseCache(type, configurator);
-    parseCacheRef(type, configurator);
+    parseCache();
+    parseCacheRef();
     Method[] methods = type.getMethods();
     for (Method method : methods) {
+      parseResults(method);
       parseStatement(method);
     }
   }
-  private void parseCache(Class type, MapperConfigurator mapperConfigurator) {
+
+  private void parseCache() {
     CacheDomain cacheDomain = (CacheDomain) type.getAnnotation(CacheDomain.class);
     if (cacheDomain != null) {
-      mapperConfigurator.cache(cacheDomain.implementation(), cacheDomain.eviction(), cacheDomain.flushInterval(),
cacheDomain.size(), !cacheDomain.readWrite(), null);
+      configurator.cache(cacheDomain.implementation(), cacheDomain.eviction(), cacheDomain.flushInterval(),
cacheDomain.size(), !cacheDomain.readWrite(), null);
     }
   }
 
-  private void parseCacheRef(Class type, MapperConfigurator mapperConfigurator) {
+  private void parseCacheRef() {
     CacheDomainRef cacheDomainRef = (CacheDomainRef) type.getAnnotation(CacheDomainRef.class);
     if (cacheDomainRef != null) {
-      mapperConfigurator.cacheRef(cacheDomainRef.value().getName());
+      configurator.cacheRef(cacheDomainRef.value().getName());
+    }
+  }
+
+  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()) {
+        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(),
+            null);
+      }
+      configurator.resultMapEnd();
+      hasResults = true;
     }
   }
 
@@ -71,7 +99,7 @@
           timeout,
           null,         // ParameterMapID
           getParameterType(method),
-          null,         // ResultMapID
+          hasResults ? mappedStatementId : null,         // ResultMapID
           getReturnType(method),
           resultSetType,
           isSelect,                  // IsSelectStatement

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/ResultMapping.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/ResultMapping.java?rev=748013&r1=748012&r2=748013&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/ResultMapping.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/ResultMapping.java
Thu Feb 26 04:40:48 2009
@@ -3,6 +3,7 @@
 import org.apache.ibatis.type.JdbcType;
 import org.apache.ibatis.type.TypeHandler;
 import org.apache.ibatis.type.TypeHandlerRegistry;
+import org.apache.derby.impl.sql.compile.SQLParser;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -105,6 +106,10 @@
       }
     }
 
+    public Builder column(String column) {
+      resultMapping.column = column;
+      return this;
+    }
   }
 
   public String getProperty() {

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=748013&r1=748012&r2=748013&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
Thu Feb 26 04:40:48 2009
@@ -326,7 +326,7 @@
     builder.nestedQueryId(applyNamespace(nestedSelect));
     builder.nestedResultMapId(applyNamespace(nestedResultMap));
     builder.typeHandler(typeHandlerInstance);
-    builder.flags(flags);
+    builder.flags(flags == null ? new ArrayList<ResultFlag>() : flags);
 
     return builder.build();
   }



Mime
View raw message