FileDocCategorySizeDatePackage
Client_61.javaAPI DocExample2264Tue Mar 05 05:00:18 GMT 2002com.titan.clients

Client_61

public class Client_61 extends Object
Example which creates and removes CustomerEJB beans

Fields Summary
Constructors Summary
Methods Summary
public static javax.naming.ContextgetInitialContext()

      return new InitialContext();
   
public static voidmain(java.lang.String[] args)


      try 
      {

         if (args.length<3 || args.length%3!=0) 
         {
            System.out.println("Usage: java com.titan.clients.Client_61 <pk1> <fname1> <lname1> ...");
            System.exit(-1);
         }

         // obtain CustomerHome
         Context jndiContext = getInitialContext();
         Object obj = jndiContext.lookup("CustomerHomeRemote");
         CustomerHomeRemote home = (CustomerHomeRemote) 
            PortableRemoteObject.narrow(obj, CustomerHomeRemote.class);
            
         // create Customers
         for(int i = 0; i < args.length; i++) 
         {
            Integer primaryKey = new Integer(args[i]);
            String firstName = args[++i];
            String lastName = args[++i];
            CustomerRemote customer = home.create(primaryKey);
            customer.setFirstName(firstName);
            customer.setLastName(lastName);
            customer.setHasGoodCredit(true);
         }

         // find and remove Customers
         for(int i = 0; i < args.length; i+=3) 
         {
            Integer primaryKey = new Integer(args[i]);
            CustomerRemote customer = home.findByPrimaryKey(primaryKey);
            String lastName = customer.getLastName( );
            String firstName = customer.getFirstName( );
            System.out.print(primaryKey+" = ");
            System.out.println(firstName+" "+lastName);

            // remove Customer
            customer.remove();
         }

      } 
      catch (java.rmi.RemoteException re)
      {
         re.printStackTrace();
      }
      catch (Throwable t)
      {
         t.printStackTrace();
      }