Author: kai
Date: Fri May  1 12:13:24 2009
New Revision: 770648

URL: http://svn.apache.org/viewvc?rev=770648&view=rev
Log:
IBATIS-536 (Errors when using PreparedStatement.setNull(i,Types.OTHER) on some 
RDBMS)
- applied the patch from Sebastien Launay

Added:
    
ibatis/trunk/java/ibatis-2/ibatis-2-core/test/com/ibatis/sqlmap/DerbyParameterMapTest.java
Modified:
    
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/mapping/parameter/ParameterMap.java
    
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/mapping/parameter/ParameterMapping.java
    
ibatis/trunk/java/ibatis-2/ibatis-2-core/test/com/ibatis/sqlmap/ParameterMapTest.java
    
ibatis/trunk/java/ibatis-2/ibatis-2-core/test/com/ibatis/sqlmap/maps/DerbySqlMapConfig.xml

Modified: 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/mapping/parameter/ParameterMap.java
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/mapping/parameter/ParameterMap.java?rev=770648&r1=770647&r2=770648&view=diff
==============================================================================
--- 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/mapping/parameter/ParameterMap.java
 (original)
+++ 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/mapping/parameter/ParameterMap.java
 Fri May  1 12:13:24 2009
@@ -1,179 +1,209 @@
-/*
- *  Copyright 2004 Clinton Begin
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-package com.ibatis.sqlmap.engine.mapping.parameter;
-
-import com.ibatis.sqlmap.engine.cache.CacheKey;
-import com.ibatis.sqlmap.engine.exchange.DataExchange;
-import com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate;
-import com.ibatis.sqlmap.engine.scope.ErrorContext;
-import com.ibatis.sqlmap.engine.scope.StatementScope;
-import com.ibatis.sqlmap.engine.type.CustomTypeHandler;
-import com.ibatis.sqlmap.engine.type.JdbcTypeRegistry;
-import com.ibatis.sqlmap.engine.type.TypeHandler;
-
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class ParameterMap {
-
-  private String id;
-  private Class parameterClass;
-
-  private ParameterMapping[] parameterMappings;
-  private DataExchange dataExchange;
-
-  private String resource;
-
-  private Map parameterMappingIndex = new HashMap();
-
-  private SqlMapExecutorDelegate delegate;
-
-  public ParameterMap(SqlMapExecutorDelegate delegate) {
-    this.delegate = delegate;
-  }
-
-  public SqlMapExecutorDelegate getDelegate() {
-    return delegate;
-  }
-
-  public String getId() {
-    return id;
-  }
-
-  public void setId(String id) {
-    this.id = id;
-  }
-
-  public Class getParameterClass() {
-    return parameterClass;
-  }
-
-  public void setParameterClass(Class parameterClass) {
-    this.parameterClass = parameterClass;
-  }
-
-  public DataExchange getDataExchange() {
-    return dataExchange;
-  }
-
-  public void setDataExchange(DataExchange dataExchange) {
-    this.dataExchange = dataExchange;
-  }
-
-  public ParameterMapping[] getParameterMappings() {
-    return parameterMappings;
-  }
-
-  public void setParameterMappingList(List parameterMappingList) {
-    this.parameterMappings = (ParameterMapping[]) 
parameterMappingList.toArray(new ParameterMapping[parameterMappingList.size()]);
-    parameterMappingIndex.clear();
-    for (int i = 0; i < parameterMappings.length; i++) {
-      parameterMappingIndex.put(parameterMappings[i].getPropertyName(), new 
Integer(i));
-    }
-    Map props = new HashMap();
-    props.put("map", this);
-
-    dataExchange = 
delegate.getDataExchangeFactory().getDataExchangeForClass(parameterClass);
-    dataExchange.initialize(props);
-  }
-
-  public int getParameterIndex(String propertyName) {
-    Integer idx = null;
-    idx = (Integer) parameterMappingIndex.get(propertyName);
-    return idx == null ? -1 : idx.intValue();
-  }
-
-  public int getParameterCount() {
-    return this.parameterMappings.length;
-  }
-
-  /**
-   * @param ps
-   * @param parameters
-   * @throws java.sql.SQLException
-   */
-  public void setParameters(StatementScope statementScope, PreparedStatement 
ps, Object[] parameters)
-      throws SQLException {
-
-    ErrorContext errorContext = statementScope.getErrorContext();
-    errorContext.setActivity("applying a parameter map");
-    errorContext.setObjectId(this.getId());
-    errorContext.setResource(this.getResource());
-    errorContext.setMoreInfo("Check the parameter map.");
-
-    if (parameterMappings != null) {
-      for (int i = 0; i < parameterMappings.length; i++) {
-        ParameterMapping mapping = parameterMappings[i];
-        errorContext.setMoreInfo(mapping.getErrorString());
-        if (mapping.isInputAllowed()) {
-          setParameter(ps, mapping, parameters, i);
-        }
-      }
-    }
-  }
-
-  public Object[] getParameterObjectValues(StatementScope statementScope, 
Object parameterObject) {
-    return dataExchange.getData(statementScope, this, parameterObject);
-  }
-
-  public CacheKey getCacheKey(StatementScope statementScope, Object 
parameterObject) {
-    return dataExchange.getCacheKey(statementScope, this, parameterObject);
-  }
-
-  public void refreshParameterObjectValues(StatementScope statementScope, 
Object parameterObject, Object[] values) {
-    dataExchange.setData(statementScope, this, parameterObject, values);
-  }
-
-  public String getResource() {
-    return resource;
-  }
-
-  public void setResource(String resource) {
-    this.resource = resource;
-  }
-
-  protected void setParameter(PreparedStatement ps, ParameterMapping mapping, 
Object[] parameters, int i) throws SQLException {
-    Object value = parameters[i];
-    // Apply Null Value
-    String nullValueString = mapping.getNullValue();
-    if (nullValueString != null) {
-      TypeHandler handler = mapping.getTypeHandler();
-      if (handler.equals(value, nullValueString)) {
-        value = null;
-      }
-    }
-
-    // Set Parameter
-    TypeHandler typeHandler = mapping.getTypeHandler();
-    if (value != null) {
-      typeHandler.setParameter(ps, i + 1, value, mapping.getJdbcTypeName());
-    } else if (typeHandler instanceof CustomTypeHandler) {
-      typeHandler.setParameter(ps, i + 1, value, mapping.getJdbcTypeName());
-    } else {
-      int jdbcType = mapping.getJdbcType();
-      if (jdbcType != JdbcTypeRegistry.UNKNOWN_TYPE) {
-        ps.setNull(i + 1, jdbcType);
-      } else {
-        ps.setNull(i + 1, Types.OTHER);
-      }
-    }
-  }
-
-}
+/*
+ *  Copyright 2004 Clinton Begin
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package com.ibatis.sqlmap.engine.mapping.parameter;
+
+import com.ibatis.common.logging.Log;
+import com.ibatis.common.logging.LogFactory;
+import com.ibatis.sqlmap.engine.cache.CacheKey;
+import com.ibatis.sqlmap.engine.exchange.DataExchange;
+import com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate;
+import com.ibatis.sqlmap.engine.scope.ErrorContext;
+import com.ibatis.sqlmap.engine.scope.StatementScope;
+import com.ibatis.sqlmap.engine.type.CustomTypeHandler;
+import com.ibatis.sqlmap.engine.type.JdbcTypeRegistry;
+import com.ibatis.sqlmap.engine.type.TypeHandler;
+
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ParameterMap {
+
+  private static final Log log = LogFactory.getLog(ParameterMap.class);
+
+  private String id;
+  private Class parameterClass;
+
+  private ParameterMapping[] parameterMappings;
+  private Boolean useSetObjectForNullValue;
+  private int sqlTypeToUseForNullValue;
+  private DataExchange dataExchange;
+
+  private String resource;
+
+  private Map parameterMappingIndex = new HashMap();
+
+  private SqlMapExecutorDelegate delegate;
+
+  public ParameterMap(SqlMapExecutorDelegate delegate) {
+    this.delegate = delegate;
+  }
+
+  public SqlMapExecutorDelegate getDelegate() {
+    return delegate;
+  }
+
+  public String getId() {
+    return id;
+  }
+
+  public void setId(String id) {
+    this.id = id;
+  }
+
+  public Class getParameterClass() {
+    return parameterClass;
+  }
+
+  public void setParameterClass(Class parameterClass) {
+    this.parameterClass = parameterClass;
+  }
+
+  public DataExchange getDataExchange() {
+    return dataExchange;
+  }
+
+  public void setDataExchange(DataExchange dataExchange) {
+    this.dataExchange = dataExchange;
+  }
+
+  public ParameterMapping[] getParameterMappings() {
+    return parameterMappings;
+  }
+
+  public void setParameterMappingList(List parameterMappingList) {
+    this.parameterMappings = (ParameterMapping[]) 
parameterMappingList.toArray(new ParameterMapping[parameterMappingList.size()]);
+    parameterMappingIndex.clear();
+    for (int i = 0; i < parameterMappings.length; i++) {
+      parameterMappingIndex.put(parameterMappings[i].getPropertyName(), new 
Integer(i));
+    }
+    Map props = new HashMap();
+    props.put("map", this);
+
+    dataExchange = 
delegate.getDataExchangeFactory().getDataExchangeForClass(parameterClass);
+    dataExchange.initialize(props);
+  }
+
+  public int getParameterIndex(String propertyName) {
+    Integer idx = null;
+    idx = (Integer) parameterMappingIndex.get(propertyName);
+    return idx == null ? -1 : idx.intValue();
+  }
+
+  public int getParameterCount() {
+    return this.parameterMappings.length;
+  }
+
+  /**
+   * @param ps
+   * @param parameters
+   * @throws java.sql.SQLException
+   */
+  public void setParameters(StatementScope statementScope, PreparedStatement 
ps, Object[] parameters)
+      throws SQLException {
+
+    ErrorContext errorContext = statementScope.getErrorContext();
+    errorContext.setActivity("applying a parameter map");
+    errorContext.setObjectId(this.getId());
+    errorContext.setResource(this.getResource());
+    errorContext.setMoreInfo("Check the parameter map.");
+
+    if (parameterMappings != null) {
+      for (int i = 0; i < parameterMappings.length; i++) {
+        ParameterMapping mapping = parameterMappings[i];
+        errorContext.setMoreInfo(mapping.getErrorString());
+        if (mapping.isInputAllowed()) {
+          setParameter(ps, mapping, parameters, i);
+        }
+      }
+    }
+  }
+
+  public Object[] getParameterObjectValues(StatementScope statementScope, 
Object parameterObject) {
+    return dataExchange.getData(statementScope, this, parameterObject);
+  }
+
+  public CacheKey getCacheKey(StatementScope statementScope, Object 
parameterObject) {
+    return dataExchange.getCacheKey(statementScope, this, parameterObject);
+  }
+
+  public void refreshParameterObjectValues(StatementScope statementScope, 
Object parameterObject, Object[] values) {
+    dataExchange.setData(statementScope, this, parameterObject, values);
+  }
+
+  public String getResource() {
+    return resource;
+  }
+
+  public void setResource(String resource) {
+    this.resource = resource;
+  }
+
+  protected void setParameter(PreparedStatement ps, ParameterMapping mapping, 
Object[] parameters, int i) throws SQLException {
+    Object value = parameters[i];
+    // Apply Null Value
+    String nullValueString = mapping.getNullValue();
+    if (nullValueString != null) {
+      TypeHandler handler = mapping.getTypeHandler();
+      if (handler.equals(value, nullValueString)) {
+        value = null;
+      }
+    }
+
+    // Set Parameter
+    TypeHandler typeHandler = mapping.getTypeHandler();
+    if (value != null) {
+      typeHandler.setParameter(ps, i + 1, value, mapping.getJdbcTypeName());
+    } else if (typeHandler instanceof CustomTypeHandler) {
+      typeHandler.setParameter(ps, i + 1, value, mapping.getJdbcTypeName());
+    } else {
+      int jdbcType = mapping.getJdbcType();
+      if (jdbcType != JdbcTypeRegistry.UNKNOWN_TYPE) {
+        ps.setNull(i + 1, jdbcType);
+      } else {
+        // Cloned from Spring StatementCreatorUtils.java (IBATIS-536)
+        if (useSetObjectForNullValue == null) {
+          // Keep current JDBC connection preferences for limiting 
introspections
+          useSetObjectForNullValue = Boolean.FALSE;
+          sqlTypeToUseForNullValue = Types.NULL;
+          try {
+            DatabaseMetaData dbmd = ps.getConnection().getMetaData();
+            String databaseProductName = dbmd.getDatabaseProductName();
+            String jdbcDriverName = dbmd.getDriverName();
+            if (databaseProductName.startsWith("Informix") || 
jdbcDriverName.startsWith("Microsoft SQL Server")) {
+              useSetObjectForNullValue = Boolean.TRUE;
+            } else if (databaseProductName.startsWith("DB2") || 
jdbcDriverName.startsWith("jConnect") ||
+                       jdbcDriverName.startsWith("SQLServer") || 
jdbcDriverName.startsWith("Apache Derby Embedded")) {
+              sqlTypeToUseForNullValue = Types.VARCHAR;
+            }
+          } catch (Throwable ex) {
+            log.debug("Could not check database or driver name: " + 
ex.getMessage());
+          }
+        }
+        if (useSetObjectForNullValue.booleanValue()) {
+          ps.setObject(i + 1, null);
+        } else {
+          ps.setNull(i + 1, sqlTypeToUseForNullValue);
+        }
+      }
+    }
+  }
+
+}

Modified: 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/mapping/parameter/ParameterMapping.java
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/mapping/parameter/ParameterMapping.java?rev=770648&r1=770647&r2=770648&view=diff
==============================================================================
--- 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/mapping/parameter/ParameterMapping.java
 (original)
+++ 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/mapping/parameter/ParameterMapping.java
 Fri May  1 12:13:24 2009
@@ -1,174 +1,176 @@
-/*
- *  Copyright 2004 Clinton Begin
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-package com.ibatis.sqlmap.engine.mapping.parameter;
-
-import com.ibatis.common.resources.Resources;
-import com.ibatis.sqlmap.client.SqlMapException;
-import com.ibatis.sqlmap.engine.type.JdbcTypeRegistry;
-import com.ibatis.sqlmap.engine.type.TypeHandler;
-
-public class ParameterMapping {
-
-  private static final String MODE_INOUT = "INOUT";
-  private static final String MODE_OUT = "OUT";
-  private static final String MODE_IN = "IN";
-
-  private String propertyName;
-  private TypeHandler typeHandler;
-  private String typeName; // this is used for REF types or user-defined types
-  private int jdbcType;
-  private String jdbcTypeName;
-  private String nullValue;
-  private String mode;
-  private boolean inputAllowed;
-  private boolean outputAllowed;
-  private Class javaType;
-  private String resultMapName;
-  private Integer numericScale;
-
-  private String errorString;
-
-  public ParameterMapping() {
-    mode = "IN";
-    inputAllowed = true;
-    outputAllowed = false;
-  }
-
-  public String getNullValue() {
-    return nullValue;
-  }
-
-  public void setNullValue(String nullValue) {
-    this.nullValue = nullValue;
-  }
-
-  public String getPropertyName() {
-    return propertyName;
-  }
-
-  public void setPropertyName(String propertyName) {
-    this.errorString = "Check the parameter mapping for the '" + propertyName 
+ "' property.";
-    this.propertyName = propertyName;
-  }
-
-  public String getErrorString() {
-    return errorString;
-  }
-
-  public TypeHandler getTypeHandler() {
-    return typeHandler;
-  }
-
-  public void setTypeHandler(TypeHandler typeHandler) {
-    this.typeHandler = typeHandler;
-  }
-
-  public Class getJavaType() {
-    return javaType;
-  }
-
-  public void setJavaType(Class javaType) {
-    this.javaType = javaType;
-  }
-
-  public String getJavaTypeName() {
-    if (javaType == null) {
-      return null;
-    } else {
-      return javaType.getName();
-    }
-  }
-
-  public void setJavaTypeName(String javaTypeName) {
-    try {
-      if (javaTypeName == null) {
-        this.javaType = null;
-      } else {
-        this.javaType = Resources.classForName(javaTypeName);
-      }
-    } catch (ClassNotFoundException e) {
-      throw new SqlMapException("Error setting javaType property of 
ParameterMap.  Cause: " + e, e);
-    }
-  }
-
-  public int getJdbcType() {
-    return jdbcType;
-  }
-
-  public String getJdbcTypeName() {
-    return jdbcTypeName;
-  }
-
-  public void setJdbcTypeName(String jdbcTypeName) {
-    this.jdbcTypeName = jdbcTypeName;
-    this.jdbcType = JdbcTypeRegistry.getType(jdbcTypeName);
-  }
-
-  public String getMode() {
-    return mode;
-  }
-
-  public void setMode(String mode) {
-    this.mode = mode;
-    inputAllowed = MODE_IN.equals(mode) || MODE_INOUT.equals(mode);
-    outputAllowed = MODE_OUT.equals(mode) || MODE_INOUT.equals(mode);
-  }
-
-  public boolean isInputAllowed() {
-    return inputAllowed;
-  }
-
-  public boolean isOutputAllowed() {
-    return outputAllowed;
-  }
-
-  /**
-   * user-defined or REF types
-   *
-   * @return typeName
-   */
-  public String getTypeName() {
-    return typeName;
-  }
-
-  /**
-   * for user-defined or REF types
-   * @param typeName
-   */
-  public void setTypeName(String typeName) {
-    this.typeName = typeName;
-  }
-
-  public String getResultMapName() {
-         return resultMapName;
-  }
-
-  public void setResultMapName(String resultMapName) {
-         this.resultMapName = resultMapName;
-  }
-
-  public Integer getNumericScale() {
-    return numericScale;
-  }
-
-  public void setNumericScale(Integer numericScale) {
-    if (numericScale != null && numericScale.intValue() < 0) {
-      throw new RuntimeException("Error setting numericScale on parameter 
mapping.  Cause: scale must be greater than or equal to zero");
-    }
-    this.numericScale = numericScale;
-  }
-
-}
+/*
+ *  Copyright 2004 Clinton Begin
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package com.ibatis.sqlmap.engine.mapping.parameter;
+
+import com.ibatis.common.resources.Resources;
+import com.ibatis.sqlmap.client.SqlMapException;
+import com.ibatis.sqlmap.engine.type.JdbcTypeRegistry;
+import com.ibatis.sqlmap.engine.type.TypeHandler;
+
+public class ParameterMapping {
+
+  private static final String MODE_INOUT = "INOUT";
+  private static final String MODE_OUT = "OUT";
+  private static final String MODE_IN = "IN";
+
+  private String propertyName;
+  private TypeHandler typeHandler;
+  private String typeName; // this is used for REF types or user-defined types
+  private int jdbcType;
+  private String jdbcTypeName;
+  private String nullValue;
+  private String mode;
+  private boolean inputAllowed;
+  private boolean outputAllowed;
+  private Class javaType;
+  private String resultMapName;
+  private Integer numericScale;
+
+  private String errorString;
+
+  public ParameterMapping() {
+    mode = "IN";
+    inputAllowed = true;
+    outputAllowed = false;
+    // Default JDBC type if UNKNOWN_TYPE
+    jdbcType = JdbcTypeRegistry.UNKNOWN_TYPE;
+  }
+
+  public String getNullValue() {
+    return nullValue;
+  }
+
+  public void setNullValue(String nullValue) {
+    this.nullValue = nullValue;
+  }
+
+  public String getPropertyName() {
+    return propertyName;
+  }
+
+  public void setPropertyName(String propertyName) {
+    this.errorString = "Check the parameter mapping for the '" + propertyName 
+ "' property.";
+    this.propertyName = propertyName;
+  }
+
+  public String getErrorString() {
+    return errorString;
+  }
+
+  public TypeHandler getTypeHandler() {
+    return typeHandler;
+  }
+
+  public void setTypeHandler(TypeHandler typeHandler) {
+    this.typeHandler = typeHandler;
+  }
+
+  public Class getJavaType() {
+    return javaType;
+  }
+
+  public void setJavaType(Class javaType) {
+    this.javaType = javaType;
+  }
+
+  public String getJavaTypeName() {
+    if (javaType == null) {
+      return null;
+    } else {
+      return javaType.getName();
+    }
+  }
+
+  public void setJavaTypeName(String javaTypeName) {
+    try {
+      if (javaTypeName == null) {
+        this.javaType = null;
+      } else {
+        this.javaType = Resources.classForName(javaTypeName);
+      }
+    } catch (ClassNotFoundException e) {
+      throw new SqlMapException("Error setting javaType property of 
ParameterMap.  Cause: " + e, e);
+    }
+  }
+
+  public int getJdbcType() {
+    return jdbcType;
+  }
+
+  public String getJdbcTypeName() {
+    return jdbcTypeName;
+  }
+
+  public void setJdbcTypeName(String jdbcTypeName) {
+    this.jdbcTypeName = jdbcTypeName;
+    this.jdbcType = JdbcTypeRegistry.getType(jdbcTypeName);
+  }
+
+  public String getMode() {
+    return mode;
+  }
+
+  public void setMode(String mode) {
+    this.mode = mode;
+    inputAllowed = MODE_IN.equals(mode) || MODE_INOUT.equals(mode);
+    outputAllowed = MODE_OUT.equals(mode) || MODE_INOUT.equals(mode);
+  }
+
+  public boolean isInputAllowed() {
+    return inputAllowed;
+  }
+
+  public boolean isOutputAllowed() {
+    return outputAllowed;
+  }
+
+  /**
+   * user-defined or REF types
+   *
+   * @return typeName
+   */
+  public String getTypeName() {
+    return typeName;
+  }
+
+  /**
+   * for user-defined or REF types
+   * @param typeName
+   */
+  public void setTypeName(String typeName) {
+    this.typeName = typeName;
+  }
+
+  public String getResultMapName() {
+         return resultMapName;
+  }
+
+  public void setResultMapName(String resultMapName) {
+         this.resultMapName = resultMapName;
+  }
+
+  public Integer getNumericScale() {
+    return numericScale;
+  }
+
+  public void setNumericScale(Integer numericScale) {
+    if (numericScale != null && numericScale.intValue() < 0) {
+      throw new RuntimeException("Error setting numericScale on parameter 
mapping.  Cause: scale must be greater than or equal to zero");
+    }
+    this.numericScale = numericScale;
+  }
+
+}

Added: 
ibatis/trunk/java/ibatis-2/ibatis-2-core/test/com/ibatis/sqlmap/DerbyParameterMapTest.java
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-2/ibatis-2-core/test/com/ibatis/sqlmap/DerbyParameterMapTest.java?rev=770648&view=auto
==============================================================================
--- 
ibatis/trunk/java/ibatis-2/ibatis-2-core/test/com/ibatis/sqlmap/DerbyParameterMapTest.java
 (added)
+++ 
ibatis/trunk/java/ibatis-2/ibatis-2-core/test/com/ibatis/sqlmap/DerbyParameterMapTest.java
 Fri May  1 12:13:24 2009
@@ -0,0 +1,25 @@
+package com.ibatis.sqlmap;
+
+import testdomain.Account;
+
+import java.sql.SQLException;
+
+/**
+ * TestCase for validating PreparedStatement.setNull calls for Derby.
+ * See IBATIS-536 for more information.
+ */
+public class DerbyParameterMapTest extends ParameterMapTest {
+
+  // SETUP & TEARDOWN
+
+  protected void setUp() throws Exception {
+    initSqlMap("com/ibatis/sqlmap/maps/DerbySqlMapConfig.xml", null);
+    initScript("scripts/account-init.sql");
+  }
+
+  // PARAMETER MAP FEATURE TESTS
+
+  protected void assertMessageIsNullValueNotAllowed(String message) {
+    assertTrue("Invalid exception message", message.indexOf("Column 'ACC_ID'  
cannot accept a NULL value.") > -1);
+  }
+}

Modified: 
ibatis/trunk/java/ibatis-2/ibatis-2-core/test/com/ibatis/sqlmap/ParameterMapTest.java
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-2/ibatis-2-core/test/com/ibatis/sqlmap/ParameterMapTest.java?rev=770648&r1=770647&r2=770648&view=diff
==============================================================================
--- 
ibatis/trunk/java/ibatis-2/ibatis-2-core/test/com/ibatis/sqlmap/ParameterMapTest.java
 (original)
+++ 
ibatis/trunk/java/ibatis-2/ibatis-2-core/test/com/ibatis/sqlmap/ParameterMapTest.java
 Fri May  1 12:13:24 2009
@@ -54,10 +54,15 @@
 
 
     assertNotNull(expected);
-       assertTrue(expected.getMessage().indexOf("Attempt to insert null into a 
non-nullable column: column: ACC_ID table: ACCOUNT in statement") > -1);
+    assertMessageIsNullValueNotAllowed(expected.getMessage());
     assertNull(account);
   }
 
+  protected void assertMessageIsNullValueNotAllowed(String message) {
+    assertTrue("Invalid exception message",
+               message.indexOf("Attempt to insert null into a non-nullable 
column: column: ACC_ID table: ACCOUNT in statement") > -1);
+  }
+
   public void testSpecifiedType() throws SQLException {
     Account account = newAccount6();
     account.setEmailAddress(null);

Modified: 
ibatis/trunk/java/ibatis-2/ibatis-2-core/test/com/ibatis/sqlmap/maps/DerbySqlMapConfig.xml
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-2/ibatis-2-core/test/com/ibatis/sqlmap/maps/DerbySqlMapConfig.xml?rev=770648&r1=770647&r2=770648&view=diff
==============================================================================
--- 
ibatis/trunk/java/ibatis-2/ibatis-2-core/test/com/ibatis/sqlmap/maps/DerbySqlMapConfig.xml
 (original)
+++ 
ibatis/trunk/java/ibatis-2/ibatis-2-core/test/com/ibatis/sqlmap/maps/DerbySqlMapConfig.xml
 Fri May  1 12:13:24 2009
@@ -46,6 +46,7 @@
   </transactionManager>
 
   <sqlMap resource="${SqlMapPath}/DerbyProc.xml"/>
+  <sqlMap resource="${SqlMapPath}/Account.xml"/>
   
 </sqlMapConfig>
 


Reply via email to