[ 
http://issues.apache.org/jira/browse/IBATIS-224?page=comments#action_12360867 ] 

Reuben Firmin commented on IBATIS-224:
--------------------------------------

Hello, here's my functional workaround:

    <insert id="createDeployment" parameterClass="deployment">
        INSERT INTO Deployment (
            environmentId, deploymentTypeId, deploymentStatusId, 
deploymentTime, threadCountOverride
        ) VALUES (
        <!--todo this is a hack - see 
http://issues.apache.org/jira/browse/IBATIS-224-->
            (#environmentId:Long#), (#deploymentTypeId:Integer#), 
(#deploymentStatusId:INTEGER#),
            (#deploymentTime:DATETIME#), (#threadCountOverride:Long:-99999#)
        )
        <selectKey resultClass="java.lang.Long" keyProperty="deploymentId">
            SELECT @@IDENTITY as value
        </selectKey>
    </insert>

My type handler for, e.g., DeploymentStatus (which works well except in the 
first ibatis statement I posted here):


public class DeploymentStatusTypeHandler extends HasValueTypeHandler {

    public HasIntegerValue[] getEnums() {
        return Deployment.Status.values();
    }
}


public abstract class HasValueTypeHandler implements TypeHandlerCallback {

    public abstract HasValue[] getEnums();

    public void setParameter(ParameterSetter setter, Object parameter) throws 
SQLException {
        if (parameter == null) {
            // todo - broken
            setter.setNull(Types.INTEGER);
        } else {
            HasValue status = (HasValue) parameter;
            setter.setObject(status.getValue());
        }
    }

    public Object getResult(ResultGetter getter) throws SQLException {
        if (getter.getObject() == null)
            return null;
        Object value = getter.getObject();

        for (HasValue status : getEnums()) {
            if (status.getValue().equals(value)) {
                return status;
            }
        }
        throw new UnsupportedOperationException("No such value : '" + value + 
"' in the enum set");
    }

    public Object valueOf(String s) {
        return s;
    }
}


I don't have time to build a self-contained test case right now, but will 
attempt to do so later this week. Incidentally Clinton is looking at another 
issue related to Enums (210) so perhaps these are the same bug.




> isNotNull node causes typehandler mappings in statement to fail
> ---------------------------------------------------------------
>
>          Key: IBATIS-224
>          URL: http://issues.apache.org/jira/browse/IBATIS-224
>      Project: iBatis for Java
>         Type: Bug
>   Components: SQL Maps
>     Versions: 2.1.6
>  Environment: linux/java 1.5
>     Reporter: Reuben Firmin
>     Priority: Critical

>
> Here's my insert statement.
>     <insert id="createDeployment" parameterClass="deployment">
>         INSERT INTO Deployment (
>             environmentId, deploymentTypeId, deploymentStatusId, 
> deploymentTime
>                 <isNotNull 
> property="threadCountOverride">,threadCountOverride</isNotNull>
>         ) VALUES (
>             #environmentId#, #deploymentTypeId#, #deploymentStatusId#, 
> #deploymentTime#
>                 <isNotNull 
> property="threadCountOverride">,#threadCountOverride#</isNotNull>
>         )
>         <selectKey resultClass="int" keyProperty="deploymentId">
>             SELECT @@IDENTITY as value
>         </selectKey>
>     </insert>
> deploymentTypeId and deploymentStatusId are enums in the bean, mapped to 
> values using custom type handlers. Without the isNotNull structure around 
> threadCountOverride (which *is* nullable), the statement works. With the 
> isNotNull, deploymentStatusId and deploymentTypeId are mapped to 
> UnknownTypeHandler, and the insert fails to map the parameters from the bean.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to