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

📄 blogentrybisiness.java

📁 开发工具为myeclipse,数据库为oracle
💻 JAVA
字号:
package com.stiven.business;

import java.util.List;
import java.util.Set;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.stiven.hibernate.Blogentry;
import com.stiven.hibernate.BlogentryDAO;
import com.stiven.hibernate.Users;
import com.stiven.hibernate.UsersDAO;

public class BlogEntryBisiness {
	
	/**
	 * 添加一条新的博客
	 * @param blog
	 * @return
	 */
	public  boolean addBlogEntry(Blogentry blog){
		UsersDAO dao=new UsersDAO();
		Users user=blog.getUsers();
		Session session=dao.getSession();
		try {
			Transaction tran=session.beginTransaction();
			user.getBlogentries().add(blog);
			session.save(user);//直接保存blog的话,缓存将与数据库不一致
			tran.commit();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	/**
	 * 修改博客
	 * @param blog
	 * @return
	 */
	public  boolean modifyBlogEntry(Blogentry blog){
		BlogentryDAO dao=new BlogentryDAO();
		Session session=dao.getSession();
		try {
			Transaction tran=session.beginTransaction();
			session.saveOrUpdate(blog);
			tran.commit();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	/**
	 * 删除博客
	 * @param blog
	 * @return
	 */
	public  boolean deleteBlogEntry(Blogentry blog){
		UsersDAO dao=new UsersDAO();
		Users user=blog.getUsers();
		Session session=dao.getSession();
		try {
			Transaction tran=session.beginTransaction();
			user.getBlogentries().remove(blog);
			session.save(user);
			tran.commit();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	
	
	/**
	 * 查找所有的blog条目
	 * @return
	 */
	public  List findAllBlog(){
		BlogentryDAO dao=new BlogentryDAO();
		return dao.findAll();


	}
}

⌨️ 快捷键说明

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