You create a new instance of an ObjectStore object with the Factory.ObjectStore.createInstance call.
Administrative prerequisites must be met to support object store creation. The following tasks are typically performed by the database and application server administrators:
The following Java and C# examples instantiate a ObjectStore object. The examples show both versions of the createInstance method, one that takes a schema script and one that does not. By using a customized schema script, a database administrator (DBA) can modify the object store database schema. The ObjectStore object does not exist in the Global Configuration Database (GCD) until a round trip to the server happens at a later commit (save) step.
After you create the object instance, you must set the following properties: DisplayName, SymbolicName, and DatabaseConnection. The DatabaseConnection property is set to a CmDatabaseConnection object, which defines the local JNDI data source name and the transaction JNDI data source name.
Before you save the new ObjectStore object, you can set the following DatabaseXXXStorageLocation properties on the object (not shown in the code examples):
Java Example
// Create an object store instance.
public static void createObjectStoreInstance(
Connection conn,
String[] adminName, // Example: "Domain Admins, CEMPAdmin"
String[] userName, // Example: "Domain Users, CEMPUser"
CmDatabaseConnection dbConn, // Defines the data sources
String objStoreName, // Object store name. Example: "ObjectStore1"
String scriptPath) // Creation script file path. Example: "C:\os_script.txt"
throws Exception {
// Get the default domain.
Domain domain = Factory.Domain.getInstance(conn, null);
// Create an object store.
String[] admins = {adminName};
String[] users = {userName};
ObjectStore objStore = null;
if (scriptPath == null) {
// Create without using a schema script.
System.out.println("Creating object store without a schema script");
objStore = Factory.ObjectStore.createInstance(
domain, admins, users);
}
else {
// Create using a schema script.
// The getScript method reads in the script from a file.
String creationScript = getScript(scriptPath);
System.out.println("Creating object store with a schema script");
// To print the contents of the script file, uncomment the next line.
// System.out.println(creationScript);
objStore = Factory.ObjectStore.createInstance(
domain, admins, users, creationScript);
}
// Set properties.
objStore.set_DisplayName(objStoreName);
objStore.set_SymbolicName(objStoreName);
objStore.set_DatabaseConnection(dbConn);
// Save object store and display name.
objStore.save(RefreshMode.REFRESH);
System.out.println("Object store name: " + objStore.get_Name());
}
C# Example
// Create an object store instance.
public static void CreateObjectStoreInstance(
IConnection conn,
String[] adminName, // Example: "Domain Admins, CEMPAdmin"
String[] userName, // Example: "Domain Users, CEMPUser"
ICmDatabaseConnection dbConn, // Defines the data sources
String objStoreName, // Object store name. Example: "ObjectStore1"
String scriptPath) // Creation script file path. Example: "C:\os_script.txt"
// Get the default domain.
{IDomain domain = Factory.Domain.GetInstance(conn, null);
// Create an object store.
String[] admins = {adminName};
String[] users = {userName};
IObjectStore objStore = null;
if (scriptPath == null) {
// Create without using a schema script.
Debug.WriteLine ("Creating object store without a schema script");
objStore = Factory.ObjectStore.CreateInstance(
domain, admins, users);
}
else {
// Create using a schema script.
// The GetScript method reads in the script from a file.
String creationScript = GetScript(scriptPath);
Debug.WriteLine("Creating object store with a schema script");
objStore = Factory.ObjectStore.CreateInstance(
domain, admins, users, creationScript);
}
// Set properties.
objStore.DisplayName = objStoreName;
objStore.SymbolicName = objStoreName;
objStore.DatabaseConnection = dbConn;
// Save object store and display name.
ojbStore.Save(RefreshMode.REFRESH);
Debug.WriteLine("Object store name: " + objStore.Name);
}