I am developing a standalone J2SE application (Can't add J2EE, Hibernate, Spring, etc...). I need idea on designing the code architecture.
- Created entity classes for each Table (mysql table), with getter and setter, named it as Bean.class (PersonBean.class)
- Created mapper classes for each table to retrieve records for that table,and populate entity. Named it as Mapper.class (PersonMapper.class).
class PersonBean {
String name;
int id;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
class PersonMapper{ PersonMapper(Connection conn){
}
PersonBean load(ResultSet rs){
PersonBean entity = new PersonBean();
entity.setId(rs.getInt("id"));
entity.setName(rs.getString("name"));
return entity;
}
PersonBean findById(int id){
String query = "SELECT * FROM Person where id = ?";
PreparedStatment stmt = conn.getPreparedStatement(query);
stmt.setInt(1, id);
ResultSet rs = stmt.executeQuery();
if (rs.next())
return load(rs);
else
return null;
}
List<PersonBean> findByName(String name) {}
}
Is there anything do I need to do to improve this design?
In object world Student object extends Person object. But in database Student and Person are two different tables, which leads to create two different classes for StudentBean and PersonBean where StudentBean will not extend PersonBean. Do I need to create business layer on top of entity Bean object layer? if so how to design?
I don't know how to start browse about this, any links also would be fine.
Aucun commentaire:
Enregistrer un commentaire