1717package com .blazebit .job .jpa .model ;
1818
1919import com .blazebit .job .JobInstance ;
20+ import com .blazebit .job .JobInstanceState ;
2021import com .blazebit .job .PartitionKey ;
2122
2223import java .util .ArrayList ;
@@ -55,6 +56,13 @@ public interface JpaPartitionKey extends PartitionKey {
5556 */
5657 String getScheduleAttributeName ();
5758
59+ /**
60+ * Returns the attribute name of the last execution attribute of the entity type as given in {@link #getJobInstanceType()}.
61+ *
62+ * @return the attribute name of the last execution attribute
63+ */
64+ String getLastExecutionAttributeName ();
65+
5866 /**
5967 * Returns the attribute name of the partition key attribute of the entity type as given in {@link #getJobInstanceType()}.
6068 *
@@ -70,13 +78,21 @@ public interface JpaPartitionKey extends PartitionKey {
7078 */
7179 String getStatePredicate (String jobAlias );
7280
81+ /**
82+ * Returns the expression for the state of a job.
83+ *
84+ * @param jobAlias The FROM clause alias for the job
85+ * @return The state JPQL expression or an empty string
86+ */
87+ String getStateExpression (String jobAlias );
88+
7389 /**
7490 * Returns the state value for ready jobs that must be bound in a query to the parameter name "readyState".
7591 * A <code>null</code> value means that no parameter should be bound.
7692 *
7793 * @return The ready state value of <code>null</code>
7894 */
79- Object getReadyStateValue ();
95+ Function < JobInstanceState , Object > getStateValueMappingFunction ();
8096
8197 /**
8298 * Returns the join fetches that should be applied to a query when fetching a job for this partition.
@@ -138,6 +154,14 @@ interface JpaPartitionKeyBuilder {
138154 */
139155 JpaPartitionKeyBuilder withScheduleAttributeName (String scheduleAttributeName );
140156
157+ /**
158+ * Sets the given job last execution attribute name.
159+ *
160+ * @param lastExecutionAttributeName The job last execution attribute name
161+ * @return this for chaining
162+ */
163+ JpaPartitionKeyBuilder withLastExecutionAttributeName (String lastExecutionAttributeName );
164+
141165 /**
142166 * Sets the given job partition key attribute name.
143167 *
@@ -155,12 +179,12 @@ interface JpaPartitionKeyBuilder {
155179 JpaPartitionKeyBuilder withStateAttributeName (String stateAttributeName );
156180
157181 /**
158- * Sets the given job ready state value.
182+ * Sets the given state value mapping function .
159183 *
160- * @param readyStateValue The job ready state value
184+ * @param stateValueMappingFunction The state value mapping function
161185 * @return this for chaining
162186 */
163- JpaPartitionKeyBuilder withReadyStateValue ( Object readyStateValue );
187+ JpaPartitionKeyBuilder withStateValueMappingFunction ( Function < JobInstanceState , Object > stateValueMappingFunction );
164188
165189 /**
166190 * Sets the given job attributes to fetch.
@@ -190,9 +214,10 @@ static JpaPartitionKeyBuilder builder() {
190214 Function <String , String > partitionPredicateProvider0 ;
191215 String idAttributeName0 ;
192216 String scheduleAttributeName0 ;
217+ String lastExecutionAttributeName0 ;
193218 String partitionKeyAttributeName0 ;
194219 String stateAttributeName0 ;
195- Object readyStateValue0 ;
220+ Function < JobInstanceState , Object > stateValueMappingFunction0 ;
196221 List <String > fetches0 = new ArrayList <>();
197222
198223 @ Override
@@ -225,6 +250,12 @@ public JpaPartitionKeyBuilder withScheduleAttributeName(String scheduleAttribute
225250 return this ;
226251 }
227252
253+ @ Override
254+ public JpaPartitionKeyBuilder withLastExecutionAttributeName (String lastExecutionAttributeName ) {
255+ this .lastExecutionAttributeName0 = lastExecutionAttributeName ;
256+ return this ;
257+ }
258+
228259 @ Override
229260 public JpaPartitionKeyBuilder withPartitionKeyAttributeName (String partitionKeyAttributeName ) {
230261 this .partitionKeyAttributeName0 = partitionKeyAttributeName ;
@@ -238,8 +269,8 @@ public JpaPartitionKeyBuilder withStateAttributeName(String stateAttributeName)
238269 }
239270
240271 @ Override
241- public JpaPartitionKeyBuilder withReadyStateValue ( Object readyStateValue ) {
242- this .readyStateValue0 = readyStateValue ;
272+ public JpaPartitionKeyBuilder withStateValueMappingFunction ( Function < JobInstanceState , Object > stateValueMappingFunction ) {
273+ this .stateValueMappingFunction0 = stateValueMappingFunction ;
243274 return this ;
244275 }
245276
@@ -257,9 +288,10 @@ public JpaPartitionKey build() {
257288 private final Function <String , String > partitionPredicateProvider = partitionPredicateProvider0 ;
258289 private final String idAttributeName = idAttributeName0 ;
259290 private final String scheduleAttributeName = scheduleAttributeName0 ;
291+ private final String lastExecutionAttributeName = lastExecutionAttributeName0 ;
260292 private final String partitionKeyAttributeName = partitionKeyAttributeName0 ;
261293 private final String stateAttributeName = stateAttributeName0 ;
262- private final Object readyStateValue = readyStateValue0 ;
294+ private final Function < JobInstanceState , Object > stateValueMappingFunction = stateValueMappingFunction0 ;
263295 private final String [] fetches = fetches0 .toArray (new String [fetches0 .size ()]);
264296
265297 @ Override
@@ -282,6 +314,11 @@ public String getScheduleAttributeName() {
282314 return scheduleAttributeName ;
283315 }
284316
317+ @ Override
318+ public String getLastExecutionAttributeName () {
319+ return lastExecutionAttributeName ;
320+ }
321+
285322 @ Override
286323 public String getPartitionKeyAttributeName () {
287324 return partitionKeyAttributeName ;
@@ -293,8 +330,13 @@ public String getStatePredicate(String jobAlias) {
293330 }
294331
295332 @ Override
296- public Object getReadyStateValue () {
297- return readyStateValue ;
333+ public String getStateExpression (String jobAlias ) {
334+ return jobAlias + "." + stateAttributeName ;
335+ }
336+
337+ @ Override
338+ public Function <JobInstanceState , Object > getStateValueMappingFunction () {
339+ return stateValueMappingFunction ;
298340 }
299341
300342 @ Override
0 commit comments