/**
* This file is part of Faktotum.
*
*
* Faktotum is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* Faktotum is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Faktotum.
*
* If not, see <http://www.gnu.org/licenses/>.
*/
package de.romankreisel.faktotum.datamodel;
import java.util.Date;
import java.util.logging.Level;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.PostPersist;
import javax.persistence.PostUpdate;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import de.romankreisel.faktotum.FaktotumObject;
@MappedSuperclass
public abstract class FaktotumEntity extends FaktotumObject {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private long id;
@Temporal(TemporalType.TIMESTAMP)
private Date creationTimestamp;
@Temporal(TemporalType.TIMESTAMP)
private Date modificationTimestamp;
public Date getCreationTimestamp() {
return this.creationTimestamp;
}
public long getId() {
return this.id;
}
public Date getModificationTimestamp() {
return this.modificationTimestamp;
}
@PostPersist
protected void postPersist() {
this.getLogger().log(Level.FINER, this.getClass().getName() + " Object with ID (" + this.id + ") was persisted in DB");
}
@PostUpdate
protected void postUpdate() {
this.getLogger().log(Level.FINER, this.getClass().getName() + " Object with ID (" + this.id + ") was updated in DB");
}
@PrePersist
protected void prePersist() {
Date currentDate = new Date();
if (this.creationTimestamp == null) {
this.creationTimestamp = currentDate;
this.modificationTimestamp = currentDate;
}
}
@PreUpdate
protected void preUpdate() {
this.modificationTimestamp = new Date();
}
public void setCreationTimestamp(Date creationTimestamp) {
this.creationTimestamp = creationTimestamp;
}
public void setId(long id) {
this.id = id;
}
public void setModificationTimestamp(Date modificationTimestamp) {
this.modificationTimestamp = modificationTimestamp;
}
}