-->
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.  [ 2 posts ] 
Author Message
 Post subject: Date problem
PostPosted: Mon Mar 17, 2008 12:05 pm 
Beginner
Beginner

Joined: Mon Mar 17, 2008 11:25 am
Posts: 42
hi,
I have fallowing problem, I will load records from 3last days.
I don't know how can I do it ?????
help :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 17, 2008 4:18 pm 
Beginner
Beginner

Joined: Wed Mar 05, 2008 10:32 am
Posts: 48
here is a sample code from my dao that gets me a set of results between certain dates.

Code:
   public List<EventEnt> searchEvents(Date fromDate, Date toDate, String orderProperty, String orderDirection,
         Long first, Long max, String query){
      Criteria criteria = getSession().createCriteria(EventEnt.class);
      //match the category if not null
//      if (venueId != null)
//         criteria.add(Restrictions.eq("venue.id", venueId));
      //match the query in either description or name
      
      if (fromDate == null) {
         GregorianCalendar g = new GregorianCalendar();
         g.set(Calendar.YEAR, (g.get(Calendar.YEAR) - 1));
         fromDate = g.getTime();
         System.err.println(Util.printDate(fromDate));
      }
      if (toDate == null) {
         GregorianCalendar g = new GregorianCalendar();
         g.set(Calendar.YEAR, (g.get(Calendar.YEAR) + 1));
         toDate = g.getTime();
         System.err.println(Util.printDate(toDate));
      }
   
      criteria.add(Restrictions.or(Restrictions.ilike("description", query, MatchMode.ANYWHERE),
                            Restrictions.ilike("name", query, MatchMode.ANYWHERE)))
            .add(Restrictions.between("date", fromDate, toDate));
      
      //add the order
      if (orderDirection.toLowerCase().equals("asc"))
         criteria.addOrder(Order.asc(orderProperty));
      else
         criteria.addOrder(Order.desc(orderProperty));
      
      //fetch count
      criteria.setFirstResult(first.intValue()).setMaxResults(max.intValue());
      System.err.println(criteria);
      return criteria.list();
   }


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

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.