From: <one...@us...> - 2003-04-06 10:16:52
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate In directory sc8-pr-cvs1:/tmp/cvs-serv29200 Added Files: CompositeUserType.java Log Message: added CompositeUserType --- NEW FILE: CompositeUserType.java --- //$Id: CompositeUserType.java,v 1.1 2003/04/06 10:16:48 oneovthafew Exp $ package net.sf.hibernate; import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import net.sf.hibernate.engine.SessionImplementor; import net.sf.hibernate.type.Type; /** * A <tt>UserType</tt> that may be dereferenced in a query. * This interface allows a custom type to define "properties". * These need not necessarily correspond to physical JavaBeans * style properties.<br> * <br> * A <tt>CompositeUserType</tt> may be used in almost every way * that a component may be used. It may even contain many-to-one * associations.<br> * <br> * Implementors must be immutable and must declare a public * default constructor. * * @see UserType for more simple cases * @see net.sf.hibernate.type.Type */ public interface CompositeUserType { /** * Get the "property names" that may be used in a * query. * * @return an array of "property names" */ public String[] getPropertyNames(); /** * Get the corresponding "property types" * * @return an array of Hibernate types */ public Type[] getPropertyTypes(); /** * Get the value of a property * * @param component an instance of class mapped by this "type" * @param property * @return the property value */ public Object getPropertyValue(Object component, int property) throws HibernateException; /** * Set the value of a property * * @param component an instance of class mapped by this "type" * @param property * @param value the value to set */ public void setPropertyValue(Object component, int property, Object value) throws HibernateException; /** * Return the SQL type codes for the columns mapped by this type. The * codes are defined on <tt>java.sql.Types</tt>. * @see java.sql.Types * @return int[] the typecodes */ public int[] sqlTypes(); /** * The class returned by <tt>nullSafeGet()</tt>. * * @param session * @return Class */ public Class returnedClass(); /** * Compare two instances of the class mapped by this type for persistence * "equality", ie. equality of persistent state. * * @param x * @param y * @return boolean */ public boolean equals(Object x, Object y) throws HibernateException; /** * Retrieve an instance of the mapped class from a JDBC resultset. Implementors * should handle possibility of null values. * * @param rs a JDBC result set * @param names the column names * @param session * @param owner the containing entity * @return Object * @throws HibernateException * @throws SQLException */ public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException; /** * Write an instance of the mapped class to a prepared statement. Implementors * should handle possibility of null values. A multi-column type should be written * to parameters starting from <tt>index</tt>. * * @param st a JDBC prepared statement * @param value the object to write * @param index statement parameter index * @param session * @throws HibernateException * @throws SQLException */ public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException; /** * Return a deep copy of the persistent state, stopping at entities and at * collections. * * @param value generally a collection element or entity field * @param session * @return Object a copy */ public Object deepCopy(Object value) throws HibernateException; /** * Are objects of this type mutable? * * @return boolean */ public boolean isMutable(); /** * Transform the object into its cacheable representation. At the very least this * method should perform a deep copy. That may not be enough for some implementation, * however; for example, associations must be cached as identifier values. (optional * operation) * * @param value the object to be cached * @param session * @return */ public Serializable disassemble(Object value, SessionImplementor session) throws HibernateException; /** * Reconstruct an object from the cacheable representation. At the very least this * method should perform a deep copy. (optional operation) * * @param value the object to be cached * @param session * @return */ public Object assemble(Serializable cached, SessionImplementor session, Object owner) throws HibernateException; } |