1616
1717package eu .dariolucia .reatmetric .persist .services ;
1818
19- import eu .dariolucia .reatmetric .api .archive .exceptions .ArchiveException ;
2019import eu .dariolucia .reatmetric .api .common .AbstractDataItem ;
2120import eu .dariolucia .reatmetric .api .common .IUniqueId ;
2221import eu .dariolucia .reatmetric .api .common .LongUniqueId ;
2322import eu .dariolucia .reatmetric .api .common .RetrievalDirection ;
24- import eu .dariolucia .reatmetric .api .messages .*;
2523import eu .dariolucia .reatmetric .api .model .SystemEntityPath ;
2624import eu .dariolucia .reatmetric .api .processing .input .ActivityRequest ;
2725import eu .dariolucia .reatmetric .api .scheduler .*;
@@ -39,10 +37,10 @@ public class ScheduledActivityDataArchive extends AbstractDataItemArchive<Schedu
3937 private static final Logger LOG = Logger .getLogger (ScheduledActivityDataArchive .class .getName ());
4038
4139 private static final String STORE_STATEMENT = "MERGE INTO SCHEDULED_ACTIVITY_DATA_TABLE USING SYSIBM.SYSDUMMY1 ON UniqueId = ? " +
42- "WHEN MATCHED THEN UPDATE SET GenerationTime = ?, ActivityRequest = ?, Path = ?, ActivityOccurrence = ?, Resources = ?, Source = ?, ExternalId = ?, Trigger = ?, LatestInvocationTime = ?, ConflictStrategy = ?, State = ?, AdditionalData = ? " +
43- "WHEN NOT MATCHED THEN INSERT (UniqueId,GenerationTime,ActivityRequest,Path,ActivityOccurrence,Resources,Source,ExternalId,Trigger,LatestInvocationTime,ConflictStrategy,State,AdditionalData) VALUES (?,?,?, ?,?,?, ?,?,?, ?,?,?, ?)" ;
40+ "WHEN MATCHED THEN UPDATE SET GenerationTime = ?, ActivityRequest = ?, Path = ?, ActivityOccurrence = ?, Resources = ?, Source = ?, ExternalId = ?, Trigger = ?, LatestInvocationTime = ?, StartTime = ?, EndTime = ?, ConflictStrategy = ?, State = ?, AdditionalData = ? " +
41+ "WHEN NOT MATCHED THEN INSERT (UniqueId,GenerationTime,ActivityRequest,Path,ActivityOccurrence,Resources,Source,ExternalId,Trigger,LatestInvocationTime,StartTime,EndTime, ConflictStrategy,State,AdditionalData) VALUES (?,?,?, ?,?,?, ?,?,?, ?,?,?, ?,?, ?)" ;
4442 private static final String LAST_ID_QUERY = "SELECT UniqueId FROM SCHEDULED_ACTIVITY_DATA_TABLE ORDER BY UniqueId DESC FETCH FIRST ROW ONLY" ;
45- private static final String RETRIEVE_BY_ID_QUERY = "SELECT UniqueId,GenerationTime,ActivityRequest,Path,ActivityOccurrence,Resources,Source,ExternalId,Trigger,LatestInvocationTime,ConflictStrategy,State,AdditionalData " +
43+ private static final String RETRIEVE_BY_ID_QUERY = "SELECT UniqueId,GenerationTime,ActivityRequest,Path,ActivityOccurrence,Resources,Source,ExternalId,Trigger,LatestInvocationTime,StartTime,EndTime, ConflictStrategy,State,AdditionalData " +
4644 "FROM SCHEDULED_ACTIVITY_DATA_TABLE " +
4745 "WHERE UniqueId=?" ;
4846 private static final String LAST_GENERATION_TIME_QUERY = "SELECT MAX(GenerationTime) FROM SCHEDULED_ACTIVITY_DATA_TABLE" ;
@@ -72,40 +70,44 @@ protected void setItemPropertiesToStatement(PreparedStatement storeStatement, Sc
7270 } else {
7371 storeStatement .setNull (10 , Types .BLOB );
7472 }
75- storeStatement .setShort (11 , (short ) item .getConflictStrategy ().ordinal ());
76- storeStatement .setShort (12 , (short ) item .getState ().ordinal ());
73+ storeStatement .setTimestamp (11 , toTimestamp (item .getStartTime ()));
74+ storeStatement .setTimestamp (12 , toTimestamp (item .getEndTime ()));
75+ storeStatement .setShort (13 , (short ) item .getConflictStrategy ().ordinal ());
76+ storeStatement .setShort (14 , (short ) item .getState ().ordinal ());
7777 Object extension = item .getExtension ();
7878 if (extension == null ) {
79- storeStatement .setNull (13 , Types .BLOB );
79+ storeStatement .setNull (15 , Types .BLOB );
8080 } else {
81- storeStatement .setBlob (13 , toInputstream (item .getExtension ()));
81+ storeStatement .setBlob (15 , toInputstream (item .getExtension ()));
8282 }
8383
8484
85- storeStatement .setLong (14 , item .getInternalId ().asLong ());
86- storeStatement .setTimestamp (15 , toTimestamp (item .getGenerationTime ()));
87- storeStatement .setBlob (16 , toInputstream (item .getRequest ()));
88- storeStatement .setString (17 , item .getRequest ().getPath ().asString ());
85+ storeStatement .setLong (16 , item .getInternalId ().asLong ());
86+ storeStatement .setTimestamp (17 , toTimestamp (item .getGenerationTime ()));
87+ storeStatement .setBlob (18 , toInputstream (item .getRequest ()));
88+ storeStatement .setString (19 , item .getRequest ().getPath ().asString ());
8989 if (item .getActivityOccurrence () != null ) {
90- storeStatement .setLong (18 , item .getActivityOccurrence ().asLong ());
90+ storeStatement .setLong (20 , item .getActivityOccurrence ().asLong ());
9191 } else {
92- storeStatement .setNull (18 , Types .BIGINT );
92+ storeStatement .setNull (20 , Types .BIGINT );
9393 }
94- storeStatement .setString (19 , resources );
95- storeStatement .setString (20 , item .getSource ());
96- storeStatement .setLong (21 , item .getExternalId ());
97- storeStatement .setBlob (22 , toInputstream (item .getTrigger ()));
94+ storeStatement .setString (21 , resources );
95+ storeStatement .setString (22 , item .getSource ());
96+ storeStatement .setLong (23 , item .getExternalId ());
97+ storeStatement .setBlob (24 , toInputstream (item .getTrigger ()));
9898 if (item .getLatestInvocationTime () != null ) {
99- storeStatement .setTimestamp (23 , toTimestamp (item .getLatestInvocationTime ()));
99+ storeStatement .setTimestamp (25 , toTimestamp (item .getLatestInvocationTime ()));
100100 } else {
101- storeStatement .setNull (23 , Types .BLOB );
101+ storeStatement .setNull (25 , Types .BLOB );
102102 }
103- storeStatement .setShort (24 , (short ) item .getConflictStrategy ().ordinal ());
104- storeStatement .setShort (25 , (short ) item .getState ().ordinal ());
103+ storeStatement .setTimestamp (26 , toTimestamp (item .getStartTime ()));
104+ storeStatement .setTimestamp (27 , toTimestamp (item .getEndTime ()));
105+ storeStatement .setShort (28 , (short ) item .getConflictStrategy ().ordinal ());
106+ storeStatement .setShort (29 , (short ) item .getState ().ordinal ());
105107 if (extension == null ) {
106- storeStatement .setNull (26 , Types .BLOB );
108+ storeStatement .setNull (30 , Types .BLOB );
107109 } else {
108- storeStatement .setBlob (26 , toInputstream (item .getExtension ()));
110+ storeStatement .setBlob (30 , toInputstream (item .getExtension ()));
109111 }
110112 }
111113
@@ -204,15 +206,19 @@ protected ScheduledActivityData mapToItem(ResultSet rs, ScheduledActivityDataFil
204206 if (rs .wasNull ()) {
205207 latestInvocTime = null ;
206208 }
207- ConflictStrategy conflictStrategy = ConflictStrategy .values ()[rs .getShort (11 )];
208- SchedulingState state = SchedulingState .values ()[rs .getShort (12 )];
209- Blob extensionBlob = rs .getBlob (13 );
209+ Timestamp startTime = rs .getTimestamp (11 );
210+
211+ Timestamp endTime = rs .getTimestamp (12 );
212+
213+ ConflictStrategy conflictStrategy = ConflictStrategy .values ()[rs .getShort (13 )];
214+ SchedulingState state = SchedulingState .values ()[rs .getShort (14 )];
215+ Blob extensionBlob = rs .getBlob (15 );
210216 Object extension = null ;
211217 if (extensionBlob != null && !rs .wasNull ()) {
212218 extension = toObject (extensionBlob );
213219 }
214220 return new ScheduledActivityData (new LongUniqueId (uniqueId ), toInstant (genTime ), request ,
215- actOcc == null ? null : new LongUniqueId (actOcc ), resources , source , extId , trigger , toInstant (latestInvocTime ), conflictStrategy , state , extension );
221+ actOcc == null ? null : new LongUniqueId (actOcc ), resources , source , extId , trigger , toInstant (latestInvocTime ), toInstant ( startTime ), toInstant ( endTime ), conflictStrategy , state , extension );
216222 }
217223
218224 private Set <String > parseResources (String string ) {
0 commit comments