All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.fluent.hibernate.request.Alias Maven / Gradle / Ivy

Go to download

A library to work with Hibernate by fluent API. This library hasn't dependencies except Hibernate dependencies. It requires Java 1.6 and above.

There is a newer version: 0.3.1
Show newest version
package com.github.fluent.hibernate.request;

import javax.persistence.criteria.JoinType;

import org.hibernate.Criteria;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.DetachedCriteria;

import com.github.fluent.hibernate.internal.util.InternalUtils;

/**
 * Field alias for SQL request.
 *
 * @author V.Ladynev
 */
/* package */final class Alias {

    private final String associationPath;

    private final String alias;

    private final JoinType joinType;

    private Criterion withClause;

    public Alias(final String associationPath, final String alias, final JoinType joinType) {
        this.associationPath = associationPath;
        this.alias = alias;
        this.joinType = joinType;
    }

    public Alias(final String associationPath, final String alias, final JoinType joinType,
            Criterion withClause) {
        this.associationPath = associationPath;
        this.alias = alias;
        this.joinType = joinType;
        this.withClause = withClause;
    }

    public void addToCriteria(final Criteria criteria) {
        if (withClause == null) {
            criteria.createAlias(associationPath, alias, joinType.ordinal());
        } else {
            criteria.createAlias(associationPath, alias, joinType.ordinal(), withClause);
        }
    }

    public void addToCriteria(final DetachedCriteria criteria) {
        if (joinType == null) {
            criteria.createAlias(associationPath, alias);
        } else if (withClause == null) {
            criteria.createAlias(associationPath, alias, joinType.ordinal());
        } else {
            criteria.createAlias(associationPath, alias, joinType.ordinal(), withClause);
        }
    }

    @Override
    public int hashCode() {
        return InternalUtils.hashCode(associationPath, alias, joinType);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }

        Alias other = (Alias) obj;

        return InternalUtils.equal(associationPath, other.associationPath)
                && InternalUtils.equal(alias, other.alias)
                && InternalUtils.equal(joinType, other.joinType)
                && InternalUtils.equal(withClause, other.withClause);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy