Example usage for org.hibernate Hibernate getClass

List of usage examples for org.hibernate Hibernate getClass

Introduction

In this page you can find the example usage for org.hibernate Hibernate getClass.

Prototype

public static Class getClass(Object proxy) 

Source Link

Document

Get the true, underlying class of a proxied persistent class.

Usage

From source file:br.cefetmg.radar.util.typeadapter.HibernateProxyTypeAdapter.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override//from  w  w  w. j a va 2  s .  com
public void write(JsonWriter out, HibernateProxy value) throws IOException {
    if (value == null) {
        out.nullValue();
        return;
    }
    // Retrieve the original (not proxy) class
    Class<?> baseType = Hibernate.getClass(value);
    // Get the TypeAdapter of the original class, to delegate the serialization
    TypeAdapter delegate = context.getAdapter(TypeToken.get(baseType));
    // Get a filled instance of the original class
    Object unproxiedValue = ((HibernateProxy) value).getHibernateLazyInitializer().getImplementation();
    // Serialize the value
    delegate.write(out, unproxiedValue);
}

From source file:com.ardikapras.main.NewMain.java

/**
 * @param args the command line arguments
 *///  w w w  .  j  av  a  2s .c  o m
public static void main(String[] args) {
    // TODO code application logic here
    Hibernate.getClass(args);
}

From source file:com.coroptis.coidi.op.view.entities.AbstractEntity.java

License:Apache License

/**
 * {@inheritDoc}//  w  w w . j  ava 2 s .co m
 */
@SuppressWarnings("unchecked")
@Override
public final boolean equals(final Object other) {
    if (this == other) {
        return true;
    }

    if (other == null || // looks into the target class of a proxy if
    // necessary
            !Hibernate.getClass(other).equals(Hibernate.getClass(this))) {
        return false;
    }

    return dataEquals((T) other);
}

From source file:com.doculibre.constellio.wicket.models.ReloadableEntityModel.java

License:Open Source License

@SuppressWarnings("unchecked")
private void prepareForSerialization() {
    if (entity != null) {
        if (entity.getId() != null) {
            entityClass = (Class<T>) Hibernate.getClass(entity);
            id = entity.getId();//from   w ww .  ja v  a 2s  .  c o m
            entity = null;
            serializedEntity = null;
        } else {
            serializedEntity = SerializationUtils.serialize((Serializable) entity);
            entity = null;
        }
    }
}

From source file:com.example.app.communication.ui.EmailTemplateConfigurationUI.java

License:Open Source License

/**
 * Instantiates a new Email template sending ui.
 *
 * @param emailTemplates the email templates
 * @param profile optional profile./*w  w w .ja  v a  2 s.  com*/
 */
public EmailTemplateConfigurationUI(List<EmailTemplate> emailTemplates, @Nullable Profile profile) {
    super();
    _profile = profile;
    Class<?> configType = null;
    for (EmailTemplate emailTemplate : emailTemplates) {
        Preconditions.checkNotNull(emailTemplate.getEmailConfig(), "EmailConfig cannot be null.");
        final Class<?> currentConfigType = Hibernate.getClass(emailTemplate.getEmailConfig());
        if (configType == null)
            configType = currentConfigType;
        else
            Preconditions.checkArgument(configType == currentConfigType,
                    "EmailTemplates must be of the same configuration type.");
    }
    @SuppressWarnings("unchecked")
    final SimpleListModel<EmailTemplate> listModel = (SimpleListModel<EmailTemplate>) _emailTemplateChoice
            .getModel();
    listModel.getList().addAll(emailTemplates);

    _recipientContainer.addClassName("recipients");
    _variableContainer.addClassName("variable-list");
    _emailTemplatePreview.addClassName("email-preview-content");
    addClassName("email-configuration-ui");
}

From source file:com.example.app.model.AbstractAuditableEntity.java

License:Open Source License

@Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings("BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS")
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
@Contract("_->!fail")
public boolean equals(Object obj) {
    if (obj == this)
        return true;
    if (obj == null)
        return false;
    if (Hibernate.getClass(obj) != Hibernate.getClass(this))
        return false;

    T thisId = getId();//from   w  w  w.java  2 s .c o  m
    // If either instance is transient, use object identity (Object.equals())
    if (thisId == null) {
        return this == obj;
    }

    Object otherId = ((AbstractAuditableEntity) obj).getId();
    if (otherId == null)
        return this == obj;
    else
        return thisId.equals(otherId);
}

From source file:com.example.app.model.AbstractAuditableEntity.java

License:Open Source License

@Override
public String toString() {
    return Hibernate.getClass(this).getName() + '#' + getId();
}

From source file:com.example.app.model.AbstractAuditableSoftDeleteEntity.java

License:Open Source License

@Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings("BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS")
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
@Contract("_->!fail")
public boolean equals(Object obj) {
    if (obj == this)
        return true;
    if (obj == null)
        return false;
    if (Hibernate.getClass(obj) != Hibernate.getClass(this))
        return false;

    Integer thisId = getId();/*w  w  w. j ava  2  s . c  o  m*/
    // If either instance is transient, use object identity (Object.equals())
    if (thisId == null) {
        return this == obj;
    }

    Integer otherId = ((AbstractAuditableSoftDeleteEntity) obj).getId();
    if (otherId == null)
        return this == obj;
    else
        return thisId.equals(otherId);
}

From source file:com.example.app.model.AbstractEntity.java

License:Open Source License

@Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings({ "BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS",
        "EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS" })
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
@Contract("_->!fail")
public boolean equals(Object obj) {
    if (obj == this)
        return true;
    if (obj == null)
        return false;
    if (Hibernate.getClass(obj) != Hibernate.getClass(this))
        return false;

    T thisId = getId();//from  w  w w . j av a  2  s . c o m
    // If either instance is transient, use object identity (Object.equals())
    if (thisId == null) {
        return this == obj;
    }

    Object otherId = ((AbstractEntity) obj).getId();
    if (otherId == null)
        return this == obj;
    else
        return thisId.equals(otherId);
}

From source file:com.example.app.model.schedule.ICal4jSchedule.java

License:Open Source License

@Override
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (o == null)
        return false;
    if (Hibernate.getClass(this) != Hibernate.getClass(o))
        return false;
    if (getId() != null)
        return super.equals(o);

    ICal4jSchedule that = EntityRetriever.getInstance().narrowProxyIfPossible(o);
    return isRepeat() == that.isRepeat()
            && Objects.equals(getEventProgrammaticIdentifier(), that.getEventProgrammaticIdentifier())
            && Objects.equals(getRecurrenceRule(), that.getRecurrenceRule())
            && getTemporalDirection() == that.getTemporalDirection();
}