-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add specific mybatis string type handler
- Loading branch information
1 parent
af0d12f
commit 6a2936a
Showing
2 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ne-common/src/main/java/org/flowable/common/engine/impl/db/FlowableStringTypeHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.flowable.common.engine.impl.db; | ||
|
||
import java.sql.CallableStatement; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Types; | ||
|
||
import org.apache.ibatis.type.BaseTypeHandler; | ||
import org.apache.ibatis.type.JdbcType; | ||
import org.apache.ibatis.type.TypeException; | ||
|
||
public class FlowableStringTypeHandler extends BaseTypeHandler<String> { | ||
|
||
@Override | ||
public void setParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException { | ||
if (parameter == null) { | ||
if (jdbcType == null) { | ||
throw new TypeException("JDBC requires that the JdbcType must be specified for all nullable parameters."); | ||
} | ||
try { | ||
ps.setNull(i, Types.NULL); | ||
} catch (SQLException e) { | ||
throw new TypeException("Error setting null for parameter #" + i + " with JdbcType " + jdbcType + " . " | ||
+ "Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. " | ||
+ "Cause: " + e, e); | ||
} | ||
} else { | ||
try { | ||
setNonNullParameter(ps, i, parameter, jdbcType); | ||
} catch (Exception e) { | ||
throw new TypeException("Error setting non null for parameter #" + i + " with JdbcType " + jdbcType + " . " | ||
+ "Try setting a different JdbcType for this parameter or a different configuration property. " + "Cause: " | ||
+ e, e); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) | ||
throws SQLException { | ||
ps.setString(i, parameter); | ||
} | ||
|
||
@Override | ||
public String getNullableResult(ResultSet rs, String columnName) throws SQLException { | ||
return rs.getString(columnName); | ||
} | ||
|
||
@Override | ||
public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException { | ||
return rs.getString(columnIndex); | ||
} | ||
|
||
@Override | ||
public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { | ||
return cs.getString(columnIndex); | ||
} | ||
} |