Class HibernateDaoUtils


  • public class HibernateDaoUtils
    extends Object
    A variety of methods useful when interacting with DAO objects.
    • Field Detail

      • ORACLE_MAXIMUM_NUMBER_OF_VALUES_FOR_IN_QUERY

        public static final int ORACLE_MAXIMUM_NUMBER_OF_VALUES_FOR_IN_QUERY
        See Also:
        Constant Field Values
    • Method Detail

      • updateTimestamp

        public static void updateTimestamp​(BambooObject bambooObject)
      • saveOrUpdate

        public static void saveOrUpdate​(@NotNull
                                        @NotNull org.hibernate.Session session,
                                        BambooObject entity)
      • saveOrUpdateAll

        public static void saveOrUpdateAll​(org.hibernate.Session session,
                                           @NotNull
                                           @NotNull Iterable<?> entities)
      • saveOrUpdateAll

        @Deprecated
        public static void saveOrUpdateAll​(org.springframework.orm.hibernate5.HibernateOperations hibernateTemplate,
                                           Iterable<?> entities)
                                    throws org.springframework.dao.DataAccessException
        Deprecated.
        since 5.12, use HibernateTemplate.execute(HibernateCallback)
        Throws:
        org.springframework.dao.DataAccessException
      • execute

        @Deprecated
        @Nullable
        public static <E extends BambooObject> E execute​(@NotNull
                                                         @NotNull org.springframework.orm.hibernate5.support.HibernateDaoSupport dao,
                                                         @NotNull
                                                         @NotNull org.springframework.orm.hibernate5.HibernateCallback action)
                                                  throws org.springframework.dao.DataAccessException
        Deprecated.
        since 5.12, use session objects directly
        Throws:
        org.springframework.dao.DataAccessException
      • exists

        @Deprecated
        public static boolean exists​(@NotNull
                                     @NotNull org.springframework.orm.hibernate5.support.HibernateDaoSupport dao,
                                     @NotNull
                                     @NotNull org.springframework.orm.hibernate5.HibernateCallback action)
                              throws org.springframework.dao.DataAccessException
        Deprecated.
        since 5.12, use session objects directly
        Throws:
        org.springframework.dao.DataAccessException
      • save

        @Deprecated
        public static void save​(org.springframework.orm.hibernate5.HibernateOperations hibernateOperations,
                                Object object,
                                Serializable id)
        Deprecated.
        since 5.8
        Saves the object with the supplied id.
      • save

        @Deprecated
        public static void save​(org.hibernate.Session session,
                                Object object,
                                Serializable id)
        Deprecated.
        since 5.8
        Saves the object with the supplied id.
      • deleteAll

        public static void deleteAll​(org.hibernate.Session session,
                                     List entities)
      • saveOrUpdateFunction

        @Deprecated
        public static <T extends BambooObject> com.google.common.base.Function<T,​T> saveOrUpdateFunction​(@NotNull
                                                                                                               @NotNull org.springframework.orm.hibernate5.HibernateTemplate hibernateTemplate)
        Deprecated.
        since 5.12, use Java 8 features instead
      • bindQueryParameters

        public static void bindQueryParameters​(@NotNull
                                               @NotNull org.hibernate.query.Query query,
                                               @NotNull
                                               @NotNull Map<String,​Object> params)
                                        throws org.hibernate.HibernateException
        Binds named parameters to the Query. For each Map.Entry, the key would be the parameter name and the value would be the value to bind.

        If the value is a Collection, it will be bound using Query.setParameterList(String, Collection).

        If the value is a Date, it will be bound using Query.setParameter(String, Object, Type).

        In any other case Query.setParameter(String, Object) will be used.

        Parameters:
        query - the query
        params - params to bind (values mapped by parameter names)
        Throws:
        org.hibernate.HibernateException
      • addRestrictionIn

        public static void addRestrictionIn​(DbmsBean dbmsBean,
                                            org.hibernate.Criteria criteria,
                                            String propertyName,
                                            List<?> values)
        Adds a Restrictions.in(String, Collection) to criteria. On Oracle, adds multiple or-ed in conditions, each not exceeding 1000 components. Will fail on SQL Server if the amount of params exceeds 2000.
      • listCriteria

        public static List listCriteria​(DbmsBean dbmsBean,
                                        Supplier<org.hibernate.Criteria> criteriaFactory,
                                        String propertyName,
                                        List<?> values)
        Sets the given query param and runs Criteria.list(). On Oracle, adds multiple or-ed in conditions, each not exceeding 1000 components. On SQL Server, runs the query as many times as needed, in batches of 1900 values.
      • listQuery

        public static List listQuery​(DbmsBean dbmsBean,
                                     org.hibernate.query.Query query,
                                     String queryParam,
                                     List<?> values)
        Sets the given query param and runs Query.list(). On Oracle, runs the query as many times as needed, in batches of 1000 values.
      • listQuery

        public static List listQuery​(DbmsBean dbmsBean,
                                     org.hibernate.query.Query query,
                                     String queryParam1,
                                     List<?> values1,
                                     String queryParam2,
                                     List<?> values2)
      • getMaximumNumberOfValuesForIn

        public static int getMaximumNumberOfValuesForIn​(DbmsBean dbmsBean)
      • setId

        public static <T extends com.atlassian.core.bean.EntityObject> T setId​(T bambooObject,
                                                                               long id)
        Sets the id on the supplied object and returns it.