beautypg.com

Implementing the business logic – HP Integrity NonStop J-Series User Manual

Page 132

background image

System.out.println("Employee found using HQL" + "\n"
+ "\to_id=" + emp.getId());
}

public void createEmp(TestManager manager) {
manager.createEmpl();

}

public static void main(String[] args) {
Test client = new Test();
Session session = client.openSession();
TestManager manager = new TestManager(session);
client.createEmp(manager);
client.testFindByHQL(manager);
session.close();

}

}

The Test.java main class file is created.

Implementing the Business Logic

The business logic for the EmpIoyeeInfo application is implemented in the TestManager.java
class file. To do this:
1.

Create the TestManager.java class file in the com.hp.imp package, as explained in

“Creating the Employee.java Class File” (page 129)

.

2.

Add the method to perform an insert operation on the database using Hibernate.

3.

Add the method to perform a select operation on the database using the HQL.

The TestManager.java class must appear as:

package com.hp.imp;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.hp.domain.Employee;

public class TestManager {

private Session session = null;
private Transaction tx = null;

public TestManager(Session session) {
if (session == null)
throw new RuntimeException(
"Invalid session object. Cannot instantiate the EmpManager");
this.session = session;

}

public Employee getEmpl() {
System.out.println(System.currentTimeMillis());
List l = session.createQuery("from Employee").list();

java.util.Iterator emps = l.iterator();

Employee emp = null;
do {

132

Hibernate Framework

This manual is related to the following products: