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

📄 basicinfoserviceimpl.java

📁 这是一款最新的野蔷薇论坛源码,有需要的朋友可以尽情下载
💻 JAVA
字号:
/* 
 * Created on 2007-1-13
 * Last modified on 2007-9-12
 * Powered by YeQiangWei.com
 */
package com.yeqiangwei.club.service.util.impl;

import java.util.ArrayList;
import java.util.List;

import com.yeqiangwei.club.param.BaseParameter;
import com.yeqiangwei.club.service.model.BasicInfoModel;
import com.yeqiangwei.club.service.util.BasicInfoService;
import com.yeqiangwei.club.cache.Cache;
import com.yeqiangwei.club.cache.singleton.CacheFactory;
import com.yeqiangwei.club.dao.BasicInfoDAO;
import com.yeqiangwei.club.dao.DAOLocator;
import com.yeqiangwei.club.dao.DAOWrapper;

import org.apache.log4j.Logger;

import com.yeqiangwei.util.StringHelper;
import com.yeqiangwei.util.TypeChange;
import com.yeqiangwei.util.Validator;
import com.yeqiangwei.club.dao.model.BasicInfo;
import com.yeqiangwei.club.util.BeanUtils;

/**
 * 社区基本配置信息
 * @author yeqiangwei
 */
public class  BasicInfoServiceImpl  implements BasicInfoService{
	
	private static final Logger logger = Logger.getLogger(BasicInfoServiceImpl.class);
	
	private Cache cache = CacheFactory.creator("BASICINFO");
	
	public static void main(String args[]){
		BasicInfoServiceImpl b = new BasicInfoServiceImpl();
		//BasicInfoModel m = b.findOnly();
		System.out.println(b.cookieDomain());
	}
	

	public String cookieDomain() {
		String domain = this.findOnly().getUrl();
		domain = domain.replace("http://","");
		if(domain.indexOf("/")!=-1){
			domain = StringHelper.substring(domain,0,domain.lastIndexOf("/"),"");
		}else{
			domain = StringHelper.substring(domain,0,domain.length(),"");
		}
		domain = StringHelper.substring(domain,domain.indexOf(".")+1,domain.length(),"");
		return domain;
	}
	

	public BasicInfoModel findById(int id) {
		BasicInfoModel model = (BasicInfoModel) cache.get("BasicInfoModel");
		if(Validator.isEmpty(model)){
			model = new BasicInfoModel();
			BasicInfo item = this.getBasicInfoDAO().findById(id);
			BeanUtils.copyProperties(model,item);
		}
		return model;
	} 
	
	public BasicInfoModel createOrUpdate(BasicInfoModel model) {
		if(model.getBasicInfoId()==0){
			model = this.create(model);
		}else{
			model = this.update(model);
		}
		return model;
	}

	public BasicInfoModel create(BasicInfoModel model) {
		if(!Validator.isEmpty(model)){
			BasicInfo item = new BasicInfo();
			BeanUtils.copyProperties(item,model);
			this.getBasicInfoDAO().create(item);
			cache.put("BasicInfoModel",model);
		}
		return model;
	}

	public BasicInfoModel update(BasicInfoModel model) {
		if(!Validator.isEmpty(model)){
			BasicInfo item = new BasicInfo();
			BeanUtils.copyProperties(item,model);
			this.getBasicInfoDAO().update(item);
			cache.put("BasicInfoModel",model);
		}
		return model;
	}
	
	public BasicInfoModel findOnly() {
		BasicInfoModel model = (BasicInfoModel) cache.get("BasicInfoModel");
		if(Validator.isEmpty(model)){
			model = new BasicInfoModel();
			BasicInfo item = this.getBasicInfoDAO().findOnly();
			BeanUtils.copyProperties(model,item);
			cache.put("BasicInfoModel",model);
		}
		return model;
	}
	
	public int delete(BasicInfoModel model) {
		int c = 0;
		try{
			BasicInfo item = new BasicInfo();
			BeanUtils.copyProperties(item,model);
			c = this.getBasicInfoDAO().delete(item);
			cache.remove("BasicInfoModel");
		}catch(Exception e){
			logger.error(e.toString());
		}
		return c;
	}

	public int delete(String[] ids) {
		int c = 0;
		try{
			List<Integer> list = new ArrayList<Integer>();
			for(int i=0; i<ids.length; i++){
				int id = TypeChange.stringToInt(ids[i]);
				list.add(new Integer(id));
			}
			c = this.getBasicInfoDAO().delete(list);
		}catch(Exception e){
			logger.error(e.toString());
		}
		return c;
	}

	public List<BasicInfoModel> findByParameter(BaseParameter param) {
		return null;
	}

	public long countByParameter(BaseParameter param) {
		return 0;
	}

	public BasicInfoDAO getBasicInfoDAO() {
		return DAOWrapper.<BasicInfoDAO>getSingletonInstance(DAOLocator.BASICINFO);
	}

}

⌨️ 快捷键说明

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