beautypg.com

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

Page 340

background image

+ "\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 so, complete the following steps:

1.

Create the

TestManager.java

class file in the

com.hp.imp

package, as explained in

the

Creating the Class File

section.

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 Hibernate Query
Language (HQL).

The

TestManager.java

class must appear as follows:

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();

340

Getting Started with Hibernate

This manual is related to the following products: