How to Use the SAS Java Metadata Interface


Example 7: Get all objects of a particular type

This is an example of how to retrieve all objects of a particular metadata type in the SAS Metadata Repository. This method retrieves all PhysicalTables contained in the repository.

   /**
    * This method displays the PhysicalTable objects contained in repository
    * @param repository CMetadata identifies the repository from which to read
    * the objects.
    */
   public void displayAllTables(CMetadata repository)
   {
      try
      {
         // Print a descriptive message about the request.
         System.out.println("\nRetrieving all PhysicalTable objects contained in " +
               " repository " + repository.getName());

         // Use the short Repository ID to pass in the method.
         String reposID = repository.getFQID();

         // We get a list of "PhysicalTable" objects.
         MdObjectStore store = _factory.createObjectStore();

         // Use the OMI_ALL_SIMPLE flag to get all attributes for each table returned
         int flags = MdOMIUtil.OMI_GET_METADATA | MdOMIUtil.OMI_ALL_SIMPLE;
         List tables = _factory.getOMIUtil().getMetadataObjectsSubset
                (store,
                reposID,                         // Repository to Search
                MetadataObjects.PHYSICALTABLE,   // Type to search for
                flags,
                "" );

         // Print information about them.
         Iterator iter = tables.iterator();
         while( iter.hasNext())
         {
            PhysicalTable ptable = (PhysicalTable)iter.next();
            System.out.println("PhysicalTable: " +
                               ptable.getName() +
                               ", " +
                               ptable.getFQID() +
                               ", " +
                               ptable.getDesc());
         }

         // When finished, clean up the objects in the store if it is no longer
         // being used
         store.dispose();
      }
      catch (MdException e)
      {
         e.printStackTrace();
      }
      catch (RemoteException e)
      {
         e.printStackTrace();
      }
   }