官术网_书友最值得收藏!

Implementing the EmployeeBusiness class

The EmployeeBusiness class has the employee business logic:

import javax.ejb.Stateless;
import javax.inject.Inject;
import java.util.Optional;

@Stateless
public class EmployeeBusiness{

@Inject @Persistence
protected PersistenceManager persistenceManager;


public boolean save ( Employee employee ) throws Exception {

//Begin Transaction
persistenceManager.begin();
persistenceManager.persist(employee);
//End Transaction
persistenceManager.commit();

return true;

}

public Optional<Employee> findById(Employee employee ){
return Optional.ofNullable( (Employee) persistenceManager.load(employee.getId()).get());
}


}

In the preceding code block, we have the EmployeeBusiness class, which has the employee business logic. This class has the save(Employee) method, which is used to save employee data, and findById(Employee ), which is used to find an employee according to their ID. Note that, on the save method, we call the begin() method as well as commit() from the PersistenceManager class. These calls define the delimiting of a transaction and only the data is saved at the data source when the commit() method is called.

主站蜘蛛池模板: 青河县| 绥化市| 米林县| 阳山县| 泰安市| 莎车县| 且末县| 黄冈市| 浦北县| 沙坪坝区| 汶上县| 略阳县| 绥芬河市| 珲春市| 德惠市| 龙川县| 台湾省| 修武县| 岑溪市| 秀山| 寿宁县| 奇台县| 东乌珠穆沁旗| 龙岩市| 黄冈市| 沅陵县| 绥阳县| 久治县| 博湖县| 阿克| 连山| 临夏市| 乌拉特后旗| 新晃| 平安县| 沙坪坝区| 湟源县| 保山市| 定安县| 阳谷县| 星子县|