EJB Optimieren

Status
Nicht offen für weitere Antworten.

mayer

Aktives Mitglied
Ich versuche gerade mein EJB zu optimieren, aber bis auf die EJB-Store Methode weiß ich nicht was ich noch optimieren kann. Ich mit meinem EJB total unzufrieden, da es extrem langsam ist.

Mein EJB sieht so aus:

Code:
public class PTierBelegungEbBean implements EntityBean 
{
  
  public String stierNummer;
  
//Felder
//-> für einfügen in Tabelle
  public String tierNummer;
  public String reihenFolge;
  public Long tierUid;
  public Long stierUid;
  public Long ebBelUid;
  public String transBa;
  public String transRdv;
  public String aktionsCode;
  public String persNr;
  public String baRdvNr;
  public String chargenNr;
  public Date belegungsdatum;
  public Long bsLfbisLkvnr;
  
//-> ausschließlich zum anzeigen in TierBesamungListTabelle
  public String tierName;
  public String stallNr;
  public String stierName;
  public String tierLnr;
  public String stierLnr;
  
//Andere Daten
  private EntityContext _context;
  public DataSource ds = null;
  public boolean update = false;
  public boolean refresh = false;

//  Creates the spezified Row
  public PTierBelegungEbPK ejbCreate(Long lfbis, Date belDatum, String tierNr, String stierNr, String baRdvNr, String besNr, String chargenNr, String reihenFolge) throws  TierNotValidException,  WrongDateException, RFNotValidException, javax.ejb.CreateException
  {
    Connection con = null;
    PreparedStatement ps = null;
    PTierBelegungEbPK pk = new PTierBelegungEbPK();
    
    this.bsLfbisLkvnr = lfbis;
    this.belegungsdatum = belDatum;
    this.chargenNr = chargenNr;
    this.baRdvNr = baRdvNr;
    this.persNr = besNr;
    this.reihenFolge = reihenFolge;
    this.aktionsCode = new String("I");
    
//  Belegungsdatum prüfen
    checkBelegungsDatum(belDatum);
    
//  Reihenfolge prüfen
    checkRf(reihenFolge);
    
    try 
    { 
      ResultSet rs;
      con = getConnection();
      
//    TierUid auslesen und prüfen
      ps = con.prepareStatement("select rdv4m_eb.get_tier_uid(?) from dual");
      ps.setString(1,tierNr);
      rs = ps.executeQuery();
      rs.next();
      this.tierUid = new Long(rs.getLong(1));
      try 
      {
        checkTierValid(this.tierUid,lfbis,belDatum);
      }
      catch(TierNotValidException etier) 
      {
        throw etier;
      }

//    StierUid auslesen und prüfen
      ps.setString(1,stierNr);
      rs = ps.executeQuery();
      rs.next();
      this.stierUid = new Long(rs.getLong(1));
      try
      {
        checkStierValid(this.stierUid,baRdvNr);
      }
      catch(TierNotValidException estier) 
      {
        throw estier;
      }
      
      ps = con.prepareStatement("insert into P_Tier_Belegung_Eigenbestand(t_st_t_st_uid,bs_bs_lfbis_lkvnr," +
                                                  "belegungsdatum,belegstier_t_st_t_st_uid,chargennummer,ba_rdv_nr,p_b_personalnr," +
                                                  "aktionscode, reihenfolge) values(?,?,?,?,?,?,?,?,?)");
      
      
      ps.setLong(1,tierUid.longValue());
      ps.setLong(2,lfbis.longValue());
      ps.setDate(3,belDatum);
      ps.setLong(4,stierUid.longValue());
      ps.setString(5,chargenNr);
      ps.setString(6,baRdvNr);
      ps.setString(7, persNr);
      ps.setString(8, new String("I"));
      ps.setString(9,reihenFolge);
      
      if(ps.executeUpdate() != 1) 
      {
        throw new CreateException("JDBC couldn't create a row");
      }
      
      ps = con.prepareStatement("commit");
      ps.executeUpdate();
//    Holen des PK
      ps = con.prepareStatement("select eb_bel_uid from P_Tier_Belegung_Eigenbestand where t_st_t_st_uid=? and bs_bs_lfbis_lkvnr = ?" +
                                "and belegungsdatum = ? and belegstier_t_st_t_st_uid = ? and  chargennummer = ? and ba_rdv_nr = ?" +
                                "and p_b_personalnr = ? and aktionscode = ? and reihenfolge = ?");
                                
      ps.setLong(1,tierUid.longValue());
      ps.setLong(2,lfbis.longValue());
      ps.setDate(3,belDatum);
      ps.setLong(4,stierUid.longValue());
      ps.setString(5,chargenNr);
      ps.setString(6,baRdvNr);
      ps.setString(7, persNr);
      ps.setString(8, new String("I"));
      ps.setString(9, reihenFolge);
      
      rs = ps.executeQuery();
      if(rs.next()) 
      {
        pk.ebBelUid = new Long(rs.getLong(1));
        this.ebBelUid = pk.ebBelUid;
        return pk;
      }
      
      else 
      {
        throw new FinderException("Couldn't find row");
      }
       
    }
    
    catch(TierNotValidException tvne) 
    {
      throw tvne;
    }
    
    catch(Exception e) 
    {
      System.out.println("FEHLER IN EJBCREATE");
      e.printStackTrace();
    }
    
    finally 
    {
      try 
      {
        ps.close();
        con.close();
        System.out.println("Schliesse Connection in ejbCreate()");
      }
      
      catch(Exception e) 
      {
        System.out.println("Couldn't close Connection or PreparedStatement at ejbCreate()");
      }
    }
    
    return pk;
  }

  public void ejbPostCreate(Long lfbis, Date belDatum, String tierNr, String stierNr, String baRdvNr, String besNr, String chargenNr, String reihenFolge) throws  TierNotValidException,  WrongDateException, RFNotValidException, javax.ejb.CreateException
  {
  }

// Gets the data for the primary key

  private void refresh(PTierBelegungEbPK pk) 
  {
    Connection con = null;
    PreparedStatement ps = null;
    
    try 
    {
      ResultSet rs = null;
      con = getConnection();
      ps = con.prepareStatement("select t_st_t_st_uid, bs_bs_lfbis_lkvnr, belegungsdatum, belegstier_t_st_t_st_uid, " +
                                "chargennummer, ba_rdv_nr, p_b_personalnr, aktionscode, status_transfer_rdv, status_transver_ba, " +
                                "reihenfolge " +
                                "from P_Tier_Belegung_Eigenbestand where eb_bel_uid = ?");
      ps.setLong(1,pk.ebBelUid.longValue());
      
      rs = ps.executeQuery();
      if(rs.next()) 
      {
        this.ebBelUid = pk.ebBelUid;
        this.tierUid = new Long(rs.getLong(1));
        this.bsLfbisLkvnr = new Long(rs.getLong(2));
        this.belegungsdatum = rs.getDate(3);
        this.stierUid = new Long(rs.getLong(4));
        this.chargenNr = rs.getString(5);
        this.baRdvNr = rs.getString(6);
        this.persNr = rs.getString(7);
        this.aktionsCode = rs.getString(8);
        this.transRdv = rs.getString(9);
        this.transBa = rs.getString(10);
        this.reihenFolge = rs.getString(11);
      }
      
      
      else 
      {
        throw new FinderException("Couldn't find row with specified primary-key");
      }
      
      ps = con.prepareStatement("select (select rdv4m_eb.get_tier_name(?) from dual), " +
                               "        (select rdv4m_eb.get_tier_name(?) from dual), " +
                               "        (select rdv4m_eb.get_tier_stallnummer(?,?) from dual), " +
                               "        (select rdv4m_eb.get_tier_lnr(?) from dual), " +
                               "        (select rdv4m_eb.get_tier_lnr(?) from dual) " +
                               "from dual");
                               
      ps.setLong(1,this.tierUid.longValue());
      ps.setLong(2,this.stierUid.longValue());
      ps.setLong(3,this.tierUid.longValue());
      ps.setLong(4,this.bsLfbisLkvnr.longValue());
      ps.setLong(5,this.tierUid.longValue());
      ps.setLong(6,this.stierUid.longValue());
      
      rs = ps.executeQuery();
      if(rs.next()) 
      {
        this.tierName = rs.getString(1);
        this.stierName = rs.getString(2);
        this.stallNr = rs.getString(3);
        this.tierLnr = rs.getString(4);
        this.stierLnr = rs.getString(5);
      }
    }
    
    catch(Exception e) 
    {
      e.printStackTrace();
    }
    
    finally 
    {
      try 
      {
        ps.close();
        con.close();
        System.out.println("Schliesse Connection in refresh()");
      }
      
      catch(Exception e) 
      {
        System.out.println("Couldn't close Connection or Prepared-Statement at refresh()");
      }
    }
  }

  public PTierBelegungEbPK ejbFindByPrimaryKey(PTierBelegungEbPK primaryKey)
  {
    try 
    {
      if ((primaryKey == null) || (primaryKey.ebBelUid == null)) 
      {
        throw new FinderException ("primary key cannot be null");
      }
    }
    catch(Exception e) 
    {
      System.out.println("Error occured at ejbFindByPrimaryKey");
      e.printStackTrace();
    }
    
    refresh(primaryKey);
    return primaryKey;
  }

  public void ejbActivate()
  {
  }


//Gets the data for the spezified primaryKey

  public void ejbLoad()
  {
    try 
    {
      refresh((PTierBelegungEbPK) this._context.getPrimaryKey());
    }
    catch (Exception fe) 
    {
      System.out.println("Error occured at ejbLoad()");
      fe.printStackTrace();
    }
  }

  public void ejbPassivate()
  {
  }

  public void ejbRemove()
  {
  	System.out.println("remove");
    Connection con = null;
    PreparedStatement ps = null;
    
    try 
    {
      con = getConnection();
      ps = con.prepareStatement("update P_Tier_Belegung_Eigenbestand set aktionscode = 'D' where eb_bel_uid = ?");
      ps.setLong(1, ebBelUid.longValue());
      
      if(ps.executeUpdate() != 1) 
      {
        throw new CreateException("JDBC couldn't delete row");
      }
      
      ps = con.prepareStatement("commit");
      ps.executeUpdate();
    }
    
    catch(Exception e) 
    {
      System.out.println("Error occured at ejbRemove()");
      e.printStackTrace();
    }
    
    finally 
    {
      try
      {
        con.close();
        ps.close();
        System.out.println("Schliesse Connection in ejbRemove()");
      }
      
      catch(Exception e) 
      {
        System.out.println("Couldn't close Connection or Prepared-Statement in ejbRemove");
      }
    }
  }

  public void ejbStore() //throws  TierNotValidException,  WrongDateException, RFNotValidException
  {
  	if(update)
  	{
  	  Connection con = null;
      PreparedStatement ps = null;
    
      try 
      {
      
        con = getConnection();
      
        ps = con.prepareStatement("update P_Tier_Belegung_Eigenbestand set t_st_t_st_uid = ?,  bs_bs_lfbis_lkvnr = ?," +
                                "belegungsdatum = ?, belegstier_t_st_t_st_uid = ?, chargennummer = ?, ba_rdv_nr = ?," +
                                "p_b_personalnr = ?, aktionscode = ?, reihenfolge = ? where eb_bel_uid = ?");
        ps.setLong(1,tierUid.longValue());
        ps.setLong(2,bsLfbisLkvnr.longValue());
        ps.setDate(3,belegungsdatum);
        ps.setLong(4,stierUid.longValue());
        ps.setString(5,chargenNr);
        ps.setString(6,baRdvNr);
        ps.setString(7, persNr);
        ps.setString(8, aktionsCode);
        ps.setString(9, reihenFolge);
        ps.setLong(10,ebBelUid.longValue());
      
        System.out.println("EJB-store: "+tierUid+" "+belegungsdatum+" "+aktionsCode);
      
        if(ps.executeUpdate() != 1) 
        {
          throw new CreateException("JDBC couldn't update row");
        }
      
        ps = con.prepareStatement("commit");
        ps.executeUpdate();
      }
    
    
      catch(Exception e) 
      {
        System.out.println("Error occured at ejbStore()");
        e.printStackTrace();
      }
    
      finally 
      {
        try
        {
          con.close();
          ps.close();
        }
      
        catch(Exception e) 
        {
          System.out.println("Couldn't close Connection or Prepared-Statement in ejbStore");
        }
      }
  	}
  }

  public void setEntityContext(EntityContext ctx)
  {
    _context = ctx;
  }

  public void unsetEntityContext()
  {
    _context = null;
  }

  public Connection getConnection() throws Exception
  {
    if(ds == null) 
    {
      InitialContext con = new InitialContext();
      
      ds = (DataSource)con.lookup("java:/OracleDS");
      
      if(ds == null) 
      {
        throw new RemoteException ( "Could not initialize DataSource in getConnection(): ");
      }
    }
    
    Connection con = ds.getConnection();
    return con;
  }
  
  public PTierBelegungEbPK ejbCreate()
  {
    return null;
  }

  public void ejbPostCreate()
  {
  }

//Getter- und Setter-Methoden
  public Long getEbBelUid()
  {
    return ebBelUid;
  }

  public void setEbBelUid(Long ebBelUid)
  {
    this.ebBelUid = ebBelUid;
  }

  public Long getTierUid()
  {
    return tierUid;
  }

  public void setTierUid(Long tierUid)
  {
    this.tierUid = tierUid;
  }

  public Long getBsLfbisLkvnr()
  {
    return bsLfbisLkvnr;
  }

  public void setBsLfbisLkvnr(Long bsLfbisLkvnr)
  {
    this.bsLfbisLkvnr = bsLfbisLkvnr;
  }

  public Date getBelegungsdatum()
  {
    return belegungsdatum;
  }

  public void setBelegungsdatum(Date belegungsdatum)
  {
    this.belegungsdatum = belegungsdatum;
  }

  public Long getStierUid()
  {
    return stierUid;
  }

  public void setStierUid(Long stierUid)
  {
    this.stierUid = stierUid;
  }

  public String getChargenNr()
  {
    return chargenNr;
  }

  public void setChargenNr(String chargenNr)
  {
    this.chargenNr = chargenNr;
  }

  public String getBaRdvNr()
  {
    return baRdvNr;
  }

  public void setBaRdvNr(String baRdvNr)
  {
    this.baRdvNr = baRdvNr;
  }

  public String getPersNr()
  {
    return persNr;
  }

  public void setPersNr(String persNr)
  {
    this.persNr = persNr;
  }

  public String getAktionsCode()
  {
    return aktionsCode;
  }

  public void setAktionsCode(String aktionsCode)
  {
    this.aktionsCode = aktionsCode;
  }

  public String getTransRdv()
  {
    return transRdv;
  }

  public void setTransRdv(String transRdv)
  {
    this.transRdv = transRdv;
  }

  public String getTransBa()
  {
    return transBa;
  }

  public void setTransBa(String transBa)
  {
    this.transBa = transBa;
  }

  public Collection ejbFindEbBesamungListFor(Long lfbis)
  {
    Connection con = null;
    PreparedStatement ps = null;
    Collection coll;
    Vector vec = new Vector();
    PTierBelegungEbPK pk = null;
    
    try 
    {
      ResultSet rs = null;
      con = getConnection();
      ps = con.prepareStatement("select eb_bel_uid from P_Tier_Belegung_Eigenbestand where bs_bs_lfbis_lkvnr = ? and aktionscode != 'D'");
      ps.setLong(1,lfbis.longValue());
      
      rs = ps.executeQuery();
      
      while(rs.next()) 
      { 
        pk = new PTierBelegungEbPK();
        pk.ebBelUid = new Long(rs.getLong(1));
        vec.addElement(pk);
      }
    }
    
    catch(Exception e) 
    {
      System.out.println("Error occured at ejbFindEbBesamungListFor");
      e.printStackTrace();
    }
    
    finally{
    	try {
    		ps.close();
    		con.close();
    		System.out.println("Schliess Connection in ejbCreate()");
    	}
    	
    	catch(Exception e) {
    		System.out.println("Prepared Statement oder Connection konnte nicht geschlossen werden");
    	}
    }
  
    coll = vec;
    
    return coll;
  }

  public String getTierName()
  {
    return tierName;
  }

  public void setTierName(String tierName)
  {
    this.tierName = tierName;
  }

  public String getStierName()
  {
    return stierName;
  }

  public void setStierName(String stierName)
  {
    this.stierName = stierName;
  }

// Prüfungen  
  private void checkTierValid(Long tierUid, Long lfbis, Date belegungsdatum) throws TierNotValidException
  {
  	Connection con = null;
    PreparedStatement ps = null;
    
    try 
    {
      con = getConnection();
      ResultSet rs;
      String isValid;
      ps = con.prepareStatement("select rdv4m_eb.tier_ist_okay(?,?,?) from dual");
      ps.setLong(1,tierUid.longValue());
      ps.setLong(2,lfbis.longValue());
      ps.setDate(3,belegungsdatum);
      
      rs = ps.executeQuery();
      rs.next();
      isValid = rs.getString(1);
      
      System.out.println(isValid);
      
      if(isValid.equals("TRUE")) 
      {
        return;
      }
      
      else 
      {
       // throw new TierNotValidException("Tier konnte nicht gefunden werden. Bitte überprüfen sie ob das Tier auch tatsächlich zum angegebenen Datum in " +
         //                               "ihrem Betrieb war.");
         
         throw new TierNotValidException(isValid);
      }
    }
    
    catch(TierNotValidException tnve) 
    {
      throw tnve;
    }
    
    catch(Exception e) 
    {
      System.out.println("Error occured at checkTierValid");
      e.printStackTrace();
    }
    
    finally {
    	try 
		{
    		ps.close();
        	con.close();
    	}
    	
    	catch(Exception e) 
		{
    		System.out.println("Fehler beim Schliessen von Prepared-Statement oder Connection");
    		e.printStackTrace();
    	}
    	
    }
  }
  
  private void checkStierValid(Long stierUid, String baRdvNr) throws TierNotValidException 
  {
  	Connection con = null;
    PreparedStatement ps = null;
    
    try 
    {
      con = getConnection();
      ResultSet rs;
      String isValid;
      ps = con.prepareStatement("select rdv4m_eb.stier_okay(?,?) from dual");
      ps.setLong(1,stierUid.longValue());
      ps.setString(2,baRdvNr);
      
      rs = ps.executeQuery();
      rs.next();
      isValid = rs.getString(1);
      
      System.out.println(isValid);
      
      if(isValid.equals("TRUE")) 
      {
        return;
      }
      
      else 
      {
        throw new TierNotValidException(isValid);
      }
    }
    
    catch(TierNotValidException tnve) 
    {
      throw tnve;
    }
    
    catch(Exception e) 
    {
      System.out.println("Error occured at checkTierValid");
      e.printStackTrace();
    }
    
    finally {
    	try 
		{
    		ps.close();
        	con.close();
    	}
    	
    	catch(Exception e) 
		{
    		System.out.println("Fehler beim Schliessen von Prepared-Statement oder Connection");
    		e.printStackTrace();
    	}
    	
    }
  }
  
  private void checkBelegungsDatum(Date belDatum) throws WrongDateException
  {
    String isValid;
    Connection con = null;
    PreparedStatement ps = null;
    
    try 
    {
      con = getConnection();
      ps = con.prepareStatement("select rdv4m_eb.belegungsdatum_okay(?) from dual");
      ResultSet rs;
      ps.setDate(1,belDatum);
      
      rs = ps.executeQuery();
      rs.next();
      isValid = rs.getString(1);
      if(isValid.equals("TRUE")) 
      {
        return;
      }
      
      else 
      {
        throw new WrongDateException(isValid);
      }
    }
    
    catch(WrongDateException wde) 
    {
      throw wde;
    }
    catch(Exception e) 
    {
      System.out.println("Fehler in checkBelgungsDatum");
      e.printStackTrace();
    }
    
    finally {
    	try 
		{
    		ps.close();
        	con.close();
    	}
    	
    	catch(Exception e) 
		{
    		System.out.println("Fehler beim Schliessen von Prepared-Statement oder Connection");
    		e.printStackTrace();
    	}
    	
    }
  }

  private void checkRf(String reihenFolge) throws RFNotValidException
  {
    String isValid = null;
    Connection con = null;
    PreparedStatement ps = null;
    
    try 
    {
      con = getConnection();
      ps = con.prepareStatement("select rdv4m_eb.reihenfolge_okay(?) from dual");
      ResultSet rs = null;
      
      ps.setString(1,reihenFolge);
      rs = ps.executeQuery();
      rs.next();
      isValid = rs.getString(1);
      
      if(isValid.equals("TRUE")) 
      {
        return;
      }
      
      else 
      {
        throw new RFNotValidException(isValid);
      }
    }
    
    catch(Exception e) 
    {
      System.out.println("Fehler in checkRf");
      e.printStackTrace();
    }
    
    finally {
    	try 
		{
    		ps.close();
        	con.close();
    	}
    	
    	catch(Exception e) 
		{
    		System.out.println("Fehler beim Schliessen von Prepared-Statement oder Connection");
    		e.printStackTrace();
    	}
    	
    }
  }

  public String getStallNr()
  {
    return stallNr;
  }

  public void setStallNr(String stallNr)
  {
    this.stallNr = stallNr;
  }

  public String getTierLnr()
  {
    return tierLnr;
  }

  public void setTierLnr(String tierLnr)
  {
    this.tierLnr = tierLnr;
  }

  public String getStierLnr()
  {
    return stierLnr;
  }

  public void setStierLnr(String stierLnr)
  {
    this.stierLnr = stierLnr;
  }

  public String getReihenFolge()
  {
    return reihenFolge;
  }

  public void setReihenFolge(String reihenFolge)
  {
    this.reihenFolge = reihenFolge;
  }

  public String getTierNummer()
  {
    return tierNummer;
  }

  public void setTierNummer(String tierNummer)
  {
    this.tierNummer = tierNummer;
  }

  public String getStierNummer()
  {
    return stierNummer;
  }

  public void setStierNummer(String stierNummer)
  {
    this.stierNummer = stierNummer;
  }

  public boolean getUpdate()
  {
    return update;
  }

  public void setUpdate(boolean update)
  {
    this.update = update;
  }

  public boolean ejbHomeUpdate(Long uid, String tierNummer, String stierNummer, Date belDatum, String chargenNr, String reihenFolge, String besNummer, String baRdvNr) throws RFNotValidException, TierNotValidException, WrongDateException
  {
//  Datensatz laden
    PTierBelegungEbPK pk = new PTierBelegungEbPK();
    pk.ebBelUid = uid;
    
    this.refresh(pk);
  
    Long stierUid = null;
    Long tierUid = null;
    Connection con = null;
    PreparedStatement ps = null;
//  Belegungsdatum prüfen
    checkBelegungsDatum(belDatum);
    
//  Reihenfolge prüfen
    checkRf(reihenFolge);
    
    try 
    { 
      ResultSet rs;
      con = getConnection();
      
//    TierUid auslesen und prüfen
      ps = con.prepareStatement("select rdv4m_eb.get_tier_uid(?) from dual");
      ps.setString(1,tierNummer);
      rs = ps.executeQuery();
      rs.next();
      tierUid = new Long(rs.getLong(1));
      try 
      {
        checkTierValid(tierUid,this.bsLfbisLkvnr,belDatum);
      }
      catch(TierNotValidException etier) 
      {
        throw etier;
      }

//    StierUid auslesen und prüfen
      ps.setString(1,stierNummer);
      rs = ps.executeQuery();
      rs.next();
      stierUid = new Long(rs.getLong(1));
      try
      {
        checkStierValid(stierUid,baRdvNr);
      }
      catch(TierNotValidException estier) 
      {
        throw estier;
      }
    }
    
    catch(TierNotValidException tnve) 
    {
      throw tnve;
    }
    
    catch(Exception e) 
    {
      System.out.println("Fehler in ejbHomeUpdate");
      e.printStackTrace();
    }
      
    finally {
    	try 
		{
    		ps.close();
        	con.close();
    	}
    	
    	catch(Exception e) 
		{
    		System.out.println("Fehler beim Schliessen von Prepared-Statement oder Connection");
    		e.printStackTrace();
    	}
    	
    }
    this.persNr = besNummer;
    this.baRdvNr = baRdvNr;
    this.belegungsdatum = belDatum;
    this.chargenNr = chargenNr;
    this.aktionsCode = new String("U");
    this.reihenFolge = reihenFolge;
    this.tierUid = tierUid;
    this.stierUid = stierUid;
    
    this.setUpdate(true);
    this.ejbStore();
    this.setUpdate(false);
    return true;
  }
  
  public void setRefresh(boolean r) {
  	this.refresh = r;
  }
  
  public boolean getRefresh(){
  	return this.refresh;
  }
}

Tut mir leid wenn ich jetzt so einen Code-Brocken herein kopiere. Ihr müsst ihn auch nicht unbedingt durchlesen (obwohol es sehr nett wäre), aber bitte sagt mir wie ich mein EJB weiter optimieren kann.

Was kann ich tun um mein EJB zu optimieren.

Kann mir jemand helfen??


mfg manuel
 

bambi

Bekanntes Mitglied
Hi,

also ich hab' mir den Code jetzt wirklich nicht komplett durchgelesen, aber JDBC-Zugriffe in einer Entity-Bean hab' ich
noch nie gesehen.
Machst Du alles in Deiner Entity Bean? Die soll doch eigentlich nur Deine Daten in der DB repraesentieren. Alles andere
wird in der SessionBean gemacht. Also ich wuerd's an Deiner Stelle viel strickter trennen.
 
G

Guest

Gast
Ich habe nur so auf die schnelle drübergeguckt.

Entferne das refresh(primaryKey); aus ejbFindByPrimaryKey und ersetze es durch etwas
einfacheres, was nur die Gültigkeit des PK prüft.
So wie es jetzt ist, lädst du die Daten zwei mal (zusätzlich in ejbLoad).
Verwende Log4J oder sonst etwas für Ausgaben auf die Console, da die Server JVM meist
einen kleinen Buffer hat, so dass die einfache Ausgabe auf die Console bremst.

Wegen so etwas würden bei uns Köpfe rollen. Log4J und eine vernünftige Fehlerbehandlung
einbauen.
Code:
catch(Exception e) 
{ 
  System.out.println("..."); 
  e.printStackTrace(); 
}

Wenn du schon dabei bist, lagere auch alles, was nach SQL aussieht aus der Bean Klasse
in eine extra Klasse, damit es übersichtlicher ist.

Der "dirty" Flag würde ich auch noch überdenken. Es ist kaum nachvollziehbar, wann ein
Update stattfinden, wann nicht (ich meine das update und refresh in deinem Code).
 

Bleiglanz

Gesperrter Benutzer
die Frage ist ja erstmal

warum BMP und nicht CMP???

und dann: sind deine Clients remote und greifen über verschiedene JVMs hinweg direkt auf die EJB zu? In diesem Fall verursacht JEDER aufruf von getX einen Netzwerk-Roundtrip, dieses Modell kannst du vergessen!!

ich würde dir dringend zu CMP raten und den Stier über eine Container Managed Relation zu verwalten, die ganzen Checks sind dann überflüssig :)
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen

Ähnliche Java Themen


Oben