How to Use the SAS Java Metadata Interface


Example 8: Get an existing object

This is an example of how to read an object from the SAS Metadata Server. This example will retrieve an existing PhysicalTable along with its attributes and a set of associations.

   /**
    * This method retrieves detailed information for a specific PhysicalTable
    * @param table the table to retrieve
    */
   public void getTableInformation(PhysicalTable table)
   {
      try
      {
         // Print a descriptive message about the request.
         System.out.println("\nRetrieving information for a specific PhysicalTable");

         // Create a template to retreive detailed information for this table
         String template = "<Templates>" +
                              "<PhysicalTable>" +
                                "<Columns/>" +
                                "<Notes/>" +
                                "<Keywords/>" +
                              "</PhysicalTable>" +
                            "</Templates>";

         // Use the OMI_ALL_SIMPLE flag to get all attributes for each table returned
         int flags = MdOMIUtil.OMI_GET_METADATA | MdOMIUtil.OMI_ALL_SIMPLE |
                        MdOMIUtil.OMI_TEMPLATE;
         table = (PhysicalTable) _factory.getOMIUtil().getMetadataAllDepths
                (table,
                 null,
                 null,
                 template,
                 flags);

         // Print information about the table
         System.out.println("Table attributes: ");
         System.out.println("  Name = " + table.getName());
         System.out.println("  Id = " + table.getId());
         System.out.println("  Description = " + table.getDesc());
         System.out.println("  Created Date = " + table.getMetadataCreated());
         System.out.println("Table associations: ");
         System.out.println("  Number of Columns = " + table.getColumns().size());
         System.out.println("  Number of Keywords = " + table.getKeywords().size());
         System.out.println("  Number of Notes = " + table.getNotes().size());
      }
      catch (MdException e)
      {
         e.printStackTrace();
      }
      catch (RemoteException e)
      {
         e.printStackTrace();
      }
   }