当前位置: 首页>>代码示例>>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;未经允许,请勿转载。