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

📄 forumhibernatedao.java

📁 天乙虚拟社区8.05版本。只支持Mysql
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		List l = getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(Session s) throws HibernateException {
				Criteria c = s.createCriteria(getForumClass());
				c.setProjection(Projections.count("id"));
				if (bid != -1) {
					c.add(Restrictions.eq("boardID", new Long(bid)));
				}
				if (isNew != -1) {
					c.add(Restrictions.eq("isNew", new Integer(isNew)));
				}
				if (delSign != -1) {
					c.add(Restrictions.eq("delSign", new Integer(delSign)));
				}
				if (auditing != -1) {
					c.add(Restrictions.eq("auditing", new Integer(auditing)));
				}
				if (auditingAttachFile != -1) {
					c.add(Restrictions.eq("auditingAttachFile", new Integer(auditingAttachFile)));
				}

				return c.list();
			}
		});
		if (l == null || l.isEmpty()) {
			return 0;
		} else {
			return ((Integer) l.get(0)).longValue();
		}
	}

	public long getForumNum(final long bid, final String tagId, final int isNew, final int delSign, final int auditing) {
		List l = getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(Session s) throws HibernateException {
				Criteria c = s.createCriteria(getForumClass());
				c.setProjection(Projections.count("id"));
				if (bid != -1) {
					c.add(Restrictions.eq("boardID", new Long(bid)));
				}
				if (StringUtils.isNotBlank(tagId)) {
					c.add(Restrictions.eq("tagID", tagId));
				}
				if (isNew != -1) {
					c.add(Restrictions.eq("isNew", new Integer(isNew)));
				}
				if (delSign != -1) {
					c.add(Restrictions.eq("delSign", new Integer(delSign)));
				}
				if (auditing != -1) {
					c.add(Restrictions.eq("auditing", new Integer(auditing)));
				}
				return c.list();
			}
		});
		if (l == null || l.isEmpty()) {
			return 0;
		} else {
			return ((Integer) l.get(0)).longValue();
		}
	}

	public long getForumNumCommend(final long commend, final int isNew, final int delSign, final int auditing) {
		List l = getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(Session s) throws HibernateException {
				Criteria c = s.createCriteria(getForumClass());
				c.setProjection(Projections.count("id"));

				if (commend != -1) {
					c.add(Restrictions.eq("commend", new Long(commend)));
				}
				if (isNew != -1) {
					c.add(Restrictions.eq("isNew", new Integer(isNew)));
				}
				if (delSign != -1) {
					c.add(Restrictions.eq("delSign", new Integer(delSign)));
				}
				if (auditing != -1) {
					c.add(Restrictions.eq("auditing", new Integer(auditing)));
				}
				return c.list();
			}
		});
		if (l == null || l.isEmpty()) {
			return 0;
		} else {
			return ((Integer) l.get(0)).longValue();
		}
	}

	public long getForumNumHotTopic(long bid, int reNum, int click) {
		Object[] o = { new Long(bid), new Integer(1), new Integer(0), new Integer(0), new Integer(reNum),
				new Integer(click) };
		String sql = "select count(id) from " + this.getObjName()
				+ " where boardID = ? and isNew = ? and delSign = ? and auditing = ? and (reNum >= ? or click >= ?)";
		List l = this.getHibernateTemplate().find(sql, o);
		if (l == null || l.isEmpty()) {
			return 0;
		} else {
			return ((Long) l.get(0)).longValue();
		}
	}

	public long getForumNumInMainIDByUserID(final long bid, final String mainID, final String userID, final int isnew,
			final int delSign, final int auditing) {
		List l = getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(Session s) throws HibernateException {
				Criteria c = s.createCriteria(getForumClass());
				c.setProjection(Projections.count("id"));
				c.add(Restrictions.eq("boardID", new Long(bid)));

				c.add(Restrictions.eq("mainID", mainID));
				c.add(Restrictions.eq("userID", userID));
				if (isnew != -1) {
					c.add(Restrictions.eq("isNew", new Integer(isnew)));
				}
				if (delSign != -1) {
					c.add(Restrictions.eq("delSign", new Integer(delSign)));
				}
				if (auditing != -1) {
					c.add(Restrictions.eq("auditing", new Integer(auditing)));
				}

				return c.list();
			}
		});
		if (l == null || l.isEmpty()) {
			return 0;
		} else {
			return ((Integer) l.get(0)).longValue();
		}
	}

	public long getForumOwnerNum(final String userID, final int isNew, final int delSign, final int auditing) {
		List l = getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(Session s) throws HibernateException {
				Criteria c = s.createCriteria(getForumClass());
				c.setProjection(Projections.count("id"));
				c.add(Restrictions.eq("userID", userID));
				if (isNew != -1) {
					c.add(Restrictions.eq("isNew", new Integer(isNew)));
				}
				if (delSign != -1) {
					c.add(Restrictions.eq("delSign", new Integer(delSign)));
				}
				if (auditing != -1) {
					c.add(Restrictions.eq("auditing", new Integer(auditing)));
				}
				return c.list();
			}
		});
		if (l == null || l.isEmpty()) {
			return 0;
		} else {
			return ((Long) l.get(0)).longValue();
		}
	}

	public long getForumTopicNum(final long bid, final String mainID, final int delSign, final int auditing) {
		List l = getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(Session s) throws HibernateException {
				Criteria c = s.createCriteria(getForumClass());
				c.setProjection(Projections.count("id"));
				c.add(Restrictions.eq("boardID", new Long(bid)));
				c.add(Restrictions.eq("mainID", mainID));
				if (delSign != -1) {
					c.add(Restrictions.eq("delSign", new Integer(delSign)));
				}
				if (auditing != -1) {
					c.add(Restrictions.eq("auditing", new Integer(auditing)));
				}
				return c.list();
			}
		});
		if (l == null || l.isEmpty()) {
			return 0;
		} else {
			return ((Integer) l.get(0)).longValue();
		}
	}

	public List getSearchList(final long bid, final String con, final String text, final int delSign,
			final int auditing, final String orderby, final int ascOrDesc, final int firstResult, final int maxResults) {
		return getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(Session s) throws HibernateException {
				Criteria c = s.createCriteria(getForumClass());
				c.add(Restrictions.eq("boardID", new Long(bid)));
				c.add(Restrictions.like(con, "%" + text + "%"));
				if (delSign != -1) {
					c.add(Restrictions.eq("delSign", new Integer(delSign)));
				}
				if (auditing != -1) {
					c.add(Restrictions.eq("auditing", new Integer(auditing)));
				}
				if (StringUtils.isNotBlank(orderby)) {
					if (ascOrDesc == Constant.ORDER_ASC) {
						c.addOrder(Order.asc(orderby));
					}
					if (ascOrDesc == Constant.ORDER_DESC) {
						c.addOrder(Order.desc(orderby));
					}
				}
				c.setFirstResult(firstResult);
				c.setMaxResults(maxResults);
				return c.list();
			}
		});
	}

	public long getSearchNum(final long bid, final String con, final String text, final int delSign, final int auditing) {
		List l = getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(Session s) throws HibernateException {
				Criteria c = s.createCriteria(getForumClass());
				c.setProjection(Projections.count("id"));
				c.add(Restrictions.eq("boardID", new Long(bid)));
				c.add(Restrictions.like(con, "%" + text + "%"));
				if (delSign != -1) {
					c.add(Restrictions.eq("delSign", new Integer(delSign)));
				}
				if (auditing != -1) {
					c.add(Restrictions.eq("auditing", new Integer(auditing)));
				}
				return c.list();
			}
		});
		if (l == null || l.isEmpty()) {
			return 0;
		} else {
			return ((Integer) l.get(0)).longValue();
		}
	}

	public void removeForum(final String id, final long bid) {
		final String sql = "delete from " + this.getObjName() + " where id = ? and boardID = ?";
		getHibernateTemplate().execute(new HibernateCallback() {
			public Object doInHibernate(Session s) throws HibernateException, SQLException {
				Query query = s.createQuery(sql);
				query.setString(0, id);
				query.setLong(1, bid);
				query.executeUpdate();
				return null;
			}
		});
	}

	public void removeForum(final String id) {
		final String sql = "delete from " + this.getObjName() + " where id = ?";
		getHibernateTemplate().execute(new HibernateCallback() {
			public Object doInHibernate(Session s) throws HibernateException, SQLException {
				Query query = s.createQuery(sql);
				query.setString(0, id);
				query.executeUpdate();
				return null;
			}
		});
	}

	public void removeForum(Forum forum) {
		this.getHibernateTemplate().delete(forum);
	}

	public Forum saveForum(Forum forum) {
		this.getHibernateTemplate().save(forum);
		return forum;
	}

	public Forum saveOrUpdateForum(Forum forum) {
		this.getHibernateTemplate().saveOrUpdate(forum);
		return forum;
	}

	public Forum updateForum(Forum forum) {
		this.getHibernateTemplate().update(forum);
		return forum;
	}

	public void updateForumsTag(final String oldTagId, final String newTagID, final String newTagName) {
		final String sql = "update " + this.getObjName() + " set tagID = ?, tagName = ? where tagID = ?";
		getHibernateTemplate().execute(new HibernateCallback() {
			public Object doInHibernate(Session s) throws HibernateException, SQLException {
				Query query = s.createQuery(sql);
				query.setString(0, newTagID);
				query.setString(1, newTagName);
				query.setString(2, oldTagId);
				query.executeUpdate();
				return null;
			}
		});
	}

	public long getForumNumCommend(final long bid, final long commend, final int isNew, final int delSign,
			final int auditing) {
		List l = getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(Session s) throws HibernateException {
				Criteria c = s.createCriteria(getForumClass());
				c.setProjection(Projections.count("id"));
				c.add(Restrictions.eq("boardID", new Long(bid)));
				if (commend != -1) {
					c.add(Restrictions.eq("commend", new Long(commend)));
				}
				if (isNew != -1) {
					c.add(Restrictions.eq("isNew", new Integer(isNew)));
				}
				if (delSign != -1) {
					c.add(Restrictions.eq("delSign", new Integer(delSign)));
				}
				if (auditing != -1) {
					c.add(Restrictions.eq("auditing", new Integer(auditing)));
				}
				return c.list();
			}
		});
		if (l == null || l.isEmpty()) {
			return 0;
		} else {
			return ((Integer) l.get(0)).longValue();
		}
	}

	public List findForumsCommend(final long bid, final long commend, final int isNew, final int delSign,
			final int auditing, final String orderby, final int ascOrDesc, final int firstResult, final int maxResults) {
		return getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(Session s) throws HibernateException {
				Criteria c = s.createCriteria(getForumClass());
				c.add(Restrictions.eq("boardID", new Long(bid)));
				if (commend != -1) {
					c.add(Restrictions.eq("commend", new Long(commend)));
				}
				if (isNew != -1) {
					c.add(Restrictions.eq("isNew", new Integer(isNew)));
				}
				if (delSign != -1) {
					c.add(Restrictions.eq("delSign", new Integer(delSign)));
				}
				if (auditing != -1) {
					c.add(Restrictions.eq("auditing", new Integer(auditing)));
				}

				if (StringUtils.isNotBlank(orderby)) {
					if (ascOrDesc == Constant.ORDER_ASC) {
						c.addOrder(Order.asc(orderby));
					}
					if (ascOrDesc == Constant.ORDER_DESC) {
						c.addOrder(Order.desc(orderby));
					}
				}

				c.setFirstResult(firstResult);
				c.setMaxResults(maxResults);
				return c.list();
			}
		});
	}

	public long getForumNumBeforeDate(long bid, long atime) {
		String sql = "select count(*) from " + this.getObjName() + " where boardID = ? and isNew = 1 and postTime < ?";
		Object[] o = { new Long(bid), new Long(atime) };
		List l = this.getHibernateTemplate().find(sql, o);
		if (l == null || l.isEmpty()) {
			return 0;
		} else {
			return ((Long) l.get(0)).longValue();
		}

	}

	public List findForumsBeforeDate(final long bid, final long atime, final int firstResult, final int maxResults) {
		final String sql = "from " + this.getObjName()
				+ " where boardID = ? and isNew = 1 and postTime < ? order by postTime desc";
		return getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(Session s) throws HibernateException, SQLException {
				Query query = s.createQuery(sql);
				query.setLong(0, bid);
				query.setLong(1, atime);
				query.setFirstResult(firstResult);
				query.setMaxResults(maxResults);

				List list = query.list();
				return list;
			}
		});
	}

	private String getObjName() {
		return "Forum" + this.flag;
	}

	private Class getForumClass() {
		return Constant.FORUM_CLASS_MAP.get(this.flag);
		/*
		 * try { //return Class.forName("com.laoer.bbscs.bean." + getObjName()); }
		 * catch (ClassNotFoundException e) {
		 *
		 * e.printStackTrace(); return ForumMain.class; // return
		 * com.laoer.bbscs.bean.ForumMain.class; }
		 */
	}

}

⌨️ 快捷键说明

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