/*
* Created on Oct 12, 2005 @author : String
*/
package com.foo.model.primatives;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.type.Type;
import org.hibernate.usertype.CompositeUserType;
import com.foo.model.AbstractState;
import com.foo.model.IControllerState;
/**
* @author String
*
*/
public class TestLabelState extends AbstractState implements IControllerState, CompositeUserType{
private String labelText = "";
/**
*
*/
public TestLabelState() {
super();
}
/**
* @param id2
*/
public TestLabelState(Integer id2) {
super(id2);
}
public TestLabelState(String text) {
this(null, text);
}
public TestLabelState(Integer id2, String text) {
super(id2);
setLabelText(text);
}
public String getLabelText() {
return labelText;
}
public void setLabelText(String text) {
if (this.labelText.equals(text)) {
return;
}
this.labelText = text;
notifyObservers(createValueChangeEvent());
}
/**
* @see org.hibernate.usertype.UserType#sqlTypes()
*/
public int[] sqlTypes() {
return null;
}
/**
* @see org.hibernate.usertype.UserType#returnedClass()
*/
public Class returnedClass() {
return TestLabelState.class;
}
/**
* @see org.hibernate.usertype.UserType#equals(java.lang.Object,
* java.lang.Object)
*/
public boolean equals(Object x, Object y) throws HibernateException {
if (x == y) {
return true;
}
if (x == null || y == null) {
return false;
}
TestLabelState lsx = (TestLabelState) x;
TestLabelState lsy = (TestLabelState) y;
return lsx.getLabelText().equals(lsy.getLabelText());
}
/**
* @see org.hibernate.usertype.UserType#hashCode(java.lang.Object)
*/
public int hashCode(Object x) throws HibernateException {
return ((TestLabelState)x).getLabelText().hashCode();
}
/**
* @see org.hibernate.usertype.UserType#deepCopy(java.lang.Object)
*/
public Object deepCopy(Object value) throws HibernateException {
return new TestLabelState(((TestLabelState)value).getLabelText());
}
/**
* @see org.hibernate.usertype.UserType#isMutable()
*/
public boolean isMutable() {
return true;
}
/**
* @see org.hibernate.usertype.CompositeUserType#getPropertyNames()
*/
public String[] getPropertyNames() {
return new String[] { "labelText" };
}
/**
* @see org.hibernate.usertype.CompositeUserType#getPropertyTypes()
*/
public Type[] getPropertyTypes() {
return new Type[] { Hibernate.STRING };
}
/**
* @see org.hibernate.usertype.CompositeUserType#getPropertyValue(java.lang.Object,
* int)
*/
public Object getPropertyValue(Object component, int property) throws HibernateException {
TestLabelState ls = (TestLabelState) component;
return ls.getLabelText();
}
/**
* @see org.hibernate.usertype.CompositeUserType#setPropertyValue(java.lang.Object,
* int, java.lang.Object)
*/
public void setPropertyValue(Object component, int property, Object value) throws HibernateException {
((TestLabelState) component).setLabel((String) value);
}
/**
* @see org.hibernate.usertype.CompositeUserType#nullSafeGet(java.sql.ResultSet,
* java.lang.String[], org.hibernate.engine.SessionImplementor,
* java.lang.Object)
*/
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
throws HibernateException, SQLException {
String text = (String)Hibernate.STRING.nullSafeGet(rs, names[0]);
if (text == null){
return null;
}
return new TestLabelState(text);
}
/**
* @see org.hibernate.usertype.CompositeUserType#nullSafeSet(java.sql.PreparedStatement,
* java.lang.Object, int, org.hibernate.engine.SessionImplementor)
*/
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
throws HibernateException, SQLException {
Hibernate.STRING.nullSafeSet(st, ((TestLabelState)value).getLabelText(), index);
}
/**
* @see org.hibernate.usertype.CompositeUserType#disassemble(java.lang.Object,
* org.hibernate.engine.SessionImplementor)
*/
public Serializable disassemble(Object value, SessionImplementor session) throws HibernateException {
return (Serializable)deepCopy(value);
}
/**
* @see org.hibernate.usertype.CompositeUserType#assemble(java.io.Serializable,
* org.hibernate.engine.SessionImplementor, java.lang.Object)
*/
public Object assemble(Serializable cached, SessionImplementor session, Object owner) throws HibernateException {
return deepCopy(cached);
}
/**
* @see org.hibernate.usertype.CompositeUserType#replace(java.lang.Object,
* java.lang.Object, org.hibernate.engine.SessionImplementor,
* java.lang.Object)
*/
public Object replace(Object original, Object target, SessionImplementor session, Object owner)
throws HibernateException {
return deepCopy(original);
}
}
|