6021 |
23 Oct 20 |
nicklas |
1 |
package net.sf.basedb.reggie.query; |
6021 |
23 Oct 20 |
nicklas |
2 |
|
6021 |
23 Oct 20 |
nicklas |
3 |
import java.util.Collection; |
6021 |
23 Oct 20 |
nicklas |
4 |
import java.util.Collections; |
6021 |
23 Oct 20 |
nicklas |
5 |
|
6021 |
23 Oct 20 |
nicklas |
6 |
import net.sf.basedb.core.DbControl; |
6021 |
23 Oct 20 |
nicklas |
7 |
import net.sf.basedb.core.Type; |
6021 |
23 Oct 20 |
nicklas |
8 |
import net.sf.basedb.core.query.Expressions; |
6021 |
23 Oct 20 |
nicklas |
9 |
import net.sf.basedb.core.query.Hql; |
6021 |
23 Oct 20 |
nicklas |
10 |
import net.sf.basedb.core.query.Join; |
6021 |
23 Oct 20 |
nicklas |
11 |
import net.sf.basedb.core.query.Query; |
6021 |
23 Oct 20 |
nicklas |
12 |
import net.sf.basedb.core.query.QueryElement; |
6021 |
23 Oct 20 |
nicklas |
13 |
import net.sf.basedb.core.query.Restrictions; |
6021 |
23 Oct 20 |
nicklas |
14 |
|
6021 |
23 Oct 20 |
nicklas |
15 |
|
6021 |
23 Oct 20 |
nicklas |
16 |
/** |
6021 |
23 Oct 20 |
nicklas |
Implements a join condition for Job queries that joins a parameter with |
6021 |
23 Oct 20 |
nicklas |
a specified name into the query. Example: |
6021 |
23 Oct 20 |
nicklas |
19 |
|
6021 |
23 Oct 20 |
nicklas |
ItemQuery<Job> jobQuery = Job.getQuery(); |
6021 |
23 Oct 20 |
nicklas |
jobQuery.join(new JobParameterJoin("models", "m")); |
6021 |
23 Oct 20 |
nicklas |
22 |
|
6021 |
23 Oct 20 |
nicklas |
The join is an inner join which means that this will also implicitely filter |
6021 |
23 Oct 20 |
nicklas |
out jobs that doesn't have a parameter with the specified name. |
6021 |
23 Oct 20 |
nicklas |
The implementation creates a join like: |
6021 |
23 Oct 20 |
nicklas |
26 |
|
6021 |
23 Oct 20 |
nicklas |
INNER JOIN job.parameters alias WITH index(alias) = :alias |
6021 |
23 Oct 20 |
nicklas |
28 |
|
6021 |
23 Oct 20 |
nicklas |
Note that the given alias is also used as a parameter name in the query. |
6021 |
23 Oct 20 |
nicklas |
30 |
|
6021 |
23 Oct 20 |
nicklas |
@since 4.28 |
6021 |
23 Oct 20 |
nicklas |
@see JobParameter |
6021 |
23 Oct 20 |
nicklas |
@see JobParameterRestriction |
6021 |
23 Oct 20 |
nicklas |
34 |
*/ |
6021 |
23 Oct 20 |
nicklas |
35 |
public class JobParameterJoin |
6021 |
23 Oct 20 |
nicklas |
36 |
implements Join |
6021 |
23 Oct 20 |
nicklas |
37 |
{ |
6021 |
23 Oct 20 |
nicklas |
38 |
|
6021 |
23 Oct 20 |
nicklas |
39 |
private final Join join; |
6021 |
23 Oct 20 |
nicklas |
40 |
|
6021 |
23 Oct 20 |
nicklas |
41 |
/** |
6021 |
23 Oct 20 |
nicklas |
Create a new join condition for parameters with the given name. An |
6021 |
23 Oct 20 |
nicklas |
alias is required. |
6021 |
23 Oct 20 |
nicklas |
44 |
*/ |
6021 |
23 Oct 20 |
nicklas |
45 |
public JobParameterJoin(String name, String alias) |
6021 |
23 Oct 20 |
nicklas |
46 |
{ |
6021 |
23 Oct 20 |
nicklas |
47 |
this.join = Hql.innerJoin(null, "parameters", alias, |
6021 |
23 Oct 20 |
nicklas |
48 |
Restrictions.eq( |
6021 |
23 Oct 20 |
nicklas |
49 |
Hql.index(alias, null), |
6021 |
23 Oct 20 |
nicklas |
50 |
Expressions.parameter(alias, name, Type.STRING)), |
6021 |
23 Oct 20 |
nicklas |
51 |
false); |
6021 |
23 Oct 20 |
nicklas |
52 |
} |
6021 |
23 Oct 20 |
nicklas |
53 |
|
6021 |
23 Oct 20 |
nicklas |
54 |
@Override |
6021 |
23 Oct 20 |
nicklas |
55 |
public String toQl(Query query, DbControl dc) |
6021 |
23 Oct 20 |
nicklas |
56 |
{ |
6021 |
23 Oct 20 |
nicklas |
57 |
return join.toQl(query, dc); |
6021 |
23 Oct 20 |
nicklas |
58 |
} |
6021 |
23 Oct 20 |
nicklas |
59 |
|
6021 |
23 Oct 20 |
nicklas |
60 |
@Override |
6021 |
23 Oct 20 |
nicklas |
61 |
public Collection<? extends QueryElement> getChildren() |
6021 |
23 Oct 20 |
nicklas |
62 |
{ |
6021 |
23 Oct 20 |
nicklas |
63 |
return Collections.singleton(join); |
6021 |
23 Oct 20 |
nicklas |
64 |
} |
6021 |
23 Oct 20 |
nicklas |
65 |
|
6021 |
23 Oct 20 |
nicklas |
66 |
@Override |
6021 |
23 Oct 20 |
nicklas |
67 |
public String getThetaJoin(Query query, DbControl dc) |
6021 |
23 Oct 20 |
nicklas |
68 |
{ |
6021 |
23 Oct 20 |
nicklas |
69 |
return join.getThetaJoin(query, dc); |
6021 |
23 Oct 20 |
nicklas |
70 |
} |
6021 |
23 Oct 20 |
nicklas |
71 |
|
6021 |
23 Oct 20 |
nicklas |
72 |
@Override |
6021 |
23 Oct 20 |
nicklas |
73 |
public String getThetaJoinCondition(Query query, DbControl dc) |
6021 |
23 Oct 20 |
nicklas |
74 |
{ |
6021 |
23 Oct 20 |
nicklas |
75 |
return join.getThetaJoinCondition(query, dc); |
6021 |
23 Oct 20 |
nicklas |
76 |
} |
6021 |
23 Oct 20 |
nicklas |
77 |
|
6021 |
23 Oct 20 |
nicklas |
78 |
@Override |
6021 |
23 Oct 20 |
nicklas |
79 |
public int hashCode() |
6021 |
23 Oct 20 |
nicklas |
80 |
{ |
6021 |
23 Oct 20 |
nicklas |
81 |
return join.hashCode(); |
6021 |
23 Oct 20 |
nicklas |
82 |
} |
6021 |
23 Oct 20 |
nicklas |
83 |
|
6021 |
23 Oct 20 |
nicklas |
84 |
@Override |
6021 |
23 Oct 20 |
nicklas |
85 |
public boolean equals(Object other) |
6021 |
23 Oct 20 |
nicklas |
86 |
{ |
6021 |
23 Oct 20 |
nicklas |
87 |
if (this == other) return true; |
6021 |
23 Oct 20 |
nicklas |
88 |
if ((other == null) || (super.getClass() != other.getClass())) return false; |
6021 |
23 Oct 20 |
nicklas |
89 |
JobParameterJoin o = (JobParameterJoin)other; |
6021 |
23 Oct 20 |
nicklas |
90 |
return join.equals(o.join); |
6021 |
23 Oct 20 |
nicklas |
91 |
} |
6021 |
23 Oct 20 |
nicklas |
92 |
|
6021 |
23 Oct 20 |
nicklas |
93 |
@Override |
6021 |
23 Oct 20 |
nicklas |
94 |
public String toString() |
6021 |
23 Oct 20 |
nicklas |
95 |
{ |
6021 |
23 Oct 20 |
nicklas |
96 |
return join.toString(); |
6021 |
23 Oct 20 |
nicklas |
97 |
} |
6021 |
23 Oct 20 |
nicklas |
98 |
|
6021 |
23 Oct 20 |
nicklas |
99 |
} |