1 package org.acme.movie; 2 3 import javax.ejb.CreateException ; 4 import javax.ejb.FinderException ; 5 import javax.ejb.RemoveException ; 6 import javax.ejb.EJBException ; 7 import javax.naming.InitialContext ; 8 import javax.naming.NamingException ; 9 import java.util.Date ; 10 import java.util.Collection ; 11 import java.util.Properties ; 12 import java.text.SimpleDateFormat ; 13 14 24 public interface MovieEntity extends javax.ejb.EJBLocalObject , Movie { 25 26 27 public static final String NAME = "MovieEJBLocal"; 28 public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat ("yyyy.MM.dd"); 29 30 44 public static final MovieHome Home = new MovieHome(){ 45 private MovieHome home; 46 private MovieHome home(){ 47 if (home == null){ 48 home = lookup(); 49 } 50 return home; 51 } 52 private MovieHome lookup() { 53 try { 54 Properties p = new Properties (System.getProperties()); 55 p.put("java.naming.factory.initial", "org.openejb.client.LocalInitialContextFactory"); 56 InitialContext initialContext = new InitialContext (p); 57 return (MovieHome) initialContext.lookup(NAME); 58 } catch (NamingException e) { 59 throw (IllegalStateException ) new IllegalStateException (NAME + " cannot be retrieved from JNDI.").initCause(e); 60 } 61 } 62 63 public MovieEntity create(String title, String director, String genre, int rating, Date releaseDate) throws CreateException { 64 return home().create(title, director, genre, rating, releaseDate); 65 } 66 67 public Collection findByTitle(String title) throws FinderException { 68 return home().findByTitle(title); 69 } 70 71 public Collection findByDirector(String director) throws FinderException { 72 return home().findByDirector(director); 73 } 74 75 public Collection findByGenre(String genre) throws FinderException { 76 return home().findByGenre(genre); 77 } 78 79 public MovieEntity findByPrimaryKey(Integer key) throws FinderException { 80 return home().findByPrimaryKey(key); 81 } 82 83 public Collection findAllMovies() throws FinderException { 84 return home().findAllMovies(); 85 } 86 87 public void remove(Object o) throws RemoveException , EJBException { 88 home().remove(o); 89 } 90 }; 91 92 } 93 | Popular Tags |