Skip to content

Commit

Permalink
srm: Use DataNucleus rather than toplink
Browse files Browse the repository at this point in the history
The AuthorizationRecord code still used toplink as its JPA
implementation. When experimenting with H2 and HSQLDB I ran into issues
with toplink.

This patch switches to using DataNucleus rather than Toplink. We already
used DataNucleus for the JDO code.

I had to make a few changes to make the code work with DataNucleus.

Unfortunately, I was unable to make DataNucleus map to the same schema
as toplink. The issue is with the boolean field in AuthorizationRecord.
I can work around the problem by forcing a JDBC type of BIT (which works
with PostgreSQL), however then it will not work with HSQLDB and H2.
Forcing a JDBC type of BOOLEAN does not work with PostgreSQL. In the end
I decided to let DataNucleus create new tables. The data in the
authorization tables is not important to preserve. DataNucleus will
recreate the tables using upper case table names and those will be
different from the lower case names used by toplink.

Release notes: Under a section about the SRM you should note that the
authrecord, authgroup and authgrouplist tables of the SRM database
will be replaced by new tables called AUTHRECORD, AUTHGROUP and
AUTHGROUPLIST. Administrators may choose to drop the old tables.

Target: trunk
Acked-by: Dmitry Litvintsev <litvinse@fnal.gov>
Patch: http://rb.dcache.org/r/4488/
  • Loading branch information
Gerd Behrmann committed May 14, 2012
1 parent 25b5e8d commit 466f9a6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 64 deletions.
20 changes: 15 additions & 5 deletions modules/dcache/pom.xml
Expand Up @@ -86,10 +86,6 @@
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
</dependency>
<dependency>
<groupId>toplink.essentials</groupId>
<artifactId>toplink-essentials</artifactId>
</dependency>
<dependency>
<groupId>com.sleepycat</groupId>
<artifactId>je</artifactId>
Expand Down Expand Up @@ -288,14 +284,28 @@
<version>2.2.1</version>
<configuration>
<verbose>false</verbose>
<metadataIncludes>**/*.jdo</metadataIncludes>
</configuration>
<executions>
<execution>
<id>datanucleus-enhance-jdo</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
<configuration>
<metadataIncludes>**/*.jdo</metadataIncludes>
</configuration>
</execution>
<execution>
<id>datanucleus-enhance-jpa</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
<configuration>
<api>JPA</api>
<persistenceUnitName>AuthRecordPersistenceUnit</persistenceUnitName>
</configuration>
</execution>
</executions>
<dependencies>
Expand Down
Expand Up @@ -182,7 +182,7 @@ public AuthorizationRecord(LoginReply login)
}
}

setId();
resetId();
}

/**
Expand Down Expand Up @@ -254,9 +254,9 @@ public void setId(long id) {
/**
* Set the id to a value computed from getId().
*/
public void setId() {
public void resetId() {
if (id != 0) return;
id = getId(this);
id = computeId(this);
}

@Basic
Expand Down Expand Up @@ -325,7 +325,7 @@ public void setRoot(String Root) {
}

@Basic
@Column( name="read_only")
@Column(name="read_only")
public boolean isReadOnly() {
return readOnly;
}
Expand Down Expand Up @@ -461,7 +461,7 @@ public int getGid() {
}

@Transient
public long getId(AuthorizationRecord authrec) {
public long computeId(AuthorizationRecord authrec) {
long id = authrec.getId();

if(id != 0 ) return id;
Expand Down
Expand Up @@ -54,21 +54,15 @@ public AuthRecordPersistenceManager(String jdbcUrl,
jdbcDriver+","+
user+","+
pass+")");
// This properties allow us to override the defaults

Properties p = new Properties();
// JPOX a.k.a. DataNucleous style properties
p.put("javax.jdo.option.ConnectionDriverName",jdbcDriver);
p.put("javax.jdo.option.ConnectionURL",jdbcUrl);
p.put("javax.jdo.option.ConnectionUserName",user);
p.put("javax.jdo.option.ConnectionPassword",pass);

// GlassFish a.k.a. TopLink style
p.put("toplink.jdbc.driver",jdbcDriver);
p.put("toplink.jdbc.url",jdbcUrl);
p.put("toplink.jdbc.user",user);
p.put("toplink.jdbc.password",pass);
p.put( "toplink.weaving","false");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("AuthRecordPersistenceUnit",p );
p.setProperty("javax.persistence.jdbc.driver", jdbcDriver);
p.setProperty("javax.persistence.jdbc.url", jdbcUrl);
p.setProperty("javax.persistence.jdbc.user", user);
p.setProperty("javax.persistence.jdbc.password", pass);

EntityManagerFactory emf =
Persistence.createEntityManagerFactory("AuthRecordPersistenceUnit", p);
em = emf.createEntityManager();
}

Expand Down
18 changes: 4 additions & 14 deletions modules/dcache/src/main/resources/META-INF/persistence.xml
Expand Up @@ -5,24 +5,13 @@

<!-- Tutorial "unit" -->
<persistence-unit name="AuthRecordPersistenceUnit">
<provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
<mapping-file>org/dcache/auth/AuthRecordORM.xml</mapping-file>
<provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
<mapping-file>org/dcache/auth/AuthRecordORM.xml</mapping-file>
<class>org.dcache.auth.AuthorizationRecord</class>
<class>org.dcache.auth.GroupList</class>
<class>org.dcache.auth.Group</class>
<properties>
<property name="toplink.jdbc.user" value="srmdcache"/>
<property name="toplink.jdbc.password" value=""/>
<property name="toplink.jdbc.url" value="jdbc:postgresql://localhost/dcache"/>
<property name="toplink.jdbc.driver" value="org.postgresql.Driver"/>
<property name="toplink.ddl-generation" value="create-tables"/>
<property name="toplink.ddl-generation.output-mode" value="database"/>
<property name="toplink.create-ddl-jdbc-file-name" value="createDDL.jdbc"/>
<property name="toplink.drop-ddl-jdbc-file-name" value="dropDDL.jdbc" />
<property name="toplink.application-location" value="/tmp" />
<property name="toplink.logging.level" value="SEVERE"/>
<property name="toplink.logging.exceptions" value="false"/>
<property name="toplink.logging.logger" value="JavaLogger"/>
<property name="datanucleus.autoCreateSchema" value="true"/>
</properties>
</persistence-unit>

Expand All @@ -37,3 +26,4 @@
</persistence-unit>

</persistence>

Expand Up @@ -6,30 +6,15 @@
<description>JPA Mapping file for AuthRecord</description>
<package>org.dcache.auth</package>

<entity class="org.dcache.auth.AuthorizationRecord" name="AUTHRECORD">
<table name="AUTHRECORD"/>
<entity class="org.dcache.auth.AuthorizationRecord" name="authrecord">
<table name="authrecord"/>
</entity>

<entity class="org.dcache.auth.GroupList" name="AUTHGROUPLIST">
<table name="AUTHGROUPLIST"/>
<!-- <attributes>
<id name="id">
<generated-value strategy="TABLE"/>
</id>
</attributes>
-->
<entity class="org.dcache.auth.GroupList" name="authgrouplist">
<table name="authgrouplist"/>
</entity>

<entity class="org.dcache.auth.Group" name="AUTHGROUP">
<table name="AUTHGROUP"/>
<!-- <attributes>
<id name="id">
<generated-value strategy="TABLE"/>
</id>

</attributes>
-->
<entity class="org.dcache.auth.Group" name="authgroup">
<table name="authgroup"/>
</entity>

</entity-mappings>
5 changes: 0 additions & 5 deletions pom.xml
Expand Up @@ -287,11 +287,6 @@
<artifactId>grizzly-framework</artifactId>
<version>2.1.8</version>
</dependency>
<dependency>
<groupId>toplink.essentials</groupId>
<artifactId>toplink-essentials</artifactId>
<version>2.1-60f</version>
</dependency>
<dependency>
<groupId>com.sleepycat</groupId>
<artifactId>je</artifactId>
Expand Down

0 comments on commit 466f9a6

Please sign in to comment.