FileDocCategorySizeDatePackage
SourceMediaType.javaAPI DocExample4223Tue Feb 10 12:16:58 GMT 2004com.oreilly.hh

SourceMediaType

public class SourceMediaType extends Object implements net.sf.hibernate.UserType
Manages persistence for the {@link SourceMedia} typesafe enumeration.

Fields Summary
Constructors Summary
Methods Summary
public java.lang.ObjectdeepCopy(java.lang.Object value)
Return a deep copy of the persistent state, stopping at entities and collections.

param
value the object whose state is to be copied.
return
the same object, since enumeration instances are singletons.
throws
ClassCastException for non {@link SourceMedia} values.

        return (SourceMedia)value;
    
public booleanequals(java.lang.Object x, java.lang.Object y)
Compare two instances of the class mapped by this type for persistence "equality".

param
x first object to be compared.
param
y second object to be compared.
return
true iff both represent the same SourceMedia type.
throws
ClassCastException if x or y isn't a {@link SourceMedia}.

        // We can compare instances, since SourceMedia are immutable singletons
        return (x == y);
    
public booleanisMutable()
Indicates whether objects managed by this type are mutable.

return
false, since enumeration instances are immutable singletons.

        return false;
    
public java.lang.ObjectnullSafeGet(java.sql.ResultSet rs, java.lang.String[] names, java.lang.Object owner)
Retrieve an instance of the mapped class from a JDBC {@link ResultSet}.

param
rs the results from which the instance should be retrieved.
param
names the columns from which the instance should be retrieved.
param
owner the entity containing the value being retrieved.
return
the retrieved {@link SourceMedia} value, or null.
throws
HibernateException if there is a problem performing the mapping.
throws
SQLException if there is a problem accessing the database.

        // Start by looking up the value name
        String name = (String) Hibernate.STRING.nullSafeGet(rs, names[0]);
        if (name == null) {
            return null;
        }
        // Then find the corresponding enumeration value
        try {
            return SourceMedia.getInstanceByName(name);
        }
        catch (java.util.NoSuchElementException e) {
            throw new HibernateException("Bad SourceMedia value: " + name, e);
        }
    
public voidnullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index)
Write an instance of the mapped class to a {@link PreparedStatement}, handling null values.

param
st a JDBC prepared statement.
param
value the SourceMedia value to write.
param
index the parameter index within the prepared statement at which this value is to be written.
throws
HibernateException if there is a problem performing the mapping.
throws
SQLException if there is a problem accessing the database.

        String name = null;
        if (value != null)
            name = ((SourceMedia)value).getName();
        Hibernate.STRING.nullSafeSet(st, name, index);
    
public java.lang.ClassreturnedClass()
Determine the class that is returned by {@link #nullSafeGet}.

return
{@link SourceMedia}, the actual type returned by {@link #nullSafeGet}.

        return SourceMedia.class;
    
public int[]sqlTypes()
Determine the SQL type(s) of the column(s) used by this type mapping.

return
a single VARCHAR column.

        // Allocate a new array each time to protect against callers changing
        // its contents.
        int[] typeList = {
            Types.VARCHAR
        };
        return typeList;