emacarron / mybatis

Automatically exported from code.google.com/p/mybatis
0 stars 0 forks source link

@ConstructorArgs inside @Case #136

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
If @ConstructorArgs would be defined inside the @Case annotation then it would 
be possible to have different constructors based on different @Case in the 
@TypeDescriminator...

According to the documentation the @ConstructorArgs corresponds to 
<constructor> which is inside the <resultMap> which corresponds to @Results.

Example:
    @TypeDiscriminator(column = "TYPE", cases = {
            @Case(value = "1", type = Character.class, constructorArgs = {
                    @Arg(),
                    @Arg
            })
    })

Original issue reported on code.google.com by jaron.schut@gmail.com on 9 Oct 2010 at 5:56

GoogleCodeExporter commented 9 years ago
I checked out the source code and I reckon it is not too much work to add this. 
Of course this is not included any time needed to perform the testing.

The simple changes that will enable the feature:

Case.java

package org.apache.ibatis.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Case {
 public abstract String value();
 public abstract Class<?> type();
 public abstract Result[] results() default {};
 public abstract Arg[] constructArgs() default {};
}

In mapperAnnotationBuilder.java:

add line +/-185:
               applyConstructorArgs( c.constructArgs(), resultType, resultMappings );

Original comment by jaron.schut@gmail.com on 9 Oct 2010 at 7:01

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Fixed in r4952. Thank you!

Original comment by eduardo.macarron on 17 Mar 2012 at 10:19