package test.ejb; import hibernate.Ejendomme; import hibernate.EjendommeDAO; import hibernate.EjendomsStatus; import hibernate.EjendomsStatusDAO; import hibernate.EjendomsTyper; import hibernate.EjendomsTyperDAO; import hibernate.KlientProfil; import hibernate.KlientProfilDAO; import hibernate.Klienter; import hibernate.KlienterDAO; import hibernate.LandeDAO; import hibernate.Maeglere; import hibernate.MaeglereDAO; import java.rmi.RemoteException; import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.ejb.EJBException; import javax.ejb.EJBHome; import javax.ejb.EJBObject; import javax.ejb.Handle; import javax.ejb.RemoveException; import javax.ejb.SessionBean; import javax.ejb.SessionContext; import org.hibernate.Hibernate; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; /** * XDoclet-based session bean. The class must be declared public according to * the EJB specification. * * To generate the EJB related files to this EJB: - Add Standard EJB module to * XDoclet project properties - Customize XDoclet configuration for your * appserver - Run XDoclet * * Below are the xdoclet-related tags needed for this EJB. * * @e jb.bean name="Test" display-name="Name for Test" description="Description * for Test" jndi-name="ejb/Test" type="Stateless" view-type="remote" */ public class FacadeBean implements SessionBean, FacadeBeanRemote { /** * */ private static final long serialVersionUID = 1L; /** The session context */ private SessionContext context; public void ejbCreate() { // TODO implement ejbCreate if necessary, acquire resources // This method has access to the JNDI context so resource aquisition // spanning all methods can be performed here such as home interfaces // and data sources. } public FacadeBean() { // TODO Auto-generated constructor stub } public void ejbActivate() throws EJBException, RemoteException { // TODO Auto-generated method stub } public void ejbPassivate() throws EJBException, RemoteException { // TODO Auto-generated method stub } public void ejbRemove() throws EJBException, RemoteException { // TODO Auto-generated method stub } /** * Set the associated session context. The container calls this method after * the instance creation. * * The enterprise bean instance should store the reference to the context * object in an instance variable. * * This method is called with no transaction context. * * @throws EJBException * Thrown if method fails due to system-level error. */ public void setSessionContext(SessionContext newContext) throws EJBException { context = newContext; } /** * An example business method * * @ejb.interface-method view-type = "remote" * * @throws EJBException * Thrown if method fails due to system-level error. */ public EJBHome getEJBHome() throws RemoteException { // TODO Auto-generated method stub return null; } public Handle getHandle() throws RemoteException { // TODO Auto-generated method stub return null; } public Object getPrimaryKey() throws RemoteException { // TODO Auto-generated method stub return null; } public boolean isIdentical(EJBObject arg0) throws RemoteException { // TODO Auto-generated method stub return false; } public void remove() throws RemoteException, RemoveException { // TODO Auto-generated method stub } public void GemKlient(Klienter klient) throws RemoteException { Session session = test.HibernateSessionFactory.getSession(); Transaction currTrans = session.beginTransaction(); session.save(klient); currTrans.commit(); } public void gemEjendom(Ejendomme ejendom) throws RemoteException { Session session = test.HibernateSessionFactory.getSession(); Transaction currTrans = session.beginTransaction(); session.save(ejendom); currTrans.commit(); } public int opretEjendom() throws RemoteException { Session session = test.HibernateSessionFactory.getSession(); Transaction currTrans = session.beginTransaction(); hibernate.Ejendomme currEjendom = new hibernate.Ejendomme(); session.save(currEjendom); currTrans.commit(); return currEjendom.getId(); } public int opretKlient() throws RemoteException { Session session = test.HibernateSessionFactory.getSession(); Transaction currTrans = session.beginTransaction(); hibernate.Klienter currKlient = new hibernate.Klienter(); session.save(currKlient); currTrans.commit(); return currKlient.getId(); } public void sletEjendom(int id) throws RemoteException { Session session = test.HibernateSessionFactory.getSession(); Transaction currTrans = session.beginTransaction(); Ejendomme ejd = (Ejendomme) session.load(Ejendomme.class, id); session.delete(ejd); currTrans.commit(); } public void sletKlient(int id) throws RemoteException { KlienterDAO currKlienterDAO = new KlienterDAO(); currKlienterDAO.delete(currKlienterDAO.findById(id)); } public ArrayList søgEjendomme(String søgeKriterie) { Session session = test.HibernateSessionFactory.getSession(); Query q = session.createQuery("from Ejendomme "+søgeKriterie); return new ArrayList(q.list()); } public ArrayList søgKlient(String søgeKriterie) { Session session = test.HibernateSessionFactory.getSession(); Query q = session.createQuery("from Klienter k"); return new ArrayList(q.list()); } public Ejendomme ÅbenEjendom(int id) throws RemoteException { EjendommeDAO ejdDao = new EjendommeDAO(); return ejdDao.findById(id); } public Klienter ÅbenKlient(int id) throws RemoteException { KlienterDAO klientDao = new KlienterDAO(); return klientDao.findById(id); } public ArrayList getLande() throws RemoteException { LandeDAO landeDao = new LandeDAO(); List findAll = landeDao.findAll(); return new ArrayList( findAll ); } public ArrayList getEjendomsTyper(boolean returnOnlyInvesteringsEjendomme, boolean returnOnlyBrugerEjendomme) throws RemoteException { EjendomsTyperDAO ejendomsTyperDao = new EjendomsTyperDAO(); if (returnOnlyBrugerEjendomme && returnOnlyInvesteringsEjendomme) { return new ArrayList(ejendomsTyperDao.findAll()); } if (returnOnlyBrugerEjendomme) { return new ArrayList(ejendomsTyperDao.findByBrugerEjendom(true)); } if (returnOnlyInvesteringsEjendomme) { return new ArrayList(ejendomsTyperDao.findByBrugerEjendom(false)); } return new ArrayList(); } public ArrayList getMaeglere() throws RemoteException { MaeglereDAO maeglereDAO = new MaeglereDAO(); return new ArrayList(maeglereDAO.findAll()); } public ArrayList getKlientProfil() throws RemoteException { KlientProfilDAO klientProfilDao = new KlientProfilDAO(); return new ArrayList( klientProfilDao.findAll()); } public ArrayList getEjendomsStatus() throws RemoteException { EjendomsStatusDAO ejendomsStatusDao = new EjendomsStatusDAO(); return new ArrayList( ejendomsStatusDao.findAll()); } }