All pastes #170249 Raw Edit

Unnamed

public text v1 · immutable
·published 2006-09-14 13:58 UTC
rendered paste body
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<hibernate.Ejendomme> søgEjendomme(String søgeKriterie) {
		Session session = test.HibernateSessionFactory.getSession();
			Query q = session.createQuery("from Ejendomme "+søgeKriterie);		
		return new ArrayList<hibernate.Ejendomme>(q.list());
	}
	
	public ArrayList<hibernate.Klienter> søgKlient(String søgeKriterie) {
		Session session = test.HibernateSessionFactory.getSession();
		Query q = session.createQuery("from Klienter k");		
	return new ArrayList<hibernate.Klienter>(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<hibernate.Lande> getLande() throws RemoteException {
		LandeDAO landeDao = new LandeDAO();

		List findAll = landeDao.findAll();
		return new ArrayList<hibernate.Lande>( findAll );
	}


	
	public ArrayList<hibernate.EjendomsTyper> getEjendomsTyper(boolean returnOnlyInvesteringsEjendomme,	boolean returnOnlyBrugerEjendomme) throws RemoteException {
		EjendomsTyperDAO ejendomsTyperDao = new EjendomsTyperDAO();

		if (returnOnlyBrugerEjendomme && returnOnlyInvesteringsEjendomme) {
			return  new ArrayList<hibernate.EjendomsTyper>(ejendomsTyperDao.findAll());
		}

		if (returnOnlyBrugerEjendomme) {
			return  new ArrayList<hibernate.EjendomsTyper>(ejendomsTyperDao.findByBrugerEjendom(true));
		}
		if (returnOnlyInvesteringsEjendomme) {
			return   new ArrayList<hibernate.EjendomsTyper>(ejendomsTyperDao.findByBrugerEjendom(false));
		}

		return   new ArrayList<hibernate.EjendomsTyper>();
	}


	public ArrayList<Maeglere> getMaeglere() throws RemoteException {
		MaeglereDAO maeglereDAO = new MaeglereDAO();
		return new  ArrayList<Maeglere>(maeglereDAO.findAll());
	}

	public ArrayList<KlientProfil> getKlientProfil() throws RemoteException {
		KlientProfilDAO klientProfilDao = new KlientProfilDAO();
		return new ArrayList<KlientProfil>( klientProfilDao.findAll());
	}


	public ArrayList<EjendomsStatus> getEjendomsStatus() throws RemoteException {
		EjendomsStatusDAO ejendomsStatusDao = new EjendomsStatusDAO();
		return new ArrayList<EjendomsStatus>( ejendomsStatusDao.findAll());
	}


}