View RSS Feed

EJB

Business Methods

Rate this Entry
by
EJB
, 01-02-2012 at 06:06 PM (1074 Views)
Business method or business process is the collection of structured and related tasks which create a certain product for specified customers. Let us now code the business methods for addition/deletion and also for the retrieval of the Book Entity Beans objects.

Java Code: This is an example of business methods
import java.util.Collection; 
import javax.ejb.Stateless; 
import javax.persistence.EntityManager; 
import javax.persistence.PersistenceContext; 
import com.visualbuilder.entity.Book; 
@Stateless 
public class Library implements LibraryLocal { 
@PersistenceContext 
protected EntityManager em; 
public void addBook(String title, String author) {
	 Book book = new Book(title, author); 
	em.persist(book); 
}
         public void addBook(Book book) { 
	em.persist(book); 
}
 ublic void deleteBook(Integer id) { 
	Book book = em.find(Book.class, new Integer(id)); 
	em.remove(book);
}
public Collection<Book> getBooks() { 
	Collection<Book> results = em.createQuery("from Book b").getResultList(); 
	return results; 
}
}

Submit "Business Methods" to Facebook Submit "Business Methods" to Digg Submit "Business Methods" to del.icio.us Submit "Business Methods" to StumbleUpon Submit "Business Methods" to Google

Updated 01-14-2012 at 06:17 PM by EJB

Categories
Tutorial

Comments