-
Notifications
You must be signed in to change notification settings - Fork 13
/
Alias.java
79 lines (62 loc) · 2.25 KB
/
Alias.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.github.fluent.hibernate.request.aliases;
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;
/**
* An alias for HQL 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(String associationPath, String alias, JoinType joinType) {
this.associationPath = associationPath;
this.alias = alias;
this.joinType = joinType;
}
public Alias(String associationPath, String alias, JoinType joinType, Criterion withClause) {
this.associationPath = associationPath;
this.alias = alias;
this.joinType = joinType;
this.withClause = withClause;
}
public void addToCriteria(Criteria criteria) {
if (withClause == null) {
criteria.createAlias(associationPath, alias, joinType.ordinal());
} else {
criteria.createAlias(associationPath, alias, joinType.ordinal(), withClause);
}
}
public void addToCriteria(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);
}
}