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

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

Introduction

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

Prototype

public Identifier getReferencedTableName();

Source Link

Document

Access the name of the table 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.  j a va  2 s . c o  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;
}

From source file:org.ligoj.bootstrap.core.dao.ImplicitNamingStrategyNiceJpaImpl.java

License:MIT License

@Override
public Identifier determineJoinColumnName(final ImplicitJoinColumnNameSource source) {
    if (source.getNature() == ImplicitJoinColumnNameSource.Nature.ELEMENT_COLLECTION
            || source.getAttributePath() == null) {
        return source.getReferencedTableName();
    }/*from ww  w . j  a  v a 2  s  . co m*/
    return toIdentifier(transformAttributePath(source.getAttributePath()), source.getBuildingContext());
}