001    package org.cumulus4j.store.model;
002    
003    import java.util.Date;
004    
005    import javax.jdo.annotations.Column;
006    import javax.jdo.annotations.IdGeneratorStrategy;
007    import javax.jdo.annotations.IdentityType;
008    import javax.jdo.annotations.NullValue;
009    import javax.jdo.annotations.PersistenceCapable;
010    import javax.jdo.annotations.Persistent;
011    import javax.jdo.annotations.PrimaryKey;
012    import javax.jdo.annotations.Unique;
013    import javax.jdo.annotations.Uniques;
014    
015    import org.cumulus4j.store.datastoreversion.DatastoreVersionCommand;
016    import org.cumulus4j.store.datastoreversion.DatastoreVersionManager;
017    
018    @PersistenceCapable(identityType=IdentityType.APPLICATION, detachable="true")
019    @Uniques({
020            @Unique(members={"keyStoreRefID", "commandID"})
021    })
022    public class DatastoreVersion {
023    
024            @PrimaryKey
025            @Persistent(valueStrategy=IdGeneratorStrategy.NATIVE, sequence="DatastoreVersionSequence")
026            private Long datastoreVersionID;
027    
028            @Persistent(nullValue=NullValue.EXCEPTION)
029            @Column(length=255)
030            private String commandID;
031    
032            private int keyStoreRefID;
033    
034            @Persistent(nullValue=NullValue.EXCEPTION)
035            private Date applyTimestamp;
036    
037            private int managerVersion;
038    
039            private int commandVersion;
040    
041            private Integer workInProgressManagerVersion;
042    
043            private Integer workInProgressCommandVersion;
044    
045            @Persistent(nullValue=NullValue.EXCEPTION)
046            @Column(jdbcType="CLOB")
047            private String workInProgressStateProperties;
048    
049            protected DatastoreVersion() { }
050    
051            public DatastoreVersion(String commandID, int keyStoreRefID) {
052                    if (commandID == null)
053                            throw new IllegalArgumentException("commandID == null");
054    
055                    this.commandID = commandID;
056                    this.keyStoreRefID = keyStoreRefID;
057            }
058    
059            public String getCommandID() {
060                    return commandID;
061            }
062    
063            public Integer getKeyStoreRefID() {
064                    return keyStoreRefID;
065            }
066    
067            /**
068             * Get the timestamp of the last time, the corresponding {@link DatastoreVersionCommand} was applied.
069             * It is measured, when the command either completed or threw a
070             * @return
071             */
072            public Date getApplyTimestamp() {
073                    return applyTimestamp;
074            }
075            public void setApplyTimestamp(Date executedTimestamp) {
076                    this.applyTimestamp = executedTimestamp;
077            }
078    
079            /**
080             * Get the version of the {@link DatastoreVersionManager manager} by whom this object was written.
081             * @return the version of the {@link DatastoreVersionManager manager} by whom this object was written.
082             */
083            public int getManagerVersion() {
084                    return managerVersion;
085            }
086    
087            public void setManagerVersion(int version) {
088                    this.managerVersion = version;
089            }
090    
091            public int getCommandVersion() {
092                    return commandVersion;
093            }
094    
095            public void setCommandVersion(int commandVersion) {
096                    this.commandVersion = commandVersion;
097            }
098    
099            public Integer getWorkInProgressManagerVersion() {
100                    return workInProgressManagerVersion;
101            }
102            public void setWorkInProgressManagerVersion(Integer workInProgressManagerVersion) {
103                    this.workInProgressManagerVersion = workInProgressManagerVersion;
104            }
105    
106            public String getWorkInProgressStateProperties() {
107                    return workInProgressStateProperties;
108            }
109            public void setWorkInProgressStateProperties(String workInPrgressStateProperties) {
110                    this.workInProgressStateProperties = workInPrgressStateProperties;
111            }
112    
113            public Integer getWorkInProgressCommandVersion() {
114                    return workInProgressCommandVersion;
115            }
116            public void setWorkInProgressCommandVersion(Integer newCommandVersion) {
117                    this.workInProgressCommandVersion = newCommandVersion;
118            }
119    }