Objectivity/DB Spark Adapter : Spark Adapter Tutorial : Using Placement and Configuring Storage Locations
4 
Using Placement and Configuring Storage Locations
With Objectivity/DB, you typically distribute related data in many individual databases, which are members of a single federated database. Those individual databases can be distributed across locations on a single machine or across a network.
You use managed placement to control how/where objects are stored in the federated database. The central component of managed placement is the placement model document (PMD), which is an XML document that defines how objects are to be placed for a given application. The schema definitions for these objects must be available before placement can be configured.
In this topic you will:
Add new schema for objects that have relationships to each other.
Import a PMD that distributes objects of those types in a round robin strategy across multiple storage locations.
Register the four storage locations that will be used.
Creating Schema Using DO
Let’s use the DO query language to provide schema descriptions for some of the classes to be used in the tutorial.
1. (Optional) Open the etc\schema.txt file in your preferred editor and note the class descriptions for Subscriber, Phone, and PhoneCall objects.
You will have a chance to examine the class description more closely later in the tutorial. For now, just note that the classes and their attributes are defined.
2. (Optional) Look at the createSchema task in the build.gradle file (in the ObjySparkTutorial directory) and note that the administrative tool DO is used to execute the statements in the schema file.
... "objy DO -inFile ${schemafile} -bootfile ${fddirhost}::${fddirpath}/${fdname}.boot"
3. Open a new command prompt in the ObjySparkTutorial directory and run the createSchema task:
gradlew createSchema
Note:Recall that in Writing a Data Frame, you added customer objects in a brand new federated database without importing any schema. For objects with simple attributes like strings and numerics, you can create schema dynamically and do not need to import the schema first.
For more information about the DO language syntax, see Declarative Objectivity (DO) Language. For help with the DO runner, issue the following command:
objy DO -help
Importing a Placement Model Document
The federated database can be configured to use multiple storage locations for files. Let’s import a PMD that will provide custom placement for objects created through the rest of the tutorial, and then create the storage locations to be utilized by that PMD.
1. (Optional) Open etc\placement.pmd in your preferred editor. In particular, note the rules at the bottom of the file that pertain to classes to be used in the tutorial:
    <Rules>
      <Rule objectClass="com.thingspan.spark.demo.Subscriber" objectPlacer="subscriberOP" />
      <Rule objectClass="com.thingspan.spark.demo.Phone" objectPlacer="phoneOP" />
      <Rule objectClass="com.thingspan.spark.demo.PhoneCall" objectPlacer="phoneCallOP"/>
    </Rules>
Each rule supplies the first building block of information needed to customize the placement of objects of that type. In our example, the PMD uses a round robin strategy for placing objects in four different storage locations.
2. From the ObjySparkTutorial directory, import the PMD as follows:
gradlew importPlacement
Adding Storage Locations
The federated database in the tutorial will use four storage locations for database files. Storage locations are registered using an administrative tool.
1. Note that the ObjySparkTutorial\data directory has four subdirectories named loc1 through loc4.
2. From the ObjySparkTutorial directory, register these four directories as storage locations using one of the following approaches:
Use the Gradle task:
   gradlew addStorageLocations
Call the tool directly for each of the four storage locations. For example, the following adds the storage location for the loc1 directory:
   objy AddStorageLocation -name data\loc1 -storageLocation data\loc1 -dbPlacerGroup tutorialDB -bootfile data\customers.boot
The federated database is now configured to use the four directories under the data directory as storage locations. The locations are associated with a database placer via the tutorialDB name, which ties into the PMD discussed earlier.
About Network Storage Locations
You can register storage locations across a network using a host::path syntax—for example:
myhost::/user/myData/ObjySparkTutorial/loc3
UNIX
myhost::C:\myData\ObjySparkTutorial\loc1
myhost::\myData\ObjySparkTutorial\loc2
Windows drive
Windows UNC name