To update an existing
metadata object, you must know its metadata object identifier. The
SAS Java Metadata Interface provides several ways to get information
about existing metadata objects.
This section provides
an example of one way to 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 metadata objects that are returned
by the request. In the example, the <TEMPLATES> and <XMLSELECT>
elements and their corresponding flags get all PhysicalTable objects
named “TableTest,” their associated Column and Keyword
metadata objects, and all attributes of the objects. The PublicType
attribute is included in the <XMLSELECT> search string to specify
to process only PhysicalTable objects that have their PublicType attribute
set.
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 denoting XML attribute
values) to indicate that they should be treated as characters. In
this example, additional double quotation marks are escaped by using
a backslash character.
The objects are created
in the specified object store, and they can be edited.
/**
* This example reads the newly created objects back from the
* SAS Metadata 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 variables used within the
// getMetadataObjectsSubset method.These XML strings are used in conjunction
// with SAS Open Metadata Interface flags. The <XMLSELECT> element
// specifies filter criteria. The objects returned are filtered by the
// PublicType and Name values. The <TEMPLATES> element specifies the
// associations to be expanded for each object.
String xmlSelect = "<XMLSELECT Search=\"*[@PublicType='Table' and " +
"@Name='TableTest']\"/>";
String template =
"<Templates>" +
"<PhysicalTable>" +
"<Columns/>" +
"</PhysicalTable>" +
"<Column>" +
"<Keywords/>" +
"</Column>" +
"</Templates>";
// Add the XMLSELECT and TEMPLATES 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
// (MetadataObjects.PHYSICALTABLE) using the OMI_XMLSELECT, OMI_TEMPLATE,
// OMI_ALL_SIMPLE, and OMI_GET_METADATA flags. OMI_ALL_SIMPLE specifies
// to get all simple attributes for all objects that are returned.
// OMI_GET_METADATA activates the GetMetadata flags in the GetMetadataObjects
// request.
//
// The table, column, and keyword will be read from the server and created
// within the specified object store.
int flags = MdOMIUtil.OMI_XMLSELECT | MdOMIUtil.OMI_TEMPLATE |
MdOMIUtil.OMI_ALL_SIMPLE | MdOMIUtil.OMI_GET_METADATA;
List tableList = _factory.getOMIUtil().getMetadataObjectsSubset(store,
repository.getFQID(),
MetadataObjects.PHYSICALTABLE,
flags,
sOptions);
Iterator iter = tableList.iterator();
while (iter.hasNext())
{
// Print the Name, Id, PublicType, UsageVersion, and ObjPath values
// of the table returned from the server. ObjPath is the folder location.
PhysicalTable table = (PhysicalTable) iter.next();
System.out.println("Found table: " + table.getName() + " (" +
table.getId() + ")");
System.out.println("\tType: " + table.getPublicType());
System.out.println("\tUsage Version: " + table.getUsageVersion());
System.out.println("\tPath: " + _factory.getOMIUtil().getObjectPath(store,
table, false));
// Get the list of columns for this table.
AssociationList columns = table.getColumns();
for (int i = 0; i < columns.size(); i++)
{
// Print the Name, Id, PublicType, UsageVersion, Desc, and ColumnName
// values for each column associated with the table.
Column column = (Column) columns.get(i);
System.out.println("Found column: " + column.getName() + " (" +
column.getId() + ")");
System.out.println("\tType: " + column.getPublicType());
System.out.println("\tUsage Version: " + column.getUsageVersion());
System.out.println("\tDescription: " + column.getDesc());
System.out.println("\tColumnName: " + column.getColumnName());
// Get the list of keywords associated with the columns.
AssociationList keywords = column.getKeywords();
for (int j = 0; j < keywords.size(); j++)
{
// Print the Name and Id values of each keyword associated with
// the column.
Keyword keyword = (Keyword) keywords.get(j);
System.out.println("Found keyword: " + keyword.getName() + " (" +
keyword.getId() + ")");
}
}
}
// 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.B8002WKO)
Type: Table
Usage Version: 1000000.0
Path: /User Folders/sasdemo/My Folder/TableTest
Found column: ColumnTest (A5PCE796.B5008RAF)
Type: Column
Usage Version: 1000000.0
Description: This is a description of a column
ColumnName: MyTestColumnName
Found keyword: KeywordTest (A5PCE796.AX001O1D)
The output prints the
name, metadata object identifier, and PublicType and UsageVersion
values of the table and column objects. In addition, it prints the
name and metadata object identifier of the Keyword object. And, it
prints the path of the table in the SAS Folders tree, and the Description
and ColumnName values of the column object.