KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > javax > ejb > EntityBean

javax.ejb
Interface EntityBean

All Superinterfaces:
EnterpriseBean, Serializable
See Also:
Top Examples, Source Code

public void ejbActivate()
                 throws EJBException,
                        RemoteException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[647]Test the serialization/deserialization of a primary key
By Anonymous on 2004/04/16 03:58:30  Rate
/** 
 * Test the serialization/deserialization of a primary key. 
 */
 
 public static void testSerialization ( myEntityBeanHomeRemote home )  
   throws Exception  
  {  
  
  
   System.out.println ( "Testing serialization of primary key" ) ; 
   Integer pk_1 = new Integer ( 101 ) ; 
   myEntityBeanRemote myEntityBean_1 = home.findByPrimaryKey ( pk_1 ) ; 
   System.out.println ( "Setting myEntityBean name to Presidential Suite" ) ; 
   myEntityBean_1.setName ( "Presidential Suite" ) ; 
  
  
   // Serialize the primary key for myEntityBean 101 to a file. 
   FileOutputStream fos = new FileOutputStream ( "pk101.ser" ) ; 
   ObjectOutputStream outStream = new ObjectOutputStream ( fos ) ; 
   System.out.println ( "Writing primary key object to file..." ) ; 
   outStream.writeObject ( pk_1 ) ; 
   outStream.flush (  ) ; 
   outStream.close (  ) ; 
   pk_1 = null; 
  
  
   // Deserialize the primary key for myEntityBean 101. 
   FileInputStream fis = new FileInputStream ( "pk101.ser" ) ; 
   ObjectInputStream inStream = new ObjectInputStream ( fis ) ; 
   System.out.println ( "Reading primary key object from file..." ) ; 
   Integer pk_2 =  ( Integer ) inStream.readObject (  ) ; 
   inStream.close (  ) ; 
  
  
   // Re-obtain a remote reference to myEntityBean 101 and read its name. 
   System.out.println ( "Acquiring reference using deserialized primary key..." ) ; 
   myEntityBeanRemote myEntityBean_2 = home.findByPrimaryKey ( pk_2 ) ; 
   System.out.println ( "Retrieving name of myEntityBean using new remote reference..." ) ; 
   System.out.println ( myEntityBean_2.getName (  )  ) ; 
  
  
  }  
  
  
 //ejbActivate


public void ejbLoad()
             throws EJBException,
                    RemoteException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void ejbPassivate()
                  throws EJBException,
                         RemoteException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void ejbRemove()
               throws RemoveException,
                      EJBException,
                      RemoteException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void ejbStore()
              throws EJBException,
                     RemoteException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[891]Map Blob field in CMP entity bean to BLOB data type in database
By Anonymous on 2004/09/10 13:54:10  Rate
//You cannot directly map a java.sql.Blob field type in CMP entity  
 //bean to BLOB data type in database and use byte [  ]  to manipulate  
 //BLOB data type.You have to remember that this is not an efficient  
 //approach if you are storing data that is very large  ( more than  
 //25M )  and probably consider alternatives. 
  
  
 // Locate and open the file 
 File imgFile = new File ( fileName ) ; 
  
  
 long imgFileSize= imgFile.length (  ) ; 
  
  
 // initialize the byte array 
 byte byteValue [  ]  = new byte [  ( int ) imgFileSize ] ; 
  
  
 // Read the file into the byte array 
 InputStream is = new BufferedInputStream ( new FileInputStream ( imgFile )  ) ; 
 int len = is.read ( byteValue ) ; 
  
  
 //Add the byte to the entity bean field 
 if ( len!=imgFileSize )   {  
      System.out.println ( "Read bytes did not equal file size on directory" ) ; 
  }  
 else  {  
   MyPicCMPLocal myPic = empHome.create ( empNo , byteValue ) ; 
  }  
  
  
  
  
 //The following is a code snippet from MyPicCMP.java  
  
  
 public abstract class MyPicCMP implements EntityBean 
  {  
   .... 
   public abstract byte [  ]  getPicture (  ) ; 
   public abstract void setPicture ( byte [  ]  newPicture ) ; 
   public Long ejbCreate ( Long empno, byte [  ]  newPicture )  
    {  
     setEmpno ( empno ) ; 
     setPicture ( newPicture ) ; 
     return empno; 
    }  
  
  
   public void ejbPostCreate ( Long empno, byte [  ]  newPicture )  
    {  
    }  
   ... 
  }  
 


public void setEntityContext(EntityContext ctx)
                      throws EJBException,
                             RemoteException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void unsetEntityContext()
                        throws EJBException,
                               RemoteException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags