-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Criteria.Count replacement
PostPosted: Thu Jun 29, 2006 8:54 am 
Beginner
Beginner

Joined: Sun Jun 19, 2005 2:21 pm
Posts: 21
Hello,

I've been using a patched version of NHibernate in order to have access to Criteria.Count. I want to stop using a modified NHibernate and I am planning to replace the following method with an equivalent from standard distribution.

How can I refactor the following snippet?

Regards,
Robert


Code:
        /// <summary>
        /// Gets the total number of objects from the storage according to the filter specified in the properties.
        /// </summary>
        /// <param name="type">type of object to be counted in storage</param>
        /// <param name="propertyNames">array of property names of the object to be counted</param>
        /// <param name="propertyValues">array of property values of the object to be counted</param>
        /// <returns>number of objects counted in storage according to filters</returns>
        public long GetObjectsCount(Type type, string[] propertyNames, object[] propertyValues)
        {
            if ((propertyNames != null) && (propertyValues != null) && (propertyNames.Length != propertyValues.Length))
                throw new ArgumentException("Number of property names must match exactly the number of property values");

            try
            {
                ICriteria crit = session.CreateCriteria(type);
                if (propertyNames != null && propertyValues != null)
                    for (int i = 0; i < propertyNames.Length; i++)
                        crit.Add(Expression.Eq(propertyNames[i], propertyValues[i]));

                return crit.Count;
            }
            catch (HibernateException ex)
            {
                if (ExceptionPolicy.HandleException(ex, "Data Access Policy"))
                    throw;
            }
            return 0;
        }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.