|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 3 of 6
PersistenceManager pm =PMFactory.initialize(..);
Company co = new Company("MyCompany");
Location l1 = new Location1 ("Boston");
Location l2 = new Location("New York");
// Create users.
User u1 = new User("Mark");
User u2 = new User("Tom");
User u3 = new User("Mary");
// Add users. A user can only "belong" to one location.
L1.addUser(u1);
L1.addUser(u2);
L2.addUser(u3);
// Add locations to the company.
co.addLocation(l1);
co.addLocation(l2);
// And finally, store the whole tree to the database.
pm.persist(c);
In another session, you can look up companies employing the user Tom:
PersistenceManager pm =PMFactory.initialize(...)
Collection companiesEmployingToms = pm.find("company.location.user.name = 'Tom'");
For relational data stores, you must create an additional mapping file. It might look like this:
<!DOCTYPE mapping PUBLIC ... >
<mapping>
<class name="com.numatica.example.Company" identity="companyID" key-generator="SEQUENCE">
<cache-type type="count-limited" capacity="5"/>
<description>Company</description>
<map-to table="Companies"/>
<field name="companyID"type="long">
<sql name="companyID" type="numeric"/>
</field>
<field name="name" type="string">
<sql name="name" type="varchar"/>
</field>
<field name="locations" type="com.numatica.example.Location" collection="arraylist">
</field>
</class>
<class name="com.numatica.example.Location "identity="locationID"
key-generator="SEQUENCE">
<cache-type type="unlimited"/>
<description>Locations</description>
<map-to table="Locations"/>
<field name="locationID" type="long">
<sql name="locationID" type="numeric"/>
</field>
<field name="name" type="string">
<sql name="name" type="varchar"/>
</field>
<field name="company" type="com.numatica.example.Company"required="true">
<sql name="companyID"/>
</field>
</class>
<class name="com.numatica.example.User" identity="userID"
depends="com.numatica.example.Location" >
<cache-type type="count-limited" capacity="200"/>
<description>User</description>
<map-to table="Users"/>
<field name="userID" type="integer">
<sql name="userID" type="numeric"/>
</field>
<field name="location" type="com.numatica.example.Location"required="true">
<sql name="locationID"/>
</field>
<field name="name" type="string">
<sql name="username" type="varchar"/>
</field>
</class>
</mapping>
The persistence layer takes care of the rest, which encompasses the following:
The available persistence layer solutions divide into the following groups:
None of the solutions currently available satisfy all the criteria set forth for the ideal persistence layer. Below I review the first three solutions, before focusing on the JDO-based approach.