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


Java HibernateCallback類代碼示例

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


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

示例1: scrollNotDeleted

import org.springframework.orm.hibernate3.HibernateCallback; //導入依賴的package包/類
@SuppressWarnings ("unchecked")
public List<User> scrollNotDeleted (final int skip, final int top)
{
   // FIXME never call
   return getHibernateTemplate ().execute (
         new HibernateCallback<List<User>> ()
         {
            @Override
            public List<User> doInHibernate (Session session)
                  throws HibernateException, SQLException
            {
               String hql =
                     "FROM User WHERE deleted = false AND not username = " +
                           "'" +
                           cfgManager.getAdministratorConfiguration ()
                                 .getName () +
                           " AND not username = '" +
                           getPublicData ().getUsername () + "'" +
                           " ORDER BY username";
               Query query = session.createQuery (hql).setReadOnly (true);
               query.setFirstResult (skip);
               query.setMaxResults (top);
               return (List<User>) query.list ();
            }
         });
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:27,代碼來源:UserDao.java

示例2: getReasonCounts

import org.springframework.orm.hibernate3.HibernateCallback; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
@Transactional(propagation = Propagation.MANDATORY)
public Map<String, Integer> getReasonCounts(final String user, final String attemptId)
{
	return (Map<String, Integer>) getHibernateTemplate().execute(new HibernateCallback()
	{
		@Override
		public Object doInHibernate(Session session) throws HibernateException, SQLException
		{
			Query query = session.createQuery("select count(reason), reason from Notification "
				+ "where attemptId = :attempt and processed = false "
				+ "and userTo = :user and institution = :inst group by reason");
			query.setParameter(ATTEMPT, attemptId);
			query.setParameter(USER, user);
			query.setParameter(INST, CurrentInstitution.get());
			Map<String, Integer> reasonMap = Maps.newHashMap();
			List<Object[]> counts = query.list();
			for( Object[] count : counts )
			{
				reasonMap.put((String) count[1], ((Number) count[0]).intValue());
			}
			return reasonMap;
		}
	});
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:27,代碼來源:NotificationDaoImpl.java

示例3: delete

import org.springframework.orm.hibernate3.HibernateCallback; //導入依賴的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

示例4: optimize

import org.springframework.orm.hibernate3.HibernateCallback; //導入依賴的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.springframework.orm.hibernate3.HibernateCallback; //導入依賴的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.springframework.orm.hibernate3.HibernateCallback; //導入依賴的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: getPage

import org.springframework.orm.hibernate3.HibernateCallback; //導入依賴的package包/類
/**
 * Returns a paged list of database entities.
 * 
 * @param query the passed query to retrieve the list.
 * @param skip the number of elements to skip in the list (0=no skip).
 * @param top number of element to be retained in the list.
 * @throws ClassCastException if query does not returns entity list of type T.
 * @see org.hibernate.Query
 */
@Override
public List<T> getPage (final String query, final int skip, final int top)
{
   return getHibernateTemplate ().execute (new HibernateCallback<List<T>> ()
   {
      // List must be instance of List<T> otherwise ClassCast
      @SuppressWarnings ("unchecked")
      @Override
      public List<T> doInHibernate (Session session) throws
            HibernateException, SQLException
      {
         Query hql_query = session.createQuery (query);
         hql_query.setFirstResult (skip);
         hql_query.setMaxResults (top);
         return hql_query.list ();
      }
   });
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:28,代碼來源:HibernateDao.java

示例8: deleteProductReferences

import org.springframework.orm.hibernate3.HibernateCallback; //導入依賴的package包/類
/**
 * Removes all the references of one product from all the existing carts.
 * @param product the product to be removed from carts.
 */
public void deleteProductReferences(final Product product)
{
   getHibernateTemplate().execute  (
      new HibernateCallback<Void>()
      {
         public Void doInHibernate(Session session) 
            throws HibernateException, SQLException
         {
            session.createSQLQuery(
               "DELETE FROM CART_PRODUCTS p " +
               " WHERE p.PRODUCT_ID = :pid").
               setParameter ("pid", product.getId()).executeUpdate ();
            return null;
         }
      });
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:21,代碼來源:ProductCartDao.java

示例9: getKeyBySubValue

import org.springframework.orm.hibernate3.HibernateCallback; //導入依賴的package包/類
/**
 * Retrieves a key from a KeyStore by a substring of its associated value.
 * @param sub_value substring of associate value
 * @return the key of searched value
 */
public String getKeyBySubValue(final String sub_value)
{
   return getHibernateTemplate().execute(new HibernateCallback<String>()
   {
      @Override
      public String doInHibernate(Session session) throws HibernateException, SQLException
      {
         Criteria criteria = session.createCriteria(entityClass);
         criteria.add(Restrictions.like("value", "%" + sub_value + "%"));
         List results = criteria.list();
         if (results.isEmpty())
         {
            return null;
         }
         return ((KeyStoreEntry) results.get(0)).getEntryKey();
      }
   });
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:24,代碼來源:KeyStoreEntryDao.java

示例10: deleteUnindexedById

import org.springframework.orm.hibernate3.HibernateCallback; //導入依賴的package包/類
@Override
@Transactional(propagation = Propagation.MANDATORY)
public int deleteUnindexedById(final String user, final Collection<Long> notifications, final String attemptId)
{
	if( notifications.isEmpty() )
	{
		return 0;
	}
	return (Integer) getHibernateTemplate().execute(new HibernateCallback()
	{
		@Override
		public Object doInHibernate(Session session)
		{
			Query query = session.createQuery(
					"delete from Notification " + "where institution = :inst and userTo = :user and processed = false "
							+ "and id in (:noteid) and attemptId = :attempt");

			query.setParameter(ATTEMPT, attemptId);
			query.setParameterList(NOTEID, notifications);
			query.setParameter(USER, user);
			query.setParameter(INST, CurrentInstitution.get());
			return query.executeUpdate();
		}
	});
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:26,代碼來源:NotificationDaoImpl.java

示例11: getDownloadedSizeByUserSince

import org.springframework.orm.hibernate3.HibernateCallback; //導入依賴的package包/類
public long getDownloadedSizeByUserSince (final User user, final Date date)
{
   Long result =
         getHibernateTemplate ().execute (new HibernateCallback<Long> ()
         {
            @Override
            public Long doInHibernate (Session session)
                  throws HibernateException, SQLException
            {
               Criteria criteria = session.createCriteria (
                     NetworkUsage.class);
               criteria.setProjection (Projections.sum ("size"));
               criteria.add (Restrictions.eq ("isDownload", true));
               criteria.add (Restrictions.eq ("user", user));
               criteria.add (Restrictions.gt ("date", date));
               return (Long) criteria.uniqueResult ();
            }
         });
   return (result == null) ? 0 : result;
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:21,代碼來源:NetworkUsageDao.java

示例12: scrollSearchesOfUser

import org.springframework.orm.hibernate3.HibernateCallback; //導入依賴的package包/類
public List<Search> scrollSearchesOfUser (final User user, final int skip,
   final int top)
{
   return getHibernateTemplate ().execute (
      new HibernateCallback<List<Search>> ()
      {
         @Override
         @SuppressWarnings ("unchecked")
         public List<Search> doInHibernate (Session session)
            throws HibernateException, SQLException
         {
            String hql =
               "SELECT s FROM User u LEFT OUTER JOIN u.preferences p "
                  + "LEFT OUTER JOIN p.searches s "
                  + "WHERE u.uuid like ? ORDER BY s.value";
            Query query = session.createQuery (hql).setReadOnly (true);
            query.setString (0, user.getUUID ());
            query.setFirstResult (skip);
            query.setMaxResults (top);
            return (List<Search>) query.list ();
         }
      });
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:24,代碼來源:SearchDao.java

示例13: delete

import org.springframework.orm.hibernate3.HibernateCallback; //導入依賴的package包/類
@Override
public void delete (final Search search)
{
   getHibernateTemplate ().execute (new HibernateCallback<Void>()
   {
      @Override
      public Void doInHibernate (Session session) throws HibernateException,
         SQLException
      {
         String sql = "DELETE FROM SEARCH_PREFERENCES WHERE SEARCHES_UUID = ?";
         Query query = session.createSQLQuery (sql);
         query.setString (0, search.getUUID ());
         query.executeUpdate ();
         return null;
      }
   });
   super.delete (search);
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:19,代碼來源:SearchDao.java

示例14: scrollUploadedProducts

import org.springframework.orm.hibernate3.HibernateCallback; //導入依賴的package包/類
public List<Product> scrollUploadedProducts (final User user, final int skip,
   final int top)
{
   checkProductNumber(top);
   return getHibernateTemplate ().execute (
         new HibernateCallback<List<Product>>()
   {
      @Override
      @SuppressWarnings ("unchecked")
      public List<Product> doInHibernate (Session session)
         throws HibernateException, SQLException
      {
         String hql = "SELECT p FROM Product p, User u" +
                  " WHERE p.owner = u and u.uuid like ? AND p.processed = true";
         Query query = session.createQuery (hql);
         query.setString (0, user.getUUID ());
         query.setFirstResult (skip);
         query.setMaxResults (top);
         return (List<Product>) query.list ();
      }
   });
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:23,代碼來源:ProductDao.java

示例15: deleteAll

import org.springframework.orm.hibernate3.HibernateCallback; //導入依賴的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


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