@Override @DeadlockAutoRestart public void eoCleanup(Class VOClazz) { _eoCleanup(VOClazz); }
void init() { buildEntityInfo(); getDbVersionOnInit(); }
@Override public long count(Class<?> entityClass) { SimpleQuery<?> query = this.createQuery(entityClass); return query.count(); }
@Override @Transactional(propagation = Propagation.REQUIRES_NEW) public void persistCollection(Collection entities) { for (Object e : entities) { this.entityForTranscationCallback(Operation.PERSIST, e.getClass()); this.getEntityManager().persist(e); } }
@Override @Transactional @ExceptionSafe public void hardDeleteCollectionSelectedBySQL(String sql, Class entityClass) { EntityInfo info = getEntityInfo(entityClass); Query q = getEntityManager().createQuery(sql); List ids = q.getResultList(); if (ids.isEmpty()) { return; } info.hardDelete(ids); }
@Override @Transactional(propagation = Propagation.REQUIRES_NEW) public void run() { getEntityManager().merge(deo); } }.run();
@Override public boolean isExist(Object id, Class<?> clazz) { return getEntityInfo(clazz).isExist(id); }
@PrePersist void onPrePersist(Object o) { getDataBaseFacade().entityEvent(EntityEvent.PRE_PERSIST, o); }
@Override @DeadlockAutoRestart public void updateCollection(Collection entities) { doUpdateCollection(entities); }
@DeadlockAutoRestart private <T> T persist(T entity, boolean isRefresh) { return doPersist(entity, isRefresh); }
@Override @Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW) public <T> T findByUuid(String uuid, Class<T> entityClass) { return this.getEntityManager().find(entityClass, uuid); }
@Transactional(propagation = Propagation.REQUIRES_NEW) private void _eoCleanup(Class VOClazz) { EntityInfo info = getEntityInfo(VOClazz); if (!info.hasEO()) { logger.warn(String.format("Class[%s] doesn't has EO.", VOClazz)); return; } String deleted = info.eoSoftDeleteColumn.getName(); String sql = String.format("select eo.%s from %s eo where eo.%s is not null", info.voPrimaryKeyField.getName(), info.eoClass.getSimpleName(), deleted); Query q = getEntityManager().createQuery(sql); List ids = q.getResultList(); if (ids.isEmpty()) { return; } info.hardDelete(ids); }
@Override public <T> void update(T entity) { getEntityInfo(entity.getClass()).update(entity); }
@Transactional(propagation = Propagation.REQUIRES_NEW) private <T> T doPersist(T entity, boolean isRefresh) { this.entityForTranscationCallback(Operation.PERSIST, entity.getClass()); getEntityManager().persist(entity); if (isRefresh) { getEntityManager().flush(); getEntityManager().refresh(entity); } return entity; }
@PostRemove void onPostRemove(Object o) { getDataBaseFacade().entityEvent(EntityEvent.POST_REMOVE, o); } }
@Transactional(propagation = Propagation.REQUIRES_NEW) private void doUpdateCollection(Collection entities) { for (Object e : entities) { getEntityManager().merge(e); } }
@Transactional(propagation = Propagation.REQUIRES_NEW) private void _eoCleanup(Class VOClazz, List ids) { EntityInfo info = getEntityInfo(VOClazz); if (!info.hasEO()) { logger.warn(String.format("Class[%s] doesn't has EO.", VOClazz)); return; } String deleted = info.eoSoftDeleteColumn.getName(); String sql = String.format("select eo.%s from %s eo where eo.%s is not null and eo.%s in (:ids)", info.voPrimaryKeyField.getName(), info.eoClass.getSimpleName(), deleted, info.voPrimaryKeyField.getName()); Query q = getEntityManager().createQuery(sql); q.setParameter("ids", ids); ids = q.getResultList(); if (ids.isEmpty()) { return; } info.hardDelete(ids); }
@Override public <T> T updateAndRefresh(T entity) { return (T) getEntityInfo(entity.getClass()).updateAndRefresh(entity); }
@PreUpdate void onPreUpdate(Object o) { getDataBaseFacade().entityEvent(EntityEvent.PRE_UPDATE, o); }
@Override @DeadlockAutoRestart public void eoCleanup(Class VOClazz, List ids) { if(ids.isEmpty()) { return; } _eoCleanup(VOClazz, ids); }