1

この粗悪なデザインをどう思いますか。私はopenjpa 2.2、struts2を使用しています。挿入削除更新にもインターフェースを使用しています。Product というエンティティがあります。私は初心者で、この種の機能をどのように作成または設計するかを知りたいです。さらに情報が必要な場合は、それを言ってください。ありがとう

私のインターフェース。

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lotmovement.business.crud.crudinterface;

/**
 *
 * @author god-gavedmework
 */
public interface CrudInterface {

    public void Insert();
    public void Delete();
    public void Update();

}

私のメイン CRUD クラス。

*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package 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() {
        return today;
    }

    public void setToday(Date today) {
        this.today = today;
    }

    public EntityStart getEntityStart() {
        return entityStart;
    }

    public void setEntityStart(EntityStart entityStart) {
        this.entityStart = entityStart;
    }

    public Product getProduct() {
        return 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.");
    }
}

私のopenjpaファクトリークラス

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package 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()
    {

        factory = 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();
    }

}
4

0 に答える 0