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 net.sf.basedb.core.Type; |
6021 |
23 Oct 20 |
nicklas |
4 |
import net.sf.basedb.core.query.Expression; |
6021 |
23 Oct 20 |
nicklas |
5 |
import net.sf.basedb.core.query.Expressions; |
6021 |
23 Oct 20 |
nicklas |
6 |
import net.sf.basedb.core.query.Hql; |
6021 |
23 Oct 20 |
nicklas |
7 |
import net.sf.basedb.core.query.Restriction; |
6021 |
23 Oct 20 |
nicklas |
8 |
import net.sf.basedb.core.query.Restrictions; |
6021 |
23 Oct 20 |
nicklas |
9 |
|
6021 |
23 Oct 20 |
nicklas |
10 |
/** |
6021 |
23 Oct 20 |
nicklas |
Helper class to make it easier to join and filter on job parameters in job queries. |
6021 |
23 Oct 20 |
nicklas |
After creating an instance, use the {@link #join()} method to join the parameter |
6021 |
23 Oct 20 |
nicklas |
to a query. Then, use {@link #restrict(Restriction)}, {@link #eq(Object)} or |
6021 |
23 Oct 20 |
nicklas |
some other helper method to create restrictions for the query. |
6021 |
23 Oct 20 |
nicklas |
15 |
|
6021 |
23 Oct 20 |
nicklas |
Example usage: |
6021 |
23 Oct 20 |
nicklas |
17 |
|
6021 |
23 Oct 20 |
nicklas |
ItemQuery<Job> jobQuery = Job.getQuery(); |
6021 |
23 Oct 20 |
nicklas |
JobParameter models = new JobParameter("models", "m", Type.STRING); |
6021 |
23 Oct 20 |
nicklas |
jobQuery.join(models.join()); |
6021 |
23 Oct 20 |
nicklas |
jobQuery.restrict(models.eq("Ki67")); |
6021 |
23 Oct 20 |
nicklas |
22 |
|
6021 |
23 Oct 20 |
nicklas |
@since 4.28 |
6021 |
23 Oct 20 |
nicklas |
24 |
*/ |
6021 |
23 Oct 20 |
nicklas |
25 |
public class JobParameter |
6021 |
23 Oct 20 |
nicklas |
26 |
{ |
6021 |
23 Oct 20 |
nicklas |
27 |
|
6021 |
23 Oct 20 |
nicklas |
28 |
private final String name; |
6021 |
23 Oct 20 |
nicklas |
29 |
private final String alias; |
6021 |
23 Oct 20 |
nicklas |
30 |
private final String valueAlias; |
6021 |
23 Oct 20 |
nicklas |
31 |
private final Type valueType; |
6021 |
23 Oct 20 |
nicklas |
32 |
|
6021 |
23 Oct 20 |
nicklas |
33 |
/** |
6021 |
23 Oct 20 |
nicklas |
Create a new instance for working with a job parameter with given name |
6021 |
23 Oct 20 |
nicklas |
and value type. |
6021 |
23 Oct 20 |
nicklas |
36 |
*/ |
6021 |
23 Oct 20 |
nicklas |
37 |
public JobParameter(String name, String alias, Type valueType) |
6021 |
23 Oct 20 |
nicklas |
38 |
{ |
6021 |
23 Oct 20 |
nicklas |
39 |
this.name = name; |
6021 |
23 Oct 20 |
nicklas |
40 |
this.alias = alias; |
6021 |
23 Oct 20 |
nicklas |
41 |
this.valueAlias = alias+"Val"; |
6021 |
23 Oct 20 |
nicklas |
42 |
this.valueType = valueType; |
6021 |
23 Oct 20 |
nicklas |
43 |
} |
6021 |
23 Oct 20 |
nicklas |
44 |
|
6021 |
23 Oct 20 |
nicklas |
45 |
/** |
6021 |
23 Oct 20 |
nicklas |
Get the name of the job parameter. |
6021 |
23 Oct 20 |
nicklas |
47 |
*/ |
6021 |
23 Oct 20 |
nicklas |
48 |
public String getName() |
6021 |
23 Oct 20 |
nicklas |
49 |
{ |
6021 |
23 Oct 20 |
nicklas |
50 |
return name; |
6021 |
23 Oct 20 |
nicklas |
51 |
} |
6021 |
23 Oct 20 |
nicklas |
52 |
|
6021 |
23 Oct 20 |
nicklas |
53 |
/** |
6021 |
23 Oct 20 |
nicklas |
Get the value type of the parameter. |
6021 |
23 Oct 20 |
nicklas |
55 |
*/ |
6021 |
23 Oct 20 |
nicklas |
56 |
public Type getValueType() |
6021 |
23 Oct 20 |
nicklas |
57 |
{ |
6021 |
23 Oct 20 |
nicklas |
58 |
return valueType; |
6021 |
23 Oct 20 |
nicklas |
59 |
} |
6021 |
23 Oct 20 |
nicklas |
60 |
|
6021 |
23 Oct 20 |
nicklas |
61 |
/** |
6021 |
23 Oct 20 |
nicklas |
Get the alias that is used to reference this parameter. |
6021 |
23 Oct 20 |
nicklas |
63 |
*/ |
6021 |
23 Oct 20 |
nicklas |
64 |
public String getAlias() |
6021 |
23 Oct 20 |
nicklas |
65 |
{ |
6021 |
23 Oct 20 |
nicklas |
66 |
return alias; |
6021 |
23 Oct 20 |
nicklas |
67 |
} |
6021 |
23 Oct 20 |
nicklas |
68 |
|
6021 |
23 Oct 20 |
nicklas |
69 |
/** |
6021 |
23 Oct 20 |
nicklas |
Get the alias that is used to reference the values for this parameter. |
6021 |
23 Oct 20 |
nicklas |
71 |
*/ |
6021 |
23 Oct 20 |
nicklas |
72 |
public String getValueAlias() |
6021 |
23 Oct 20 |
nicklas |
73 |
{ |
6021 |
23 Oct 20 |
nicklas |
74 |
return valueAlias; |
6021 |
23 Oct 20 |
nicklas |
75 |
} |
6021 |
23 Oct 20 |
nicklas |
76 |
|
6021 |
23 Oct 20 |
nicklas |
77 |
/** |
6021 |
23 Oct 20 |
nicklas |
Creates a join instance that joins this parameter to a query. |
6021 |
23 Oct 20 |
nicklas |
79 |
*/ |
6021 |
23 Oct 20 |
nicklas |
80 |
public JobParameterJoin join() |
6021 |
23 Oct 20 |
nicklas |
81 |
{ |
6021 |
23 Oct 20 |
nicklas |
82 |
return new JobParameterJoin(name, alias); |
6021 |
23 Oct 20 |
nicklas |
83 |
} |
6021 |
23 Oct 20 |
nicklas |
84 |
|
6021 |
23 Oct 20 |
nicklas |
85 |
/** |
6021 |
23 Oct 20 |
nicklas |
Returns an expression for referencing the values of this parameter. |
6021 |
23 Oct 20 |
nicklas |
Intended to be used to create {@link Restriction}:s for the |
6021 |
23 Oct 20 |
nicklas |
{@link #restrict(Restriction)} method. |
6021 |
23 Oct 20 |
nicklas |
89 |
*/ |
6021 |
23 Oct 20 |
nicklas |
90 |
public Expression value() |
6021 |
23 Oct 20 |
nicklas |
91 |
{ |
6021 |
23 Oct 20 |
nicklas |
92 |
return Hql.alias(valueAlias); |
6021 |
23 Oct 20 |
nicklas |
93 |
} |
6021 |
23 Oct 20 |
nicklas |
94 |
|
6021 |
23 Oct 20 |
nicklas |
95 |
/** |
6021 |
23 Oct 20 |
nicklas |
Create a restriction that can be added to a query so that only jobs |
6021 |
23 Oct 20 |
nicklas |
with parameter values matching the given restriction are returned. |
6021 |
23 Oct 20 |
nicklas |
98 |
*/ |
6021 |
23 Oct 20 |
nicklas |
99 |
public Restriction restrict(Restriction valueRestriction) |
6021 |
23 Oct 20 |
nicklas |
100 |
{ |
6021 |
23 Oct 20 |
nicklas |
101 |
return new JobParameterRestriction(alias, valueType, valueRestriction); |
6021 |
23 Oct 20 |
nicklas |
102 |
} |
6021 |
23 Oct 20 |
nicklas |
103 |
|
6021 |
23 Oct 20 |
nicklas |
104 |
/** |
6021 |
23 Oct 20 |
nicklas |
Creates a restriction that return jobs with parameter values equal to |
6021 |
23 Oct 20 |
nicklas |
the given value. |
6021 |
23 Oct 20 |
nicklas |
107 |
*/ |
6021 |
23 Oct 20 |
nicklas |
108 |
public Restriction eq(Object value) |
6021 |
23 Oct 20 |
nicklas |
109 |
{ |
6021 |
23 Oct 20 |
nicklas |
110 |
return restrict(Restrictions.eq(value(), Expressions.parameter(valueAlias, value, valueType))); |
6021 |
23 Oct 20 |
nicklas |
111 |
} |
6021 |
23 Oct 20 |
nicklas |
112 |
|
6021 |
23 Oct 20 |
nicklas |
113 |
} |