Sample Programs for Middleware

September 19, 2010 at 2:50 pm (Programs) ()

Bank Bean:

http://www.4shared.com/file/MS3O7cYT/Bank_Bean.html

BANK Operations:

http://www.4shared.com/document/7cgKH2qN/BANK_Operations.html

Using BDK:

http://www.4shared.com/document/4FkRONc5/bdk.html

Book Bean:

http://www.4shared.com/file/0-_paXlp/Book_Bean.html

C#  Programs

http://www.4shared.com/document/tViFmNpY/C_programs.html

CORBA Programs:

http://www.4shared.com/document/oMKlkUQH/CORBA_Programs.html

Hello Bean:

http://www.4shared.com/file/FFQzOpo5/Hello_Bean.html

Library:

http://www.4shared.com/document/XMzsABS1/LIB.html

Permalink Leave a Comment

Lecture Slides for Middleware

September 19, 2010 at 2:39 pm (Slides) ()

Click the link

http://www.4shared.com/dir/Veur7v-E/Slides.html

Permalink Leave a Comment

Using BEA Weblogic Server – Demos

September 19, 2010 at 2:35 pm (EJB, Practical) ()

Some Demos using BEA Weblogic Server

http://www.4shared.com/file/jgwM9ERU/Changing_JNDI_Name_of_a_Bean.html

http://www.4shared.com/file/ZBY-fGHa/Creating_a_Connection_Pool_for.html

http://www.4shared.com/file/JTU-bHHp/Creating_a_Data_Source_for_Ent.html

http://www.4shared.com/file/4zWYuLEu/Creating_Bank_JAR_for_Entity_B.html

Permalink Leave a Comment

Stateful Session Bean Lifecycle: PrePassivate

August 9, 2009 at 11:01 pm (JBoss) (, )

File: Employee.java

import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.PostRemove;

@Entity

public class Employee implements java.io.Serializable {
private int id;

private String firstName;

private String lastName;

@Id
@GeneratedValue
public int getId() {
return id;
}

@PostRemove
public void postRemove()
{
System.out.println(“@PostRemove”);
}

public void setId(int id) {
this.id = id;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String first) {
this.firstName = first;
}

public String getLastName() {
return lastName;
}

public void setLastName(String last) {
this.lastName = last;
}
}

File: EmployeeBean.java

import javax.ejb.PrePassivate;
import javax.ejb.Stateful;

@Stateful
public class EmployeeBean implements EmployeeServiceLocal, EmployeeServiceRemote {

public EmployeeBean() {
}
public void doAction(){
System.out.println(“doAction”);

}

@PrePassivate
public void PrePassivate() {
System.out.println(“PrePassivate”);
}
}

File: EmployeeServiceLocal.java

import java.util.Map;

import javax.ejb.Local;

@Local
public interface EmployeeServiceLocal {
public void doAction();
}

File: EmployeeServiceRemote.java

import javax.ejb.Remote;

@Remote
public interface EmployeeServiceRemote {
public void doAction();
}

File: jndi.properties

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost:1099

File: Main.java

import javax.ejb.EJB;
import javax.naming.InitialContext;

public class Main {

public static void main(String[] a) throws Exception {

EmployeeServiceRemote service = null;

// Context compEnv = (Context) new InitialContext().lookup(“java:comp/env”);

// service = (HelloService)new InitialContext().lookup(“java:comp/env/ejb/HelloService”);
service = (EmployeeServiceRemote) new InitialContext().lookup(“EmployeeBean/remote”);

service.doAction();

}

}

Permalink Leave a Comment

EJB Tutorial from JBoss: Stateful Session Bean

August 7, 2009 at 12:09 am (JBoss, Programs) (, )

File: ShoppingCart.java

/*
* JBoss, Home of Professional Open Source.
* Copyright 2006, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.tutorial.stateful.bean;

import java.util.HashMap;
import javax.ejb.Remove;

public interface ShoppingCart
{
void buy(String product, int quantity);

HashMap<String, Integer> getCartContents();

@Remove void checkout();
}

File: ShoppingCartBean.java

/*
* JBoss, Home of Professional Open Source.
* Copyright 2006, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.tutorial.stateful.bean;

import java.io.Serializable;
import java.util.HashMap;
import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.ejb.Remote;

@Stateful
@Remote(ShoppingCart.class)
public class ShoppingCartBean implements ShoppingCart, Serializable
{
private HashMap<String, Integer> cart = new HashMap<String, Integer>();

public void buy(String product, int quantity)
{
if (cart.containsKey(product))
{
int currq = cart.get(product);
currq += quantity;
cart.put(product, currq);
}
else
{
cart.put(product, quantity);
}
}

public HashMap<String, Integer> getCartContents()
{
return cart;
}

@Remove
public void checkout()
{
System.out.println(“To be implemented”);
}
}

File: Client.java

/*
* JBoss, Home of Professional Open Source.
* Copyright 2006, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.tutorial.stateful.client;

import java.util.HashMap;
import javax.naming.InitialContext;
import org.jboss.tutorial.stateful.bean.ShoppingCart;

/**
* Comment
*
* @author <a href=”mailto:bill@jboss.org”>Bill Burke</a>
* @version $Revision: 57207 $
*/
public class Client
{
public static void main(String[] args) throws Exception
{
InitialContext ctx = new InitialContext();
ShoppingCart cart = (ShoppingCart) ctx.lookup(“ShoppingCartBean/remote”);

System.out.println(“Buying 1 memory stick”);
cart.buy(“Memory stick”, 1);
System.out.println(“Buying another memory stick”);
cart.buy(“Memory stick”, 1);

System.out.println(“Buying a laptop”);
cart.buy(“Laptop”, 1);

System.out.println(“Print cart:”);
HashMap<String, Integer> fullCart = cart.getCartContents();
for (String product : fullCart.keySet())
{
System.out.println(fullCart.get(product) + ”     ” + product);
}

System.out.println(“Checkout”);
cart.checkout();

System.out.println(“Should throw an object not found exception by invoking on cart after @Remove method”);
try
{
cart.getCartContents();
}
catch (javax.ejb.EJBNoSuchObjectException e)
{
System.out.println(“Successfully caught no such object exception.”);
}

}
}

Permalink Leave a Comment

EJB Tutorial from JBoss: Entity with Blob data

August 5, 2009 at 9:18 am (JBoss, Programs) (, )

Entity Bean with Blob Data

File: BlobEntity.java

/*
* JBoss, Home of Professional Open Source.
* Copyright 2006, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.tutorial.blob.bean;

import java.io.Serializable;
import java.sql.Blob;
import java.sql.Clob;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;

/**
* Comment
*
* @author <a href=”mailto:bill@jboss.org”>Bill Burke</a>
* @version $Revision: 57207 $
*/
@Entity
public class BlobEntity implements Serializable
{
private long id;
private Blob blobby;
private Clob clobby;

@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
public long getId()
{
return id;
}

public void setId(long id)
{
this.id = id;
}

@Lob @Basic(fetch = FetchType.EAGER)
public Blob getBlobby()
{
return blobby;
}

public void setBlobby(Blob blobby)
{
this.blobby = blobby;
}

@Lob @Basic(fetch = FetchType.EAGER)
public Clob getClobby()
{
return clobby;
}

public void setClobby(Clob clobby)
{
this.clobby = clobby;
}

}

File: LobTester.java

/*
* JBoss, Home of Professional Open Source.
* Copyright 2006, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.tutorial.blob.bean;

import java.util.HashMap;

/**
* Comment
*
* @author <a href=”mailto:bill@jboss.org”>Bill Burke</a>
* @version $Revision: 57207 $
*/
public interface LobTester
{
long create();

HashMap findBlob(long id) throws Exception;

String findClob(long id) throws Exception;

long create2();

BlobEntity2 findBlob2(long id) throws Exception;
}

File: LobTesterBean.java

/*
* JBoss, Home of Professional Open Source.
* Copyright 2006, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.tutorial.blob.bean;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContext;
import org.hibernate.Hibernate;

/**
* Comment
*
* @author <a href=”mailto:bill@jboss.org”>Bill Burke</a>
* @version $Revision: 57207 $
*/
@Stateless
@Remote(LobTester.class)
public class LobTesterBean implements LobTester
{

@PersistenceContext EntityManager manager;

public long create()
{
BlobEntity blob = new BlobEntity();

HashMap map = new HashMap();
map.put(“hello”, “world”);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
{
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(map);
blob.setBlobby(Hibernate.createBlob(baos.toByteArray()));
}
catch (IOException e)
{
throw new RuntimeException(e);
}

String clobby = “This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work”;
blob.setClobby(Hibernate.createClob(clobby));
manager.persist(blob);
return blob.getId();
}

public HashMap findBlob(long id) throws Exception
{
BlobEntity blob = manager.find(BlobEntity.class, id);
ObjectInputStream ois = new ObjectInputStream(blob.getBlobby().getBinaryStream());
return (HashMap) ois.readObject();
}

public String findClob(long id) throws Exception
{
BlobEntity blob = manager.find(BlobEntity.class, id);
return blob.getClobby().getSubString(1, 31);
}

public long create2()
{
BlobEntity2 blob = new BlobEntity2();

HashMap map = new HashMap();
map.put(“hello”, “world”);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
{
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(map);
blob.setBlobby(baos.toByteArray());
}
catch (IOException e)
{
throw new RuntimeException(e);
}

String clobby = “This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work” +
“This is a very long string that will be stored in a java.sql.Clob hopefully.  We’ll see how this works and if it will work”;
blob.setClobby(clobby);
manager.persist(blob);
return blob.getId();
}

public BlobEntity2 findBlob2(long id) throws Exception
{
return manager.find(BlobEntity2.class, id);
}

}

File: BlobEntity2.java

/*
* JBoss, Home of Professional Open Source.
* Copyright 2006, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.tutorial.blob.bean;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;

/**
* comment
*
* @author <a href=”mailto:bill@jboss.org”>Bill Burke</a>
*/
@Entity
public class BlobEntity2 implements Serializable
{
private long id;
private byte[] blobby;
private String clobby;

@Id @GeneratedValue(strategy=GenerationType.AUTO)
public long getId()
{
return id;
}

public void setId(long id)
{
this.id = id;
}

@Lob @Basic(fetch = FetchType.EAGER)
public byte[] getBlobby()
{
return blobby;
}

public void setBlobby(byte[] blobby)
{
this.blobby = blobby;
}

@Lob @Basic(fetch = FetchType.EAGER)
public String getClobby()
{
return clobby;
}

public void setClobby(String clobby)
{
this.clobby = clobby;
}

}

File: Client.java

/*
* JBoss, Home of Professional Open Source.
* Copyright 2006, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.tutorial.blob.client;

import java.util.HashMap;
import javax.naming.InitialContext;
import org.jboss.tutorial.blob.bean.LobTester;
import org.jboss.tutorial.blob.bean.BlobEntity2;

/**
* Comment
*
* @author <a href=”mailto:bill@jboss.org”>Bill Burke</a>
* @version $Revision: 57207 $
*/
public class Client
{
public static void main(String[] args) throws Exception
{
InitialContext ctx = new InitialContext();
LobTester test = (LobTester) ctx.lookup(“LobTesterBean/remote”);
long blobId = test.create();
HashMap map = test.findBlob(blobId);
System.out.println(“is hello in map: ” + map.get(“hello”));
System.out.println(test.findClob(blobId));
System.out.println(“creating and getting a BlobEntity2 that uses byte[] and String instead of Clob/Blob”);
blobId = test.create2();
BlobEntity2 entity = test.findBlob2(blobId);

}
}

Permalink Leave a Comment

Working with Binary Data using EJB

August 5, 2009 at 9:13 am (Programs) ()

// Working with Binary Data in EJB

File: CustomerType.java

public enum CustomerType
{
UNREGISTERED,
REGISTERED,
BIG_SPENDAH
}

File: Employee.java

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
//@Table(name=”EMP”, schema=”HR”)
@Table(name=“EMP”)
public class Employee implements Serializable {
@Id
@Column(name = “EMP_ID”)
private int id;
@Column(name = “COMM”)
private String name;
@Column(name = “SAL”)
private long salary;

private CustomerType customerType;
private Date timeCreated = new Date();
private MyImage picture;

public Employee() {
}

public Employee(int id) {
this.id = id;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public long getSalary() {
return salary;
}

public void setSalary(long salary) {
this.salary = salary;
}

@Enumerated(EnumType.STRING)
public CustomerType getCustomerType() { return customerType; }
public void setCustomerType(CustomerType type) { customerType = type; }

@Temporal(TemporalType.TIME)
public Date getTimeCreated() { return timeCreated; }
public void setTimeCreated(Date time) { timeCreated = time; }

@Lob @Basic(fetch=FetchType.LAZY)
public MyImage getPicture() { return picture; }
public void setPicture(MyImage jpeg) { picture = jpeg; }

public String toString() {
return “Employee id: ” + getId() + ” name: ” + getName() + ” salary: ” + getSalary();
}
}

File: EmployeeService.java

import java.util.Collection;

import javax.ejb.Remove;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless
public class EmployeeService implements EmployeeServiceLocal, EmployeeServiceRemote {
@PersistenceContext(unitName=“EmployeeService”)
EntityManager em;

public EmployeeService() {
}

public Employee createEmployee(Employee emp) {
em.persist(emp);
em.flush();
return emp;
}
public Employee createEmployee(int id, String name, long salary) {
Employee emp = new Employee(id);
emp.setName(name);
emp.setSalary(salary);

em.persist(emp);
em.flush();
return emp;
}

public void removeEmployee(int id) {
Employee emp = findEmployee(id);
if (emp != null) {
em.remove(emp);
}
}

public Employee raiseEmployeeSalary(int id, long raise) {
Employee emp = em.find(Employee.class, id);
if (emp != null) {
emp.setSalary(emp.getSalary() + raise);
}
return emp;
}

public Employee findEmployee(int id) {
return em.find(Employee.class, id);
}

public Collection<Employee> findAllEmployees() {
Query query = em.createQuery(“SELECT e FROM Employee e”);
return (Collection<Employee>) query.getResultList();
}

public void doAction(){
}

@Remove
public void remove()
{
System.out.println(“removed”);
}
}

File: EmployeeServiceLocal.java

import java.util.Collection;

import javax.ejb.Local;

@Local
public interface EmployeeServiceLocal {
public void doAction();

public Employee createEmployee(int id, String name, long salary) ;
public Employee createEmployee(Employee emp) ;
public void removeEmployee(int id);
public Employee raiseEmployeeSalary(int id, long raise) ;
public Employee findEmployee(int id);
public Collection<Employee> findAllEmployees() ;
}

File: EmployeeServiceRemote.java

import java.util.Collection;

import javax.ejb.Remote;

@Remote
public interface EmployeeServiceRemote{
public void doAction();
public Employee createEmployee(int id, String name, long salary) ;
public Employee createEmployee(Employee emp) ;
public void removeEmployee(int id);
public Employee raiseEmployeeSalary(int id, long raise) ;
public Employee findEmployee(int id);
public Collection<Employee> findAllEmployees() ;

}

File: MyImage.java

public class MyImage implements java.io.Serializable
{
public MyImage() {}
}

File: Main.java

import java.util.Collection;

import javax.naming.InitialContext;

public class Main {

public static void main(String[] a) throws Exception {

EmployeeServiceRemote service = null;

// Context compEnv = (Context) new InitialContext().lookup(“java:comp/env”);

// service = (HelloService)new InitialContext().lookup(“java:comp/env/ejb/HelloService”);
service = (EmployeeServiceRemote) new InitialContext().lookup(“EmployeeService/remote”);



service.createEmployee(158, “AAA”, 45000);
service.createEmployee(159, “AAA”, 45000);

Employee emp = new Employee();
emp.setId(160);
emp.setCustomerType(CustomerType.BIG_SPENDAH);
MyImage oneUglyDude = new MyImage();
emp.setPicture(oneUglyDude);

service.createEmployee(emp);
Employee emp1 = service.findEmployee(160);
System.out.println(emp1);

Collection<Employee> list = service.findAllEmployees();

System.out.println(list);
}

}

File: jndi.properties

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost:1099

Permalink Leave a Comment

What is Moniker?

May 12, 2008 at 10:52 pm (COM, Technical Questions, Two Marks) ()

A moniker is an object (or component ) in Microsoft’s Component Object Model ( COM ) that refers to a specific instance of another object. Monikers originated in Microsoft’s Object Linking and Embedding ( OLE ) technology as a means of linking objects.

A moniker may refer to any single object, or may be a composite made of a number of separate monikers, each of which refers to a particular instantiation of an object.

The moniker is sometimes referred to as an “intelligent name,” because it retains information about how to create, initialize , and bind to a single instance of an object. Once created, the moniker holds this information, as well as information about the object’s states in that specific instantiation.

Since COM is not language-specific, a moniker can be used with any programming language. The programmer gives the instantiation of the object a name. By calling the moniker in code, a programmer can refer to the same object with the same states.

If, for example, a moniker is created for a query , the programmer can reuse the query simply by calling the moniker in the code, because the moniker itself has the necessary information.

Permalink Leave a Comment

EJB – Two Marks Q & A

May 2, 2008 at 9:57 am (EJB, Technical Questions, Two Marks) (, )

What is EJB?

EJB stands for Enterprise Java Bean and is widely-adopted server side component architecture for J2EE. It enables rapid development of mission-critical application that are versatile, reusable and portable across middleware while protecting IT investment and preventing vendor lock-in.

What is the difference between EJB and Java beans?

EJB is a specification for J2EE server, not a product; Java beans may be a graphical component in IDE.

What is EJB role in J2EE?

EJB technology is the core of J2EE. It enables developers to write reusable and portable server-side business logic for the J2EE platform.

What are the key features of the EJB technology?

1. EJB components are server-side components written entirely in the Java programming language

2. EJB components contain business logic only – no system-level programming & services, such as transactions, security, life-cycle, threading, persistence, etc. are automatically managed for the EJB component by the EJB server.

3. EJB architecture is inherently transactional, distributed, portable multi-tier, scalable and secure.

4. EJB components are fully portable across any EJB server and any OS.

5. EJB architecture is wire-protocol neutral–any protocol can be utilized like IIOP,JRMP, HTTP, DCOM,etc.

What are the key benefits of the EJB technology?

1. Rapid application development

2. Broad industry adoption

3. Application portability

4. Protection of IT investment

How many enterprise beans?

There are three kinds of enterprise beans:

1. session beans,

2. entity beans, and

3. Message-driven beans.

What is message-driven bean?

A message-driven bean combines features of a session bean and a Java Message Service (JMS) message listener, allowing a business component to receive JMS. A message-driven bean enables asynchronous clients to access the business logic in the EJB tier.

What are Entity Bean and Session Bean?

Entity Bean is a Java class which implements an Enterprise Bean interface and provides the implementation of the business methods. There are two types: Container Managed Persistence (CMP) and Bean-Managed Persistence (BMP).

Session Bean is used to represent a workflow on behalf of a client. There are two types: Stateless and Stateful. Stateless bean is the simplest bean. It doesn’t maintain any conversational state with clients between method invocations. Stateful bean maintains state between invocations.

What is Session Bean? Explain

A session bean is a non-persistent object that implements some business logic running on the server. One way to think of a session object is as a logical extension of the client program that runs on the server.


Session beans are used to manage the interactions of entity and other session beans,access resources, and generally perform tasks on behalf of the client.


There are two basic kinds of session bean: stateless and stateful.


Stateless session beans are made up of business methods that behave like procedures; they operate only on the arguments passed to them when they are invoked. Stateless beans are called stateless because they are transient; they do not maintain business state between method invocations. Each invocation of a stateless business method is independent from previous invocations. Because stateless session beans are stateless, they are easier for the EJB container to manage, so they tend to process requests faster and use fewer resources.


Stateful session beans encapsulate business logic and state specific to a client. Stateful beans are called “stateful” because they do maintain business state between method invocations, held in memory and not persistent. Unlike stateless session beans, clients do not share stateful beans. When a client creates a stateful bean, that bean instance is dedicated to service only that client. This makes it possible to maintain conversational state, which is business state that can be shared by methods in the same stateful bean.

What is the difference between session and entity beans?

An entity bean represents persistent global data from the database; a session bean represents transient user-specific data that will die when the user disconnects (ends his session). Generally, the session beans implement business methods (e.g. Bank.transferFunds) that call entity beans (e.g. Account.deposit, Account.withdraw)

What are the services provided by container?

Container services are totally depends upon the “vendor implementation”. But more or less most of the vendors suppots the basic services like,

1. LifeCycle Management – It is Automatic.

2. Session Management – it is used by Developer coded callback methods…

3. Transaction Management – it is used by configuring deployment descriptor (DD).

4. Security management – it is used by configuring deployment descriptor (DD).

The other services, if any will be in advanced versions, and depends on Vendor specific.

What is Deployment descriptor?

A deployment descriptor is an XML file packaged with the enterprise beans in an EJB JAR file or an EAR file. It contains metadata describing the contents and structure of the enterprise beans, and runtime transaction and security information for the EJB container.

How many EJB Objects are created for a Bean?

For a Session bean – one EJB object for one bean instance.

For entity bean – it depends , if two users are accessing one row at time then one EJB object is used for both the beans other wise for each bean one EJB object.

What is re-entrant. Is session beans reentrant. Is entity beans reentrant?
If we define the entity bean as being reentrant, multiple clients can connect to the Entity bean & execute methods within the entity bean concurrently. Container takes care of synchronization. If we define the entity bean as non-reentrant and many clients connect to it concurrently to execute a method, exception is thrown

What is EJB container?

An EJB container is a run-time environment that manages one or more enterprise beans. The EJB container manages the life cycles of enterprise bean objects, coordinates distributed transactions, and implements object security. Generally, each EJB container is provided by an EJB server and contains a set of enterprise beans that run on the server.

What is EJB server?

An EJB server is a high-level process or application that provides a run-time environment to support the execution of server applications that use enterprise beans. An EJB server provides a JNDI-accessible naming service, manages and coordinates the allocation of resources to client applications, provides access to system resources, and provides a transaction service. An EJB server could be provided by, for example, a database or application server.

What is the difference between ejbCreate() and ejbPostCreate?

The purpose of ejbPostCreate() is to perform clean-up database operations after SQL INSERTs (which occur when ejbCreate() is called) when working with CMP entity beans. ejbCreate() is called before database INSERT operations. You need to use ejbPostCreate() to define operations, like set a flag, after INSERT completes successfully.

Why does EJB needs two interfaces(Home and Remote Interface)

There is a pure division of roles between the two .
Home Interface is the way to communicate with the container which is responsible for creating , locating and removing beans and Remote Interface is the link to the bean that allows acces to all methods and members.

What is the difference between a Server, a Container, and a Connector?

An EJB server is an application, usually a product such as BEA WebLogic, that provides (or should provide) for concurrent client connections and manages system resources such as threads, processes, memory, database connections, network connections, etc. An EJB container runs inside (or within) an EJB server, and provides deployed EJB beans with transaction and security management, etc. The EJB container insulates an EJB bean from the specifics of an underlying EJB server by providing a simple, standard API between the EJB bean and its container. A Connector provides the ability for any Enterprise Information System (EIS) to plug into any EJB server which supports the Connector architecture. See Sun’s J2EE Connectors for more in-depth information on Connectors.

Why is ejbFindByPrimaryKey mandatory?

An Entity Bean represents persistent data that is stored outside of the EJB Container/Server. The ejbFindByPrimaryKey is a method used to locate and load an Entity Bean into the container, similar to a SELECT statement in SQL. By making this method mandatory, the client programmer can be assured that if they have the primary key of the Entity Bean, then they can retrieve the bean without having to create a new bean each time – which would mean creating duplications of persistent data and break the integrity of EJB.

What is the default transaction attribute for an EJB?

There is no default transaction attribute for an EJB. Section 11.5 of EJB v1.1 spec says that the deployer must specify a value for the transaction attribute for those methods having container managed transaction. In WebLogic, the default transaction attribute for EJB is SUPPORTS.

What is software architecture of EJB?

Session and Entity EJBs consist of 4 and 5 parts respetively:

1. A remote interface (a client interacts with it),

2. A home interface (used for creating objects and for declaring business methods),

3. A bean object (an object, which actually performs business logic and EJB-specific operations).

4. A deployment descriptor (an XML file containing all information required for maintaining the EJB) or a set of deployment descriptors (if you are using some container-specific features).

5. A Primary Key class – is only Entity bean specific.

What is an EJB Context?

EJBContext is an interface that is implemented by the container, and it is also a part of the bean-container contract. Entity beans use a subclass of EJBContext called EntityContext. Session beans use a subclass called SessionContext. These EJBContext objects provide the bean class with information about its container, the client using the bean and the bean itself. They also provide other functions.

Permalink Leave a Comment

EJB – Interview Questions & Answers

May 2, 2008 at 9:54 am (EJB, Technical Questions) (, )

What is session Facade?

Session Facade is a design pattern to access the Entity bean through local interface than accessing directly. It increases the performance over the network. In this case we call session bean which on turn call entity bean.

What technologies are included in J2EE?

The main technologies in J2EE are: Enterprise JavaBeansTM (EJBsTM), JavaServer PagesTM (JSPsTM), Java Servlets, the Java Naming and Directory InterfaceTM (JNDITM), the Java Transaction API (JTA), CORBA, and the JDBCTM data access API.

What is EJB role in J2EE?

EJB technology is the core of J2EE. It enables developers to write reusable and portable server-side business logic for the J2EE platform.

What is Enterprise JavaBeans (EJB) container?

It manages the execution of enterprise beans for J2EE applications.
Enterprise beans and their container run on the J2EE server.

What is the new basic requirement for a CMP entity bean class in 2.0 from that of ejb 1.1?

It must be abstract class. The container extends it and implements methods which are required for managing the relationships

What’s new in the EJB 2.0 specification?

Following are some of the main features supported in EJB 2.0:

1. Integration of EJB with JMS,

2. Message Driven Beans,

3. Implement additional Business methods in Home interface which are not specific for bean instance, EJB QL.

How can I access EJB from ASP?

We can use the Java 2 Platform, Enterprise Edition Client Access Services (J2EETM CAS) COM Bridge 1.0, currently downloadable from Sun

How EJB Invocation happens?

Step 1: Retrieve Home Object reference from Naming Service via JNDI.

step 2: Return Home Object reference to the client.

step 3: Create me a new EJB Object through Home Object interface.

step 4: Create EJB Object from the Ejb Object

step 5: Return EJB Object reference to the client.

step 6: Invoke business method using EJB Object reference.

step 7: Delegate request to Bean (Enterprise Bean).

What is the relationship between local interfaces and container-managed relationships?
Entity beans that have container-managed relationships with other entity beans, must be accessed in the same local scope as those related beans, and therefore typically provide a local client view. In order to be the target of a container-managed relationship, an entity bean with container-managed persistence must provide a local interface.

Are enterprise beans allowed to use Thread.sleep()?

Enterprise beans make use of the services provided by the EJB container, such as life-cycle management. To avoid conflicts with these services, enterprise beans are restricted from performing certain operations: Managing or synchronizing threads

What are Local Interfaces? Describe.

EJB was originally designed around remote invocation using the Java Remote Method Invocation (RMI) mechanism, and later extended to support to standard CORBA transport for these calls using RMI/IIOP. This design allowed for maximum flexibility in developing applications without consideration for the deployment scenario, and was a strong feature in support of a goal of component reuse in J2EE. Many developers are using EJBs locally, that is, some or all of their EJB calls are between beans in a single container. With this feedback in mind, the EJB 2.0 expert group has created a local interface mechanism. The local interface may be defined for a bean during development, to allow streamlined calls to the bean if a caller is in the same container. This does not involve the overhead involved with RMI like marshalling etc. This facility will thus improve the performance of applications in which co-location is planned. Local interfaces also provide the foundation for container-managed relationships among entity beans with container-managed persistence.

What are transaction isolation levels in EJB?

1. Transaction_read_uncommitted- Allows a method to read uncommitted data from a DB(fast but not wise).

2. Transaction_read_committed- Guarantees that the data you are getting has been committed.

3. Transaction_repeatable_read – Guarantees that all reads of the database will be the same during the transaction (good for read and update operations).

4. Transaction_serializable- All the transactions for resource are performed serial.

What is the difference between Container-Managed Persistent (CMP) bean and Bean-Managed Persistent(BMP) ?

Container-managed persistence beans are the simplest for the bean developer to create and the most difficult for the EJB server to support. This is because all the logic for synchronizing the bean’s state with the database is handled automatically by the container. This means that the bean developer doesn’t need to write any data access logic, while the EJB server is supposed to take care of all the persistence needs automatically. With CMP, the container manages the persistence of the entity bean. A CMP bean developer doesn’t need to worry about JDBC code and transactions, because the Container performs database calls and transaction management instead of the programmer. Vendor tools are used to map the entity fields to the database and absolutely no database access code is written in the bean class. All table mapping is specified in the deployment descriptor. Otherwise, a BMP bean developer takes the load of linking an application and a database on his shoulders.


The bean-managed persistence (BMP) enterprise bean manages synchronizing its state with the database as directed by the container. The bean uses a database API to read and write its fields to the database, but the container tells it when to do each synchronization operation and manages the transactions for the bean automatically. Bean-managed persistence gives the bean developer the flexibility to perform persistence operations that are too complicated for the container or to use a data source that is not supported by the container.BMP beans are not 100% database-independent, because they may contain database-specific code, but CMP beans are unable to perform complicated DML (data manipulation language) statements. EJB 2.0 specification introduced some new ways of querying database (by using the EJB QL – query language).

What is bean managed transaction?

If a developer doesn’t want a Container to manage transactions, it’s possible to implement all database operations manually by writing the appropriate JDBC code. This often leads to productivity increase, but it makes an Entity Bean incompatible with some databases and it enlarges the amount of code to be written. All transaction management is explicitly performed by a developer.

What are transaction attributes?

The transaction attribute specifies how the Container must manage transactions for a method when a client invokes the method via the enterprise bean’s home or component interface or when the method is invoked as the result of the arrival of a JMS message. (Sun’s EJB Specification) Below is a list of transactional attributes:

1. NotSupported – transaction context is unspecified.

2. Required – bean’s method invocation is made within a transactional context. If a client is not associated with a transaction, a new transaction is invoked automatically.

3. Supports – if a transactional context exists, a Container acts like the transaction attribute is Required, else – like NotSupported.

4. RequiresNew – a method is invoked in a new transaction context.

5. Mandatory – if a transactional context exists, a Container acts like the transaction attribute is Required, else it throws a javax.ejb.TransactionRequiredException.

6. Never – a method executes only if no transaction context is specified.

What is the difference between Message Driven Beans and Stateless Session beans?

In several ways, the dynamic creation and allocation of message-driven bean instances mimics the behavior of stateless session EJB instances, which exist only for the duration of a particular method call. However, message-driven beans are different from stateless session EJBs (and other types of EJBs) in several significant ways: Message-driven beans process multiple JMS messages asynchronously, rather than processing a serialized sequence of method calls. Message-driven beans have no home or remote interface, and therefore cannot be directly accessed by internal or external clients. Clients interact with message-driven beans only indirectly, by sending a message to a JMS Queue or Topic. Only the container directly interacts with a message-driven bean by creating bean instances and passing JMS messages to those instances as necessary. The Container maintains the entire lifecycle of a message-driven bean; instances cannot be created or removed as a result of client requests or other API calls.


Permalink 1 Comment

Next page »

Follow

Get every new post delivered to your Inbox.