當前位置: 首頁>>代碼示例>>Java>>正文


Java Session類代碼示例

本文整理匯總了Java中org.hibernate.Session的典型用法代碼示例。如果您正苦於以下問題:Java Session類的具體用法?Java Session怎麽用?Java Session使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Session類屬於org.hibernate包,在下文中一共展示了Session類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getComposition

import org.hibernate.Session; //導入依賴的package包/類
@Override
public List<Integer> getComposition(int task_id) {
	 
	List<Integer> img_ids = new ArrayList<Integer>();
       Session session = HibernateUtils.getSession();//生成Session實例
	Transaction tx = session.beginTransaction();//生成事務實例  
	 try {
		 img_ids = session.createQuery("SELECT img_id FROM Composition WHERE task_id = ?").setInteger(0, task_id).list();
		 tx.commit();//提交事務
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();
	}finally {
		HibernateUtils.closeSession();//關閉session實例
	}
	 return img_ids;
}
 
開發者ID:codekongs,項目名稱:ImageClassify,代碼行數:18,代碼來源:CompositionService.java

示例2: deleteInterests

import org.hibernate.Session; //導入依賴的package包/類
@Override
public int deleteInterests(int user_id) {  
			Session session = HibernateUtils.getSession(); //生成session實例
		    Transaction tx = session.beginTransaction();  //創建transaction實例 
		    int temp = 0;
		    try {  
		    	String hql = "delete from Interest where user_id  =  ?"; 
		    	Query query = session.createQuery(hql);
		    	query.setInteger(0, user_id);  
		    	temp = query.executeUpdate(); 
		    	tx.commit();            //提交事務  
			} catch (Exception e) {
				e.printStackTrace();
				tx.rollback();   
			}finally {
			  HibernateUtils.closeSession();  //關閉Session實例
			} 
		    return temp;
}
 
開發者ID:codekongs,項目名稱:ImageClassify,代碼行數:20,代碼來源:InterestService.java

示例3: createRoomUtilizationReportFor

import org.hibernate.Session; //導入依賴的package包/類
@Override
public void createRoomUtilizationReportFor(PointInTimeData pointInTimeData, Session hibSession) {
	
	calculatePeriodsWithEnrollments(pointInTimeData, hibSession);
	
	int minute = (startOnHalfHour ? 30 : 0);
	for(Department department : depts) {
		for(int dayOfWeek = 1 ; dayOfWeek < 8 ; dayOfWeek++) {
			ArrayList<String> row = new ArrayList<String>();
			row.add(department.getDeptCode());
			row.add(department.getAbbreviation());
			row.add(department.getName());
			row.add(getDayOfWeekLabel(periodDayOfWeek(dayOfWeek)));
			for(int hourOfDay = 0 ; hourOfDay < 24 ; hourOfDay++) {
				String key = getPeriodTag(department.getUniqueId().toString(), dayOfWeek, hourOfDay, minute);
				row.add(periodEnrollmentMap.get(key) == null ? "0": "" + periodEnrollmentMap.get(key).getWeeklyStudentEnrollment());
			}
			addDataRow(row);			
		}
	}
			
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:23,代碼來源:WSCHByDepartmentDayOfWeekHourOfDay.java

示例4: main

import org.hibernate.Session; //導入依賴的package包/類
public static void main(String[] args) {
	Configuration cfg=null;
	SessionFactory factory=null;
	Session ses=null;
	Transaction tx=null;
			cfg=new Configuration().configure("com/app/cfgs/hibernate.cfg.xml");
			factory=cfg.buildSessionFactory();
		ses=factory.openSession();
	
		 String hql="select item_name from bigbazarModel where bazarid=:id";
		 Query q=ses.createQuery(hql);
		 		q.setParameter("id", 1001);
		 			String s=(String) q.uniqueResult();
		 			System.out.println("\t\t"+s);
		 			
		 			factory.close();

}
 
開發者ID:pratikdimble,項目名稱:Hibernate_HQL_UniqueResult_ExecuteUpdate_CopyData_Delete_Update,代碼行數:19,代碼來源:TestClass.java

示例5: findAllPitClassesWithContactHoursForDepartmentsAndSubjectAreas

import org.hibernate.Session; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private HashSet<PitClass> findAllPitClassesWithContactHoursForDepartmentsAndSubjectAreas(
		PointInTimeData pointInTimeData, Session hibSession) {
	
	HashSet<PitClass> pitClasses = new HashSet<PitClass>();
			
	for(Long deptId : getDepartmentIds()) {
		List<PitClass> pitClassesQueryResult = findAllPitClassesWithContactHoursForDepartment(pointInTimeData, deptId, hibSession);
		for(PitClass pc : pitClassesQueryResult) {
			if(pc.getPitSchedulingSubpart().getPitInstrOfferingConfig().getPitInstructionalOffering().getControllingPitCourseOffering().isIsControl().booleanValue() 
					&& getSubjectAreaIds().contains(pc.getPitSchedulingSubpart().getPitInstrOfferingConfig().getPitInstructionalOffering().getControllingPitCourseOffering().getSubjectArea().getUniqueId())) {
				pitClasses.add(pc);
			};
		}
	}
	return(pitClasses);

}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:19,代碼來源:WSEByDayOfWeekAndPeriod.java

示例6: enumerateAllIds

import org.hibernate.Session; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
@Transactional
public List<ID> enumerateAllIds()
{
	return getHibernateTemplate().executeFind(new TLEHibernateCallback()
	{
		@Override
		public Object doInHibernate(Session session) throws HibernateException
		{
			// NOTE: Don't order by name here - use NumberStringComparator
			// on the returned list.
			Query query = session.createQuery("select id from " + getPersistentClass().getName() //$NON-NLS-1$
				+ " where institution = :institution"); //$NON-NLS-1$
			query.setParameter("institution", CurrentInstitution.get()); //$NON-NLS-1$
			query.setCacheable(true);
			query.setReadOnly(true);
			return query.list();
		}
	});
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:22,代碼來源:GenericInstitionalDaoImpl.java

示例7: getCheckIns

import org.hibernate.Session; //導入依賴的package包/類
@Override
public List<CheckIn> getCheckIns(int user_id) {
	
	 List<CheckIn> checkIns=new ArrayList<CheckIn>();
        Session session=HibernateUtils.getSession();//生成Session實例
	 Transaction tx=session.beginTransaction();//生成事務實例 
	 
	 try {
		 //select * from checkin where user_id=user_id order by checkin_time asc
		 checkIns= session.createCriteria(CheckIn.class).add(Restrictions.eq("user_id", user_id)).addOrder(Order.asc("checkin_time")).list();				 
		 tx.commit();//提交事務
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();
	}finally {
		HibernateUtils.closeSession();//關閉session實例
	}
	 return checkIns; 
}
 
開發者ID:codekongs,項目名稱:ImageClassify,代碼行數:20,代碼來源:CheckInService.java

示例8: delete

import org.hibernate.Session; //導入依賴的package包/類
@Override
public void delete (final FileScanner scanner)
{
   getHibernateTemplate ().execute (new HibernateCallback<Void>()
   {
      @Override
      public Void doInHibernate (Session session) throws HibernateException,
         SQLException
      {
         String sql = "DELETE FROM FILE_SCANNER_PREFERENCES " +
            "WHERE FILE_SCANNER_ID = ?";
         SQLQuery query = session.createSQLQuery (sql);
         query.setLong (0, scanner.getId ());
         query.executeUpdate ();
         return null;
      }
   });
   super.delete (scanner);
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:20,代碼來源:FileScannerDao.java

示例9: findData

import org.hibernate.Session; //導入依賴的package包/類
@Override
public List<App> findData() {
    Session session = null;
    List<App> list = null;
    try {
        session = this.sessionFactory.openSession();
        Query q = session.createQuery("from App app where app.hidden = false");
        list = HibernateHelper.list(q);
        // if (list != null) {
        // logger.debug("in findData all .{} ", list.size());
        // }
    } catch (Exception e) {
        logger.error("error:", e);
    } finally {
        session.close();
    }
    return list;
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:19,代碼來源:AppDaoImpl.java

示例10: invoke

import org.hibernate.Session; //導入依賴的package包/類
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
	SessionFactory sf = getSessionFactory();
	if (!TransactionSynchronizationManager.hasResource(sf)) {
		// New Session to be bound for the current method's scope...
		Session session = openSession();
		try {
			TransactionSynchronizationManager.bindResource(sf, new SessionHolder(session));
			return invocation.proceed();
		}
		finally {
			SessionFactoryUtils.closeSession(session);
			TransactionSynchronizationManager.unbindResource(sf);
		}
	}
	else {
		// Pre-bound Session found -> simply proceed.
		return invocation.proceed();
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:OpenSessionInterceptor.java

示例11: moveToHistory

import org.hibernate.Session; //導入依賴的package包/類
public void moveToHistory(Step step, int actionId, Date finishDate, String status, String actor) throws WorkflowStoreException {

        Session session = null;
        
        try {
            
            session = sessionFactory.openSession();
            session.refresh(step);

            super.markFinished(step, actionId, finishDate, status, actor);
            update(session, step);

            HibernateStep currentStep = (HibernateStep)step;
            HibernateStep historyStep = new HibernateHistoryStep(currentStep);
            HibernateProcessInstance entry = currentStep.getEntry();

            entry.removeCurrentStep(currentStep);
            entry.addHistoryStep(historyStep);

            // Session transaction managed by the delete, save and update DAO methods
            delete(session, currentStep);
            save(session, historyStep);
            update(session, entry);
       
            if(logger.isDebugEnabled()) {
                logger.debug(historyStep.toString());
                logger.debug(entry.toString());
            }
       
        } catch(HibernateException hibernateException) {
            throw new WorkflowStoreException(hibernateException);
        } finally {

            if (session != null)
                session.close();
        }
        
        // Logging the results of this action

    }
 
開發者ID:will-gilbert,項目名稱:OSWf-OSWorkflow-fork,代碼行數:41,代碼來源:HibernateStore.java

示例12: getMarkListByUserId

import org.hibernate.Session; //導入依賴的package包/類
@Override
public List<String> getMarkListByUserId(int user_id) {
	List<String> accuracy = new ArrayList<String>();
       Session session = HibernateUtils.getSession();//生成Session實例
	 Transaction tx = session.beginTransaction();//生成事務實例 
	 
	 try {
		 accuracy = session.createQuery("select mark_accuracy from Mark where user_id = ?").setInteger(0, user_id).list();
		 tx.commit();//提交事務
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();
	}finally {
		HibernateUtils.closeSession();//關閉session實例
	}
	 return accuracy;
}
 
開發者ID:codekongs,項目名稱:ImageClassify,代碼行數:18,代碼來源:MarkService.java

示例13: updateUserByAdmin

import org.hibernate.Session; //導入依賴的package包/類
@Override
public int updateUserByAdmin(User user){
	Session session = HibernateUtils.getSession();
	 Transaction tx = session.beginTransaction();
	 int aa = 0;
	 try {
		Query query = session.createQuery("update User u set u.username =?,u.sex = ?,u.integral=?,u.accuracy=? where u.user_id = ?");  
	    query.setString(0, user.getUsername());
	    query.setString(1, user.getSex());
	    query.setInteger(2, user.getIntegral());
	    query.setString(3, user.getAccuracy());
	    query.setInteger(4, user.getUser_id());
		aa = query.executeUpdate();  
		tx.commit(); 
	} catch (Exception e) {
		 e.printStackTrace();
		 tx.rollback(); 
	}finally {
		HibernateUtils.closeSession();
	}  
	return aa;
}
 
開發者ID:codekongs,項目名稱:ImageClassify,代碼行數:23,代碼來源:AdminService.java

示例14: getAmountByCategoryId

import org.hibernate.Session; //導入依賴的package包/類
@Override
public int getAmountByCategoryId(int category_id) {
	 String sql = "SELECT COUNT(*) FROM image,image_category,category WHERE image.img_id = image_category.img_id AND category.category_id = image_category.category_id AND image.img_is_finish <>0 AND category.category_id = "+category_id;
	 Session session = HibernateUtils.getSession();//生成Session實例
	 Transaction tx = session.beginTransaction();//生成事務實例  
	  int amount = 0;
	 try { 
	 List arr  =  session.createSQLQuery(sql).list(); 
	 amount = Integer.parseInt(arr.get(0).toString());
	 tx.commit();//提交事務 
	} catch (Exception e) {
		e.printStackTrace();
		tx.rollback();
	}finally {
		HibernateUtils.closeSession();//關閉session實例
	} 
	return amount;
}
 
開發者ID:codekongs,項目名稱:ImageClassify,代碼行數:19,代碼來源:ImageService.java

示例15: execute

import org.hibernate.Session; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public Object execute(Context context) {
	ProcessService processService=context.getProcessService();
	ProcessInstanceQuery query=context.getProcessService().createProcessInstanceQuery();
	query.processId(processDefinition.getId());
	Session session=context.getSession();
	for(ProcessInstance pi:query.list()){
		processService.deleteProcessInstance(pi);
		session.createQuery("delete "+Variable.class.getName()+" where processInstanceId=:processInstanceId").setLong("processInstanceId", pi.getId()).executeUpdate();
	}
	
	List<HistoryProcessInstance> hisInstances=session.createQuery("from "+HistoryProcessInstance.class.getName()+" where processId=:processId").setLong("processId", processDefinition.getId()).list();
	for(HistoryProcessInstance instance:hisInstances){
		session.createQuery("delete "+HistoryVariable.class.getName()+" where historyProcessInstanceId=:historyProcessInstanceId").setLong("historyProcessInstanceId", instance.getId()).executeUpdate();
	}
	
	session.createQuery("delete "+Blob.class.getName()+" where processId=:processId").setLong("processId", processDefinition.getId()).executeUpdate();
	session.createQuery("delete "+HistoryProcessInstance.class.getName()+" where processId=:processId").setLong("processId", processDefinition.getId()).executeUpdate();
	session.createQuery("delete "+HistoryTask.class.getName()+" where processId=:processId").setLong("processId", processDefinition.getId()).executeUpdate();
	session.createQuery("delete "+HistoryActivity.class.getName()+" where processId=:processId").setLong("processId", processDefinition.getId()).executeUpdate();
	session.delete(processDefinition);
	return null;
}
 
開發者ID:youseries,項目名稱:uflo,代碼行數:24,代碼來源:DeleteProcessDefinitionCommand.java


注:本文中的org.hibernate.Session類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。