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


Java SQLQuery類代碼示例

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


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

示例1: getStatisticsBySession

import org.hibernate.SQLQuery; //導入依賴的package包/類
@Override
   @SuppressWarnings("unchecked")
   public List<VoteStatsDTO> getStatisticsBySession(Long toolContentId) {

SQLQuery query = getSession().createSQLQuery(GET_STATISTICS);
query.addScalar("sessionUid", LongType.INSTANCE).addScalar("sessionName", StringType.INSTANCE)
	.addScalar("countUsersComplete", IntegerType.INSTANCE).setLong("contentId", toolContentId)
	.setResultTransformer(Transformers.aliasToBean(VoteStatsDTO.class));

return query.list();
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:12,代碼來源:VoteUsrAttemptDAO.java

示例2: deleteHoldingExtras

import org.hibernate.SQLQuery; //導入依賴的package包/類
protected void deleteHoldingExtras(Session session, long itemId)
{
	SQLQuery sqlQuery = session
		.createSQLQuery(sqlQuery("delete from %h_authors where %h_id in (select id from %h where item_id = ?)"));
	sqlQuery.setLong(0, itemId);
	sqlQuery.executeUpdate();
	sqlQuery = session
		.createSQLQuery(sqlQuery("delete from %h_ids where %h_id in (select id from %h where item_id = ?)"));
	sqlQuery.setLong(0, itemId);
	sqlQuery.executeUpdate();
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:12,代碼來源:AbstractCopyrightDao.java

示例3: generateCardId

import org.hibernate.SQLQuery; //導入依賴的package包/類
@Override
public String generateCardId(Long cardId) {
	Card card = Card.findCard(cardId);
	if(card.getDesfireIds().get(appName) == null || card.getDesfireIds().get(appName).isEmpty()) {
		Session session = (Session) entityManager.getDelegate();
		SQLQuery existSequenceQuery = session.createSQLQuery("SELECT 1 FROM pg_class where relname = '" + postgresqlSequence + "'");
		if(existSequenceQuery.list().isEmpty()) {
			SQLQuery createSequenceQuery = session.createSQLQuery("CREATE SEQUENCE " + postgresqlSequence);
			int createSequenceQueryResult = createSequenceQuery.executeUpdate();
			log.info("create sequence result : " + createSequenceQueryResult);
		}
		SQLQuery nextValQuery = session.createSQLQuery("SELECT nextval('" + postgresqlSequence + "')");
		BigInteger nextVal = (BigInteger)nextValQuery.list().get(0);
		card.getDesfireIds().put(appName, Long.toString(nextVal.longValue() + getIdCounterBegin(card)));
		card.merge();
	}
	return card.getDesfireIds().get(appName);
}
 
開發者ID:EsupPortail,項目名稱:esup-sgc,代碼行數:19,代碼來源:GenericCardIdService.java

示例4: optimize

import org.hibernate.SQLQuery; //導入依賴的package包/類
public static void optimize ()
{
   HibernateDaoLocalSupport support = ApplicationContextProvider.getBean (
         HibernateDaoLocalSupport.class);
   support.getHibernateTemplate ().flush ();
   support.getHibernateTemplate ().executeWithNativeSession (
      new HibernateCallback<Void> ()
      {
         @Override
         public Void doInHibernate (Session session) throws
               HibernateException, SQLException
         {
            SQLQuery query = session.createSQLQuery ("CHECKPOINT DEFRAG");
            query.executeUpdate ();
            return null;
         }
      });
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:19,代碼來源:DaoUtils.java

示例5: countOpenSessions

import org.hibernate.SQLQuery; //導入依賴的package包/類
@SuppressWarnings ("rawtypes")
private int countOpenSessions ()
{
   return DataAccessUtils.intResult (getHibernateTemplate ().execute (
      new HibernateCallback<List>()
      {
         @Override
         public List doInHibernate(Session session) 
            throws HibernateException, SQLException
         {
            String sql = 
               "SELECT count (*) FROM INFORMATION_SCHEMA.SYSTEM_SESSIONS";
            SQLQuery query = session.createSQLQuery (sql);
            return query.list ();
         }
      }));
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:18,代碼來源:HibernateDao.java

示例6: getSystemByName

import org.hibernate.SQLQuery; //導入依賴的package包/類
@SuppressWarnings ({ "unchecked", "rawtypes" })
private String getSystemByName (final String name, final int index)
{
   return DataAccessUtils.uniqueResult (getHibernateTemplate ().execute (
      new HibernateCallback<List>()
      {
         @Override
         public List doInHibernate(Session session) 
            throws HibernateException, SQLException
         {
            String sql = 
               "SELECT " + name +
               " FROM INFORMATION_SCHEMA.SYSTEM_SESSIONS" +
               " LIMIT  1 OFFSET " + index;
            SQLQuery query = session.createSQLQuery (sql);
            return query.list ();
         }
      })).toString ();
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:20,代碼來源:HibernateDao.java

示例7: deleteCollectionReferences

import org.hibernate.SQLQuery; //導入依賴的package包/類
public int deleteCollectionReferences(final Collection collection)
{
   return getHibernateTemplate().execute  (
      new HibernateCallback<Integer>()
      {
         public Integer doInHibernate(Session session) 
            throws HibernateException, SQLException
         {
            String sql = "DELETE FROM FILESCANNER_COLLECTIONS s " +
                     " WHERE s.COLLECTIONS_UUID = :cid";
            SQLQuery query = session.createSQLQuery(sql);
            query.setString ("cid", collection.getUUID());
            return query.executeUpdate ();
         }
      });
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:17,代碼來源:FileScannerDao.java

示例8: delete

import org.hibernate.SQLQuery; //導入依賴的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: deleteAll

import org.hibernate.SQLQuery; //導入依賴的package包/類
@Override
public void deleteAll ()
{
   getHibernateTemplate ().execute (new HibernateCallback<Void> ()
   {
      @Override
      public Void doInHibernate (Session session)
            throws HibernateException, SQLException
      {
         SQLQuery query =
               session.createSQLQuery ("DELETE FROM USER_RESTRICTIONS");
         query.executeUpdate ();
         query = session.createSQLQuery ("DELETE  FROM ACCESS_RESTRICTION");
         query.executeUpdate ();
         return null;
      }
   });
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:19,代碼來源:AccessRestrictionDao.java

示例10: updateLastRun

import org.hibernate.SQLQuery; //導入依賴的package包/類
@SuppressWarnings("nls")
@Override
public void updateLastRun(final HarvesterProfile profile, final Date date)
{
	getHibernateTemplate().execute(new HibernateCallback()
	{
		@Override
		public Object doInHibernate(Session session)
		{
			SQLQuery query = session.createSQLQuery("update harvester_profile set last_run = :date where id = :id");
			query.setDate("date", date);
			query.setLong("id", profile.getId());
			query.executeUpdate();
			return null;
		}
	});
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:18,代碼來源:HarvesterProfileDaoImpl.java

示例11: getTotalChildCounts

import org.hibernate.SQLQuery; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private Map<Long, Integer> getTotalChildCounts(Session session)
{
	// get total child counts in one hit
	// NOTE THAT THIS IS NOT HQL!!! IT IS PRETTY MUCH SQL!!!
	final StringBuilder sql = new StringBuilder(
		"SELECT all_parents_id, COUNT(*) AS CHILD_COUNT FROM taxonomy_node_all_parents GROUP BY all_parents_id");

	final Map<Long, Integer> totalChildCounts = new HashMap<Long, Integer>();
	final SQLQuery countQuery = session.createSQLQuery(sql.toString());
	final List<Object[]> countResults = countQuery.list();
	for( Object[] countResult : countResults )
	{
		totalChildCounts.put(((Number) countResult[0]).longValue(), ((Number) countResult[1]).intValue());
	}
	return totalChildCounts;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:18,代碼來源:MigrateOldTaxonomyToNew.java

示例12: querySqlObjects

import org.hibernate.SQLQuery; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public List<Map<String, Object>> querySqlObjects(String sql, Object params, Integer currentPage,Integer rowsInPage){
	Query qry = em.createNativeQuery(sql);
	SQLQuery s = qry.unwrap(SQLQuery.class);
	
	//設置參數
	if(params != null){
		if(params instanceof List){
			List<Object> paramList = (List<Object>) params;
			for(int i = 0, size = paramList.size(); i < size; i++){
				qry.setParameter(i+1, paramList.get(i));
			}
		}else if(params instanceof Map){
			Map<String, Object> paramMap = (Map<String, Object>) params;
			for(String key : paramMap.keySet()){
				qry.setParameter(key, paramMap.get(key));
			}
		}
	}
	
	if (currentPage != null && rowsInPage != null) {//判斷是否有分頁
		// 起始對象位置
		qry.setFirstResult(rowsInPage * (currentPage - 1));
		// 查詢對象個數
		qry.setMaxResults(rowsInPage);
	}
	s.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
	List<Map<String, Object>> resultList=new ArrayList<Map<String, Object>>();
	try {
		resultList=s.list();
	} catch (Exception e) {
	}finally{
		em.close();
	}
	return resultList;
}
 
開發者ID:xujeff,項目名稱:tianti,代碼行數:37,代碼來源:CustomBaseSqlDaoImpl.java

示例13: setParameter

import org.hibernate.SQLQuery; //導入依賴的package包/類
private Query setParameter(SQLQuery query, Object... values) {
    if (Objects.isNull(values) || values.length == 0) {
        return query;
    }
    int i = 0;
    for (Object value : values) {
        query.setParameter(i, value);
        i++;
    }
    return query;
}
 
開發者ID:wu05281,項目名稱:admin-shiro,代碼行數:12,代碼來源:DaoSupport.java

示例14: doLimitBackInfo

import org.hibernate.SQLQuery; //導入依賴的package包/類
public List doLimitBackInfo(final String hql,final int pageCode,final int pageSize){
    //調用模板的execute方法,參數是實現了HibernateCallback接口的匿名類,
    return (List) this.getHibernateTemplate().execute(new HibernateCallback(){
        //重寫其doInHibernate方法返回一個object對象,
        public Object doInHibernate(Session session)
                throws HibernateException, SQLException {
            //創建query對象
        	SQLQuery query=session.createSQLQuery(hql);
            //返回其執行了分布方法的list
            return query.setFirstResult((pageCode-1)*pageSize).setMaxResults(pageSize).list();
             
        }
         
    });
     
}
 
開發者ID:cckevincyh,項目名稱:LibrarySystem,代碼行數:17,代碼來源:BackDaoImpl.java

示例15: findByNative

import org.hibernate.SQLQuery; //導入依賴的package包/類
@Override
public <X> List<X> findByNative(String sql, List<?> params, Pageable pageable, Class<X> clazz) {
    Assert.hasText(sql, "native sql can not been null or blank");
    Query query = entityManager.createNativeQuery(sql);
    if (query != null) {
        query.unwrap(SQLQuery.class).setResultTransformer(Transformers.aliasToBean(clazz));
        query.setFirstResult(pageable.getOffset());
        query.setMaxResults(pageable.getPageSize());
        if (CollectionUtils.isNotEmpty(params)) {
            for (int i = 0; i < params.size(); i++) {
                query.setParameter(i + 1, params.get(i));
            }
        }
        return query.getResultList();
    }
    return Lists.newArrayList();
}
 
開發者ID:zhaoqilong3031,項目名稱:spring-cloud-samples,代碼行數:18,代碼來源:BaseRepositoryImpl.java


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