@Override public boolean isExist(Object id, Class<?> clazz) { return getEntityInfo(clazz).isExist(id); }
@Override public <T> void update(T entity) { getEntityInfo(entity.getClass()).update(entity); }
@Override public <T> T updateAndRefresh(T entity) { return (T) getEntityInfo(entity.getClass()).updateAndRefresh(entity); }
@Override public <T> T reload(T entity) { return (T) getEntityInfo(entity.getClass()).reload(entity); }
@Override public <T> List<T> listByPrimaryKeys(Collection ids, int offset, int length, Class<T> clazz) { return getEntityInfo(clazz).listByPrimaryKeys(ids, offset, length); }
@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 @DeadlockAutoRestart public void removeCollection(Collection entities, Class entityClass) { if (entities.isEmpty()) { return; } getEntityInfo(entityClass).removeCollection(entities); }
@Override @DeadlockAutoRestart public void remove(Object entity) { getEntityInfo(entity.getClass()).remove(entity); }
@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 @DeadlockAutoRestart public void removeByPrimaryKeys(Collection priKeys, Class entityClazz) { if (priKeys.isEmpty()) { return; } getEntityInfo(entityClazz).removeByPrimaryKeys(priKeys); }
@Override @DeadlockAutoRestart public void removeByPrimaryKey(Object primaryKey, Class<?> entityClass) { getEntityInfo(entityClass).removeByPrimaryKey(primaryKey); }
@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 @Transactional public void delete() { DebugUtils.Assert(entityClass!=null, "entity class cannot be null"); EntityInfo info = dbf.getEntityInfo(entityClass); DebugUtils.Assert(entityClass!=null, "entity class cannot be null"); StringBuilder sb = new StringBuilder(String.format("SELECT vo.%s FROM %s vo", info.voPrimaryKeyField.getName(), entityClass.getSimpleName())); String where = where(); if (where != null) { sb.append(String.format(" WHERE %s", where)); } String sql = sb.toString(); if (logger.isTraceEnabled()) { logger.trace(sql); } Query q = dbf.getEntityManager().createQuery(sql); if (where != null) { fillConditions(q); } List ids = q.getResultList(); if (ids.isEmpty()) { return; } info.removeByPrimaryKeys(ids); }