package org.objectweb.jonas.jtests.beans.relation.tier;

import javax.ejb.SessionContext;
import javax.naming.NamingException;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.ejb.EJBException;
import javax.ejb.RemoveException;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class TestFacadeBean {

    private SessionContext _ctx;

    protected int nbMaxLignes = 20;

    // Tier entity bean methods
    protected TierLocalHome getTierLocalHome() throws NamingException {
        return TierUtil.getLocalHome();
    }

    public TierValue create(TierValue value) throws CreateException, RemoteException, FinderException, NamingException {
        return getTierLocalHome().create(value).getTierValue();
    }

    public TierValue findTierByKey(java.lang.Integer pk) throws FinderException, RemoteException, NamingException {
        return getTierLocalHome().findByPrimaryKey(pk).getTierValue();
    }

    public TiephyValue getTiephyValueOfTier(java.lang.Integer pk) throws FinderException, NamingException,
            RemoteException {
        return getTierLocalHome().findByPrimaryKey(pk).getTiephyValue();
    }

    public TiemorValue getTiemorValueOfTier(java.lang.Integer pk) throws FinderException, NamingException,
            RemoteException {
        return getTierLocalHome().findByPrimaryKey(pk).getTiemorValue();
    }

    public void update(TierValue value) throws FinderException, NamingException, RemoteException {
        getTierLocalHome().findByPrimaryKey(value.getPrimaryKey()).update(value);
    }

    public java.util.Collection tierfindByTiemorOrTiephy(java.lang.String nom) throws FinderException, RemoteException,
            NamingException {
        Collection col = getTierLocalHome().findByTiemorOrTiephy(nom);
        Iterator ite = col.iterator();
        TierLocal tl = null;
        ArrayList al = new ArrayList();
        int page = 0;
        while (ite.hasNext()) {
            tl = (TierLocal) ite.next();
            if (page < nbMaxLignes)
                al.add(tl.getTierValue());
            else
                al.add(tl.getPrimaryKey());
            page++;
        }
        return al;
    }

    public void removeTier(java.lang.Integer pk) throws FinderException, NamingException, EJBException, RemoveException {
        try {
            getTierLocalHome().findByPrimaryKey(pk).remove();
        } catch (EJBException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (RemoveException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FinderException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public java.util.Collection getTierValueWithCollectionPK(Collection pks) throws RemoteException, FinderException,
            NamingException {
        ArrayList al = new ArrayList();
        Iterator ite = pks.iterator();
        java.lang.Integer pk = null;
        while (ite.hasNext()) {
            pk = (java.lang.Integer) ite.next();
            al.add(findTierByKey(pk));
        }
        return al;
    }

    public void ejbCreate() throws CreateException {
    }

    public void setSessionContext(SessionContext ctx) {
        _ctx = ctx;
    }

    public void ejbActivate() {
    }

    public void ejbPassivate() {
    }

    public void unsetSessionContext() {
    }

    public void ejbRemove() {
    }

}