Wednesday, August 02, 2006

Hibernate Customized Query To Get Max Values

This is the query to how to get the max string value from a table.

 

Option 1

Use max function inside the DBMS.

 

Double max = (Double) sess.createSQLQuery("select max(cat.weight) as maxWeight  from cats cat where extLicenseID < '5000-0000' ")

        .addScalar("extLicenseID", Hibernate.STRING);

        .uniqueResult();

 

Option 2

Use setMaxResults of the hibernate and addOrder of asc or desc.

 

List cats = sess.createCriteria(Cat.class)

    .add( Property.forName("name").like("F%") )

    .addOrder( Property.forName("name").asc() )

    .addOrder( Property.forName("age").desc() )

    .setMaxResults(50)

    .list();

 

Tony

Forward vs Redirect

 

Forward

  • forward is performed internally by the servlet
  • the browser is completely unaware that it has taken place, so its original URL remains intact
  • any browser reload will simple repeat the original request, with the original URL

Redirect

  • redirect is a two step process, where the web application instructs the browser to fetch a second URL, which differs from the original
  • a browser reload of the second URL will not repeat the original request, but will rather fetch the second URL
  • redirect is always slower than a forward, since it requires a second browser request
  • beans placed in the original request scope are not available to the second request

 

 private void redirect(
    ResponsePage aDestinationPage, 
    HttpServletResponse aResponse
  ) throws IOException {
    
    String urlWithSessionID = aResponse.encodeRedirectURL(aDestinationPage.toString());
    fLogger.fine("REDIRECT: " + Util.quote(urlWithSessionID));
    aResponse.sendRedirect( urlWithSessionID );
  }
 
  private void forward(
    ResponsePage aDestination, 
    HttpServletRequest aRequest, 
    HttpServletResponse aResponse
  ) throws ServletException, IOException {
    
    RequestDispatcher dispatcher = aRequest.getRequestDispatcher(aDestination.toString());
    dispatcher.forward(aRequest, aResponse);
  }

http://www.javapractices.com/Topic181.cjp

 

Tony

 

Content-disposition: Attachment

Best of all, prevent the browser from opening the document in the first place. Instead offer users the choice to save the file on their hard disk or to open it in its native application (Adobe Reader for PDF, PowerPoint for slides, etc.). Unfortunately, doing so requires a bit of technical trickery: you have to add an extra HTTP header to the transmission of the offending file. The header line to be added is "Content-disposition: Attachment". If possible, also add "; filename=somefile.pdf" at the end of this line, to give the browser an explicit filename if the user chooses to save the file.

 

http://www.useit.com/alertbox/open_new_windows.html

 

Tony

 

Monday, July 03, 2006

Server Side - Stratetical and Tactical Programming

I've been always wanting to start a professional blog spot where I could share my technical points with the others. After this perfect Canada Day long weekend, I feel more energetic with the sunshine tan. Today should be nice start. :-)

Be A Developer That Uses AI

Developers will not be replaced by AI, they'll be replaced by developers that use AI. Generative AI tools are revolutionizing the way de...