Example usage for org.hibernate.boot.model.source.spi AttributePath getParent

List of usage examples for org.hibernate.boot.model.source.spi AttributePath getParent

Introduction

In this page you can find the example usage for org.hibernate.boot.model.source.spi AttributePath getParent.

Prototype

@Override
    public AttributePath getParent() 

Source Link

Usage

From source file:com.evolveum.midpoint.repo.sql.util.MidPointImplicitNamingStrategy.java

License:Apache License

@Override
public Identifier determineJoinColumnName(ImplicitJoinColumnNameSource source) {
    Identifier i = super.determineJoinColumnName(source);

    // RObject, creatorRef.target, oid -> m_object.creatorRef_targetOid
    // RObjectReference, owner, oid -> m_object_reference.owner_oid
    // RObjectReference, target, oid -> m_object_reference.targetOid

    AttributePath path = source.getAttributePath();
    String property = path.getProperty();
    String columnName = source.getReferencedColumnName().getText();

    Identifier real;/* www  .  j a  v  a 2 s  . co m*/
    if (path.getDepth() == 1) {
        String name;
        if (property.endsWith("target") && "oid".equals(columnName)) {
            name = property + "Oid";
        } else {
            name = StringUtils.join(Arrays.asList(property, columnName), "_");
        }

        real = toIdentifier(name, source.getBuildingContext());
    } else {
        // TODO fixme BRUTAL HACK -- we are not able to eliminate columns like 'ownerRefCampaign_targetOid' from the schema (even with @AttributeOverride/@AssociationOverride)
        if ("ownerRefCampaign.target".equals(path.getFullPath())
                || "ownerRefDefinition.target".equals(path.getFullPath())
                || "ownerRefTask.target".equals(path.getFullPath())) {
            path = AttributePath.parse("ownerRef.target");
        }

        AttributePath parent = path.getParent();
        String translatedParent = transformAttributePath(parent);

        columnName = property + StringUtils.capitalize(columnName);

        real = toIdentifier(StringUtils.join(Arrays.asList(translatedParent, columnName), "_"),
                source.getBuildingContext());
    }

    LOGGER.trace("determineJoinColumnName {} {} -> {}, {}", source.getReferencedTableName(),
            source.getReferencedColumnName(), i, real);

    return real;
}