Example usage for org.hibernate.boot.model.naming ImplicitJoinColumnNameSource getReferencedColumnName

List of usage examples for org.hibernate.boot.model.naming ImplicitJoinColumnNameSource getReferencedColumnName

Introduction

In this page you can find the example usage for org.hibernate.boot.model.naming ImplicitJoinColumnNameSource getReferencedColumnName.

Prototype

public Identifier getReferencedColumnName();

Source Link

Document

Access the name of the column that is the target of the FK being described

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;/*from ww  w  . ja v a  2s  .  com*/
    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;
}

From source file:com.example.ejb3.auction.NamingStrategy.java

License:Apache License

@Override
public Identifier determineJoinColumnName(ImplicitJoinColumnNameSource source) {
    if (source.getAttributePath() != null) {
        return toIdentifier((source.getNature() == ImplicitJoinColumnNameSource.Nature.ELEMENT_COLLECTION
                ? addUnderscores(transformEntityName(source.getEntityNaming()))
                : addUnderscores(source.getAttributePath().getFullPath())) + '_'
                + source.getReferencedColumnName().getText(), source.getBuildingContext());
    }//from   w w  w  .  ja va  2 s  . c  o  m
    if (source.getNature() != ImplicitJoinColumnNameSource.Nature.ELEMENT_COLLECTION) {
        String name = transformEntityName(source.getEntityNaming()) + '_'
                + source.getReferencedColumnName().getText();
        return toIdentifier(addUnderscores(name), source.getBuildingContext());
    }
    return super.determineJoinColumnName(source);
}