Menu

loadAll + ordering

Help
tcy
2005-07-16
2013-04-25
  • tcy

    tcy - 2005-07-16

    I can't seem to find a way of listing and ordering the bean.

    my edit of the xmanagertemplate.vm
    I commented out the whole // 38.5  and wrapped the current loadAll into loadAllOrderBy
    ----------

        public $beanClass[] loadAll(int startRow, int numRows) throws SQLException
        {
            return loadAllOrderBy(null, startRow, numRows);
        }
       
        public $beanClass[] loadAllOrderBy(String orderField, int startRow, int numRows) throws SQLException
        {
            Connection c = null;
            PreparedStatement ps = null;
            // check if any ordering by needs to be done
            StringBuffer _sql = new StringBuffer("SELECT " + ALL_FIELDS + " FROM $tablename");
            if (orderField != null)
            {
                _sql.append(" ORDER BY " + orderField);       
            }

            try
            {
                c = getConnection();           
                ps = c.prepareStatement(_sql.toString(),ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
                // tcy edit
                return loadByPreparedStatement(ps, null, startRow, numRows);
            }
            finally
            {
                getManager().close(ps);
                freeConnection(c);
            }
        }

     
    • nr

      nr - 2005-07-19

      > can't seem to find a way of listing and ordering the bean.

      the trick is to use loadByWhere methods... and pass for example "ORDER BY LASTNAME" as a 'where' argument...

      N.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.