src/main/java/ru/indvdum/mywork/openjpa/model/Day.java
changeset 9 6a02cfcc7460
parent 6 a0d8aa779e50
child 10 b062ed9a28f1
equal deleted inserted replaced
8:56338d6d58c2 9:6a02cfcc7460
     1 package ru.indvdum.mywork.openjpa.model;
     1 package ru.indvdum.mywork.openjpa.model;
     2 
     2 
     3 import java.sql.Time;
     3 import java.sql.Time;
       
     4 import java.text.DateFormat;
       
     5 import java.text.SimpleDateFormat;
     4 import java.util.Date;
     6 import java.util.Date;
     5 
     7 
     6 import javax.persistence.Column;
     8 import javax.persistence.Column;
     7 import javax.persistence.Entity;
     9 import javax.persistence.Entity;
     8 import javax.persistence.GeneratedValue;
    10 import javax.persistence.GeneratedValue;
    20 public class Day implements IDatabaseObject {
    22 public class Day implements IDatabaseObject {
    21 
    23 
    22 	private static final long serialVersionUID = 1471705339524132968L;
    24 	private static final long serialVersionUID = 1471705339524132968L;
    23 	
    25 	
    24 	@Id
    26 	@Id
    25 	@GeneratedValue(strategy = GenerationType.IDENTITY)
    27 	@GeneratedValue
    26 	@Column(name = "ID", nullable = false)
    28 	@Column(name = "ID", nullable = false)
    27 	private Integer id = null;
    29 	private Integer id = null;
    28 	
    30 	
    29 	@Column(name = "DAY")
    31 	@Column(name = "DAY")
    30 	private Date day = null;
    32 	private Date day = null;
    37 	
    39 	
    38 	@Column(name = "HOURS")
    40 	@Column(name = "HOURS")
    39 	private Float hours = null;
    41 	private Float hours = null;
    40 	
    42 	
    41 	public Day(){
    43 	public Day(){
    42 		
    44 
    43 	}
    45 	}
    44 
    46 
    45 	@Override
    47 	@Override
    46 	public boolean equals(Object obj) {
    48 	public boolean equals(Object obj) {
    47 		if (this == obj)
    49 		if (this == obj)
    49 		if (obj == null)
    51 		if (obj == null)
    50 			return false;
    52 			return false;
    51 		if (!(obj instanceof Day))
    53 		if (!(obj instanceof Day))
    52 			return false;
    54 			return false;
    53 		final Day other = (Day) obj;
    55 		final Day other = (Day) obj;
    54 		return (this.id == other.id || (this.id != null && this.id.equals(other.id)));
    56 		return (getId() == other.getId() || (getId() != null && getId().equals(other.getId())));
       
    57 	}
       
    58 	
       
    59 	@Override
       
    60 	public int hashCode() {
       
    61 		if(getId() != null && getId() != 0)
       
    62 			return getId().hashCode();
       
    63 		else
       
    64 			return super.hashCode();
       
    65 	}
       
    66 
       
    67 	@Override
       
    68 	public String toString() {
       
    69 		return getDateFormatter().format(getDay());
    55 	}
    70 	}
    56 
    71 
    57 	public Integer getId() {
    72 	public Integer getId() {
    58 		return id;
    73 		return id;
    59 	}
    74 	}
    91 	}
   106 	}
    92 
   107 
    93 	public void setHours(Float hours) {
   108 	public void setHours(Float hours) {
    94 		this.hours = hours;
   109 		this.hours = hours;
    95 	}
   110 	}
       
   111 
       
   112 	protected DateFormat getDateFormatter() {
       
   113 		return new SimpleDateFormat("dd.MM.yyyy");
       
   114 	}
    96 }
   115 }