Example usage for org.hibernate.persister.entity AbstractEntityPersister getSubclassPropertyColumnNames

List of usage examples for org.hibernate.persister.entity AbstractEntityPersister getSubclassPropertyColumnNames

Introduction

In this page you can find the example usage for org.hibernate.persister.entity AbstractEntityPersister getSubclassPropertyColumnNames.

Prototype

public String[] getSubclassPropertyColumnNames(String propertyName) 

Source Link

Usage

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

License:Apache License

private boolean isColumnShared(AbstractEntityPersister persister, String rootName, String[] subclassNames,
        String attributeName) {//from ww  w .j  av a 2  s .c o m
    String[] columnNames = persister.getSubclassPropertyColumnNames(attributeName);
    for (String subclass : subclassNames) {
        if (!subclass.equals(persister.getName()) && !subclass.equals(rootName)) {
            AbstractEntityPersister subclassPersister = (AbstractEntityPersister) entityPersisters
                    .get(subclass);
            if (isColumnShared(subclassPersister, columnNames)) {
                return true;
            }
        }
    }
    return false;
}

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

License:Apache License

private boolean isColumnShared(AbstractEntityPersister subclassPersister, String[] columnNames) {
    List<String> propertiesToCheck = new ArrayList<>(Arrays.asList(subclassPersister.getPropertyNames()));
    while (!propertiesToCheck.isEmpty()) {
        String propertyName = propertiesToCheck.remove(propertiesToCheck.size() - 1);
        Type propertyType = subclassPersister.getPropertyType(propertyName);
        if (propertyType instanceof ComponentType) {
            ComponentType componentType = (ComponentType) propertyType;
            for (String subPropertyName : componentType.getPropertyNames()) {
                propertiesToCheck.add(propertyName + "." + subPropertyName);
            }/*w ww  .j ava2 s. co  m*/
        } else {
            String[] subclassColumnNames = subclassPersister.getSubclassPropertyColumnNames(propertyName);
            if (Arrays.deepEquals(columnNames, subclassColumnNames)) {
                return true;
            }
        }
    }

    return false;
}

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

License:Apache License

private static Set<String> getColumnMatchingAttributeNames(AbstractEntityPersister ownerEntityPersister,
        List<String> idColumnNames) {
    Set<String> idAttributeNames = new LinkedHashSet<>();
    Type identifierType = ownerEntityPersister.getIdentifierType();
    if (identifierType instanceof ComponentType) {
        String[] idPropertyNames = ((ComponentType) identifierType).getPropertyNames();
        for (String propertyName : idPropertyNames) {
            String attributeName = ownerEntityPersister.getIdentifierPropertyName() + "." + propertyName;
            String[] propertyColumnNames = ownerEntityPersister.getSubclassPropertyColumnNames(attributeName);
            if (propertyColumnNames != null) {
                for (int j = 0; j < propertyColumnNames.length; j++) {
                    String propertyColumnName = propertyColumnNames[j];
                    if (idColumnNames.contains(propertyColumnName)) {
                        idAttributeNames.add(attributeName);
                        break;
                    }/*from   w  w w  . ja v  a  2 s  .c  o m*/
                }
            }
        }
        // We assume that when a primary identifier attribute is part of the id column names, that we are done
        if (!idAttributeNames.isEmpty()) {
            return idAttributeNames;
        }
    } else {
        for (String identifierColumnName : ownerEntityPersister.getIdentifierColumnNames()) {
            if (idColumnNames.contains(identifierColumnName)) {
                idAttributeNames.add(ownerEntityPersister.getIdentifierPropertyName());
                return idAttributeNames;
            }
        }
    }
    String[] propertyNames = ownerEntityPersister.getPropertyNames();
    for (int i = 0; i < propertyNames.length; i++) {
        String propertyName = propertyNames[i];
        String[] propertyColumnNames = ownerEntityPersister.getSubclassPropertyColumnNames(propertyName);
        if (propertyColumnNames != null) {
            for (int j = 0; j < propertyColumnNames.length; j++) {
                String propertyColumnName = propertyColumnNames[j];
                if (idColumnNames.contains(propertyColumnName)) {
                    idAttributeNames.add(propertyName);
                    break;
                }
            }
        }
    }
    return idAttributeNames;
}