Sunday, 15 July 2012

java - Struts2 ,OPENJPA DAO. Is this a good design for DAO-CRUD? -



java - Struts2 ,OPENJPA DAO. Is this a good design for DAO-CRUD? -

what think of crud design. using openjpa 2.2,struts2. using interface insert delete update. have entity called product. beginner , want know how how guys create or design kind of functionality. if want more info, please it.

my interface.

/* * alter template, take tools | templates * , open template in editor. */ bundle lotmovement.business.crud.crudinterface; /** * * @author god-gavedmework */ public interface crudinterface { public void insert(); public void delete(); public void update(); }

my main crud class.

* * alter template, take tools | templates * , open template in editor. */ bundle lotmovement.business.crud; import java.text.dateformat; import java.text.simpledateformat; import java.util.date; import lotmovement.business.crud.crudinterface.crudinterface; import lotmovement.business.entity.product; /** * * @author god-gavedmework */ public class productcrud implements crudinterface { private date today; entitystart entitystart; product product; public date gettoday() { homecoming today; } public void settoday(date today) { this.today = today; } public entitystart getentitystart() { homecoming entitystart; } public void setentitystart(entitystart entitystart) { this.entitystart = entitystart; } public product getproduct() { homecoming product; } public void setproduct(product product) { this.product = product; } public void insert() { throw new unsupportedoperationexception("not supported yet."); } public void insert(product product) { entitystart.startdbaseconnection(); dateformat dateformat = new simpledateformat("dd-mm-yyyy"); dateformat timeformat = new simpledateformat("hh:mm:ss a"); settoday(new date()); string datetoday = dateformat.format(gettoday()); string timetoday = timeformat.format(gettoday()); // product.setproduct_id(product_id); // product.setserial_number(serial_number); // product.setdate_assembled(date_assembled); // product.setmodel(model); /// product.setbatch_id(batch_id); // product.setprocess_code(process_code); // product.setdc_power_pcb_serial(dc_power_pcb_serial); // product.setcontrol_power_pcb_serial(control_power_pcb_serial); // product.setmains_power_pcb_serial(mains_power_pcb_serial); // product.setblower_serial(blower_serial); // product.setheaterplate_serial(heaterplate_serial); // product.setlast_process(last_process); product.settime_assembled(timetoday); product.setdate_assembled(datetoday); entitystart.startpopulatetransaction(product); entitystart.closedbaseconnection(); } @override public void delete() { throw new unsupportedoperationexception("not supported yet."); } @override public void update() { throw new unsupportedoperationexception("not supported yet."); } }

my openjpa mill class

/* * alter template, take tools | templates * , open template in editor. */ bundle lotmovement.business.crud; import javax.persistence.entitymanager; import javax.persistence.entitymanagerfactory; import javax.persistence.entitytransaction; import javax.persistence.persistence; public class entitystart { public entitymanagerfactory factory; public entitymanager em; public void startdbaseconnection() { mill = persistence.createentitymanagerfactory("lotmovementpu"); em = factory.createentitymanager(); } public void begintransaction(){ entitytransaction usertransaction = em.gettransaction(); usertransaction.begin(); } public void startpopulatetransaction(object entity){ entitytransaction usertransaction = em.gettransaction(); usertransaction.begin(); em.merge(entity); usertransaction.commit(); em.close(); } public void closedbaseconnection(){ factory.close(); } }

java struts2 dao crud openjpa

No comments:

Post a Comment