mercredi 31 mars 2021

What's the correct way to create an DAO class for an a composition class

I am doing this 'B' class that have 'C' and/or 'D' class common attributes that I will implement in their parent class 'A', like client and employee that inherits person values, in this case, I am replacing inheritance for composition, for now, I don't want to use a ORM framework, will I have an BDAO and CDAO, that evokes ADAO to make association in BD or create every A attribute in an B and C table?

 public class A{
 public long ID;
 public int attributeA;
 }
 public class B{
 public long ID;
 public int attributeB;
 A a = new A();
 }
 public class C{
 A a = new A();
 public int attributeC;
 }

 public class Main{
 public static void main(String[] args) 
 {
 B bObject = new B();
 bObject.attributeB=0;
 A aObject = new A();
 aObject.attributeA=1;
 bObject.A=a;
 }
 }

 public class BDAO{
 public void add(B b){
 Conn.preparedStatement(("insert into bTable (id,attributeB,FK_idA) 
values("b.ID+","+b.attributeB+","+b.A.id+")").execute();
 new ADAO().add(B.a);
 }
 }

 public class CDAO{
 public void add(C C){
 Conn.preparedStatement(...
 new ADAO().add(A.a);
 }
 }

 public class ADAO{
 public void add(A a){
 Conn.preparedStatement("insert into aTable (id,attributeA)
 values ("a.ID+","+a.attributeA+")").execute();
 }
 }

Aucun commentaire:

Enregistrer un commentaire