Skip to content
Permalink
Browse files
Fix year on copyright. Add various hyperlinks between sections.
  • Loading branch information
andyjefferson committed Apr 15, 2022
1 parent 416667a commit de9d4ca8f0168c2b842ce07a2b0b24e730443d74
Showing 3 changed files with 52 additions and 19 deletions.
@@ -32,7 +32,7 @@ Person per = pm.getObjectById(Person.class, identity);

If the object is in the JDO cache (Level 1 or Level 2) then it is retrieved from there,
otherwise the JDO implementation goes to the datastore.
When the object is retrieved its fields are populated according to its Fetch Group.
When the object is retrieved its fields are populated according to its link:fetchgroups.html[Fetch Plan].



@@ -65,9 +65,9 @@ It can also be used where you just want to retrieve all persisted objects of a t
=== Retrieve an object based on a query criteria

Where we want to retrieve all objects based on some criteria (e.g all objects of class A where field 'x' of A is a certain value) we need to
use a query language.
The JDO API provides the JDOQL object-based query language where you express your query in terms of classes and fields you are using.
Dependent on your JDO provider and the datastore being used you may also be able to use a (native) query language such as SQL, expressing
use a query language and the link:query_api.html[JDO Query API].
The JDO API provides the link:jdoql.html[JDOQL] object-based query language where you express your query in terms of classes and fields you are using.
Dependent on your JDO provider and the datastore being used you may also be able to use a (native) query language such as link:query_sql.html[SQL], expressing
your query in terms of datastore tables/columns.

To give an example of a JDOQL query
@@ -1,41 +1,40 @@
[[pmf]]
= PersistenceManagerFactory
:_basedir:
:_imagesdir: images/
:notoc:
:notitle:
:grid: cols
:usage:

[[index]]

[[Persistence_Manager_Factory]]
== Persistence Manager Factory

Any JDO-enabled application will require at least one _PersistenceManagerFactory_.
Any JDO-enabled application will require (at least) one _PersistenceManagerFactory_.
Typically applications create one per datastore being utilised.
A _PersistenceManagerFactory_ provides access to __PersistenceManager__s which allow objects to be persisted, and retrieved.
The _PersistenceManagerFactory_ can be configured to provide particular behaviour.

The simplest way of creating a _PersistenceManagerFactory_
A simple way of creating a _PersistenceManagerFactory_
link:api32/apidocs/javax/jdo/PersistenceManagerFactory.html[image:images/javadoc.png[image]]
is as follows
is using a set of properties controlling its behaviour, as follows

[source,java]
....
Properties properties = new Properties();
properties.setProperty("javax.jdo.PersistenceManagerFactoryClass", "{my_implementation_pmf_class}");
properties.setProperty("javax.jdo.option.ConnectionDriverName", "com.mysql.jdbc.Driver");
properties.setProperty("javax.jdo.option.ConnectionURL", "jdbc:mysql://localhost/myDB");
properties.setProperty("javax.jdo.option.ConnectionUserName", "login");
properties.setProperty("javax.jdo.option.ConnectionPassword", "password");
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(properties);
....

A slight variation on this, is to use a file ("jdo.properties" for
example) to specify these properties like this


A slight variation on this, is to use a file containg these properties (`jdo.properties` for example) to create the PMF, like this

....
javax.jdo.PersistenceManagerFactoryClass={my_implementation_pmf_class}
javax.jdo.option.ConnectionDriverName=com.mysql.jdbc.Driver
javax.jdo.option.ConnectionURL=jdbc:mysql://localhost/myDB
javax.jdo.option.ConnectionUserName=login
javax.jdo.option.ConnectionPassword=password
@@ -48,8 +47,41 @@ and then to create the _PersistenceManagerFactory_ using this file
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("jdo.properties");
....

A final alternative would be to call
_JDOHelper.getPersistenceManagerFactory(jndiLocation, context);_, hence


You could alternatively make use of a JPA `persistence.xml` file to create a PMF, like this

[source,xml]
....
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence
https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd" version="3.0">
<!-- MyApp persistence unit -->
<persistence-unit name="MyApp">
<class>mydomain.Product</class>
<class>mydomain.Book</class>
<class>mydomain.CompactDisc</class>
<exclude-unlisted-classes/>
<properties>
<property name="datanucleus.ConnectionURL" value="jdbc:mysql://localhost/myDB"/>
<property name="datanucleus.ConnectionUserName" value="mysql"/>
<property name="datanucleus.ConnectionPassword" value=""/>
</properties>
</persistence-unit>
</persistence>
....

and then instantiate the PMF using the _persistence unit name_, defining the classes that have JDO annotations that make up this application.

[source,java]
....
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("MyApp");
....


An alternative using JNDI would be to call _JDOHelper.getPersistenceManagerFactory(jndiLocation, context);_, hence
accessing the properties via JNDI.

Whichever way we wish to obtain the _PersistenceManagerFactory_ we have defined a series of properties to give the behaviour of the _PersistenceManagerFactory_.
@@ -59,7 +91,8 @@ define the datastore that it should connect to.
{empty} +


=== Standard JDO Propertiesanchor:Standard_JDO_Properties[]
[[standard_properties]]
=== Standard JDO Properties

[cols=",",options="header",]
|===
@@ -111,7 +144,7 @@ Range of Values: true \| false
Range of Values: true \| false

|*javax.jdo.option.Optimistic*
|Whether to use xref:transactions.html[Optimistic transactions].
|Whether to use xref:transactions.html#locking[Optimistic locking] on transactions.
Range of Values: true \| false

|*javax.jdo.option.RetainValues*
@@ -153,7 +153,6 @@
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">API Usage<span class="caret"></span></a>
<% end %>
<ul class="dropdown-menu">
<li><a href="<%= (attr :_basedir) %>jdohelper.html">JDO Helper</a></li>
<li><a href="<%= (attr :_basedir) %>pmf.html">PersistenceManagerFactory</a></li>
<li><a href="<%= (attr :_basedir) %>pm.html">PersistenceManager</a></li>
<li><a href="<%= (attr :_basedir) %>transactions.html">Transactions</a></li>
@@ -162,6 +161,7 @@
<li><a href="<%= (attr :_basedir) %>state_transition.html">Object States</a></li>
<li><a href="<%= (attr :_basedir) %>object_retrieval.html">Object Retrieval</a></li>
<li><a href="<%= (attr :_basedir) %>exceptions.html">Exceptions</a></li>
<li><a href="<%= (attr :_basedir) %>jdohelper.html">JDO Helper</a></li>
<li role="separator" class="divider"></li>
<li><a href="<%= (attr :_basedir) %>guides-replication.html">Data Replication</a></li>
</ul>
@@ -307,7 +307,7 @@
<a href="api31/apidocs/index.html" title="Latest Javadocs">Latest Javadocs</a>
</div>
</div>
<p class="text-center" style="margin-top:16px">&copy; 2005-2021 Apache Software Foundation. All Rights Reserved.</p>
<p class="text-center" style="margin-top:16px">&copy; 2005-2022 Apache Software Foundation. All Rights Reserved.</p>
</div>
</footer>
<% end %>

0 comments on commit de9d4ca

Please sign in to comment.