Previous Page | Next Page

Using the SAS Java Metadata Interface

Getting and Updating Existing Objects

To update an existing metadata object, you must know its metadata object instance identifier. The SAS Java Metadata Interface provides several ways for getting information about existing metadata objects. This section provides an example of one way you can get information about the metadata objects created in Creating Objects. The example uses the getMetadataObjectsSubset method from the MdOMIUtil interface.

The getMetadataObjectsSubset method gets a list of metadata objects in the repository of a specified metadata type. The method supports the use of SAS Open Metadata Interface flags and options to enable you to specify properties to return in the request and to filter the objects that are returned by the request. In the example that follows, the <TEMPLATES> and <XMLSELECT> elements and their corresponding flags are used to get all PhysicalTable objects named "TableTest," their associated Column and Note metadata objects, and specific attributes of all of the objects.

Note:   The <TEMPLATES> and <XMLSELECT> elements submit input to the SAS Metadata Server as a string literal (a quoted string). To ensure that the string is parsed correctly, you must escape any additional double quotation marks specified in the input string, such as those used to denote XML attribute values, to indicate that they should be treated as characters. In this example, additional quotation marks are escaped by using a backslash (\) character. For example, ""is specified as \"\".   [cautionend]

The objects are returned in an object store and can be edited.

   /**
    * This example reads the newly created objects from the server.
    * @param repository identifies the repository from which to read our objects.
    */
   public void readTable(CMetadata repository)
   {
      if(repository != null)
      {
         try
         {
            System.out.println("\nReading objects from the server...");

            // First we create an MdObjectStore as a container for the objects
            // that we will create/read/persist to the server as one collection.
            MdObjectStore store = _factory.createObjectStore();

            // The following statements define GetMetadataObjectsSubset options 
            // strings. These XML strings are used in conjunction with SAS Open  
            // Metadata Interface flags. The <XMLSELECT> element specifies filter  
            // criteria. The <TEMPLATES> element specifies the metadata properties   
            // to be returned for each object from the server.
            String xmlSelect = "<XMLSELECT Search=\"@Name='TableTest'\"/>";
            String template = 
               "<Templates>" + 
                  "<PhysicalTable Id=\"\" Name=\"\" Desc=\"\">" +
                    "<Columns/>" +
                  "</PhysicalTable>" +
                  "<Column Id=\"\" Name=\"\" Desc=\"\" ColumnName=\"\">" + 
                     "<Notes/>" + 
                  "</Column>" +
                  "<TextStore Id=\"\" Name=\"\" Desc=\"\" StoredText=\"\"/>" +
                "</Templates>";
            
            // Add the xmlSelect  and  template strings together
            String sOptions = xmlSelect + template; 

            // The following statements go to the server with a fully qualified 
            // repository ID and specify the type of object we are searching for 
            // (MdObjectFactory.PHYSICALTABLE) using the OMI_XMLSELECT, 
            // OMI_TEMPLATE, and OMI_GET_METADATA flags. OMI_GET_METADATA
            // tells the server to get  all of the attributes specified in the 
            // template for each object that is returned. The table, column, and  
            // note will be read from the server and created within the specified
            // object store.
            int flags = MdOMIUtil.OMI_XMLSELECT | MdOMIUtil.OMI_TEMPLATE | 
                           MdOMIUtil.OMI_GET_METADATA;
            List tableList = _factory.getOMIUtil().getMetadataObjectsSubset(
                    store,
                    repository.getFQID(),
                    MetadataObjects.PHYSICALTABLE,
                    flags,
                    sOption
                    );
            Iterator iter = tableList.iterator();
            while (iter.hasNext())
            {
               // Print the Id= and Name= of the table returned from the server
               PhysicalTable table = (PhysicalTable) iter.next();
               System.out.println("Found table: " + table.getName() + " (" + 
                                    table.getId() + ")");

               // Get the columns for this table.
               AssociationList columns = table.getColumns();
               for (int i = 0; i < columns.size(); i++)
               {
                  // Print the Id= and Name= of associated columns
                  Column column = (Column) columns.get(i);
                  System.out.println("Found column: " + column.getName() + " 
                                       (" + column.getId() + ")");
                  System.out.println("\tDescription: " + column.getDesc());
                  System.out.println("\tColumnName: " + column.getColumnName());
                  
                  // Get notes associated with the columns.
                  AssociationList notes = column.getNotes();
                  for (int j = 0; j < notes.size(); j++)
                  {
                     // Print the Id=, Name=, and StoredText= values of associated
                    //  notes
                     TextStore note = (TextStore) notes.get(j);
                     System.out.println("Found textstore: " + note.getName() + "  
                                          (" +note.getId() + ")");
                         System.out.println("\tStoredText: " + note.getStoredText());
                  }
               }
            }

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

Here is the output of the code:

Reading objects from the server...
Found table: TableTest (A5PCE796.B8001K8S)
Found column: ColumnTest (A5PCE796.B5005N66)
            Description: This is a description of a column
            ColumnName: MyTestColumnName
Found textstore: NoteTest (A5PCE796.A3002BIS)
            StoredText: Information about the note 

The output prints the metadata type, name, and metadata object identifier of the PhysicalTable, Column, and TextStore objects. In addition, it prints the values of the Column object's Description= and ColumnName= attributes, and it prints the value of the TextStore object's StoredText= attribute.

For more information about the search criteria supported in the <XMLSELECT> element, see Filtering a GetMetadataObjects Request. For more information about the templates supported in the <TEMPLATES> element, see Using Templates.

Previous Page | Next Page | Top of Page