Added: db/jdo/site/docs/pm.html URL: http://svn.apache.org/viewvc/db/jdo/site/docs/pm.html?rev=581796&view=auto ============================================================================== --- db/jdo/site/docs/pm.html (added) +++ db/jdo/site/docs/pm.html Thu Oct 4 01:11:54 2007 @@ -0,0 +1,181 @@ +Java Data Objects (JDO) - Persistence Manager

Persistence Manager

+ Any JDO-enabled application will require at least one PersistenceManager (PM). + This is obtained from the PersistenceManagerFactory for the datastore. +

+ The simplest way of creating a PersistenceManager + + is as follows +

+
+PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(props);
+PersistenceManager pm = pmf.getPersistenceManager();
+

+ A PersistenceManager is the key to all persistence operations in JDO. With it you can + persist, update, delete, and retrieve objects from the datastore. A PersistenceManager + has a single transaction. +



Persist Objects

+ To persist an object, the object must first be marked as persistable using + MetaData (XML/Annotations). Then you would start the + PM transaction, and use makePersistent as follows +

+
+PersistenceManager pm = pmf.getPersistenceManager();
+Transaction tx = pm.currentTransaction();
+try
+{
+    // Start the transaction
+    tx.begin();
+
+    // Create the object to persist
+    MyClass obj = new MyClass();
+
+    // Persist it to the datastore
+    pm.makePersistent(obj);
+
+    // Commit the transaction, flushing the object to the datastore
+    tx.commit();
+}
+catch (Exception e)
+{
+    ... handle exceptions
+}
+finally
+{
+    if (tx.isActive())
+    {
+        // Error occurred so rollback the transaction
+        tx.rollback();
+    }
+    pm.close();
+}
+

+ The makePersistent method of PersistenceManager makes the object persistent in + the datastore, and updates the 'state' of the object from Transient (at the start) + to Hollow (after commit() of the transaction). +

+ When an object is persisted, if it has any other objects referenced from that object they + also will be made persistent. This is referred to as persistence-by-reachability. + The main benefit of this is that if you have an object graph to persist, then you don't + need to call makePersistent() on all objects, instead just using one that can be + used to find all of the others. persistence-by-reachability is also run at the time of + calling commit() on the transaction. This has the effect that if you had called + makePersistent() on an object and that had persisted another object, and before + commit you had removed the relation to this other object, then at commit() the + reachability algorithm will find that this other object is no longer reachable and will + remove it from persistence. +



Retrieve Objects

+ So we've made some of our objects persistent, and now we want to retrieve them in + our application. Here's one way of retrieving objects of a particular type. +

+
+tx = pm.currentTransaction();
+try
+{
+    tx.begin();
+
+    Extent e = pm.getExtent(mydomain.MyClass.class, true);
+    Iterator iter=e.iterator();
+    while (iter.hasNext())
+    {
+        MyClass my_obj=(MyClass)iter.next();
+        ...
+    }
+
+    tx.commit();
+}
+catch (Exception e)
+{
+    if (tx.isActive())
+    {
+        tx.rollback();
+    }
+}
+

+ The Extent interface is one of the ways to retrieve your objects. + The others use the Query interface, allowing more precise filtering over the + objects returned. +



Update Objects

+ To update an object we firstly retrieve it, as above, and then we call any of its + mutator methods. For example +

+
+tx = pm.currentTransaction();
+try
+{
+    tx.begin();
+
+    Extent e = pm.getExtent(mydomain.MyClass.class, true);
+    Iterator iter=e.iterator();
+    while (iter.hasNext())
+    {
+        MyClass my_obj=(MyClass)iter.next();
+        my_obj.setValue(25.0); // Change the value
+        ...
+    }
+
+    tx.commit();
+}
+catch (Exception e)
+{
+    if (tx.isActive())
+    {
+        tx.rollback();
+    }
+}
+

+ When setValue() is called on the persistent object this change is intercepted + by JDO and the value change will be automatically sent to the datastore ... transparently! +



Delete Objects

+ So we can persist objects, and retrieve them. Now we want to remove one from persistence. +

+
try
+{
+    tx = pm.currentTransaction();
+    tx.begin();
+
+    ... (code to retrieve object in question) ...
+
+    pm.deletePersistent(my_obj);
+
+    tx.commit();
+}
+catch (Exception e)
+{
+    if (tx.isActive())
+    {
+        tx.rollback();
+    }
+}
+

Making an object transient

+ As we have seen in the JDO States guide, an object can + have many possible states. When we want to take an object and work on it, but removing + its identity we can make it transient. This means that it will retain the values + of its fields, yet will no longer be associated with the object in the datastore. + We do this as follows +

+
try
+{
+    tx = pm.currentTransaction();
+    tx.begin();
+
+    ... (code to retrieve object in question) ...
+
+    pm.makeTransient(my_obj);
+
+    tx.commit();
+}
+catch (Exception e)
+{
+    if (tx.isActive())
+    {
+        tx.rollback();
+    }
+}
+
+... (code to work on "my_obj")
+

\ No newline at end of file Modified: db/jdo/site/docs/pmf.html URL: http://svn.apache.org/viewvc/db/jdo/site/docs/pmf.html?rev=581796&r1=581795&r2=581796&view=diff ============================================================================== --- db/jdo/site/docs/pmf.html (original) +++ db/jdo/site/docs/pmf.html Thu Oct 4 01:11:54 2007 @@ -1,7 +1,7 @@ Java Data Objects (JDO) - Persistence Manager Factory

Persistence Manager Factory

+ @import url("./style/maven-theme.css");

Persistence Manager Factory

Any JDO-enabled application will require at least one PersistenceManagerFactory. Typically applications create one per datastore being utilised. A PersistenceManagerFactory provides access to PersistenceManagers which allow @@ -110,5 +110,5 @@ "persistence-unit" concept from JPA for use with JDO 2.1.

javax.jdo.option.ServerTimeZoneID
DescriptionId of the TimeZone under which the datastore server is running. If this is not specified or is set to null it is assumed that the datastore server is running in the same timezone as the JVM under which the implementation is running.


javax.jdo.option.Name
DescriptionName of the PMF. This is for use with "named PMF" functionality in JDO 2.1





Modified: db/jdo/site/docs/project-info.html URL: http://svn.apache.org/viewvc/db/jdo/site/docs/project-info.html?rev=581796&r1=581795&r2=581796&view=diff ============================================================================== --- db/jdo/site/docs/project-info.html (original) +++ db/jdo/site/docs/project-info.html Thu Oct 4 01:11:54 2007 @@ -1,7 +1,7 @@ Java Data Objects (JDO) - Project Information

General Project Information

+ @import url("./style/maven-theme.css");

General Project Information

This document provides an overview of the various documents and links that are part of this project's general information. All of this content is automatically generated by @@ -22,5 +22,5 @@ project. Issues (bugs, features, change requests) can be created and queried using this link.


Modified: db/jdo/site/docs/references.html URL: http://svn.apache.org/viewvc/db/jdo/site/docs/references.html?rev=581796&r1=581795&r2=581796&view=diff ============================================================================== --- db/jdo/site/docs/references.html (original) +++ db/jdo/site/docs/references.html Thu Oct 4 01:11:54 2007 @@ -1,7 +1,7 @@ Java Data Objects (JDO) - References

JDO References

Articles

+ @import url("./style/maven-theme.css");

JDO References

Articles

There have been several articles about JDO on various websites. Some are listed below

  • SUN : JDO Web Site
  • @@ -21,5 +21,5 @@ Core Java Data Objects by Sameer Tyagi, Michael Vorburger, Keiron McCammon, Heiko Bobzin. Publisher: Prentice Hall



Modified: db/jdo/site/docs/releases/release-2.0-beta.html URL: http://svn.apache.org/viewvc/db/jdo/site/docs/releases/release-2.0-beta.html?rev=581796&r1=581795&r2=581796&view=diff ============================================================================== --- db/jdo/site/docs/releases/release-2.0-beta.html (original) +++ db/jdo/site/docs/releases/release-2.0-beta.html Thu Oct 4 01:11:54 2007 @@ -1,7 +1,7 @@ Java Data Objects (JDO) - Apache JDO 2.0 Release

JDO 2.0 Beta Distributions

Use the links below to download a distribution of Apache JDO from one of our mirrors. To run the Technology Compatibility Kit (TCK), you need only download and extract jdo2-tck-2.0-beta-src-24_Jan_2006.zip, follow the instructions in the Prerequisites section of README.txt, and then follow the procedure in RunRules.html in the jdo2-tck-2.0-beta directory. + @import url("../style/maven-theme.css");

JDO 2.0 Beta Distributions

Use the links below to download a distribution of Apache JDO from one of our mirrors. To run the Technology Compatibility Kit (TCK), you need only download and extract jdo2-tck-2.0-beta-src-24_Jan_2006.zip, follow the instructions in the Prerequisites section of README.txt, and then follow the procedure in RunRules.html in the jdo2-tck-2.0-beta directory. All the distributions below may be extracted into the same directory.

It is good practice to verify the integrity of the distribution files.

You are currently using [preferred]. If you encounter a problem with this mirror, then please select another. If all mirrors are failing, there are backup mirrors at the end of the list. See status of mirrors.

Other mirrors: