public void persist(Object obj); // Save obj to the data store. public Object load(Class c, Object pK); // Read obj with a given PRimary key. public void update(Object obj); // Update the modified object obj. public void delete(Object obj); // Delete obj from the database.
public Collection find(Query q); // Find objects that satisfy conditions of our query.
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.
使用對象-關(guān)系映射工具: O/R工具已經(jīng)被經(jīng)常使用了,這種方法也比較成熟了,有很多O/R工具的提供商,業(yè)界的領(lǐng)導(dǎo)者是WebGain的TopLink以及Thought公司的CocoBase,還有ObjectMatter的Visual Business Sight Framework(VBSF)
雖然Sun的JDO提供的是透明的存儲,但是ODMG(Object Data Management Group)的數(shù)據(jù)存儲接口和幾個主要的ODBMS提供商還是很大地影響這個規(guī)范。比如,映射機制格式(按xml格式定義)脫離了實現(xiàn)提供商而定義自己的格式,這限制了可移植性,在對抗JDO
About the author Jacek Kruszelnicki is president of Numatica Corporation, an information technology consulting firm providing eXPertise in information-systems strategy development, analysis, and planning; software development; and training. Jacek (pronounced Yatsek) received his master´s degree in computer science from Northeastern University in Boston, Mass., and has more than 15 years´ experience delivering maintainable, large-scale, distributed enterprise solutions.