本文整理汇总了Java中org.hibernate.Session.flush方法的典型用法代码示例。如果您正苦于以下问题:Java Session.flush方法的具体用法?Java Session.flush怎么用?Java Session.flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.Session
的用法示例。
在下文中一共展示了Session.flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beforeCommit
import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public void beforeCommit(boolean readOnly) throws DataAccessException {
if (!readOnly) {
Session session = getCurrentSession();
// Read-write transaction -> flush the Hibernate Session.
// Further check: only flush when not FlushMode.MANUAL.
if (!session.getFlushMode().equals(FlushMode.MANUAL)) {
try {
SessionFactoryUtils.logger.debug("Flushing Hibernate Session on transaction synchronization");
session.flush();
}
catch (HibernateException ex) {
throw SessionFactoryUtils.convertHibernateAccessException(ex);
}
}
}
}
示例2: loadCalendars
import org.hibernate.Session; //导入方法依赖的package包/类
@DataProvider
public Collection<JobCalendar> loadCalendars(String jobId){
String hql="from "+JobCalendarRelation.class.getName()+" j where j.jobId=:jobId";
Map<String,Object> map=new HashMap<String,Object>();
map.put("jobId",jobId);
List<JobCalendar> result=new ArrayList<JobCalendar>();
List<JobCalendarRelation> relations=this.query(hql, map);
Session session=this.getSessionFactory().openSession();
try{
for(JobCalendarRelation r:relations){
result.add((JobCalendar)session.get(JobCalendar.class, r.getCalendarId()));
}
}finally{
session.flush();
session.close();
}
return result;
}
示例3: saveJobParameters
import org.hibernate.Session; //导入方法依赖的package包/类
@DataResolver
public void saveJobParameters(Collection<JobParameter> parameters){
Session session=this.getSessionFactory().openSession();
try{
for(JobParameter p:parameters){
EntityState state=EntityUtils.getState(p);
if(state.equals(EntityState.NEW)){
p.setId(UUID.randomUUID().toString());
session.save(p);
}
if(state.equals(EntityState.MODIFIED)){
session.update(p);
}
if(state.equals(EntityState.DELETED)){
session.delete(p);
}
}
}finally{
session.flush();
session.close();
}
}
示例4: send
import org.hibernate.Session; //导入方法依赖的package包/类
public void send(MessagePacket message) {
Collection<IUser> toUsers=message.getTo();
if(toUsers==null || toUsers.size()==0){
throw new IllegalAddException("You must define at least one message recipient!");
}
Collection<IUser> ccUsers=message.getCc();
if(ccUsers!=null && ccUsers.size()>0){
toUsers.addAll(ccUsers);
}
Session session=this.getSessionFactory().openSession();
try{
for(IUser user:toUsers){
Message msg=new Message();
msg.setId(UUID.randomUUID().toString());
msg.setSendDate(new Date());
msg.setSender(message.getSender().getUsername());
msg.setReply(false);
msg.setRead(false);
msg.setContent(message.getContent());
msg.setTitle(message.getTitle());
msg.setReceiver(user.getUsername());
session.save(msg);
}
}finally{
session.flush();
session.close();
}
}
示例5: updateAppStatus2Del
import org.hibernate.Session; //导入方法依赖的package包/类
/**
* 设置appStatus 状态 为可删除 状态 3,索引状态 indexStatus为 -1
*/
@Override
public int updateAppStatus2Del(List<Integer> ids) {
Session session = null;
try {
session = this.sessions.openSession();
String hql = "update AppHistory4Index set appStatus=3,indexStatus=-1,lastOpTime=:lastOpTime where appId in (:appIds)";
Query query = session.createQuery(hql);
query.setParameterList("appIds", ids);
query.setTimestamp("lastOpTime", new Date());
return query.executeUpdate();
} catch (Exception e) {
logger.error("error:", e);
return 0;
} finally {
if (session != null && session.isOpen()) {
session.flush();
session.clear();
session.close();
}
}
}
示例6: update
import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public int update(List<Integer> ids) {
Session session = null;
try {
session = this.sessions.openSession();
// 设置状态 为更新
// 需要重新索引
String hql = "update AppHistory4Index set appStatus=2,indexStatus=0,lastOpTime=:lastOpTime where appId in (:appIds)";
Query query = session.createQuery(hql);
query.setParameterList("appIds", ids);
query.setTimestamp("lastOpTime", new Date());
return query.executeUpdate();
} catch (Exception e) {
logger.error("error:", e);
return 0;
} finally {
if (session != null && session.isOpen()) {
session.flush();
session.clear();
session.close();
}
}
}
示例7: getAllBigGameFromMarketApp
import org.hibernate.Session; //导入方法依赖的package包/类
@Override
public List<MarketApp> getAllBigGameFromMarketApp() {
String hqlStr = "from MarketApp a where a.catalog =100";
List<MarketApp> list = null;
Session session = null;
try {
session = sessionFactory.openSession();
list = session.createQuery(hqlStr).list();
} finally {
session.flush();
session.clear();
session.close();
}
return list;
}
示例8: saveValidatorEvents
import org.hibernate.Session; //导入方法依赖的package包/类
@DataResolver
public void saveValidatorEvents(Collection<ValidatorEvent> events){
Session session=this.getSessionFactory().openSession();
try{
for(ValidatorEvent v:events){
EntityState state=EntityUtils.getState(v);
if(state.equals(EntityState.NEW)){
v.setId(UUID.randomUUID().toString());
session.save(v);
}
if(state.equals(EntityState.DELETED)){
session.delete(v);
}
if(state.equals(EntityState.MODIFIED)){
session.update(v);
}
}
}finally{
session.flush();
session.close();
}
}
示例9: saveValidatorProperties
import org.hibernate.Session; //导入方法依赖的package包/类
@DataResolver
public void saveValidatorProperties(Collection<ValidatorProperty> properties){
Session session=this.getSessionFactory().openSession();
try{
for(ValidatorProperty v:properties){
EntityState state=EntityUtils.getState(v);
if(state.equals(EntityState.NEW)){
v.setId(UUID.randomUUID().toString());
session.save(v);
}
if(state.equals(EntityState.DELETED)){
session.delete(v);
}
if(state.equals(EntityState.MODIFIED)){
session.update(v);
}
}
}finally{
session.flush();
session.close();
}
}
示例10: saveAssignmentDefs
import org.hibernate.Session; //导入方法依赖的package包/类
@DataResolver
public void saveAssignmentDefs(Collection<AssignmentDef> assignments){
IUser user=ContextHolder.getLoginUser();
if(user==null){
throw new RuntimeException("Please login first!");
}
Session session=this.getSessionFactory().openSession();
try{
String companyId=user.getCompanyId();
if(StringUtils.isNotEmpty(getFixedCompanyId())){
companyId=getFixedCompanyId();
}
for(AssignmentDef def:assignments){
EntityState state=EntityUtils.getState(def);
if(state.equals(EntityState.NEW)){
def.setId(UUID.randomUUID().toString());
def.setCompanyId(companyId);
session.save(def);
}
if(state.equals(EntityState.MODIFIED)){
session.update(def);
}
if(state.equals(EntityState.DELETED)){
for(IAssignmentProvider p:providers){
if(p.isDisabled() || !p.getTypeId().equals(def.getType()))continue;
p.deleteAssignmentInfos(def.getId());
}
session.delete(def);
}
}
}finally{
session.flush();
session.close();
}
}
示例11: saveUsers
import org.hibernate.Session; //导入方法依赖的package包/类
@DataResolver
public void saveUsers(Collection<DefaultUser> users) throws Exception {
IUser loginuser=ContextHolder.getLoginUser();
if(loginuser==null){
throw new NoneLoginException("Please login first!");
}
String companyId=loginuser.getCompanyId();
if(StringUtils.isNotEmpty(getFixedCompanyId())){
companyId=getFixedCompanyId();
}
Session session = this.getSessionFactory().openSession();
try{
for (DefaultUser user : users) {
EntityState state = EntityUtils.getState(user);
if (state.equals(EntityState.NEW)) {
String salt = String.valueOf(RandomUtils.nextInt(100));
String password = passwordEncoder.encodePassword(
user.getPassword(), salt);
user.setPassword(password);
user.setSalt(salt);
user.setCompanyId(companyId);
session.save(user);
} else if (state.equals(EntityState.MODIFIED)) {
session.update(user);
} else if (state.equals(EntityState.DELETED)) {
String userName = user.getUsername();
roleService.deleteRoleMemeber(userName, MemberType.User);
groupService.deleteGroupMemeber(userName, MemberType.User);
positionService.deleteUserPositionByUser(userName);
deptService.deleteUserDept(userName);
session.delete(user);
}
}
}finally{
session.flush();
session.close();
}
}
示例12: savePostions
import org.hibernate.Session; //导入方法依赖的package包/类
@DataResolver
public void savePostions(final Collection<DefaultPosition> positions) {
Session session = this.getSessionFactory().openSession();
try {
IUser user = ContextHolder.getLoginUser();
if (user == null) {
throw new NoneLoginException("Please login first");
}
String companyId = user.getCompanyId();
if (StringUtils.isNotEmpty(getFixedCompanyId())) {
companyId = getFixedCompanyId();
}
for (DefaultPosition position : positions) {
EntityState state = EntityUtils.getState(position);
if (state.equals(EntityState.NEW)) {
position.setCompanyId(companyId);
position.setCreateDate(new Date());
session.save(position);
} else if (state.equals(EntityState.MODIFIED)) {
session.update(position);
} else if (state.equals(EntityState.DELETED)) {
roleService.deleteRoleMemeber(position.getId(), MemberType.Position);
groupService.deleteGroupMemeber(position.getId(), MemberType.Position);
positionService.deleteUserPosition(position.getId());
session.delete(position);
}
}
} finally {
session.flush();
session.close();
}
}
示例13: jobWasExecuted
import org.hibernate.Session; //导入方法依赖的package包/类
public void jobWasExecuted(JobExecutionContext context,
JobExecutionException jobException) {
JobDetail jobDetail = context.getJobDetail();
if (!(jobDetail instanceof SpringBeanJobExecutorDetail)) {
return;
}
JobDataMap map = jobDetail.getJobDataMap();
if (!map.containsKey(IJobDefinitionService.JOB_DEFINITION_ID)) {
return;
}
Date end = new Date();
String exception = getExceptionStackMessage(jobException);
JobHistory history = new JobHistory();
history.setSuccessful(exception == null ? true : false);
if (exception != null) {
history.setExceptionMessage(exception.length() > 1500 ? exception
.substring(0, 1500) : exception);
}
history.setEndDate(end);
history.setStartDate((Date)map.get(START_DATE_KEY));
history.setId(UUID.randomUUID().toString());
history.setJobId(map.getString(IJobDefinitionService.JOB_DEFINITION_ID));
Session session = getSessionFactory().openSession();
try {
session.save(history);
} finally {
session.flush();
session.close();
}
}
示例14: query
import org.hibernate.Session; //导入方法依赖的package包/类
public Collection<?> query(DetachedCriteria detachedCriteria, String dataSourceName) {
Session session = this.getSessionFactory(dataSourceName).openSession();
try {
return detachedCriteria.getExecutableCriteria(session).list();
} finally {
session.flush();
session.close();
}
}
示例15: clean
import org.hibernate.Session; //导入方法依赖的package包/类
private void clean(){
Map<String,Session> sessionMap=ContextHolder.getHibernateSessionMap();
if(sessionMap==null){
return;
}
for(Session session:sessionMap.values()){
if(session!=null && session.isOpen()){
session.flush();
session.close();
session=null;
}
}
sessionMap.clear();
}