?? sitedao.java
字號(hào):
/*
* SiteDAO.java
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Author: Winter Lau (javayou@gmail.com)
* http://dlog4j.sourceforge.net
*/
package com.liusoft.dlog4j.dao;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import com.liusoft.dlog4j.base.FunctionStatus;
import com.liusoft.dlog4j.beans.SiteBean;
import com.liusoft.dlog4j.util.StringUtils;
/**
* 個(gè)人站點(diǎn)對應(yīng)的數(shù)據(jù)庫接口
* SiteBean的url字段必須做唯一索引,url字段不應(yīng)該由用戶進(jìn)行手工修改
* @author liudong
*/
public class SiteDAO extends DAO {
/**
* 搜索個(gè)人網(wǎng)記
* @param key
* @return
*/
public static List searchSite(String key){
String pattern = '%' + key + '%';
return executeNamedQuery("SEARCH_SITE", -1, 20, new Object[]{SiteBean.I_STATUS_NORMAL, pattern,pattern});
}
/**
* 列出最新注冊的site
* @param fromIdx
* @param count
* @return
*/
public static List listNewestSites(int fromIdx , int count){
return executeNamedQuery("LIST_NEW_SITES", fromIdx, count, SiteBean.STATUS_NORMAL);
}
/**
* 列出推薦的網(wǎng)站
* 也就是site_level>1的網(wǎng)站
* @param fromIdx
* @param count
* @return
*/
public static List listRecommendSites(int fromIdx ,int count){
return executeNamedQuery("LIST_RECOMMEND_SITES", fromIdx, count, null);
}
/**
* 返回注冊的站點(diǎn)總數(shù)
* @param site
* @return
*/
public static int getSiteCount(){
return executeNamedStat("SITE_COUNT", SiteBean.STATUS_NORMAL).intValue();
}
/**
* 開通個(gè)人網(wǎng)記
* @param site
*/
public static void createSite(SiteBean site){
site.setFunctionStatus(new FunctionStatus());
Session ssn = getSession();
try{
beginTransaction();
ssn.save(site);
site.getOwner().setOwnSiteId(site.getId());
ssn.update(site.getOwner());
commit();
}catch(HibernateException e){
rollback();
throw e;
}
}
/**
* 更新網(wǎng)站資料
* @param site
*/
public static void updateSite(SiteBean site){
flush();
}
/**
* 根據(jù)網(wǎng)站編號(hào)獲取詳細(xì)信息
* @param site_id
* @return
* @throws HibernateException
*/
public static SiteBean getSiteByID(int site_id){
if(site_id<1)
return null;
return (SiteBean)getBean(SiteBean.class, site_id);
}
/**
* 根據(jù)網(wǎng)站的唯一標(biāo)識(shí)來獲取對應(yīng)網(wǎng)站的詳細(xì)信息
* @param site_name
* @return
*/
public static SiteBean getSiteByName(String site_name){
if(StringUtils.isEmpty(site_name))
return null;
return (SiteBean)namedUniqueResult("GET_SITE_BY_NAME", site_name);
}
/**
* 根據(jù)網(wǎng)站名來獲取對應(yīng)網(wǎng)站的詳細(xì)信息
* @param site_name
* @return
*/
public static SiteBean getSiteByFriendlyName(String site_name){
if(StringUtils.isEmpty(site_name))
return null;
return (SiteBean)namedUniqueResult("GET_SITE_BY_FRIENDLYNAME", site_name);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -