You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juddi.apache.org by sv...@apache.org on 2005/03/17 02:24:54 UTC

cvs commit: ws-juddi/src/java/org/apache/juddi/datastore/jdbc JDBCDataStore.java FindServiceByTModelKeyQuery.java FindBusinessByTModelKeyQuery.java

sviens      2005/03/16 17:24:54

  Modified:    src/java/org/apache/juddi/datastore/jdbc JDBCDataStore.java
                        FindServiceByTModelKeyQuery.java
                        FindBusinessByTModelKeyQuery.java
  Log:
  Added support for default 'LOGICAL AND' behavior and for 'orAllKeys' findQualifier in find_business and find_service when seaching using a TModelBag.
  
  Revision  Changes    Path
  1.13      +46 -34    ws-juddi/src/java/org/apache/juddi/datastore/jdbc/JDBCDataStore.java
  
  Index: JDBCDataStore.java
  ===================================================================
  RCS file: /home/cvs/ws-juddi/src/java/org/apache/juddi/datastore/jdbc/JDBCDataStore.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- JDBCDataStore.java	16 Mar 2005 03:49:40 -0000	1.12
  +++ JDBCDataStore.java	17 Mar 2005 01:24:54 -0000	1.13
  @@ -1430,29 +1430,39 @@
   
       try
       {
  -      if ((tModelBag != null) && (tModelBag.size() > 0))
  -        keyVector = FindBusinessByTModelKeyQuery.select(tModelBag,keyVector,findQualifiers,connection);
  -
         if ((discoveryURLs != null) && (discoveryURLs.size() > 0))
           keyVector = FindBusinessByDiscoveryURLQuery.select(discoveryURLs,keyVector,findQualifiers,connection);
   
  -//    TODO (CategoryBag Error)        
  -//      if ((categoryBag != null) && (categoryBag.size() > 0))
  -//        keyVector = FindBusinessByCategoryQuery.select(categoryBag,keyVector,findQualifiers,connection);
  -
         if ((findQualifiers != null) && (findQualifiers.orAllKeys))  
         {
  -        // orAllKeys = Use logical "OR" when searching by category 
  -        // bag. See UDDI v2.04 API Specification - Appendix E.
  -        //
  +        // orAllKeys = Use logical "OR" when searching by categoryBag
  +        // or tModelBag. See UDDI v2.04 API Specification - Appendix E.
  +            
  +        if ((tModelBag != null) && (tModelBag.size() > 0))
  +          keyVector = FindBusinessByTModelKeyQuery.select(tModelBag,keyVector,findQualifiers,connection);
  +        
           if ((categoryBag != null) && (categoryBag.size() > 0))
             keyVector = FindBusinessByCategoryQuery.select(categoryBag,keyVector,findQualifiers,connection);
         }
         else 
         {
           // Default UDDI v2 behavior: Use logical "AND" when searching 
  -        // by category bag. See UDDI v2.04 API Specification - Appendix E.
  -        //
  +        // by categoryBagor tModelBag. See Appendix E of the UDDI v2.04 
  +        // API Specification.
  +
  +        if ((tModelBag != null) && (tModelBag.size() > 0))
  +        {
  +          Vector tModelKeyVector = tModelBag.getTModelKeyVector();
  +          if (tModelKeyVector != null)
  +          {
  +            for (int i=0; i<tModelKeyVector.size(); i++)
  +            {
  +              String tModelKey = (String)tModelKeyVector.elementAt(i);
  +              keyVector = FindBusinessByTModelKeyQuery.select(tModelKey,keyVector,findQualifiers,connection);
  +            }
  +          }
  +        }
  +
           if ((categoryBag != null) && (categoryBag.size() > 0))
           {
             Vector keyedRefVector = categoryBag.getKeyedReferenceVector();
  @@ -1465,7 +1475,7 @@
               }
             }
           }
  -      }
  +      } // end else
         
         if ((identifierBag != null) && (identifierBag.size() > 0))
           keyVector = FindBusinessByIdentifierQuery.select(identifierBag,keyVector,findQualifiers,connection);
  @@ -1498,26 +1508,36 @@
         if (businessKey != null)
           keyVector = FindServiceByBusinessKeyQuery.select(businessKey,keyVector,findQualifiers,connection);
               
  -      if ((tModelBag != null) && (tModelBag.size() > 0))
  -        keyVector = FindServiceByTModelKeyQuery.select(businessKey,tModelBag,keyVector,findQualifiers,connection);
  -
  -//    TODO (CategoryBag Error)        
  -//      if ((categoryBag != null) && (categoryBag.size() > 0))
  -//        keyVector = FindServiceByCategoryQuery.select(businessKey,categoryBag,keyVector,findQualifiers,connection);
  -
         if ((findQualifiers != null) && (findQualifiers.orAllKeys))  
         {
  -        // orAllKeys = Use logical "OR" when searching by category 
  -        // bag. See UDDI v2.04 API Specification - Appendix E.
  -        //
  +        // orAllKeys = Use logical "OR" when searching by categoryBag
  +        // or tModelBag. See UDDI v2.04 API Specification - Appendix E.
  +          
  +        if ((tModelBag != null) && (tModelBag.size() > 0))
  +          keyVector = FindServiceByTModelKeyQuery.select(businessKey,tModelBag,keyVector,findQualifiers,connection);
  +
           if ((categoryBag != null) && (categoryBag.size() > 0))
             keyVector = FindServiceByCategoryQuery.select(businessKey,categoryBag,keyVector,findQualifiers,connection);
         }
         else 
         {
           // Default UDDI v2 behavior: Use logical "AND" when searching 
  -        // by category bag. See UDDI v2.04 API Specification - Appendix E.
  -        //
  +        // by categoryBagor tModelBag. See Appendix E of the UDDI v2.04 
  +        // API Specification.
  +
  +        if ((tModelBag != null) && (tModelBag.size() > 0))
  +        {
  +          Vector tModelKeyVector = tModelBag.getTModelKeyVector();
  +          if (tModelKeyVector != null)
  +          {
  +            for (int i=0; i<tModelKeyVector.size(); i++)
  +            {
  +              String tModelKey = (String)tModelKeyVector.elementAt(i);
  +              keyVector = FindServiceByTModelKeyQuery.select(businessKey,tModelKey,keyVector,findQualifiers,connection);
  +            }
  +          }
  +        }
  +
           if ((categoryBag != null) && (categoryBag.size() > 0))
           {
             Vector keyedRefVector = categoryBag.getKeyedReferenceVector();
  @@ -1530,7 +1550,7 @@
               }
             }
           }
  -      }
  +      } // end else
         
         // always perform this query - even when not searching by Name!!!
         keyVector = FindServiceByNameQuery.select(businessKey,nameVector,keyVector,findQualifiers,connection);
  @@ -1556,10 +1576,6 @@
   
       try
       {
  -// TODO (CategoryBag Error)        
  -//      if ((categoryBag != null) && (categoryBag.size() > 0))
  -//        keyVector = FindTModelByCategoryQuery.select(categoryBag,keyVector,findQualifiers,connection);
  -
         if ((findQualifiers != null) && (findQualifiers.orAllKeys))  
         {
           // orAllKeys = Use logical "OR" when searching by category 
  @@ -1620,10 +1636,6 @@
         if ((tModelBag != null) && (tModelBag.size() > 0))
           keyVector = FindBindingByTModelKeyQuery.select(serviceKey,tModelBag,keyVector,findQualifiers,connection);
   
  -//    TODO (CategoryBag Error)        
  -//      if ((categoryBag != null) && (categoryBag.size() > 0))
  -//        keyVector = FindBindingByCategoryQuery.select(serviceKey,categoryBag,keyVector,findQualifiers,connection);
  -
         if ((findQualifiers != null) && (findQualifiers.orAllKeys))  
         {
           // orAllKeys = Use logical "OR" when searching by category 
  
  
  
  1.6       +80 -0     ws-juddi/src/java/org/apache/juddi/datastore/jdbc/FindServiceByTModelKeyQuery.java
  
  Index: FindServiceByTModelKeyQuery.java
  ===================================================================
  RCS file: /home/cvs/ws-juddi/src/java/org/apache/juddi/datastore/jdbc/FindServiceByTModelKeyQuery.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FindServiceByTModelKeyQuery.java	2 Jul 2004 12:54:59 -0000	1.5
  +++ FindServiceByTModelKeyQuery.java	17 Mar 2005 01:24:54 -0000	1.6
  @@ -154,6 +154,86 @@
     }
   
     /**
  +   * Select ...
  +   *
  +   * @param connection JDBC connection
  +   * @throws java.sql.SQLException
  +   */
  +  public static Vector select(String businessKey,String tModelKey,Vector keysIn,FindQualifiers qualifiers,Connection connection)
  +    throws java.sql.SQLException
  +  {
  +    // if there is a keysIn vector but it doesn't contain
  +    // any keys then the previous query has exhausted
  +    // all possibilities of a match so skip this call.
  +    if ((keysIn != null) && (keysIn.size() == 0))
  +      return keysIn;
  +
  +    Vector keysOut = new Vector();
  +    PreparedStatement statement = null;
  +    ResultSet resultSet = null;
  +
  +    // construct the SQL statement
  +    DynamicQuery sql = new DynamicQuery(selectSQL);
  +    appendWhere(sql,businessKey,tModelKey,qualifiers);
  +    appendIn(sql,keysIn);
  +    appendOrderBy(sql,qualifiers);
  +
  +    try
  +    {
  +      log.debug(sql.toString());
  +
  +      statement = sql.buildPreparedStatement(connection);
  +      resultSet = statement.executeQuery();
  +
  +      while (resultSet.next())
  +        keysOut.addElement(resultSet.getString(1));//("SERVICE_KEY"));
  +
  +      return keysOut;
  +    }
  +    finally
  +    {
  +      try {
  +        resultSet.close();
  +      }
  +      catch (Exception e)
  +      {
  +        log.warn("An Exception was encountered while attempting to close " +
  +          "the Find BusinessService ResultSet: "+e.getMessage(),e);
  +      }
  +
  +      try {
  +        statement.close();
  +      }
  +      catch (Exception e)
  +      {
  +        log.warn("An Exception was encountered while attempting to close " +
  +          "the Find BusinessService Statement: "+e.getMessage(),e);
  +      }
  +    }
  +  }
  +
  +  /**
  +   *
  +   */
  +  private static void appendWhere(DynamicQuery sql,String businessKey,String tModelKey,FindQualifiers qualifiers)
  +  {
  +    sql.append("WHERE I.BINDING_KEY = T.BINDING_KEY ");
  +    sql.append("AND T.SERVICE_KEY = S.SERVICE_KEY ");
  +
  +    if ((businessKey != null) && (businessKey.trim().length() > 0))
  +    {
  +      sql.append("AND S.BUSINESS_KEY = ? ");
  +      sql.addValue(businessKey);
  +    }
  +    
  +    if ((tModelKey != null) && (tModelKey.trim().length() > 0))
  +    {
  +      sql.append("AND I.TMODEL_KEY = ? ");
  +      sql.addValue(tModelKey);
  +    }
  +  }
  +
  +  /**
      * Utility method used to construct SQL "IN" statements such as
      * the following SQL example:
      *
  
  
  
  1.5       +78 -0     ws-juddi/src/java/org/apache/juddi/datastore/jdbc/FindBusinessByTModelKeyQuery.java
  
  Index: FindBusinessByTModelKeyQuery.java
  ===================================================================
  RCS file: /home/cvs/ws-juddi/src/java/org/apache/juddi/datastore/jdbc/FindBusinessByTModelKeyQuery.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FindBusinessByTModelKeyQuery.java	1 May 2004 00:55:12 -0000	1.4
  +++ FindBusinessByTModelKeyQuery.java	17 Mar 2005 01:24:54 -0000	1.5
  @@ -142,6 +142,84 @@
     }
   
     /**
  +   * Select ...
  +   *
  +   * @param tModelKey
  +   * @param keysIn
  +   * @param qualifiers
  +   * @param connection JDBC connection
  +   * @throws java.sql.SQLException
  +   */
  +  public static Vector select(String tModelKey,Vector keysIn,FindQualifiers qualifiers,Connection connection)
  +    throws java.sql.SQLException
  +  {
  +    // if there is a keysIn vector but it doesn't contain
  +    // any keys then the previous query has exhausted
  +    // all possibilities of a match so skip this call.
  +    if ((keysIn != null) && (keysIn.size() == 0))
  +      return keysIn;
  +
  +    Vector keysOut = new Vector();
  +    PreparedStatement statement = null;
  +    ResultSet resultSet = null;
  +
  +    // construct the SQL statement
  +    DynamicQuery sql = new DynamicQuery(selectSQL);
  +    appendWhere(sql,tModelKey,qualifiers);
  +    appendIn(sql,keysIn);
  +    appendOrderBy(sql,qualifiers);
  +
  +    try
  +    {
  +      log.debug(sql.toString());
  +
  +      statement = sql.buildPreparedStatement(connection);
  +      resultSet = statement.executeQuery();
  +
  +      while (resultSet.next())
  +        keysOut.addElement(resultSet.getString(1));//("BUSINESS_KEY"));
  +
  +      return keysOut;
  +    }
  +    finally
  +    {
  +      try {
  +        resultSet.close();
  +      }
  +      catch (Exception e)
  +      {
  +        log.warn("An Exception was encountered while attempting to close " +
  +          "the Find BusinessEntity ResultSet: "+e.getMessage(),e);
  +      }
  +
  +      try {
  +        statement.close();
  +      }
  +      catch (Exception e)
  +      {
  +        log.warn("An Exception was encountered while attempting to close " +
  +          "the Find BusinessEntity Statement: "+e.getMessage(),e);
  +      }
  +    }
  +  }
  +
  +  /**
  +   *
  +   */
  +  private static void appendWhere(DynamicQuery sql,String tModelKey,FindQualifiers qualifiers)
  +  {
  +    sql.append("WHERE I.BINDING_KEY = T.BINDING_KEY ");
  +    sql.append("AND T.SERVICE_KEY = S.SERVICE_KEY ");
  +    sql.append("AND S.BUSINESS_KEY = B.BUSINESS_KEY ");
  +
  +    if ((tModelKey != null) && (tModelKey.trim().length() > 0))
  +    {
  +      sql.append("AND I.TMODEL_KEY = ? ");
  +      sql.addValue(tModelKey);
  +    }
  +  }
  +
  +  /**
      * Utility method used to construct SQL "IN" statements such as
      * the following SQL example:
      *