User: schulze 
  Date: 00/10/25 16:01:25

  Added:       src/main/org/jboss/test/bmp/test Main.java
  Log:
  Test for BMP added tests create/remove store/load activation/passivation transaction 
rollback
  Should work with almost all databases (used types: INTEGER, VARCHAR(200))
  uses Hypersonic by default
  
  Revision  Changes    Path
  1.1                  jbosstest/src/main/org/jboss/test/bmp/test/Main.java
  
  Index: Main.java
  ===================================================================
  package org.jboss.test.bmp.test;
  
  
  import javax.naming.*;
  import java.util.Collection;
  import java.util.Iterator;
  
  import org.jboss.test.bmp.interfaces.*;
  
  public class Main
  {
     public Main (String[] _args) throws Exception
     {
        System.out.print ("deploying beans...");
        new org.jboss.jmx.client.Deployer().deploy("../deploy/bmp.jar");
        System.out.println ("done.");
        
        BMPHelperSessionHome sessionHome = (BMPHelperSessionHome)new InitialContext 
().lookup ("bmp.BMPHelperSession");
        BMPHelperSession session = sessionHome.create ();
        
        System.out.println ("looking up table:");
        boolean exists =  session.existsSimpleBeanTable ();
        
        if (exists)
        {
           System.out.println ("table exists.");
           System.out.print ("delete it...");
           session.dropSimpleBeanTable();
           System.out.println ("done.");
        }
        else
        {
           System.out.println ("table does not exist.");
           System.out.print ("create it...");
           session.createSimpleBeanTable();
           System.out.println ("done.");
           System.out.println ();
           
           System.out.println ("start playing with bmp beans.");
           System.out.println ();
           SimpleBMPHome home = (SimpleBMPHome)new InitialContext ().lookup 
("bmp.SimpleBMP");
           System.out.println ("create bean1: 1, Daniel");
           SimpleBMP b1 = home.create (1, "Daniel");
           System.out.println ("getName (): "+b1.getName ());
           System.out.println ();
  
           System.out.println ("create bean2: 2, Robert");
           b1 = home.create (2, "Robert");
           System.out.println ("getName (): "+b1.getName ());
           System.out.println ();
  
           try
           {
              System.out.println ("trying to create one with same primkey: 1, 
Patrick");
              b1 = home.create (1, "Patrick");
           }
           catch (Exception _e)
           {
              System.out.println (_e.toString ());
           }
           System.out.println ();
           
           System.out.println ("create some more dummys:");
           for (int i = 0; i < 50; ++i)
              home.create (i + 3, ("Dummy "+i));
  
           System.out.println ();
           try
           {
              System.out.println ("trying to find Robert again");
              b1 = home.findByPrimaryKey (new Integer (2));
              System.out.println ("getName (): "+b1.getName ());
           }
           catch (Exception _e)
           {
              System.out.println (_e.toString ());
           }
           System.out.println ();
  
           try
           {
              System.out.println ("trying to find an not existing bean");
              b1 = home.findByPrimaryKey (new Integer (0));
              System.out.println ("getName (): "+b1.getName ());
           }
           catch (Exception _e)
           {
              System.out.println (_e.toString ());
           }
           System.out.println ();
           
           
           System.out.println ("rename Daniel to Maria: 1, Daniel");
           b1 = home.findByPrimaryKey (new Integer (1));
           System.out.println ("name old: " + b1.getName ());
           b1.setName ("Maria");
           System.out.println ("name new: " + b1.getName ());
          
           System.out.println ();
           
           System.out.println ("find all beans:");
           Iterator it = home.findAll ().iterator ();
           while (it.hasNext ())
           {
              System.out.println ("found:"+((SimpleBMP)it.next ()).getName ());
           }            
  
           System.out.println ();
  
           System.out.println ("Now trying from within the Session bean (to be able to 
rollback):");
           System.out.println (session.doTest ());
  
           System.out.println ("removing all beans:");
           it = home.findAll ().iterator ();
           while (it.hasNext ())
              ((SimpleBMP)it.next ()).remove ();
        }
  
     }
  
  
  
     public static void main (String[] _args) throws Exception
     {
        new Main (_args);
     }
  }
  
  
  

Reply via email to