package au.gov.ga.geodesy.domain.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;

@Entity
@Table(name = "DOMAIN_EVENT")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "EVENT_NAME")
@Configurable
public abstract class Event implements Cloneable {

    /* @Autowired(required = true) */
    /* @Transient */
    /* private EventRepository events; */

    @Id
    @GeneratedValue(generator = "surrogateKeyGenerator")
    @SequenceGenerator(name = "surrogateKeyGenerator", sequenceName = "SEQ_EVENT")
    private Integer id;

    @Column(name = "TIME_RAISED", nullable = false)
    private Date timeRaised;

    @Column(name = "SUBSCRIBER", nullable = false)
    public String subscriber;

    @Column(name = "TIME_HANDLED")
    public Date timeHandled;

    @Column(name = "TIME_PUBLISHED")
    public Date timePublished;

    @Column(name = "RETRIES")
    public Integer retries;

    public Event() {
        setTimeRaised(new Date());
    }

    public Date getEventTime() {
        return timeRaised;
    }

    private void setTimeRaised(Date t) {
        timeRaised = t;
    }

    public String getSubscriber() {
        return subscriber;
    }

    protected void setSubscriber(String s) {
        subscriber = s;
    }

    public Date getTimeHandled() {
        return timeHandled;
    }

    private void setTimeHandled(Date t) {
        timeHandled = t;
    }

    public Date getTimePublished() {
        return timePublished;
    }

    public void setTimePublished(Date timePublished) {
        this.timePublished = timePublished;
    }

    public Integer getRetries() {
        return retries;
    }

    public void setRetries(Integer retries) {
        this.retries = retries;
    }

    public void published() {
        if (getTimePublished() != null) {
            setRetries(getRetries() == null ? 1 : getRetries());
        }
        setTimePublished(new Date());
        /* if (id != null && events.exists(id)) { */
        /*     events.save(this); */
        /* } */
    }

    public void handled() {
        if (timeHandled == null) {
            setTimeHandled(new Date());
        }
        /* if (id != null && events.exists(id)) { */
        /*     events.save(this); */
        /* } */
    }

    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

@@ -400,107 +400,8 @@
 le;%0A
-import javax.persistence.Transient;%0A%0Aimport org.springframework.beans.factory.annotation.Autowired;
 %0Aimp
@@ -662,110 +662,8 @@
  %7B%0A%0A
-    /* @Autowired(required = true) */%0A    /* @Transient */%0A    /* private EventRepository events; */%0A%0A
     
@@ -2144,19 +2144,23 @@
 etries()
+ + 1
 );%0A
-
         
@@ -2203,114 +2203,8 @@
 ));%0A
-        /* if (id != null && events.exists(id)) %7B */%0A        /*     events.save(this); */%0A        /* %7D */%0A
     
@@ -2305,24 +2305,24 @@
 ew Date());%0A
+
         %7D%0A  
@@ -2323,114 +2323,8 @@
   %7D%0A
-        /* if (id != null && events.exists(id)) %7B */%0A        /*     events.save(this); */%0A        /* %7D */%0A
     

Fix counting of event retries.