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

📄 sqlmapcategorydao.java

📁 java写的blog
💻 JAVA
字号:
/*
 * Created on 2004-9-30
 * Author: Xuefeng, Copyright (C) 2004, Xuefeng.
 */
package org.crystalblog.dao.ibatis;

import java.util.*;
import java.sql.SQLException;

import org.crystalblog.dao.CategoryDao;
import org.crystalblog.domain.*;
import org.crystalblog.exception.*;

import com.ibatis.sqlmap.client.SqlMapClient;

/**
 * @author Xuefeng
 */
public class SqlMapCategoryDao implements CategoryDao {

    private SqlMapClient sqlMap = SqlConfig.getSqlMapInstance();

    public List getCategories(int accountId) throws QueryException {
        try {
            return sqlMap.queryForList("getCategories", new Integer(accountId));
        }
        catch(SQLException sqle) {
            throw new QueryException("Get categories failed: " + sqle);
        }
    }

    public List getCategoriesOfArticle(int accountId) throws QueryException {
        try {
            return sqlMap.queryForList("getCategoriesOfArticle", new Integer(accountId));
        }
        catch(SQLException sqle) {
            throw new QueryException("Get categories of article failed: " + sqle);
        }
    }

    public List getCategoriesOfType(int accountId, int type) throws QueryException {
        try {
            Map map = new HashMap();
            map.put("accountId", new Integer(accountId));
            map.put("type", new Integer(type));
            return sqlMap.queryForList("getCategoriesOfType", map);
        }
        catch(SQLException sqle) {
            throw new QueryException("Get categories of type failed: " + sqle);
        }
    }

    public Category getCategory(int categoryId) throws QueryException {
        try {
            Category category = (Category)sqlMap.queryForObject("getCategory", new Integer(categoryId));
            return category;
        }
        catch(SQLException sqle) {
            throw new QueryException("Get category failed: " + sqle);
        }
    }

    public void createCategory(Category category) throws CreateException {
        try {
            sqlMap.insert("createCategory", category);
        }
        catch(SQLException sqle) {
            throw new CreateException("Create category failed: " + sqle);
        }
    }

    public void updateCategory(Category category) throws UpdateException {
        try {
            sqlMap.update("updateCategory", category);
        }
        catch(SQLException sqle) {
            throw new UpdateException("Update category failed: " + sqle);
        }
    }

    public void deleteCategory(int categoryId) throws DeleteException {
        try {
            //sqlMap.startBatch();
            //List list = sqlMap.queryForList("getArticlesByCategory", new Integer(categoryId));
            //Iterator it = list.iterator();
            //while(it.hasNext()) {
            //    Article article = (Article)it.next();
            //    sqlMap.delete("deleteArticle", new Integer(article.getArticleId()));
            //}
            sqlMap.delete("deleteCategory", new Integer(categoryId));
            //sqlMap.executeBatch();
        }
        catch(SQLException sqle) {
            throw new DeleteException("Delete category failed: " + sqle);
        }
    }

}

⌨️ 快捷键说明

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