package com.qualityCourse.dao;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceException;
import javax.persistence.Query;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.jpa.JpaCallback;
import org.springframework.orm.jpa.support.JpaDaoSupport;
import org.springframework.transaction.annotation.Transactional;
import com.qualityCourse.Idao.IReplyDAO;
import com.qualityCourse.model.Reply;
import com.qualityCourse.model.Talkingarea;
/**
* A data access object (DAO) providing persistence and search support for Reply
* entities. Transaction control of the save(), update() and delete() operations
* can directly support Spring container-managed transactions or they can be
* augmented to handle user-managed Spring transactions. Each of these methods
* provides additional information for how to configure it for the desired type
* of transaction control.
*
* @see com.qualityCourse.model.Reply
* @author MyEclipse Persistence Tools
*/
public class ReplyDAO extends JpaDaoSupport implements IReplyDAO {
// property constants
public static final String REPLY_CONTENT = "replyContent";
/**
* Perform an initial save of a previously unsaved Reply entity. All
* subsequent persist actions of this entity should use the #update()
* method. This operation must be performed within the a database
* transaction context for the entity's data to be permanently saved to the
* persistence store, i.e., database. This method uses the
* {@link javax.persistence.EntityManager#persist(Object)
* EntityManager#persist} operation.
* <p>
* User-managed Spring transaction example:
*
* <pre>
* TransactionStatus txn = txManager
* .getTransaction(new DefaultTransactionDefinition());
* ReplyDAO.save(entity);
* txManager.commit(txn);
* </pre>
*
* @see <a href =
* "http://www.myeclipseide.com/documentation/quickstarts/jpaspring#containermanaged">Spring
* container-managed transaction examples</a>
* @param entity
* Reply entity to persist
* @throws RuntimeException
* when the operation fails
*/
public void save(Reply entity) {
logger.info("saving Reply instance");
try {
getJpaTemplate().persist(entity);
Talkingarea t= getJpaTemplate().getReference(Talkingarea.class, entity.getTalkingarea().getId());;
Integer st=t.getSize();
if(null==st||st<0)
st=0;
else
st++;
t.setSize(st);
getJpaTemplate().persist(t);
logger.info("save successful");
} catch (RuntimeException re) {
logger.error("save failed", re);
throw re;
}
}
/**
* Delete a persistent Reply entity. This operation must be performed within
* the a database transaction context for the entity's data to be
* permanently deleted from the persistence store, i.e., database. This
* method uses the {@link javax.persistence.EntityManager#remove(Object)
* EntityManager#delete} operation.
* <p>
* User-managed Spring transaction example:
*
* <pre>
* TransactionStatus txn = txManager
* .getTransaction(new DefaultTransactionDefinition());
* ReplyDAO.delete(entity);
* txManager.commit(txn);
* entity = null;
* </pre>
*
* @see <a href =
* "http://www.myeclipseide.com/documentation/quickstarts/jpaspring#containermanaged">Spring
* container-managed transaction examples</a>
* @param entity
* Reply entity to delete
* @throws RuntimeException
* when the operation fails
*/
public void delete(Reply entity) {
logger.info("deleting Reply instance");
try {
entity = getJpaTemplate().getReference(Reply.class, entity.getId());
Talkingarea t=entity.getTalkingarea();
Integer st=t.getSize();
if(null==st||st<0)
st=0;
else
st--;
t.setSize(st);
getJpaTemplate().persist(t);
getJpaTemplate().remove(entity);
logger.info("delete successful");
} catch (RuntimeException re) {
logger.error("delete failed", re);
throw re;
}
}
/**
* Persist a previously saved Reply entity and return it or a copy of it to
* the sender. A copy of the Reply entity parameter is returned when the JPA
* persistence mechanism has not previously been tracking the updated
* entity. This operation must be performed within the a database
* transaction context for the entity's data to be permanently saved to the
* persistence store, i.e., database. This method uses the
* {@link javax.persistence.EntityManager#merge(Object) EntityManager#merge}
* operation.
* <p>
* User-managed Spring transaction example:
*
* <pre>
* TransactionStatus txn = txManager
* .getTransaction(new DefaultTransactionDefinition());
* entity = ReplyDAO.update(entity);
* txManager.commit(txn);
* </pre>
*
* @see <a href =
* "http://www.myeclipseide.com/documentation/quickstarts/jpaspring#containermanaged">Spring
* container-managed transaction examples</a>
* @param entity
* Reply entity to update
* @return Reply the persisted Reply entity instance, may not be the same
* @throws RuntimeException
* if the operation fails
*/
public Reply update(Reply entity) {
logger.info("updating Reply instance");
try {
Reply result = getJpaTemplate().merge(entity);
logger.info("update successful");
return result;
} catch (RuntimeException re) {
logger.error("update failed", re);
throw re;
}
}
public Reply findById(Integer id) {
logger.info("finding Reply instance with id: " + id);
try {
Reply instance = getJpaTemplate().find(Reply.class, id);
return instance;
} catch (RuntimeException re) {
logger.error("find failed", re);
throw re;
}
}
/**
* Find all Reply entities with a specific property value.
*
* @param propertyName
* the name of the Reply property to query
* @param value
* the property value to match
* @param rowStartIdxAndCount
* Optional int varargs. rowStartIdxAndCount[0] specifies the the
* row index in the query result-set to begin collecting the
* results. rowStartIdxAndCount[1] specifies the the maximum
* number of results to return.
* @return List<Reply> found by query
*/
@SuppressWarnings("unchecked")
public List<Reply> findByProperty(String propertyName, final Object value,
final int... rowStartIdxAndCount) {
logger.info("finding Reply instance with property: " + propertyName
+ ", value: " + value);
try {
final String queryString = "select model from Reply model where model."
+ propertyName + "= :propertyValue";
return getJpaTemplate().executeFind(new JpaCallback() {
public Object doInJpa(EntityManager em)
throws PersistenceException {
Query query = em.createQuery(queryString);
query.setParameter("propertyValue", value);
if (rowStartIdxAndCount != null
&& rowStartIdxAndCount.length > 0) {
int rowStartIdx = Math.max(0, rowStartIdxAndCount[0]);
if (rowStartIdx > 0) {
query.setFirstResult(rowStartIdx);
}
if (rowStartIdxAndCount.length > 1) {
int rowCount = Math.max(0, rowStartIdxAndCount[1]);
if (rowCount > 0) {
query.setMaxResults(rowCount);
}
}
}
return query.getResultList();
}
});
} catch (RuntimeException re) {
logger.error("find by property name failed", re);
throw re;
}
}
public List<Reply> findByReplyContent(Object replyContent,
int... rowStartIdxAndCount) {
return findByProperty(REPLY_CONTENT, replyContent, rowStartIdxAndCount);
}
/**
* Find all Reply entities.
*
* @param rowStartIdxAndCount
* Optional int varargs. rowStartIdx
没有合适的资源?快使用搜索试试~ 我知道了~
JavaSSH做的精品课程系统
共3791个文件
gif:1676个
js:514个
repository:296个
5星 · 超过95%的资源 需积分: 10 30 下载量 41 浏览量
2012-05-26
15:21:53
上传
评论 2
收藏 16.77MB ZIP 举报
温馨提示
采用Java三大框架SSH+Extjs4+JQuery1.7,前台用Struts2标签,后台采用Extjs4
资源推荐
资源详情
资源评论
收起资源包目录
JavaSSH做的精品课程系统 (3791个子文件)
.#BBSReplayService.java.1.1 2KB
.#BBSReplayService.java.1.1 2KB
.#BBSReplayService.java.1.1 2KB
.#IBBSReplayService.java.1.1 981B
.#IBBSReplayService.java.1.1 981B
.#IBBSReplayService.java.1.1 981B
.#LoginAction.java.1.2 7KB
.#LoginAction.java.1.2 7KB
.#LoginAction.java.1.2 7KB
.#BBSReplayAction.java.1.2 5KB
.#BBSReplayAction.java.1.2 5KB
.#BBSReplayAction.java.1.2 5KB
.#BBSService.java.1.3 3KB
.#BBSService.java.1.3 3KB
.#BBSService.java.1.3 3KB
.#SaveTets.java.1.3 1KB
.#SaveTets.java.1.3 1KB
.#SaveTets.java.1.3 1KB
.#struts.xml.1.4 5KB
.#struts.xml.1.4 5KB
.#struts.xml.1.4 5KB
.#.struts.mex.1.4 4KB
.#.struts.mex.1.4 4KB
.#.struts.mex.1.4 4KB
.#IBBSService.java.1.4 547B
.#IBBSService.java.1.4 547B
.#IBBSService.java.1.4 547B
.#BBSAction.java.1.7 4KB
.#BBSAction.java.1.7 4KB
.#BBSAction.java.1.7 4KB
.#lei.xml.1.7 2KB
.#lei.xml.1.7 2KB
.#lei.xml.1.7 2KB
Ext-mess.backup 6KB
LessonServiceImp.class 9KB
CoursewareAction.class 9KB
VideoServiceImp.class 9KB
CoursewareImp.class 9KB
PapersAction.class 9KB
PapersServiceImp.class 9KB
BBSReplayAction.class 8KB
VideoAction.class 8KB
BBSService.class 7KB
LoginAction.class 7KB
LessonAction.class 7KB
BBSAction.class 7KB
TalkingareaDAO.class 7KB
ReplyDAO.class 7KB
BBSReplayService.class 6KB
StudentDAO.class 6KB
AdministorDAO.class 6KB
LessonDAO.class 6KB
PapersDAO.class 6KB
Lesson.class 6KB
CoursewareDAO.class 6KB
StudentServiceImp.class 6KB
VideoDAO.class 5KB
Reply.class 5KB
InformDAO.class 5KB
InformServiceImp.class 5KB
Student.class 5KB
AdministorServiceImp.class 5KB
InformAction.class 4KB
Talkingarea.class 4KB
StudentAction.class 4KB
PluginConfigCreator.class 3KB
AdministorAction.class 3KB
Courseware.class 3KB
Video.class 3KB
Papers.class 3KB
UserLoginServiceImp.class 3KB
Administor.class 2KB
FileStore.class 2KB
StringTest.class 2KB
TalkingareaDAO$2.class 2KB
Inform.class 2KB
TalkingareaDAO$1.class 2KB
AdministorDAO$1.class 2KB
CoursewareDAO$1.class 2KB
StudentDAO$1.class 2KB
InformDAO$1.class 2KB
PapersDAO$1.class 2KB
LessonDAO$1.class 2KB
VideoDAO$1.class 2KB
ReplyDAO$1.class 2KB
PropertyOperation.class 2KB
Result.class 2KB
GzipFilter.class 2KB
SaveTets.class 2KB
TalkingareaDAO$4.class 2KB
CoursewareDAO$4.class 2KB
PapersDAO$4.class 2KB
LessonDAO$4.class 2KB
ReplyDAO$3.class 2KB
VideoDAO$4.class 2KB
ReplyDAO$4.class 2KB
TalkingareaDAO$3.class 1KB
AdministorDAO$2.class 1KB
CoursewareDAO$2.class 1KB
StudentDAO$2.class 1KB
共 3791 条
- 1
- 2
- 3
- 4
- 5
- 6
- 38
资源评论
- getHelloworld2013-04-09有点复杂,看的不太懂,相信经过一段时间的学习会跟好的。感谢分享给大家。
- Leethr2015-04-29初学不太懂 不过对我帮助很大
zpc15200790194
- 粉丝: 8
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功