Code:
/*
* Copyright 2005 Bedag Informatik AG
*
*/
package ch.bedag.gba.test.type;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.HibernateException;
import ch.bedag.gba.type.AbstractUserType;
/**
* @alias LanguageStringType
* @since 21.07.2005
*/
public class TestMultiLanguageStringUserType extends AbstractUserType {
private static final int[] SQL_TYPES = {
Types.VARCHAR,Types.VARCHAR, Types.VARCHAR, Types.VARCHAR};
public static final int DE=1;
public static final int FR=2;
public static final int IT=3;
public static final int EN=4;
private static final int COUNT=4;
public Object assemble(Serializable arg0, Object arg1) throws HibernateException {
return null;
}
public Object deepCopy(Object arg0) throws HibernateException {
return arg0;
}
public Serializable disassemble(Object arg0) throws HibernateException {
return null;
}
public boolean equals(Object x, Object y) throws HibernateException {
if (x == y) return true;
if (x == null || y == null) return false;
return x.equals(y);
}
public int hashCode(Object arg0) throws HibernateException {
if (arg0 == null) {
return 0;
} else {
return arg0.hashCode();
}
}
public boolean isMutable() {
return false;
}
public Object nullSafeGet(ResultSet result, String[] names, Object owner)
throws HibernateException, SQLException {
String textSpracheDe = result.getString(names[0]);
String textSpracheFr = result.getString(names[1]);
String textSpracheIt = result.getString(names[2]);
String textSpracheEn = result.getString(names[3]);
if (textSpracheDe == null && textSpracheFr == null &&
textSpracheIt == null && textSpracheEn == null) {
return null;
} else {
TestMultiLanguageString languageString=new TestMultiLanguageString(textSpracheDe,
textSpracheFr, textSpracheIt, textSpracheEn);
notify(languageString,owner);
return languageString;
}
}
public void nullSafeSet(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException {
if (value == null) {
st.setNull(index, SQL_TYPES[0]);
st.setNull(index+1, SQL_TYPES[1]);
st.setNull(index+2, SQL_TYPES[2]);
st.setNull(index+3, SQL_TYPES[3]);
}else{
nullSafeSetString(st,index, SQL_TYPES[0],
((TestMultiLanguageString)value).getTextSpracheDe());
nullSafeSetString(st,index+1, SQL_TYPES[1],
((TestMultiLanguageString)value).getTextSpracheFr());
nullSafeSetString(st,index+2, SQL_TYPES[2],
((TestMultiLanguageString)value).getTextSpracheIt());
nullSafeSetString(st,index+3, SQL_TYPES[3],
((TestMultiLanguageString)value).getTextSpracheEn());
}
}
public Object replace(Object arg0, Object arg1, Object arg2)
throws HibernateException {
return null;
}
public Class returnedClass() {
return TestMultiLanguageString.class;
}
public int[] sqlTypes() {
return SQL_TYPES;
}
private void nullSafeSetString(PreparedStatement st,
int index,
int sqlType,
String value)
throws SQLException {
if (value == null) {
st.setNull(index, sqlType);
} else {
st.setString(index, value);
}
}
}