Using the SAS Java Metadata Interface |
You can create objects by using the methods in the MdFactory interface. You must create a Java object instance for every new and existing metadata object that you want to update or delete in a SAS Metadata Repository. You must also create an object store in which to hold the metadata objects. The object store maintains a list of the objects that need to be persisted to the SAS Metadata Server with a single request.
The following code creates a new PhysicalTable object, a new Column object, and a new TextStore object. The code then creates associations between these objects. After the metadata objects are created, they are persisted to the SAS Metadata Server.
Notes:
To persist a metadata object, you must specify a metadata repository in which to store the object. You can specify a repository identifier directly in the createComplexMetadataObject method. Or, you can use methods from the CMetadata interface. The CMetadata interface enables you to determine the identifier of a target repository, and then reference it in the createComplexMetadataObject method as a variable.
Because these are new metadata objects, they are assigned metadata object identifiers when they are persisted to the SAS Metadata Server. A request that creates Java objects to represent existing metadata objects needs to determine their metadata object instance identifiers before persisting changes to the SAS Metadata Server. For more information, see Getting and Updating Existing Objects.
/** * This example creates a table, column, and a note on the column using * the store methods. * @param Repository CMetadata object with id of form: A0000001.A5KHUI98 */ public void createTable(CMetadata repository) { if (repository != null) { try { System.out.println("\nCreating objects on the server..."); // We have a repository object. // We use the reposFQID method to get its fully qualified ID. String reposFQID = repository.getFQID(); // We need the short repository ID to create an object. String shortReposID = reposFQID.substring(reposFQID.indexOf(".") + 1, reposFQID.length()); // Now we create an object store to hold all our objects. // This will be used to maintain a list of objects to persist // to the SAS Metadata Server. MdObjectStore store = _factory.createObjectStore(); // Create a PhysicalTable object named "TableTest". PhysicalTable table=(PhysicalTable) _factory.createComplexMetadataObject( store, null, "TableTest", MetadataObjects.PHYSICALTABLE, shortReposID ); // Create a Column named "ColumnTest". Column column = (Column) _factory.createComplexMetadataObject( store, null, "ColumnTest", MetadataObjects.COLUMN, shortReposID ); // Set the attributes of the column. column.setColumnName("MyTestColumnName"); column.setSASColumnName("MyTestSASColumnName"); column.setDesc("This is a description of a column"); // Use the get"AssociationName"() method to associate the column with // the table. This method creates an AssociationList object for the table // object. The inverse association will be created automatically. // The add(MetadataObject) method adds myColumn to the AssociationList. table.getColumns().add(column); // Create a note for the column named "NoteTest". TextStore note = (TextStore) _factory.createComplexMetadataObject( store, null, "NoteTest", MetadataObjects.TEXTSTORE, shortReposID ); // Set the StoredText= attribute for the note note.setStoredText("Information about the note"); // Associate the note with the column. column.getNotes().add(note); // Now, persist all of these changes to the // SAS Metadata Server table.updateMetadataAll(); // 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(); } } }
For more information about object stores and AssociationList objects, see SAS Java Metadata Interface Overview.
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.