18 package org.turro.jpa.entity;
20 import java.io.Serializable;
21 import java.lang.reflect.ParameterizedType;
22 import java.util.ArrayList;
23 import java.util.List;
24 import javax.persistence.Id;
25 import org.turro.string.Strings;
26 import org.turro.entities.Entities;
27 import org.turro.entities.IElephantEntity;
28 import org.turro.jpa.Dao;
29 import org.turro.json.Jsons;
30 import org.turro.log.SystemLogType;
31 import org.turro.log.SystemLogger;
32 import org.turro.reflection.Beans;
33 import org.turro.reflection.stub.Stubs;
43 private final Class<T> persistentClass;
47 protected List<String>
messages =
new ArrayList<>();
50 this.persistentClass = (Class<T>) ((ParameterizedType) getClass()
51 .getGenericSuperclass()).getActualTypeArguments()[0];
55 this.persistentClass = persistentClass;
60 this.persistentClass = (Class<T>)
entity.getClass();
81 @SuppressWarnings(
"unchecked")
84 entity =
getDao().find(persistentClass,
id);
88 @SuppressWarnings(
"unchecked")
99 public boolean delete() {
113 }
else if(
id ==
null) {
114 id = (ID) Beans.of(
entity).silentGetter(f -> f.isAnnotationPresent(Id.class));
130 String entityData = Stubs.json(
entity);
131 if(Jsons.isEmpty(entityData)) {
158 if (getClass() != obj.getClass() &&
entity.getClass() != obj.getClass()) {
167 return (
getId() ==
null && obj ==
null) ||
173 return getId() ==
null ? 0 :
getId().hashCode();
178 return Beans.of(
entity).silentGetter(f -> f.isAnnotationPresent(Id.class));
184 if(
id instanceof String) {
185 return Strings.isBlank((String)
id);
186 }
else if(
id instanceof Long) {
187 return ((Long)
id) == 0L;
static IElephantEntity getController(String path)
void deleteObject(Object obj)
static Object getEntityId(Object entity)
String dataEntity(Object entity)
void logEntity(SystemLogType logType, Object entity, String action, String data)
abstract boolean shouldLog()
void addMessage(String message)
boolean equals(Object obj)
static boolean isNewId(Object id)
DaoEntity(Class< T > persistentClass)
List< String > getMessages()
static ILogWrapper type(SystemLogType type)
ILogWrapper object(Serializable data)
ILogWrapper comment(String comment)
ILogWrapper entity(Object entity)