Fireburn
Fireburn

Reputation: 1021

persistence.xml configuration to pure Java JDO configuration

I have this persistence.xml config file:

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
        http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" version="2.1">
    <persistence-unit name="transactions-optional">
        <class>myapp.Room</class>
        <exclude-unlisted-classes/>
        <properties>
            <property name="javax.jdo.PersistenceManagerFactoryClass"
                      value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory" />
            <property name="datanucleus.ConnectionURL" value="mongodb:localhost:27017/admin" />
            <property name="datanucleus.ConnectionUserName" value="admin" />
            <property name="datanucleus.ConnectionPassword" value="adminadmin" />
            <property name="datanucleus.storeManagerType" value="mongodb" />
            <property name="datanucleus.autoCreateSchema" value="true" />
        </properties>
    </persistence-unit>
</persistence>

And I need to convert it to pure-Java code implementation like this:

protected PersistenceManager getPersistenceManager() {
  if (pm == null) {
    synchronized(lock) {
      if (pm == null) {
        Properties newProperties = new Properties();
        newProperties.put("javax.jdo.PersistenceManagerFactoryClass", "org.datanucleus.api.jdo.JDOPersistenceManagerFactory");
        newProperties.put("datanucleus.ConnectionURL", "mongodb:localhost:27017/admin");
        newProperties.put("datanucleus.ConnectionUserName", "admin");
        newProperties.put("datanucleus.ConnectionPassword", "adminadmin");
        newProperties.put("datanucleus.storeManagerType", "mongodb");
        newProperties.put("datanucleus.autoCreateSchema", "true");
        pmf = JDOHelper.getPersistenceManagerFactory(newProperties, "transactions-optional");
        pm = pmf.getPersistenceManager();;
      }
    }
  }
  return pm;
}

How do I add these attributes to the JDOHelper initialization?

<class>myapp.Room</class>
<exclude-unlisted-classes/>

Upvotes: 1

Views: 95

Answers (0)

Related Questions