Example usage for org.hibernate.persister.entity EntityPersister getPropertyType

List of usage examples for org.hibernate.persister.entity EntityPersister getPropertyType

Introduction

In this page you can find the example usage for org.hibernate.persister.entity EntityPersister getPropertyType.

Prototype

Type getPropertyType(String propertyName) throws MappingException;

Source Link

Document

Get the type of a particular property by name.

Usage

From source file:com.autobizlogic.abl.metadata.hibernate.HibMetaRole.java

License:Open Source License

/**
 * Get the MetaEntity at the other end of this role.
 *///from  w w  w .  j  ava  2 s  .c  om
@Override
public HibMetaEntity getOtherMetaEntity() {

    if (otherMetaEntity != null)
        return otherMetaEntity;

    SessionFactoryImplementor sfi = (SessionFactoryImplementor) metaEntity.getMetaModel().getSessionFactory();
    EntityPersister thisPers = metaEntity.getPersister();
    Type type = thisPers.getPropertyType(roleName);
    if (type.isCollectionType() && !isCollection)
        throw new RuntimeException("Internal metadata inconsistency: role name " + roleName + " of "
                + metaEntity.getEntityName() + " is and isn't a collection");
    else if (type.isEntityType() && isCollection)
        throw new RuntimeException("Internal metadata inconsistency: role name " + roleName + " of "
                + metaEntity.getEntityName() + " is and isn't an entity");

    String otherEntityName = null;
    if (isCollection) {
        CollectionType ctype = (CollectionType) type;
        otherEntityName = ctype.getAssociatedEntityName(sfi);
    } else {
        EntityType etype = (EntityType) type;
        otherEntityName = etype.getAssociatedEntityName(sfi);
    }

    otherMetaEntity = (HibMetaEntity) metaEntity.getMetaModel().getMetaEntity(otherEntityName);
    if (otherMetaEntity == null)
        throw new RuntimeException("Unable to find entity " + otherEntityName + ", which is the value of role "
                + metaEntity.getEntityName() + "." + roleName);

    return otherMetaEntity;
}

From source file:com.blazebit.persistence.integration.hibernate.base.HibernateJpaProvider.java

License:Apache License

@Override
public String getMappedBy(EntityType<?> ownerType, String attributeName) {
    CollectionPersister persister = getCollectionPersister(ownerType, attributeName);
    if (persister != null) {
        if (persister.isInverse()) {
            return getMappedBy(persister);
        } else if (persister instanceof OneToManyPersister) {
            // A one-to-many association without a join table is like an inverse association
            return "";
        }/* ww w .ja  v a2  s .c o  m*/
    } else {
        EntityPersister entityPersister = getEntityPersister(ownerType);
        Type propertyType = entityPersister.getPropertyType(attributeName);
        if (propertyType instanceof OneToOneType) {
            return ((OneToOneType) propertyType).getRHSUniqueKeyPropertyName();
        }
    }
    return null;
}

From source file:com.googlecode.hibernate.audit.synchronization.work.InsertAuditWorkUnit.java

License:Open Source License

private void processProperties(Session session, AuditConfiguration auditConfiguration, AuditEvent auditEvent,
        EntityPersister persister, Object entity, AuditObject auditObject) {

    for (String propertyName : persister.getPropertyNames()) {
        Type propertyType = persister.getPropertyType(propertyName);
        Object propertyValue = persister.getPropertyValue(entity, propertyName);

        processProperty(session, auditConfiguration, auditEvent, entity, propertyName, propertyValue,
                propertyType, auditObject);
    }//  ww w  . j a  v  a 2s.  c o m
}

From source file:com.googlecode.hibernate.audit.synchronization.work.UpdateAuditWorkUnit.java

License:Open Source License

private void processProperties(Session session, AuditConfiguration auditConfiguration, AuditEvent auditEvent,
        EntityPersister persister, Object entity, AuditObject auditObject) {
    String[] propertyNames = persister.getPropertyNames();

    int[] changedPropertyIndexes = null;
    if (oldState == null) {
        // if the old state does not exist - for example directly updating an entity that is not associated with the session before that.
        changedPropertyIndexes = new int[propertyNames.length];
        for (int i = 0; i < propertyNames.length; i++) {
            changedPropertyIndexes[i] = i;
        }//from w  ww .  ja  v a 2s  .c o  m
    } else {
        changedPropertyIndexes = persister.findDirty(newState, oldState, entity, (SessionImplementor) session);
    }

    for (int i = 0; i < changedPropertyIndexes.length; i++) {
        String propertyName = propertyNames[changedPropertyIndexes[i]];

        if (auditConfiguration.getExtensionManager().getAuditableInformationProvider().isAuditable(entityName,
                propertyName)) {

            Type propertyType = persister.getPropertyType(propertyName);
            Object propertyValue = persister.getPropertyValue(entity, propertyName);

            processProperty(session, auditConfiguration, auditEvent, entity, propertyName, propertyValue,
                    propertyType, auditObject);
        }
    }
}

From source file:com.mg.framework.service.HibernateListenerInjectorImpl.java

License:Open Source License

private void setUpdatedAttributes(PersistentObject entity, Object[] state, EntityPersister entityPersister) {
    String[] propertyNames = entityPersister.getPropertyNames();
    int versionProperty = entityPersister.getVersionProperty();
    for (int i = 0, len = propertyNames.length; i < len; i++) {
        if (versionProperty == i) //http://issues.m-g.ru/bugzilla/show_bug.cgi?id=4535
            continue;

        String name = propertyNames[i];

        Type type = entityPersister.getPropertyType(name);
        //  ??  , ..  ? ?  
        if (type.isCollectionType() || type.isEntityType())
            continue;

        Object valueEntity = entity.getAttribute(name);
        Object value = state[i];/*  w  w  w.  j a  va2s .c  om*/
        if (valueEntity == null) {
            if (value != null)
                state[i] = null;
        } else if (value == null || !value.equals(valueEntity))
            state[i] = valueEntity;
    }
}