From 466f9a63a82d1cc1491745a39ac78591910c373b Mon Sep 17 00:00:00 2001 From: Gerd Behrmann Date: Mon, 14 May 2012 14:15:17 +0000 Subject: [PATCH] srm: Use DataNucleus rather than toplink 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 Patch: http://rb.dcache.org/r/4488/ --- modules/dcache/pom.xml | 20 ++++++++++---- .../org/dcache/auth/AuthorizationRecord.java | 10 +++---- .../AuthRecordPersistenceManager.java | 22 ++++++--------- .../main/resources/META-INF/persistence.xml | 18 +++---------- .../org/dcache/auth/AuthRecordORM.xml | 27 +++++-------------- pom.xml | 5 ---- 6 files changed, 38 insertions(+), 64 deletions(-) diff --git a/modules/dcache/pom.xml b/modules/dcache/pom.xml index 03edd593941..ae53f69cc95 100644 --- a/modules/dcache/pom.xml +++ b/modules/dcache/pom.xml @@ -86,10 +86,6 @@ org.jboss.netty netty - - toplink.essentials - toplink-essentials - com.sleepycat je @@ -288,14 +284,28 @@ 2.2.1 false - **/*.jdo + datanucleus-enhance-jdo + process-classes + + enhance + + + **/*.jdo + + + + datanucleus-enhance-jpa process-classes enhance + + JPA + AuthRecordPersistenceUnit + diff --git a/modules/dcache/src/main/java/org/dcache/auth/AuthorizationRecord.java b/modules/dcache/src/main/java/org/dcache/auth/AuthorizationRecord.java index 20c0f5a3b82..a2f92c53784 100644 --- a/modules/dcache/src/main/java/org/dcache/auth/AuthorizationRecord.java +++ b/modules/dcache/src/main/java/org/dcache/auth/AuthorizationRecord.java @@ -182,7 +182,7 @@ public AuthorizationRecord(LoginReply login) } } - setId(); + resetId(); } /** @@ -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 @@ -325,7 +325,7 @@ public void setRoot(String Root) { } @Basic - @Column( name="read_only") + @Column(name="read_only") public boolean isReadOnly() { return readOnly; } @@ -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; diff --git a/modules/dcache/src/main/java/org/dcache/auth/persistence/AuthRecordPersistenceManager.java b/modules/dcache/src/main/java/org/dcache/auth/persistence/AuthRecordPersistenceManager.java index bec823b9d73..d68dd3efbff 100644 --- a/modules/dcache/src/main/java/org/dcache/auth/persistence/AuthRecordPersistenceManager.java +++ b/modules/dcache/src/main/java/org/dcache/auth/persistence/AuthRecordPersistenceManager.java @@ -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(); } diff --git a/modules/dcache/src/main/resources/META-INF/persistence.xml b/modules/dcache/src/main/resources/META-INF/persistence.xml index cd26ae6f48f..094ac550f06 100644 --- a/modules/dcache/src/main/resources/META-INF/persistence.xml +++ b/modules/dcache/src/main/resources/META-INF/persistence.xml @@ -5,24 +5,13 @@ - oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider - org/dcache/auth/AuthRecordORM.xml + org.datanucleus.api.jpa.PersistenceProviderImpl + org/dcache/auth/AuthRecordORM.xml org.dcache.auth.AuthorizationRecord org.dcache.auth.GroupList org.dcache.auth.Group - - - - - - - - - - - - + @@ -37,3 +26,4 @@ + diff --git a/modules/dcache/src/main/resources/org/dcache/auth/AuthRecordORM.xml b/modules/dcache/src/main/resources/org/dcache/auth/AuthRecordORM.xml index 830b71d61f9..d9bf7870207 100644 --- a/modules/dcache/src/main/resources/org/dcache/auth/AuthRecordORM.xml +++ b/modules/dcache/src/main/resources/org/dcache/auth/AuthRecordORM.xml @@ -6,30 +6,15 @@ JPA Mapping file for AuthRecord org.dcache.auth - - + +
- -
- + +
- - -
- + +
- diff --git a/pom.xml b/pom.xml index ff87604de15..ed7abeff06f 100644 --- a/pom.xml +++ b/pom.xml @@ -287,11 +287,6 @@ grizzly-framework2.1.8 - - toplink.essentials - toplink-essentials - 2.1-60f - com.sleepycat je