01: package org.jbpm.db.hibernate;
02:
03: import java.sql.PreparedStatement;
04: import java.sql.SQLException;
05: import java.util.Properties;
06:
07: import org.hibernate.type.StringType;
08: import org.jbpm.JbpmException;
09:
10: public class StringMax extends StringType implements
11: org.hibernate.usertype.ParameterizedType {
12:
13: private static final long serialVersionUID = 1L;
14:
15: int length = 4000;
16:
17: public void set(PreparedStatement st, Object value, int index)
18: throws SQLException {
19: String string = (String) value;
20: if ((value != null) && (string.length() > length)) {
21: value = string.substring(0, length);
22: }
23: super .set(st, value, index);
24: }
25:
26: public void setParameterValues(Properties parameters) {
27: if ((parameters != null) && (parameters.containsKey("length"))) {
28: try {
29: length = Integer.parseInt(parameters
30: .getProperty("length"));
31: } catch (NumberFormatException e) {
32: throw new JbpmException(
33: "hibernate column type 'string_max' can't parse value '"
34: + parameters.getProperty("length")
35: + "' as a max length. default is 4000.",
36: e);
37: }
38: }
39: }
40: }
|