User: forder  
  Date: 00/08/26 12:37:03

  Modified:    src/main/org/jboss/ejb/plugins/jaws/jdbc
                        JDBCFindEntitiesCommand.java
  Log:
  All finder command creation is now at deploy time.
  
  Revision  Changes    Path
  1.3       +34 -38    
jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCFindEntitiesCommand.java
  
  Index: JDBCFindEntitiesCommand.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCFindEntitiesCommand.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JDBCFindEntitiesCommand.java      2000/08/24 10:56:36     1.2
  +++ JDBCFindEntitiesCommand.java      2000/08/26 19:37:03     1.3
  @@ -25,16 +25,13 @@
   /**
    * Keeps a map from finder name to specific finder command, and
    * delegates to the relevant specific finder command.
  - * The map is initially populated with the defined finders.
  - * It is lazily populated with commands for the magic finders (findAll and
  - * findByXXX) as and when they are called.
    *
  - * @see <related>
  + * @see org.jboss.ejb.plugins.jaws.JPMFindEntitiesCommand
    * @author <a href="mailto:[EMAIL PROTECTED]">Rickard �berg</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Joe Shevland</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public class JDBCFindEntitiesCommand implements JPMFindEntitiesCommand
   {
  @@ -64,6 +61,34 @@
               knownFinderCommands.put(f.getName(), finderCommand);
            }
         }
  +      
  +      // Make commands for any autogenerated finders required
  +      
  +      Method[] homeMethods = factory.getContainer().getHomeClass().getMethods();
  +      
  +      for (int i = 0; i < homeMethods.length; i++)
  +      {
  +         Method m = homeMethods[i];
  +         String name = m.getName();
  +         
  +         if (!knownFinderCommands.containsKey(name))
  +         {
  +            if (name.equals("findAll"))
  +            {
  +               knownFinderCommands.put(name, factory.createFindAllCommand());
  +            } else if (name.startsWith("findBy")  && 
!name.equals("findByPrimaryKey"))
  +            {
  +               try
  +               {
  +                  knownFinderCommands.put(name, factory.createFindByCommand(m));
  +               } catch (IllegalArgumentException e)
  +               {
  +                  factory.getLog().debug("Could not create the finder " + name +
  +                                         ", because no matching CMP field was 
found.");
  +               }
  +            }
  +         }
  +      }
      }
      
      // JPMFindEntitiesCommand implementation -------------------------
  @@ -77,42 +102,13 @@
         
         JPMFindEntitiesCommand finderCommand = null;
         
  -      synchronized(this) {
  -         // JF: TODO: get rid of this lazy instantiation, which
  -         // requires synchronization, by doing all specific Finder
  -         // creation in the constructor (i.e. at deployment time).
  -
  -         // Do we know a finder command for this method name?
  -
  -         finderCommand = 
  -            (JPMFindEntitiesCommand)knownFinderCommands.get(finderName);
  -
  -         // If we didn't get a finder command, see if we can make one
  -
  -         if (finderCommand == null)      
  -         {
  -            try
  -            {
  -               if (finderName.equals("findAll"))
  -               {
  -                  finderCommand = factory.createFindAllCommand();
  -               } else if (finderName.startsWith("findBy"))
  -               {
  -                  finderCommand = factory.createFindByCommand(finderMethod);
  -               }
  -
  -               // Remember the new finder command
  -               knownFinderCommands.put(finderName, finderCommand);
  -
  -            } catch (IllegalArgumentException e)
  -            {
  -               factory.getLog().warning(e.getMessage());
  -            }
  -         }
  -      }
  +      finderCommand = 
  +         (JPMFindEntitiesCommand)knownFinderCommands.get(finderName);
         
  -      // If we now have a finder command, delegate to it,
  +      // If we found a finder command, delegate to it,
         // otherwise return an empty collection.
  +      
  +      // JF: Shouldn't tolerate the "not found" case!
         
         return (finderCommand != null) ?
            finderCommand.execute(finderMethod, args, ctx) : new ArrayList();
  
  
  

Reply via email to