- Java EE 8 Design Patterns and Best Practices
- Rhuan Rocha Jo?o Purifica??o
- 276字
- 2021-07-23 16:55:01
Implementing the StageManager interface
StageManager is an interface that is implemented by EmployeeStageManager:
public interface StageManager {
public void flush();
public void load();
public Entity getEntity();
}
In the preceding code block, we have the StageManager interface. This interface is implemented by EmployeeStageManager:
public class EmployeeStageManager implements StageManager {
private boolean isNew;
private Employee employee;
public EmployeeStageManager ( Employee employee ){
this.employee = employee;
}
public void flush(){
EmployeeStoreManager employeeStoreManager = new EmployeeStoreManager();
if( isNew ){
try {
employeeStoreManager.storeNew( employee );
} catch ( Exception e ) {
e.printStackTrace();
}
isNew = false;
}
else {
try {
employeeStoreManager.update( employee );
} catch ( Exception e ) {
e.printStackTrace();
}
}
}
public void load() {
EmployeeStoreManager storeManager =
new EmployeeStoreManager();
Employee empl = storeManager.load( employee.getId() );
updateEmployee( empl );
}
private void updateEmployee( Employee empl ) {
employee.setId( empl.getId() );
employee.setAddress( empl.getAddress() );
employee.setName( empl.getName() );
employee.setSalary( empl.getSalary() );
isNew = false;
}
public Entity getEntity() {
return employee;
}
}
In the preceding code block, we have the isNew attribute, which is used to define whether or not the object model is a new write (new data will be created on data source). The code also contains the employee attribute, which is the object model used to represent employee data. We can also see the flush method, used to execute the process for writing data on the data source; the load method, used to read data from the data source; the updateEmployee method, which is the private method used to update the employee attribute; and the getEntity method, which is used to return the employee attribute.
- Mobile-first Bootstrap
- Linux從零開始學(視頻教學版)
- 無蘋果不生活 OS X Mountain Lion隨身寶典
- Ubuntu Linux操作系統
- 計算機系統開發與優化實戰
- Linux網絡內核分析與開發
- 移動應用UI設計模式(第2版)
- 嵌入式實時操作系統μC/OS原理與實踐
- 深入淺出Node.js
- 從實踐中學習Kali Linux無線網絡滲透測試
- Learn SwiftUI
- Learn Quantum Computing with Python and IBM Quantum Experience
- Linux系統安全:縱深防御、安全掃描與入侵檢測
- 操作系統之哲學原理第2版
- Less Web Development Essentials