package ejava.examples.ejb.session.client;

import ejava.examples.ejb.session.bean.QueryLocalHome;
import ejava.examples.ejb.session.bean.QueryLocal;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Collection;

public class QueryAccessor {
   QueryLocal query_;

   public QueryAccessor() throws Exception {
      this(new InitialContext(), "java:comp/env/ejb/QueryLocalHome");
   }

   public QueryAccessor(Context jndi, String name) throws Exception {
      Object object = jndi.lookup(name);
      QueryLocalHome tHome = (QueryLocalHome)object;
      query_ = tHome.create();
   }
   public void close() {
       try {
          if (query_ != null) query_.remove();
       }
       catch (Exception ignored) {}
   }

   public Collection getAllAccounts(int maxrows) {
      return query_.getAllAccounts(maxrows);
   }
   public Collection getNext(int maxrows) {
      return query_.getNext(maxrows);
   }
}

