Archive for August, 2007

232 CHAPTER 11 n FILTERING THE RESULTS OF (Web hosting companies)

Thursday, August 2nd, 2007

232 CHAPTER 11 n FILTERING THE RESULTS OF SEARCHES CHAPTER 11 n FILTERING THE RESULTS OF SEARCHES Because filters do not use any database-specific functionality beyond the Hibernate configuration, you should not encounter any difficulty running this example on databases other than HSQLDB. The Hibernate configuration file defines the database configuration and connection information, along with the XML mapping document for the Userclass (see Listing 11-4). Listing 11-4. The Hibernate XML Configuration File for the Example
org.hsqldb.jdbcDriver jdbc:hsqldb:file:filterdb;SHUTDOWN=true sa 0 org.hibernate.dialect.HSQLDialect
The source code for this chapter includes the schema we used for the HSQL database to create the table for the filterdb database. Summary Filters are a useful way to separate some database concerns from the rest of your code. A set of filters can cut back on the complexity of the HQL queries used in the rest of your application, at the expense of some runtime flexibility. Instead of using views (which must be created at the database level), your applications can take advantage of dynamic filters that can be activated as and when they are required.
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

CHAPTER 11 n FILTERING THE RESULTS OF SEARCHES (Business web hosting)

Thursday, August 2nd, 2007

CHAPTER 11 n FILTERING THE RESULTS OF SEARCHES 231 n FILTERING THE RESULTS OF SEARCHES 231 ===ACTIVATED USERS=== ray is activated. jason is activated. ===NON-ACTIVATED USERS=== beth is not activated. judy is not activated. rob is not activated. Listing 11-3 gives the User class used for this chapter s examples. The only fields it contains are id, username, and activated. Listing 11-3. The Source Code for the User Class package com.hibernatebook.filters; public class User { private int id; private String username; private boolean activated; public boolean isActivated() { return activated; } public void setActivated(boolean activated) { this.activated = activated; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } }
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

X web hosting - 230 CHAPTER 11 n FILTERING THE RESULTS OF

Wednesday, August 1st, 2007

230 CHAPTER 11 n FILTERING THE RESULTS OF SEARCHES CHAPTER 11 n FILTERING THE RESULTS OF SEARCHES session.close(); } public static void displayUsers(Session session) { session.beginTransaction(); Query query = session.createQuery(”from User”); Iterator results = query.iterate(); while (results.hasNext()) { User user = (User) results.next(); System.out.print(user.getUsername() + ” is “); if (user.isActivated()) { System.out.println(”activated.”); } else { System.out.println(”not activated.”); } } session.getTransaction().commit(); } public static void insertUser(String name, boolean activated, Session session) { session.beginTransaction(); User user = new User(); user.setUsername(name); user.setActivated(activated); session.save(user); session.getTransaction().commit(); } } The output of SimpleFilterExampleis as follows: ===ALL USERS=== ray is activated. jason is activated. beth is not activated. judy is not activated. rob is not activated.
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

CHAPTER 11 (Web hosting rating) n FILTERING THE RESULTS OF SEARCHES

Wednesday, August 1st, 2007

CHAPTER 11 n FILTERING THE RESULTS OF SEARCHES 229 n FILTERING THE RESULTS OF SEARCHES 229 Listing 11-2. Invoking Filters from Code package com.hibernatebook.filters; import java.util.Iterator; import org.hibernate.Filter; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; public class SimpleFilterExample { public static void main (String args[]) { SessionFactory factory = new Configuration().configure().buildSessionFactory(); Session session = factory.openSession(); //insert the users insertUser(”ray”,true,session); insertUser(”jason”,true,session); insertUser(”beth”,false,session); insertUser(”judy”,false,session); insertUser(”rob”,false,session); //Show all users System.out.println(”===ALL USERS===”); displayUsers(session); //Show activated users Filter filter = session.enableFilter(”activatedFilter”); filter.setParameter(”activatedParam”,new Boolean(true)); System.out.println(”===ACTIVATED USERS===”); displayUsers(session); //Show nonactivated users filter.setParameter(”activatedParam”,new Boolean(false)); System.out.println(”===NON-ACTIVATED USERS===”); displayUsers(session);
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.