Package com.github.dactiv.orm.annotation

Examples of com.github.dactiv.orm.annotation.TreeEntity


   */
  @Override
  public boolean onSave(E entity, JpaSupportRepository<E, ID> persistentContext,Serializable id) {

    Class<?> entityClass = ReflectionUtils.getTargetClass(entity);
    TreeEntity treeEntity = ReflectionUtils.getAnnotation(entityClass,TreeEntity.class);
   
    if (treeEntity != null) {
      E parent = ReflectionUtils.invokeGetterMethod(entity,treeEntity.parentProperty());
      // 如果对象父类不为null,将父类的leaf设置成true,表示父类下存在子节点
      if (parent != null) {
        Object value = ConvertUtils.convertToObject(treeEntity.leafValue(), treeEntity.leafClass());
        ReflectionUtils.invokeSetterMethod(parent,treeEntity.leafProperty(), value);
      }
    }

    return Boolean.TRUE;
  }
View Full Code Here


  @Override
  @SuppressWarnings("unchecked")
  public void onPostSave(E entity,JpaSupportRepository<E, ID> persistentContext,Serializable id) {
   
    Class<?> entityClass = ReflectionUtils.getTargetClass(entity);
    TreeEntity treeEntity = ReflectionUtils.getAnnotation(entityClass,TreeEntity.class);

    if (treeEntity != null) {
      //from {0} tree where tree.{1} = {2} and (select count(c) from {0} c where c.{3}.{4} = r.{4}) = {5}
      String hql = MessageFormat.format(treeEntity.refreshHql(),
          persistentContext.getEntityName(),
          treeEntity.leafProperty(),
          treeEntity.leafValue(),
          treeEntity.parentProperty(),
          persistentContext.getIdName(),
          treeEntity.unleafValue());
     
      List<E> list = persistentContext.getEntityManager().createQuery(hql).getResultList();

      for (E e : list) {
        Object value = ConvertUtils.convertToObject(treeEntity.unleafValue(), treeEntity.leafClass());
        ReflectionUtils.invokeSetterMethod(e,treeEntity.leafProperty(), value);
        persistentContext.save(e);
      }
    }

  }
View Full Code Here

   */
  @Override
  public boolean onSave(E entity, BasicHibernateDao<E, ID> persistentContext,Serializable id) {

    Class<?> entityClass = ReflectionUtils.getTargetClass(entity);
    TreeEntity treeEntity = ReflectionUtils.getAnnotation(entityClass,TreeEntity.class);
   
    if (treeEntity != null) {
      E parent = ReflectionUtils.invokeGetterMethod(entity,treeEntity.parentProperty());
      // 如果对象父类不为null,将父类的leaf设置成true,表示父类下存在子节点
      if (parent != null) {
        Object value = ConvertUtils.convertToObject(treeEntity.leafValue(), treeEntity.leafClass());
        ReflectionUtils.invokeSetterMethod(parent,treeEntity.leafProperty(), value);
      }
    }

    return Boolean.TRUE;
  }
View Full Code Here

   */
  @Override
  public void onPostSave(E entity,BasicHibernateDao<E, ID> persistentContext,Serializable id) {
   
    Class<?> entityClass = ReflectionUtils.getTargetClass(entity);
    TreeEntity treeEntity = ReflectionUtils.getAnnotation(entityClass,TreeEntity.class);

    if (treeEntity != null) {
      //from {0} tree where tree.{1} = {2} and (select count(c) from {0} c where c.{3}.{4} = r.{4}) = {5}
      String hql = MessageFormat.format(treeEntity.refreshHql(),
          persistentContext.getEntityName(),
          treeEntity.leafProperty(),
          treeEntity.leafValue(),
          treeEntity.parentProperty(),
          persistentContext.getIdName(),
          treeEntity.unleafValue());
     
      List<E> list = persistentContext.findByQuery(hql);

      for (E e : list) {
        Object value = ConvertUtils.convertToObject(treeEntity.unleafValue(), treeEntity.leafClass());
        ReflectionUtils.invokeSetterMethod(e,treeEntity.leafProperty(), value);
        persistentContext.merge(e);
      }
    }

  }
View Full Code Here

TOP

Related Classes of com.github.dactiv.orm.annotation.TreeEntity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.