Example usage for org.hibernate.type Type disassemble

List of usage examples for org.hibernate.type Type disassemble

Introduction

In this page you can find the example usage for org.hibernate.type Type disassemble.

Prototype

Serializable disassemble(Object value, SharedSessionContractImplementor session, Object owner)
        throws HibernateException;

Source Link

Document

Return a disassembled representation of the object.

Usage

From source file:com.hazelcast.hibernate.region.NaturalIdCacheKey.java

License:Open Source License

@SuppressWarnings("checkstyle:magicnumber")
public NaturalIdCacheKey(final Object[] naturalIdValues, Type[] propertyTypes, int[] naturalIdPropertyIndexes,
        final String entityName, final SharedSessionContractImplementor session) {

    this.naturalIdValues = new Serializable[naturalIdValues.length];
    this.entityName = entityName;
    this.tenantId = session.getTenantIdentifier();

    SessionFactoryImplementor factory = session.getFactory();

    int result = 1;
    result = 31 * result + (entityName != null ? entityName.hashCode() : 0);
    result = 31 * result + (tenantId != null ? tenantId.hashCode() : 0);

    for (int i = 0; i < naturalIdValues.length; i++) {
        final int naturalIdPropertyIndex = naturalIdPropertyIndexes[i];
        final Type type = propertyTypes[naturalIdPropertyIndex];
        final Object value = naturalIdValues[i];

        result = 31 * result + (value != null ? type.getHashCode(value, factory) : 0);

        if (type instanceof EntityType
                && type.getSemiResolvedType(factory).getReturnedClass().isInstance(value)) {
            this.naturalIdValues[i] = (Serializable) value;
        } else {/*from  ww w  .  java  2 s .  c om*/
            this.naturalIdValues[i] = type.disassemble(value, session, null);
        }
    }
    this.hashCode = result;
}