📄 enumtype.java
字号:
package org.jbpm.persistence.hibernate;
import java.sql.*;
import org.jbpm.util.lang.*;
import org.jbpm.util.log.*;
import org.jbpm.model.definition.EventType;
import org.jbpm.model.definition.impl.*;
import org.jbpm.service.*;
import net.sf.hibernate.*;
import net.sf.hibernate.type.*;
public class EnumType extends ImmutableType implements Type {
public static class EventTypeType extends EnumType { public EventTypeType() { super(EventType.class, Types.VARCHAR); } }
public static class DefaultTypeType extends EnumType { public DefaultTypeType() { super(DefaultType.class, Types.VARCHAR); } }
public static class ServiceMethodType extends EnumType { public ServiceMethodType() { super(ServiceMethod.class, Types.VARCHAR); } }
public static class LevelType extends EnumType { public LevelType() { super(Level.class, Types.INTEGER); } }
private Class enumClazz = null;
private int idType = -1;
public EnumType( Class enumClazz, int idType ) {
this.enumClazz = enumClazz;
this.idType = idType;
}
public Object get(ResultSet rs, String name) throws HibernateException, SQLException {
Enum enum = null;
Object id = rs.getObject(name);
if ( id != null ) {
enum = Enum.findById( enumClazz, id );
}
return enum;
}
public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
st.setObject( index, ((Enum)value).getId() );
}
public int sqlType() {
return idType;
}
public String toString(Object value) throws HibernateException {
String text = null;
if ( value != null ) {
text = ((Enum)value).getId().toString();
}
return text;
}
public Object fromStringValue(String xml) throws HibernateException {
return Enum.findById( enumClazz, xml );
}
public Class getReturnedClass() {
return enumClazz;
}
public boolean equals(Object x, Object y) throws HibernateException {
return (x==y);
}
public String getName() {
return enumClazz.getName();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -