Code EJB : Lesson - 10

3.     SportsNewsBean
DistributeSportsNewsMDB.java
import javax.ejb.*;
import javax.jms.*;
public class DistributeSportsNewsMDB implements MessageDrivenBean,MessageListener
protected MessageDrivenContext ctx;
String text;
public void setMessageDrivenContext(MessageDrivenContext ctx)     {          this.ctx=ctx;     }
public void ejbCreate()     {     //     System.out.println("ejbcreate");     }
public void onMessage(Message msg)
     TextMessage tm=(TextMessage) msg;
     try
               text=tm.getText();
               System.out.println("TOPIC: SPORTS # GOING TO DISTRIBUTE :"+msg);
               insertMessageToDB(); //JavaMAIL should be used to send mail
     catch(JMSException e)
               e.printStackTrace();
public void ejbRemove()      {       //System.err.println("ejbremove");     }
void insertMessageToDB() //JavaMAIL should be used to send mail
try
     Class.forName("oracle.jdbc.driver.OracleDriver");
     java.sql.Connection con=java.sql.DriverManager.getConnection("jdbc:oracle:thin:@192.168.29.62:1521:ORCL","pravash","pravash");
     java.sql.PreparedStatement     stat=con.prepareStatement("Insert into TopicInfo values(?,?)");
     stat.setString(1,"SportsNews");
     stat.setString(2,text);
     stat.executeUpdate();
     stat.close();
     con.close();
catch(Exception e)
     e.printStackTrace();
ejb-jar.xml
<?xml version="1.0"?>
<!DOCTYPE ejb-jar>
<ejb-jar>
<enterprise-beans>
<message-driven>
<ejb-name>DistributeSportsNews</ejb-name>
<ejb-class>DistributeSportsNewsMDB</ejb-class>
<message-selector></message-selector>
<resource-env-ref-name>SportsTopic</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Topic</resource-env-ref-type>
<resource-ref>
<res-ref-name>TopicConnectionFactory </res-ref-name>
<res-type>javax.jms.TopicConnectionFactory</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<transaction-type>Container</transaction-type>
<message-driven-destination>
<destination-type>javax.jms.Topic</destination-type>
<subscription-durability>NonDurable</subscription-durability>
</message-driven-destination>
</message-driven>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>DistributeSportsNews</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>NotSupported</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
jboss.xml
<?xml version="1.0" encoding="UTF-8" ?>
<jboss>
<enterprise-beans>
<message-driven>
<ejb-name>DistributeSportsNews</ejb-name>
<configuration-name>Standard Message Driven Bean</configuration-name>
<destination-jndi-name>SportsTopic</destination-jndi-name>
</message-driven>
</enterprise-beans>
</jboss>
BUILD.BAT
@echo off
echo COMPILING THE MDBEAN
javac DistributeSportsNewsMDB.java
echo CREATING THE JAR FOR DEPLOYMENT
jar -cv0f DistributeSportsNewsMDB.jar META-INF DistributeSportsNewsMDB.class
echo DEPLOYING THE JAR FOR USE
copy DistributeSportsNewsMDB.jar c:\jbosstomcat\jboss\deploy
echo DEPLOYMENT PROCESS OVER ....

wtf ? what the hell is that ?:-) I wonder how he does it without the EJB QL. Not that I want him to post it.

Similar Messages

  • Code EJB : Lesson - 8

    [ M E S S A G E - D R I V E N B E A N    C O D E ]
    1.     NewsLetterBean
    DistributeNewsLetterMDB.java
    import javax.ejb.*;
    import javax.jms.*;
    public class DistributeNewsLetterMDB implements MessageDrivenBean,MessageListener
    protected MessageDrivenContext ctx;
    String text;
    public void setMessageDrivenContext(MessageDrivenContext ctx)     {          this.ctx=ctx;     }
    public void ejbCreate()     {     //     System.out.println("ejbcreate");     }
    public void onMessage(Message msg)
         TextMessage tm=(TextMessage) msg;
         try
                   text=tm.getText();
                   System.out.println("NEWS # GOING TO DISTRIBUTE :"+msg);
                   insertMessageToDB();//MUST BE REPLACED WITH JAVAMAIL CODE IN FUTURE
         catch(JMSException e)
                   e.printStackTrace();
    public void ejbRemove()      {       //System.err.println("ejbremove");     }
    void insertMessageToDB() //JavaMAIL should be used to send mail
    try
         Class.forName("oracle.jdbc.driver.OracleDriver");
         java.sql.Connection con=java.sql.DriverManager.getConnection("jdbc:oracle:thin:@192.168.29.62:1521:ORCL","pravash","pravash");
         java.sql.PreparedStatement     stat=con.prepareStatement("Insert into TopicInfo values(?,?)");
         stat.setString(1,"WeeklyNews");
         stat.setString(2,text);
         stat.executeUpdate();
         stat.close();
         con.close();
    catch(Exception e)
         e.printStackTrace();
    ejb-jar.xml
    <?xml version="1.0"?>
    <!DOCTYPE ejb-jar>
    <ejb-jar>
    <enterprise-beans>
    <message-driven>
    <ejb-name>DistributeNewsLetter</ejb-name>
    <ejb-class>DistributeNewsLetterMDB</ejb-class>
    <message-selector></message-selector>
    <resource-env-ref-name>WeeklyNewsLetterTopic</resource-env-ref-name>
    <resource-env-ref-type>javax.jms.Topic</resource-env-ref-type>
    <resource-ref>
    <res-ref-name>TopicConnectionFactory </res-ref-name>
    <res-type>javax.jms.TopicConnectionFactory</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    <transaction-type>Container</transaction-type>
    <message-driven-destination>
    <destination-type>javax.jms.Topic</destination-type>
    <subscription-durability>NonDurable</subscription-durability>
    </message-driven-destination>
    </message-driven>
    </enterprise-beans>
    <assembly-descriptor>
    <container-transaction>
    <method>
    <ejb-name>DistributeNewsLetter</ejb-name>
    <method-name>*</method-name>
    </method>
    <trans-attribute>NotSupported</trans-attribute>
    </container-transaction>
    </assembly-descriptor>
    </ejb-jar>
    ejb-jar.xml
    <?xml version="1.0" encoding="UTF-8" ?>
    <jboss>
    <enterprise-beans>
    <message-driven>
    <ejb-name>DistributeNewsLetter</ejb-name>
    <configuration-name>Standard Message Driven Bean</configuration-name>
    <destination-jndi-name>WeeklyNewsLetterTopic</destination-jndi-name>
    </message-driven>
    </enterprise-beans>
    </jboss>
    BUILD.BAT
    @echo off
    echo COMPILING THE MDBEAN
    javac DistributeNewsLetterMDB.java
    echo CREATING THE JAR FOR DEPLOYMENT
    jar -cv0f DistributeNewsLetterMDB.jar META-INF DistributeNewsLetterMDB.class
    echo DEPLOYING THE JAR FOR USE
    copy DistributeNewsLetterMDB.jar c:\jbosstomcat\jboss\deploy
    echo DEPLOYMENT PROCESS OVER ....

    wtf ? what the hell is that ?:-) I wonder how he does it without the EJB QL. Not that I want him to post it.

  • Code EJB : Lesson - 2

    [CONTENTS OF ENTITY BEAN]
    {CONTAINER MANAGED PERSISTANCE}
    CMEJBHomeIFace.java
    import javax.ejb.*;
    import java.rmi.*;
    public interface CMEJBHomeIFace extends EJBHome
    public CMEJBRemoteIFace create(int id, String name,String password,int age,String location) throws CreateException,RemoteException;
    /* IN THIS EXAMPLE BOTH THE FOLLOWING METHODS DO THE SAME JOB AS P-KEY AND ID ARE THE SAME FIELD */
    public CMEJBRemoteIFace findById(int id) throws RemoteException,FinderException;
    public CMEJBRemoteIFace findByPrimaryKey(CMEJB_PKeyCode obj) throws RemoteException,FinderException;
    CMEJBRemoteIFace.java
    import javax.ejb.*;
    import java.rmi.*;
    public interface CMEJBRemoteIFace extends EJBObject
    public void setId(int id) throws RemoteException;
    public void setName(String name) throws RemoteException;
    public void setPassword(String password) throws RemoteException;
    public void setAge(int age) throws RemoteException;
    public void setLocation(String location) throws RemoteException;
    public int getId() throws RemoteException;
    public String getName() throws RemoteException;
    public String getPassword() throws RemoteException;
    public int getAge() throws RemoteException;
    public String getLocation() throws RemoteException;
    CMEJB_BeanCode.java
    import javax.ejb.*;
    import java.rmi.*;
    /* ONE ENTITY BEAN INSTANCE ASSOCIATED WITH ONE RECORD OF A TABLE.
    A RECORD IS KNOWN AS AN ENTITY.P-KEY IS REQUIRED TO IDENTIFY THE RECORD.
    P-KEY NEED NOT BE CREATED IN DATABASE, VIRTUAL P-KEY CAN BE MAINTAINED IN THE BEAN ITSELF.
    THIS P-KEY WILL MAINTAIN UNIQUNESS OF RECORD AS LONG AS WE ARE ACCESSING THE TABLE USING ENTITY BEAN.IF WE ACCESS THE TABLE DIRECTLY THROUGH SQL-PLUS AND INSERT DUPLICATE RECORD, ejbLoad() WILL FAIL,NEXT TIME WE TRY TO LOAD*/
    public class CMEJB_BeanCode implements EntityBean
    public int id;
    public String name;
    public String password;
    public int age;
    public String location;
    EntityContext tx;
    public CMEJB_PKeyCode ejbCreate(int id, String name,String password,int age,String location) //same as create() of HomeIFace but return type is different
    System.out.println("#########  Entered ejbCreate of Entity Bean ################");
         this.id = id;
         this.name = name;
         this.password = password;
         this.age = age;
         this.location = location;
         CMEJB_PKeyCode obj = new CMEJB_PKeyCode();
         obj.id = id;
    System.out.println("#########  Exited ejbCreate of Entity Bean ################");
         return obj;
    public void ejbPostCreate(int id, String name,String password,int age,String location) { }
    public void ejbActivate() { }
    public void ejbPassivate(){}
    public void setEntityContext(EntityContext etx)
         tx = etx;
    public void unsetEntityContext() {}
    public void ejbLoad() {} //taken care of by Container... in BMP we have to code it
    public void ejbStore() {}//taken care of by Container... in BMP we have to code it
    public void ejbRemove() {}
    public boolean isModified() // in  ejbStore()it is checked to store latest changes
    {     return true;     }
    public void setId(int id)               {     this.id = id;     }
    public void setName(String name)          {     this.name = name;   }
    public void setPassword(String password)     {     this.password = password;}
    public void setAge(int age)               {     this.age = age;     }
    public void setLocation(String location)     {     this.location = location;}
    public int getId()                    {     return id;          }
    public String getName()               {     return name;     }
    public String getPassword()               {     return password;     }
    public int getAge()                    {     return age;     }
    public String getLocation()               {     return location;     }
    CMEJB_PkeyCode.java
    import javax.ejb.*;
    import java.rmi.*;
    import java.io.*;
    /* used for findByPrimarykey() .used for ejbLoad() and ejbStore().*/
    public class CMEJB_PKeyCode implements Serializable
    public int id; // PKey can be applied to multiple fields
    public int hashCode() // for comparision... when we try to create a record
    {     return id;          }
    public boolean equals(Object o) // for comparision ... when we try to find a record
         CMEJB_PKeyCode pkobj = (CMEJB_PKeyCode) o;
         return (pkobj.id == this.id)?true:false;
    }   }

    wtf ? what the hell is that ?:-) I wonder how he does it without the EJB QL. Not that I want him to post it.

  • Code EJB : Lesson - 1

    USING REMOTE-I-FACE TO CONNECT EJBs
    [CONTENTS OF STATELESS SESSION BEAN]
    HomeIFace.java
    import java.rmi.*;
    import javax.ejb.*;
    public interface HomeIFace extends EJBHome
    public RemoteIFace create()throws RemoteException,CreateException;
    RemoteIFace.java
    import java.rmi.*;
    import javax.ejb.*;
    import java.util.Vector;
    public interface RemoteIFace extends EJBObject
    public String   insertData(int id,String name,String password,int age,String location)  throws RemoteException;
    public Vector   fetchData()   throws RemoteException;
    BusinessLogicCode.java
    import java.rmi.*;
    import javax.rmi.*;
    import javax.ejb.*;
    import javax.naming.*;
    import java.util.*;
    public class BusinessLogicCode implements SessionBean
    public void ejbCreate(){}
    public void ejbRemove(){}
    public void ejbActivate(){}
    public void ejbPassivate(){}
    public void setSessionContext(SessionContext s){}
    public String insertData(int id,String name,String password,int age,String location)
    System.out.println("\nStateless Beans insertData() Entered ....");
         Properties p;
         Context ctx;
         Object obj;
         CMEJBHomeIFace h;
         CMEJBRemoteIFace rem;
         try
         p=new Properties();
         p.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
              p.put(Context.PROVIDER_URL,"jnp://localhost:1099");
              ctx=new InitialContext(p);
              obj=ctx.lookup("EntityBeanViaRemoteIFace");
    h=(CMEJBHomeIFace)PortableRemoteObject.narrow(obj,CMEJBHomeIFace.class);
    rem=h.create(id,name,password,age,location);
    System.out.println("\nStateless Beans insertData() Exited ......");
    return "Inserted Successfully To Entity Bean...";
         catch(Exception e)
              return "Exception While Inserting Record" +e;
    public Vector fetchData()
              //Code to call Finder method of entity bean through LocalInterface
              Vector v1=new Vector();
              v1.addElement("Hello Vector");
              return v1;
    ejb-jar.xml
    <?xml version="1.0"?>
    <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN' 'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'>
    <ejb-jar>
    <enterprise-beans>
    <session>
    <ejb-name>EjbStatelessDemo</ejb-name>
    <home>HomeIFace</home>
    <remote>RemoteIFace</remote>
    <ejb-class>BusinessLogicCode</ejb-class>
    <session-type>Stateless</session-type>
    <transaction-type>Container</transaction-type>
    </session>
    </enterprise-beans>
    </ejb-jar>
    jboss.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <jboss>
    <secure>false</secure>
    <container-configurations />
    <resource-managers />
    <enterprise-beans>
    <session>
         <ejb-name>EjbStatelessDemo</ejb-name>
         <jndi-name>StatelessRemoteAccessFacility</jndi-name>
         <configuration-name></configuration-name>
    </session>
    </enterprise-beans>
    </jboss>
    BUILD.BAT
    @ECHO OFF
    echo ==== SETTING PATHS CLASSPATHS ===
    set CLASSPATH=%CLASSPATH%;.;
    path=c:\windows;c:\windows\command;c:\jdk1.3\bin
    echo ==== COMPILING ALL SERVERSIDE CODE ===
    javac *.java
    echo ==== GENERATING .JAR FILE FOR DEPLOYMENT ===
    jar -cv0f %1 META-INF *.class
    echo ==== DEPLOYING THE JAR ===
    copy %1 C:\jbosstomcat\jboss\deploy
    copy HomeIFace.class RemoteIFace.class C:\JBossTomcat\tomcat\webapps\MyJsp\WEB-INF\Classes
    echo ==== READY......... START THE SERVER IF NOT STARTED ... AND GO AHEAD ===

    wtf ? what the hell is that ?:-) I wonder how he does it without the EJB QL. Not that I want him to post it.

  • Code EJB : Lesson - 2 (Continue)

    ejb-jar.xml
    <?xml version="1.0"?>
    <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN' 'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'>
    <ejb-jar>
    <enterprise-beans>
    <entity>
         <ejb-name>CMEntityDemo</ejb-name>
         <home>CMEJBHomeIFace</home>
         <remote>CMEJBRemoteIFace</remote>
         <ejb-class>CMEJB_BeanCode</ejb-class>
         <persistence-type>Container</persistence-type>
         <prim-key-class>CMEJB_PKeyCode</prim-key-class>
         <reentrant>False</reentrant>
         <cmp-field>     <field-name>id</field-name>          </cmp-field>
         <cmp-field>     <field-name>name</field-name>     </cmp-field>
         <cmp-field>     <field-name>password</field-name>     </cmp-field>
         <cmp-field>     <field-name>age</field-name>     </cmp-field>
         <cmp-field>     <field-name>location</field-name>     </cmp-field>
    </entity>
    </enterprise-beans>
    </ejb-jar>
    jaws.xml
    <jaws>
         <datasource>java:/orclPool</datasource>
         <type-mapping>Oracle8</type-mapping>
         <enterprise-beans>
              <entity>
                   <ejb-name>CMEntityDemo</ejb-name>
                   <table-name>MyLoginTable</table-name>
                   <remove-table>false</remove-table>
                   <create-table>true</create-table>
                   <cmp-field>
                        <field-name>id</field-name>
                        <column-name>ID</column-name>
              </cmp-field>
                   <cmp-field>
                        <field-name>name</field-name>
                        <column-name>NAME</column-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>password</field-name>
                        <column-name>PASSWORD</column-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>age</field-name>
                        <column-name>AGE</column-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>location</field-name>
                        <column-name>LOCATION</column-name>
                   </cmp-field>
              </entity>
         </enterprise-beans>
    </jaws>
    jboss.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <jboss>
    <secure>false</secure>
    <container-configurations />
    <resource-managers />
    <enterprise-beans>
    <entity>
         <ejb-name>CMEntityDemo</ejb-name>
         <jndi-name>EntityBeanViaRemoteIFace</jndi-name>
         <configuration-name></configuration-name>
    </entity>
    </enterprise-beans>
    </jboss>
    BUILD.BAT
    @ECHO OFF
    echo ==== SETTING PATHS CLASSPATHS ===
    set CLASSPATH=%CLASSPATH%;.;
    path=c:\windows;c:\windows\command;c:\jdk1.3\bin
    echo ==== COMPILING ALL SERVERSIDE CODE ===
    javac *.java
    echo ==== GENERATING .JAR FILE FOR DEPLOYMENT ===
    jar -cv0f %1 META-INF *.class
    echo ==== DEPLOYING THE JAR ===
    copy %1 C:\jbosstomcat\jboss\deploy
    echo ==== READY......... START THE SERVER IF NOT STARTED ... AND GO AHEAD ===

    wtf ? what the hell is that ?:-) I wonder how he does it without the EJB QL. Not that I want him to post it.

  • Code EJB : Lesson - 9

    2.     ScienceNewsBean
    DistributeScienceNewsMDB.java
    import javax.ejb.*;
    import javax.jms.*;
    public class DistributeScienceNewsMDB implements MessageDrivenBean,MessageListener
    protected MessageDrivenContext ctx;
    String text;
    public void setMessageDrivenContext(MessageDrivenContext ctx)     {          this.ctx=ctx;     }
    public void ejbCreate()     {     //     System.out.println("ejbcreate");     }
    public void onMessage(Message msg)
              Open Con to DB
              Get Subscriber List
              Send Mail to Them(JavaMail Preferred)
         TextMessage tm=(TextMessage) msg;
         try
                   text=tm.getText();
                   System.out.println("RECEIVED THE NEWS # GOING TO DISTRIBUTE :"+msg);
                   insertMessageToDB(); //JavaMAIL should be used to send mail
         catch(JMSException e)
                   e.printStackTrace();
    public void ejbRemove()      {       //System.err.println("ejbremove");     }
    void insertMessageToDB() //JavaMAIL should be used to send mail
    try
         Class.forName("oracle.jdbc.driver.OracleDriver");
         java.sql.Connection con=java.sql.DriverManager.getConnection("jdbc:oracle:thin:@192.168.29.62:1521:ORCL","pravash","pravash");
         java.sql.PreparedStatement     stat=con.prepareStatement("Insert into TopicInfo values(?,?)");
         stat.setString(1,"ScienceNews");
         stat.setString(2,text);
         stat.executeUpdate();
         stat.close();
         con.close();
    catch(Exception e)
         e.printStackTrace();
    ejb-jar.xml
    <?xml version="1.0"?>
    <!DOCTYPE ejb-jar>
    <ejb-jar>
    <enterprise-beans>
    <message-driven>
    <ejb-name>DistributeScienceNews</ejb-name>
    <ejb-class>DistributeScienceNewsMDB</ejb-class>
    <message-selector></message-selector>
    <resource-env-ref-name>ScienceTopic</resource-env-ref-name>
    <resource-env-ref-type>javax.jms.Topic</resource-env-ref-type>
    <resource-ref>
    <res-ref-name>TopicConnectionFactory </res-ref-name>
    <res-type>javax.jms.TopicConnectionFactory</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    <transaction-type>Container</transaction-type>
    <message-driven-destination>
    <destination-type>javax.jms.Topic</destination-type>
    <subscription-durability>NonDurable</subscription-durability>
    </message-driven-destination>
    </message-driven>
    </enterprise-beans>
    <assembly-descriptor>
    <container-transaction>
    <method>
    <ejb-name>DistributeScienceNews</ejb-name>
    <method-name>*</method-name>
    </method>
    <trans-attribute>NotSupported</trans-attribute>
    </container-transaction>
    </assembly-descriptor>
    </ejb-jar>
    jboss.xml
    <?xml version="1.0" encoding="UTF-8" ?>
    <jboss>
    <enterprise-beans>
    <message-driven>
    <ejb-name>DistributeScienceNews</ejb-name>
    <configuration-name>Standard Message Driven Bean</configuration-name>
    <destination-jndi-name>ScienceTopic</destination-jndi-name>
    </message-driven>
    </enterprise-beans>
    </jboss>
    BUILD.BAT
    @echo off
    echo COMPILING THE MDBEAN
    javac DistributeScienceNewsMDB.java
    echo CREATING THE JAR FOR DEPLOYMENT
    jar -cv0f DistributeScienceNewsMDB.jar META-INF DistributeScienceNewsMDB.class
    echo DEPLOYING THE JAR FOR USE
    copy DistributeScienceNewsMDB.jar c:\jbosstomcat\jboss\deploy
    echo DEPLOYMENT PROCESS OVER ....

    wtf ? what the hell is that ?:-) I wonder how he does it without the EJB QL. Not that I want him to post it.

  • Code EJB(QL) : Lesson - 12

    EJBQLDemoHomeIFace
    import javax.ejb.*;
    import java.rmi.*;
    import java.util.*;
    public interface EJBQLDemoHomeIFace extends EJBHome
    public EJBQLDemoRemoteIFace create(int id, String name,double salary,int deptno) throws CreateException,RemoteException;
    public EJBQLDemoRemoteIFace findById(int id) throws RemoteException,FinderException;
    public EJBQLDemoRemoteIFace findByPrimaryKey(EJBQLDemoPk obj) throws RemoteException,FinderException;
    public Collection findByName(String name) throws RemoteException,FinderException;
    public Collection findByDeptno(int deptno) throws RemoteException,FinderException;
    public Collection findByAll() throws RemoteException,FinderException;
    EJBQLDemoRemoteIFace
    import javax.ejb.*;
    import java.rmi.*;
    public interface EJBQLDemoRemoteIFace extends EJBObject
    public void setId(int id) throws RemoteException;
    public void setName(String name) throws RemoteException;
    public void setSalary(double salary) throws RemoteException;
    public void setDeptno(int deptno) throws RemoteException;
    public int getId() throws RemoteException;
    public String getName() throws RemoteException;
    public double getSalary() throws RemoteException;
    public int getDeptno() throws RemoteException;
    EJBQLDemoPk
    import javax.ejb.*;
    import java.rmi.*;
    import java.io.*;
    public class EJBQLDemoPk implements Serializable
    public int id;
    public int hashCode()
         return id;
    public boolean equals(Object o)
    EJBQLDemoPk pkobj = (EJBQLDemoPk) o;
    return (pkobj.id == this.id)?true:false;
    EJBQLDemoBeanCode
    import javax.ejb.*;
    import java.rmi.*;
    /* BEAN CLASS MUST BE DECLARED AS AN ABSTRACT CLASS */
    abstract public class EJBQLDemoBeanCode implements EntityBean
    /****************** MEMBER FIELDS ARE NOT REQUIERED ****************************
         public int id;
         public String name;
         public double salary;
         public int deptno;
    private EntityContext tx;
    public EJBQLDemoBeanCode(){}
    public EJBQLDemoPk ejbCreate(int id, String name,double salary,int deptno) throws CreateException // throws is a must here
         setId(id);
         setName(name);
         setSalary(salary);
         setDeptno(deptno);
         return null;
    public void ejbPostCreate(int id, String name,double salary,int deptno) { }
    public void ejbActivate() { }
    public void ejbPassivate(){}
    public void setEntityContext(EntityContext etx){ tx = etx; }
    public void unsetEntityContext() {}
    public void ejbLoad() {}
    public void ejbStore() {}
    public void ejbRemove() {}
    public boolean isModified() {          return true;     }
    /****************** MEMBER METHODS ARE DECLARED ABSTRACT ****************************/
    abstract public void setId(int id);               //{this.id=id;}
    abstract public void setName(String name);     //{this.name=name;}
    abstract public void setSalary(double salary);     //{this.salary=salary;}
    abstract public void setDeptno(int deptno);     //{this.deptno=deptno;}
    abstract public int getId();                    //{return id;}
    abstract public String getName();               //{return name;}
    abstract public double getSalary();               //{return salary;}
    abstract public int getDeptno();               //{return deptno;}
    JSPCient
    <%@ page import="javax.ejb.*,javax.naming.*,java.rmi.*,javax.rmi.*,java.util.*" %>
    <%@ page import="EJBQLDemoHomeIFace,EJBQLDemoRemoteIFace" %>
    <%!
    InitialContext c = null;
    Properties p = null;
    EJBQLDemoHomeIFace homref = null;
    EJBQLDemoRemoteIFace remref = null;
    %>
    <%
    p=new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
    p.put(Context.PROVIDER_URL,"jnp://localhost:1099");
    c=new InitialContext(p);
    homref=(EJBQLDemoHomeIFace)c.lookup("EJBQLBean");
    out.println("<h1>Ready....</h1>");
         //CODE TO INSERT A RECORD
         remref=homref.create(104,"DEWANG",5780.0,10);
         out.println("Record Inserted ,...");
         //CODE TO FIND A RECORD
         remref = homref.findById(100);
         out.println("NAME OF THE PERSON : " +remref.getName());
         //CODE TO FIND ALL RECORD
         Iterator i = homref.findByAll().iterator();
         while(i.hasNext())
              remref = (EJBQLDemoRemoteIFace)PortableRemoteObject.narrow(i.next(),EJBQLDemoRemoteIFace.class);
              out.println(remref.getName() + " " + remref.getSalary() );
    %>

    wtf ? what the hell is that ?:-) I wonder how he does it without the EJB QL. Not that I want him to post it.

  • Creation Code EJB

    Dear all,
    is it possible to let Developer studio create the code for calling an ejb automatically?
    the following code is actually always the same and it's not practical to type that code over and over again every time we want to call a method on an EJB...
    InitialContext ctx = new InitialContext();
              TestEJBLocalHome localHome = (TestEJBLocalHome)ctx.lookup("localejbs/TestEJBBean");
              TestEJBLocal bean = localHome.create();
    So it would be nice if there was a way to say to developer studio, this is the bean i want to use, please generate the code so i can call my method on it.
    Kind regards,
    J.

    Joren,
    Almost exactly what you need:
    1. In NW IDE open Window -> Preferences
    2. Navigate to Java -> Editor -> Templates
    Got the idea?
    Valery Silaev
    SaM Solutions
    http://www.sam-solutions.net

  • How to code EJB in Eclipse IDE

    Hello Forum
    I have downloaded eclipse-SDK-3_1.2-win32.zip and installed but I couldnt findout J2EE development in it
    (that how we add session beans, how we configure application server and how we generate entity beans)
    do I need any plugin to work with J2ee in it,
    Please help me - Thank u very much
    - Tahir

    Sorry, this forum is for questions about the javadoc tool for generating documentation, so you might try elsewhere.

  • Error when opening a EJB code

    Hi All,
    When I try to open by ejb code ( ejb.java file) I am getting the following error
    An internal error occurred during: "Resynching JPA model ...".
    IWAE0011E Key already used to access Resource : org.eclipse.wst.common.internal.emfworkbench.EditModelLeastUsedCache@e55d75
    Please help me in this
    Thanks!
    Swarnaprakash

    Hi,
    First check in
    IMG-FA-FA GS - Tax on sales & Purchase
    1. Check the calculation procedure - TAX<Country> E.g. for India - TAXIN
    2. Check whether the country has been assignmed to the calculation procedure
    3. Calculation - Define Tax codes for Sales / Pur - Enter country and enter tax codes (Tax Type: A: Output tax; v-Input Tax) and give Tax percent
    Save
    It should solve ur problem
    <i>Pls. assign points, if useful</i>
    Regards,
    sridevi

  • Error while running EJB Client

    Hi All,
    I have just written a program in EJB for currency conversion. But while running the client , i am getting the following error:
    C:\Java Source Code\EJB>java CalculatorClient
    java.lang.NoSuchMethodError: loadClass0
    at com.sun.corba.ee.internal.util.JDKClassLoader.specialLoadClass(Native
    Method)
    at com.sun.corba.ee.internal.util.JDKClassLoader.loadClass(JDKClassLoade
    r.java:58)
    at com.sun.corba.ee.internal.util.JDKBridge.loadClassM(JDKBridge.java:18
    0)
    at com.sun.corba.ee.internal.util.JDKBridge.loadClass(JDKBridge.java:83)
    at com.sun.corba.ee.internal.javax.rmi.CORBA.Util.loadClass(Util.java:37
    8)
    at javax.rmi.CORBA.Util.loadClass(Unknown Source)
    at javax.rmi.PortableRemoteObject.createDelegateIfSpecified(Unknown Sour
    ce)
    at javax.rmi.PortableRemoteObject.<clinit>(Unknown Source)
    at com.sun.enterprise.naming.SerialContext.getProvider(SerialContext.jav
    a:57)
    etc........
    The files that have been created are in the same folder which are as follows:
    Calculator.java Calculator.class - Remote Interface
    CalculatorHome.java CalculatorHome.class - Home Interface
    CalculatorEJB.java CalculatorEJB.class - EJB class
    ejbClient.jar - Client Jar
    ejb.ear
    The version for J2EE is 1.2.1
    Version for Jdk is 1.4.2
    Operating System - WinXP
    Could somebody pls help?
    Cooljacks

    ... but you did deploy it to an application server, right?

  • How to add environment entry in EJB3 ejb-jar.xml

    Hi,
    Is that a build in way of add environment entries in JDev for EJB 3 beans? For EJB 2 beans you can do that using properties. But the bean properties is not available in EJB 3. Please help.
    Thanks
    Kenny

    Thank you for the reply. But I need a way to enter env-entry value in ejb-jar.xml for EJB 3 in Jdev. In EJB 2, Jdev generate ejb-jar.xml for the bean and also let you add env-entry through bean's properties menu. But in there in no properties menu for EJB 3, also generated ejb-jar.xml is only a empty file doesn't contain any EJB depolyment information. That means you have to code ejb-jar.xml all manually.
    If I am wrong, can someone show me how to do this right?

  • Could not dereference object when running the EJB

    Hi,
    I want to reference my jsp page to EJB but get a "could not dereference object" upon running the jsp with this as it went into the catch exception instead of looking up to the EJB:
    Part of my jsp codes in jspinit( ):
    try {
    objref = initial.lookup("java:comp/env/ejb/MyMusicCart");
    System.out.println("lookup success for ejb/MyMusicCart");
    // a reference to the home interface is shareable
    cartHome = (MusicCartHome)PortableRemoteObject.narrow(objref, MusicCartHome.class);
    System.out.println("created MusicCartHome object");
    } catch (Exception ex) {
    System.out.println("Unexpected Exception: " +ex.getMessage());
    My web.xml
    Code:
    <ejb-ref>
    <ejb-ref-name>ejb/MyMusicCart</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <home>asg.MusicCartEJB.MusicCartHome</home>
    <remote>asg.MusicCartEJB.MusicCart </remote>
    <ejb-link>ejb-jar-ic.jar#MusicCartBean</ejb-link>
    </ejb-ref>
    anyone encounter this problem before? Please help.. I
    I can produce more of my files if you guys feel that is not enough
    Message was edited by:
    [email protected]

    Is the EJB you are referencing part of the same EAR file as your JSP?
    -- Rob
    WLS Blog http://dev2dev.bea.com/blog/rwoollen/

  • Stateless EJB is null using TimerService

    Hi,
    I created a stateless ejb using TimerService to run it in weblogic 10.3. After deploying it, I could not get the ejb instantiated properly. The code is as below.
    Could anyone explain what is missing?
    Thanks in advance.
    //=================================================
    public interface ReconTimer {
    public void createTimer();
    //================================================
    import static javax.ejb.TransactionAttributeType.NOT_SUPPORTED;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import javax.annotation.Resource;
    import javax.ejb.EJB;
    import javax.ejb.Stateless;
    import javax.ejb.Timeout;
    import javax.ejb.Timer;
    import javax.ejb.TimerService;
    import javax.ejb.Local;
    import javax.ejb.TransactionAttribute;
    import javax.ejb.TransactionManagement;
    import javax.ejb.TransactionManagementType;
    @Stateless (name="ReconTimerBean")
    @Local (ReconTimer.class)
    @TransactionManagement(value=TransactionManagementType.BEAN )
    @TransactionAttribute(value=NOT_SUPPORTED)
    public class ReconTimerBean implements ReconTimer {
         private static final Log log = LogFactory.getLog(ReconTimerBean.class);
    @Resource
    TimerService timerService;
    public void createTimer() {
         log.info("Crating timer");
         log.info("timerService [" + timerService + "]");
    Timer timer = timerService.createTimer(20000,
    "Created new timer");
    @Timeout
    public void timeout(Timer timer) {
    log.info("Timeout occurred !!!");
    ========================================
    client code:
    @EJB(beanName="ReconTimerBean")
    ReconTimer timerBean
    if (timerBean != null)
    timerBean.createTimer();
    else log.error ("Timer Bean is null !!!");
    Error is always logged when the bean is deployed.
    ======================================
    weblogic-ejb-jar.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <weblogic-ejb-jar xmlns="http://www.bea.com/ns/weblogic/weblogic-ejb-jar"
         xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd http://www.bea.com/ns/weblogic/weblogic-ejb-jar http://www.bea.com/ns/weblogic/weblogic-ejb-jar/1.0/weblogic-ejb-jar.xsd">
    <weblogic-enterprise-bean>
    <ejb-name>ReconTimerBean</ejb-name>
         <stateless-session-descriptor>
              <pool>          
                   <max-beans-in-free-pool>1</max-beans-in-free-pool>          
                   <initial-beans-in-free-pool>1</initial-beans-in-free-pool>     
              </pool>
         </stateless-session-descriptor>
    <jndi-name>app-recon-bean</jndi-name>
    </weblogic-enterprise-bean>
    </weblogic-ejb-jar>

    Hi Ashley,
    The Dependency injection has some limitations as well…Please referto the following link: (Web Component Classes That Support Annotations)
    http://download.oracle.com/docs/cd/E13222_01/wls/docs100/webapp/annotateservlet.html
    …Which says that DI is not possible from every web component.
    Thanks
    Jay SenSharma
    http://jaysensharma.wordpress.com/ejbs_weblogic/#comment-165  (Dependency Injection Issues)

  • EJB + CORBA problems

    Hi there,
    I've got some code (EJB) which connect
    me to OLAPService on my 9i Oracle server. I deployed it to Oracle AS which
    is istalled on another machine. Then I wrote client application which has to
    connect to OAS and invoke EJB method to connect to OLAPService.
    The connection to EJB was successfully established (of course through a
    CORBA). But when EJB was trying to connect to Oracle9i I got such error :
    javax.naming.NameNotFoundException:
    sess_iiop://<server_ip>:<port>:<sid>/etc/OLAPServer/OLAPServer not found
    I think it something wrong with my OAS enviroment. I have tried to do my best , but still nothing .... ( I am sure that everything else is OK, because I tried to make connection through
    JDBC to relational database and it worked fine).
    When I'm starting EJB's code as client application everything is OK. The
    connection to OLAPService is established every time. When I modyfied code
    for EJB (commenting code responsible for preparing InitailContextEnviroment
    and connecting to OLAPService) everything was OK. So :
    1) I can connect and invoke EJB's method deployed to OAS,
    2) I can connect to Oracle9i OLAPService and use OLAPAPI methods,
    3) I can't do it when I try to connect to OLAPService through the OAS (where
    is EJB)
    client_application (java) ===CORBA===> OAS ( EJB with OLAPAPI) ==CORBA==>
    OLAPService
    This is the EJB's method code ( when it is calling as client application it
    works!!!!):
    import javax.ejb.SessionBean;
    import javax.ejb.SessionContext;
    import org.omg.CORBA.Object;
    import oracle.aurora.jndi.sess_iiop.ServiceCtx;
    import oracle.express.connection.Connection;
    import oracle.express.connection.ConnectionManager;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import java.util.*;
    public String Polaczenie()
    String serviceURL="sess_iiop://<server_ip>:<port>:<sid>";
    String objectName="/etc/OLAPServer/OLAPServer";
    Hashtable env=new Hashtable();
    env.put(Context.URL_PKG_PREFIXES,"oracle.aurora.jndi");
    env.put(Context.SECURITY_PRINCIPAL,<user>);
    env.put(Context.SECURITY_CREDENTIALS,<password>);
    env.put(Context.SECURITY_AUTHENTICATION,ServiceCtx.NON_SSL_LOGIN);
    try
    Context ic=new InitialContext(env);
    org.omg.CORBA.Object
    ServiceStub=(org.omg.CORBA.Object)(ic.lookup(serviceURL+objectName));
    Properties connParams = new Properties();
    connParams.put("UserID",<user>);
    connParams.put("Password",<password>);
    ConnectionManager cm=ConnectionManager.init();
    Connection conn=
    cm.connect((org.omg.CORBA.Object)ServiceStub,connParams);
    conn.close();
    catch(Exception e)
    return "\nError:" + e + "\n";
    return "\nIt works\n";
    This is client's code:
    public static void main(String[] args)
    try {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.evermind.server.rmi.RMIInitialContextFactory");
    env.put(Context.PROVIDER_URL, "ormi://sasza/SerwerEjb");
    env.put(Context.SECURITY_PRINCIPAL, "admin");
    env.put(Context.SECURITY_CREDENTIALS, "oracle");
    Context context = new
    com.evermind.server.rmi.RMIInitialContextFactory().getInitialContext(env);
    Object homeObject = context.lookup("<myEJBName>");
    SerwerEjbHome home = (SerwerEjbHome)
    PortableRemoteObject.narrow(homeObject, pakiet.SerwerEjbHome.class);
    SerwerEjb remote = home.create();
    System.out.println(remote.Polaczenie()); <------------------ there is
    error !!!!!!!!!!!!!!!!!! ------------------>
    catch(Exception e)
    System.err.println("Error: " + e + ":::" + e.getMessage());
    Any idea ??
    Thank you in advance.

    "Taesun, An" <[email protected]> writes:
    Thanks for your concern !Its my code - I should be concerned :)
    I have successfuly tested the sample program that you attached.
    and I have some more questions.Great!
    Q1) Can I use idl files generated by weblogic.ejbc on the other ORB like as
    orbix, etc..?Yes. But the problem is that Orbix is known to have problems with the
    codeset that we send out. For silversword we are doing a GIOP 1.2
    implementation a by-product of which will be that we have to do some
    form of codeset negotiation, so hopefully these issues will be sorted
    in the near future.
    And I know that the Client.cpp program you sent differs from original source
    code in the respects which is including TradeResultFactory and
    TradeResultImpl classes.
    Q2) If so, Do i have to implement the above classes for all of call by value
    parameters or return type ?You have to write some C++ code for any valuetypes that you use. This
    basically means any non-primitive object that is not a remote
    interface and implements serializable.
    I wanna know for the needed classes how to easily get generated or the other
    solutions.I attach the entity bean example I cooked up which shows you how you
    can use C++ macros to take away some of this pain. Note that you cannot make the finder method work with 6.0SP2. This will be fixed in 6.1
    [generic_idl_entity.zip]
    I got error message following as, when i used "-idlFactories" of
    weblogic.ejbc option to generate Factory definition.
    Usage: java weblogic.rmic [options] <classes>...
    option descriptions ,.,........
    option descriptions ,.,........
    ERROR: Error from ejbc: Unrecognized option or flag, -idlFactories
    ERROR: ejbc found errors
    make: *** [ejbc] Error 1Hmm, you are right. It looks like the option didn't get inverted in
    rmic. The attached class file should fix this.
    [IDLGeneratorOptions.class]
    andy

Maybe you are looking for

  • Sharing the same Aperture Library between two Mac's?

    gents does any of you manage to share the same Aperture Library between your iMAC and a MacBook? How can I do it without risking to lose anything or to jeopardize the integrity of my library backup? the idea is to work on Projects while I am on the m

  • How to change movement type 531 for by-product ???

    Hi, While creating production order (CO01), by-product component with negative quantity is automatically assigned movement type 531.  Can anybody tell how this movement type is picked automatically ? How can it be changed  to some other movement type

  • How to go back to the ios 5 in the ipod touch 4g?

    My entire ipod 4g is acting nuts. 1) I open any kind of apps and it crashes. 2) I try to use my camera and it lags.  3) Keyboard lags. 3) My photos are appearing out of focus. 4) I try to log in to itunes and it say "I have entered the wrong password

  • Many Red entries in SM35 ...!!

    Hello , when i execute TA sm35 i found many red entries with status - error. What can be done to resolve them and what can be the reason. And when i click on process Tab it is blank and *In process* Tab it has many entries with last years date and in

  • Regarding BAPI_PO_CREATE1

    Hi Freinds, I am using BAPI_PO_CREATE1 to create a purchase order based on the purchase requisition from ME21n. but I am struck up with the following 2 errors. 1. 'Procurement without material from vendor with plant assignment is not defined'. 2. 'Su