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

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

Introduction

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

Prototype

public AttributePath getAttributePath();

Source Link

Document

Access to the name of the attribute that defines the association.

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;/*  w  ww.  j  a v a2s  .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;
}

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());
    }// ww w.  ja v a2s  .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);
}

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 w ww  .  java2s.c o m*/
    return toIdentifier(transformAttributePath(source.getAttributePath()), source.getBuildingContext());
}