Examples of TreeEntity


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

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

  @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

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

   */
  @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

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

   */
  @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

Examples of org.one.stone.soup.core.data.EntityTree.TreeEntity

  public static EntityTree loadXml(InputStream in,boolean closeAtEnd) throws XmlParseException, IOException{
    try {

      EntityTree entityTree = new EntityTree( "root" );
      BufferedInputStream bin = new BufferedInputStream(in);
      TreeEntity entity = parseEntity( entityTree.getRoot(),bin );
      entityTree = new EntityTree(entity);
     
      return entityTree;
    } finally {
      if(closeAtEnd==true) {
View Full Code Here

Examples of org.one.stone.soup.core.data.EntityTree.TreeEntity

    }
    if(name.equals("/"+parent.getName())) {
      return null;
    }
   
    TreeEntity entity = parent.addChild(name);

    //Add Attributes
    tag = tag.trim();
    if(tag.length()>0) {
      tag = tag.replace(" =", "=").replace("= ", "=");
      String[] attributes = StringHelper.split(tag, " ", "\"", "\"");
      for(String attribute: attributes) {
        if(attribute.indexOf("=")==-1) {
          continue;
        }
        String key = attribute.substring(0,attribute.indexOf("="));
        attribute = attribute.substring(attribute.indexOf("=")+1);
        String value = attribute.substring(attribute.indexOf("\"")+1,attribute.lastIndexOf("\""));
        entity.setAttribute(key, value);
      }
    }
   
    if(tag.length()!=0 && (tag.lastIndexOf('/')==tag.length()-1||tag.lastIndexOf('?')==tag.length()-1)) {
      return entity;
    }
   
    TreeEntity child = parseEntity(entity,in);
    while(child!=null) {
      child = parseEntity(entity,in);
    }
   
    //String closeTag = parseTo(in,'>');
View Full Code Here

Examples of org.one.stone.soup.core.data.EntityTree.TreeEntity

    return JavaTree.toObject(tree);
  }
 
  private static TreeEntity parseEntity(TreeEntity parent,String data) throws IOException {
    String name = StringHelper.before(data, ":").trim();
    TreeEntity child = parent.addChild(name);
   
    data = StringHelper.after(data, "{");
 
    String[] parts = data.split(",");
    for(String part: parts) {
      if(part.contains("{")) {
        parseEntity(child, part);
      } else {
        KeyValuePair kvp = KeyValuePair.parseKeyAndValue(part, ":");
        child.setAttribute(kvp.getKey().trim(), kvp.getValue().trim());
      }
    }
   
    return child;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.