Created
March 12, 2014 17:40
-
-
Save luizkowalski/9512109 to your computer and use it in GitHub Desktop.
Log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Embedded | |
private Log log = new Log(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TransactionInterceptor implements MethodInterceptor { | |
private Logger log = Logger.getLogger(getClass()); | |
@Override | |
public Object invoke(MethodInvocation mi) throws Throwable { | |
// não interessa aqui | |
// Objetos que vão ser manipulados, geralmente, entities | |
for(Object e : objs){ | |
if(e.getClass().isAnnotationPresent(Entity.class)){ | |
UsuarioHelper.setLog(e, dataAtual); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.germantech.ecf.dominio.compartilhado; | |
import java.io.Serializable; | |
import java.util.Date; | |
import javax.persistence.Column; | |
import javax.persistence.Embeddable; | |
import javax.persistence.JoinColumn; | |
import javax.persistence.ManyToOne; | |
import javax.persistence.Temporal; | |
import javax.persistence.TemporalType; | |
import br.com.germantech.ecf.dominio.modelo.usuario.Usuario; | |
@Embeddable | |
public class Log implements Serializable { | |
private static final long serialVersionUID = -3528343752956930988L; | |
@Column(updatable=false) | |
@Temporal(TemporalType.TIMESTAMP) | |
private Date dataCadastro; | |
@Temporal(TemporalType.TIMESTAMP) | |
private Date dataAlteracao; | |
@ManyToOne | |
@JoinColumn(updatable=false) | |
private Usuario usuarioCadastro; | |
@ManyToOne | |
@JoinColumn | |
private Usuario usuarioAlteracao; | |
public Date getDataCadastro() { | |
return dataCadastro; | |
} | |
public void setDataCadastro(Date dataCadastro) { | |
this.dataCadastro = dataCadastro; | |
} | |
public Date getDataAlteracao() { | |
return dataAlteracao; | |
} | |
public void setDataAlteracao(Date dataAlteracao) { | |
this.dataAlteracao = dataAlteracao; | |
} | |
public Usuario getUsuarioCadastro() { | |
return usuarioCadastro; | |
} | |
public void setUsuarioCadastro(Usuario usuarioCadastro) { | |
this.usuarioCadastro = usuarioCadastro; | |
} | |
public Usuario getUsuarioAlteracao() { | |
return usuarioAlteracao; | |
} | |
public void setUsuarioAlteracao(Usuario usuarioAlteracao) { | |
this.usuarioAlteracao = usuarioAlteracao; | |
} | |
@Override | |
public String toString() { | |
return "Log [dataCadastro=" + dataCadastro + ", dataAlteracao=" + dataAlteracao + ", usuarioCadastro=" + usuarioCadastro + ", usuarioAlteracao=" + usuarioAlteracao + "]"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Esse metodo preenche os campos do log | |
private static Log logar(Log log, Date dataAtual) { | |
Usuario usuarioLogado = UsuarioHelper.getUsuarioLogado(); | |
if(log == null) | |
log = new Log(); | |
if(log.getDataCadastro() == null) | |
log.setDataCadastro(dataAtual); | |
if(log.getUsuarioCadastro() == null) | |
log.setUsuarioCadastro(usuarioLogado); | |
log.setDataAlteracao(dataAtual); | |
log.setUsuarioAlteracao(new UsuarioService().find(usuarioLogado.getId())); | |
return log; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment