⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 businessservice.java

📁 通过面向对象的对象-关系映射持久化技术
💻 JAVA
字号:
package com.faw_qm.ipa.service;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.*;

import com.faw_qm.ipa.servlet.HibernateFilter;
import com.faw_qm.ipa.bo.*;
import com.faw_qm.ipa.frame.util.*;

public class BusinessService extends HibernateDAO {
	
    private static Log log = LogFactory.getLog(BusinessService.class);

    /**
     * 20080428
     * 20080507修改。找根目录。 
     * @param name
     * @return
     */
    public List findApplicationsByName(String name) throws Exception {
    	if(!Util.NVL(name))
    		return getObjects("from Item i where i.name like '%"+name+"%' and i.parent.id is null order by i.id desc");
    	else
    		//return getObjects("from Item i where  i.parent.id='-1' order by i.id desc");
    		return getObjects("from Item i where  i.parent.id is null order by i.id desc");
    }
    
    /**
     * 20080429
     * @param name
     * @return
     */
    public Item getApplicationByName(String name) throws Exception {
    	Item item = null;
    	Object o = getObject("from Item i where i.name = '"+name+"'");
    	log.info(o);
    	log.info(o==null);
    	if(o!=null)
    		item = (Item)o;
    	return item;
    } 
    
    /**
     * 
     * @param item
     */
    public void saveItem(Item item) throws Exception  {
//    	log.info("-saveItem1-"+item.getParent().getId());
//    	long parent_id = item.getParent().getId();
//    	long last_sub_id = (long)getObject("select id from Item i where i.parent.id='"+parent_id+"' order by i.id desc");
//    	log.info("-last_sub_id-"+last_sub_id);
//    	if(Util.NVL(last_sub_id)) {
//    		last_sub_id = parent_id+"01";
//    		log.info(last_sub_id);
//    	}
//    	//20080508这里的算法存在一些问题。不知道能否对排序产生影响。000103按照算法后下一个值变成104了。应该是000104。
//    	last_sub_id =  String.valueOf(Integer.parseInt(last_sub_id)+1);
//    	log.info(last_sub_id);

    	//item.setId(last_sub_id);
    	
    	log.info(item);
    	log.info(item.getChild());
    	log.info(item.getParent());
    	
    	saveObject(item);
    }

    /**
     * 遍历对象图
     * @param category Category
     * @param categories Set
     */
    public void navigateCategories() throws Exception {
    	Item food = getApplicationByName("food");
        HashSet categories = new HashSet();
        navigateCategories(food, categories);
        for (Iterator it = categories.iterator(); it.hasNext(); ) {
            System.out.println(((Item) it.next()).getName());
        }
    }

    /**
     * 遍历对象图,递归算法
     * @param category Category
     * @param categories Set
     */
    private void navigateCategories(Item category, Set categories) {
        if (categories.contains(category) || category == null) {
            return;
        }
        categories.add(category);

        //遍历父类Category
        navigateCategories(category.getParent(), categories);

        //遍历所有子类Category
        Set childCategories = category.getChild();
        if (childCategories == null) {
            return;
        }

        for (Iterator it = childCategories.iterator(); it.hasNext(); ) {
            navigateCategories((Item) it.next(), categories);
        }
    }
    
    /**
     * 20080519
     * 遍历当前节点的所有子节点,递归算法。
     * @param currentItem
     * @param childItems
     */
    public void navigateAllChild (Item currentItem, List childItems) {
        if (childItems.contains(currentItem) || currentItem == null) {
            return;
        }
        childItems.add(currentItem);

        //遍历父类Category
        //navigateCategories(currentItem.getParent(), childItems);

        //遍历所有子类Category
        Set childCategories = currentItem.getChild();
        if (childCategories == null) {
            return;
        }

        for (Iterator it = childCategories.iterator(); it.hasNext(); ) {
        	navigateAllChild((Item) it.next(), childItems);
        }
    }
    
    /**
     * 20080811
     * @param id
     * @return
     * @throws Exception
     */
    public String getItemUrlByItemID(String id) throws Exception {
    	return (String) getObject("select i.url from Item i where i.id="+id);
    }   
    
    /**
     * 20080927
     * 当应用只有一个链接时,直接进入到应用里而绕过IPA_P
     * @param root_id
     * @return
     * @throws Exception
     */
    public int ItemsAmountOfRootItem (long root_id)throws Exception  {
    	Integer i = (Integer)getObject("select count(i.id) from Item i where i.root_id ="+root_id);
    	if (i!=null)
    		return i.intValue();
    	else
    		return 0;
    }
    
    
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub		
		try {
			BusinessService bs = new BusinessService();
//			Item item = (Item)bs.loadObject(Item.class,"48");
//			List set = new ArrayList();
			
			log.info(bs.ItemsAmountOfRootItem(168));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -