下面列出了怎么用org.hibernate.usertype.EnhancedUserType的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public Object fromStringValue(String string) throws HibernateException {
if ( StringRepresentableType.class.isInstance( getUserType() ) ) {
return ( (StringRepresentableType) getUserType() ).fromStringValue( string );
}
if ( EnhancedUserType.class.isInstance( getUserType() ) ) {
//noinspection deprecation
return ( (EnhancedUserType) getUserType() ).fromXMLString( string );
}
throw new HibernateException(
String.format(
"Could not process #fromStringValue, UserType class [%s] did not implement %s or %s",
name,
StringRepresentableType.class.getName(),
EnhancedUserType.class.getName()
)
);
}
@Override
@SuppressWarnings("unchecked")
public String toString(Object value) throws HibernateException {
if ( StringRepresentableType.class.isInstance( getUserType() ) ) {
return ( (StringRepresentableType) getUserType() ).toString( value );
}
if ( value == null ) {
return null;
}
if ( EnhancedUserType.class.isInstance( getUserType() ) ) {
//noinspection deprecation
return ( (EnhancedUserType) getUserType() ).toXMLString( value );
}
return value.toString();
}
public String toXMLString(Object value, SessionFactoryImplementor factory) {
if (value==null) return null;
if (userType instanceof EnhancedUserType) {
return ( (EnhancedUserType) userType ).toXMLString(value);
}
else {
return value.toString();
}
}
@Override
public String objectToSQLString(Object value, Dialect dialect) throws Exception {
return ( (EnhancedUserType) getUserType() ).objectToSQLString( value);
}
public Object fromXMLString(String xml, Mapping factory) {
return ( (EnhancedUserType) userType ).fromXMLString(xml);
}
public Object stringToObject(String xml) {
return ( (EnhancedUserType) userType ).fromXMLString(xml);
}
public String objectToSQLString(Object value, Dialect dialect) throws Exception {
return ( (EnhancedUserType) userType ).objectToSQLString(value);
}