Я новичок в Oracle MAF.
Я создал код для CRUD, используя следующий код.
Вот мой POJO.
import oracle.adfmf.java.beans.PropertyChangeListener;
import oracle.adfmf.java.beans.PropertyChangeSupport;
public class Employee implements Cloneable {
private Integer employeeId;
private String firstName;
private String lastName;
private String email;
private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
public Employee() {
super();
}
public void setEmployeeId(Integer employeeId) {
Integer oldEmployeeId = this.employeeId;
this.employeeId = employeeId;
propertyChangeSupport.firePropertyChange("employeeId", oldEmployeeId, employeeId);
}
public Integer getEmployeeId() {
return employeeId;
}
public void setFirstName(String firstName) {
String oldFirstName = this.firstName;
this.firstName = firstName;
propertyChangeSupport.firePropertyChange("firstName", oldFirstName, firstName);
}
public String getFirstName() {
return firstName;
}
public void setLastName(String lastName) {
String oldLastName = this.lastName;
this.lastName = lastName;
propertyChangeSupport.firePropertyChange("lastName", oldLastName, lastName);
}
public String getLastName() {
return lastName;
}
public void setEmail(String email) {
String oldEmail = this.email;
this.email = email;
propertyChangeSupport.firePropertyChange("email", oldEmail, email);
}
public String getEmail() {
return email;
}
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
public void addPropertyChangeListener(PropertyChangeListener l) {
propertyChangeSupport.addPropertyChangeListener(l);
}
public void removePropertyChangeListener(PropertyChangeListener l) {
propertyChangeSupport.removePropertyChangeListener(l);
}
}
Вот мой класс БД, который я использую для привязки.
EmployeeD C - это класс управления данными.
Когда я пытался выполнить CRUD, просмотр списка операций не refre sh, как ожидалось .
Я не хочу ничего писать в классе POJO.
Все методы должны вызываться из EmployeeD C
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import oracle.adfmf.java.beans.ProviderChangeListener;
import oracle.adfmf.java.beans.ProviderChangeSupport;
import oracle.adfmf.util.Utility;
public class EmployeeDC {
private Employee employee;
private List employees = new ArrayList();
private DBAdapter dBAdapter = new DBAdapter();
private int currentId=0;
protected transient ProviderChangeSupport providerChangeSupport = new ProviderChangeSupport(this);
public void addProviderChangeListener(ProviderChangeListener l) {
providerChangeSupport.addProviderChangeListener(l);
}
public void removeProviderChangeListener(ProviderChangeListener l) {
providerChangeSupport.removeProviderChangeListener(l);
}
public EmployeeDC() {
super();
findAll();
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
public Employee getEmployee() {
return employee;
}
public Employee[] getEmployees() {
return (Employee[]) employees.toArray(new Employee[employees.size()]);
}
public void findAll() {
try {
ResultSet result =
dBAdapter.executeQuery("SELECT EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL FROM EMPLOYEES;");
while (result.next()) {
Employee employee = new Employee();
employee.setEmployeeId(new Integer(result.getInt("EMPLOYEE_ID")));
employee.setFirstName(result.getString("FIRST_NAME"));
employee.setLastName(result.getString("LAST_NAME"));
employee.setEmail(result.getString("EMAIL"));
employees.add(employee);
Utility.ApplicationLogger.severe("Employee: " + employee.getEmployeeId() + "," +
employee.getFirstName() + "," + employee.getLastName() + "," +
employee.getEmail());
}
System.out.println("employees=============>"+employees.size());
} catch (Exception ex) {
Utility.ApplicationLogger.severe(ex.getMessage());
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
public void delete(Integer employeeId) {
boolean success = dBAdapter.executeUpdate("DELETE FROM EMPLOYEES WHERE EMPLOYEE_ID=" + employeeId);
if (success)
providerChangeSupport.fireProviderDelete("employees",employeeId);
}
public void insert(Employee employee) {
System.out.println("employee.getEmployeeId() : "+employee.getEmployeeId());
boolean success = false;
try {
Utility.ApplicationLogger.severe("employee.getEmployeeId(): " + employee.getEmployeeId());
success =
dBAdapter.executeUpdate("INSERT INTO EMPLOYEES (EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL) VALUES (" +
employee.getEmployeeId() + ",'" + employee.getFirstName() + "','" +
employee.getLastName() + "','" + employee.getEmail() + "')");
if(success){
providerChangeSupport.
fireProviderCreate("employees", employee.getEmployeeId(), employee);
}
} catch (Exception ex) {
Utility.ApplicationLogger.severe(ex.getMessage());
ex.printStackTrace();
throw new RuntimeException(ex);
}
providerChangeSupport.
fireProviderCreate("employees", employee.getEmployeeId(), employee);
// if (success) {
// employees.add(employee);
// }
}
public void update(Employee employee) {
boolean success =
dBAdapter.executeUpdate("UPDATE EMPLOYEES SET FIRST_NAME='" + employee.getFirstName() + "', LAST_NAME='" +
employee.getLastName() + "', EMAIL='" + employee.getEmail() +
"' WHERE EMPLOYEE_ID=" + employee.getEmployeeId());
if (success) {
providerChangeSupport.fireProviderChange("employees", employee.getEmployeeId(), employee);
}
}
public int getNextEmployeeId(){
try{
ResultSet result = dBAdapter.executeQuery("SELECT Max(EMPLOYEE_ID) as currentId FROM EMPLOYEES;");
while (result.next()) {
currentId = new Integer(result.getInt("currentId"))+1;
System.out.println("currentId :"+currentId);
}
} catch (Exception ex) {
Utility.ApplicationLogger.severe(ex.getMessage());
ex.printStackTrace();
throw new RuntimeException(ex);
}
return currentId;
}
public void prepareEmployeeToAdd() {
employee = new Employee();
employee.setEmployeeId(getNextEmployeeId());
System.out.println("prepareEmployeeToAdd=====>"+employee.getEmployeeId());
}
public void prepareEmployeeToEdit(Employee employee) throws CloneNotSupportedException {
System.out.println(employee.getEmployeeId() + ":" + employee.getFirstName() + ":" + employee.getLastName() +
":" + employee.getEmail());
this.employee = (Employee) employee.clone();
}
}