As shown in the following Java™ and C# examples, you can get an existing instance of an ObjectStore with a factory method: getInstance or fetchInstance.
getInstance Method
The getInstance method constructs a local instance of the ObjectStore class. This method does not verify the existence of the requested object on the server; it returns a local reference to the object, which is not affiliated with a server object until you perform a function on the object (for example, fetch a property value or call the refresh method) that causes a round trip to the server. This technique, also called "fetchless instantiation", is useful when the wanted object will serve only passively, for example, as the target value of an object-valued property.
Java Example
// Get object store instance.
static void getObjectStoreInstance(
Domain domain,
String objStoreName) // Example: "ObjectStore1"
{
// Get object store (fetchless instantiation).
ObjectStore ojbStore = Factory.ObjectStore.getInstance(domain, objStoreName);
// Show object store name.
objStore.refresh();
System.out.println("Object store name: " + objStore.get_Name());
}
C# Example
// Get object store instance.
static void GetObjectStoreInstance(
IDomain domain,
String objStoreName) // Example: "ObjectStore1"
{
// Get object store (fetchless instantiation).
IObjectStore objStore = Factory.ObjectStore.GetInstance(domain, objStoreName);
// Show object store name.
objStore.Refresh();
Debug.WriteLine("Object store name: " + objStore.Name);
}
fetchInstance Method
The fetchInstance method makes a round trip to the server to retrieve the property values of the ObjectStore object. You can limit the number of properties that are returned by using a property filter.
Java Example
// Get object store instance.
static void fetchObjectStoreInstance(
Domain domain,
String objStoreName) // Example: "ObjectStore1"
{
// Define a property filter to limit the returned properties.
PropertyFilter filter = new PropertyFilter();
filter.addIncludeProperty(0, null, null,
PropertyNames.ROOT_CLASS_DEFINITIONS, null);
filter.addIncludeProperty(0, null, null,
PropertyNames.DISPLAY_NAME, null);
// Fetch object store using the property filter.
ObjectStore objStore = Factory.ObjectStore.fetchInstance(
domain, objStoreName, filter);
// Show object store display name.
System.out.println("Object store name: " + objStore.get_DisplayName());
}
C# Example
// Get object store instance.
static void FetchObjectStoreInstance(
IDomain domain,
String objStoreName) // Example: "ObjectStore1"
{
// Define a property filter to limit the returned properties.
PropertyFilter filter = new PropertyFilter();
filter.AddIncludeProperty(0, null, null,
PropertyNames.ROOT_CLASS_DEFINITIONS, null);
filter.AddIncludeProperty(0, null, null,
PropertyNames.DISPLAY_NAME, null);
// Fetch object store using the property filter.
IObjectStore objStore = Factory.ObjectStore.FetchInstance(
domain, objStoreName, filter);
// Show object store display name.
Debug.WriteLine("Object store name: " + objStore.DisplayName);
}