From: Erik Brakkee Date: Tue, 11 May 2010 09:44:27 +0000 (+0000) Subject: JPA mapping updates X-Git-Tag: wamblee-utils-0.7~464 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=a0e5219a62cafc60127bcbb9ea2b7c3f8c403ccb;p=utils JPA mapping updates --- diff --git a/security/impl/src/main/java/org/wamblee/security/AbstractPersistent.java b/security/impl/src/main/java/org/wamblee/security/AbstractPersistent.java index cd2837dd..ced29a3f 100644 --- a/security/impl/src/main/java/org/wamblee/security/AbstractPersistent.java +++ b/security/impl/src/main/java/org/wamblee/security/AbstractPersistent.java @@ -26,12 +26,12 @@ import org.wamblee.persistence.Persistent; */ public abstract class AbstractPersistent implements Persistent { - private Serializable primaryKey; + private Serializable id; private Number version; protected AbstractPersistent() { - primaryKey = null; + id = null; version = -1; } @@ -42,7 +42,7 @@ public abstract class AbstractPersistent implements Persistent { * Object to copy. */ protected AbstractPersistent(AbstractPersistent aPersistent) { - primaryKey = aPersistent.primaryKey; + id = aPersistent.id; version = aPersistent.version; } @@ -53,7 +53,7 @@ public abstract class AbstractPersistent implements Persistent { */ @Override public Serializable getPrimaryKey() { - return primaryKey; + return id; } /* @@ -64,7 +64,7 @@ public abstract class AbstractPersistent implements Persistent { */ @Override public void setPrimaryKey(Serializable aKey) { - primaryKey = aKey; + id = aKey; } /* diff --git a/security/impl/src/main/java/org/wamblee/security/authentication/Group.java b/security/impl/src/main/java/org/wamblee/security/authentication/Group.java index ca77582f..1cac00f8 100644 --- a/security/impl/src/main/java/org/wamblee/security/authentication/Group.java +++ b/security/impl/src/main/java/org/wamblee/security/authentication/Group.java @@ -48,7 +48,7 @@ public class Group implements Serializable, Comparable { @Id @GeneratedValue(strategy = GenerationType.AUTO) - private Long primaryKey; + private Long id; @Version private int version; @@ -74,7 +74,7 @@ public class Group implements Serializable, Comparable { * */ public Group(Group aGroup) { - primaryKey = aGroup.primaryKey; + id = aGroup.id; version = aGroup.version; name = aGroup.name; } @@ -143,11 +143,11 @@ public class Group implements Serializable, Comparable { } public Long getPrimaryKey() { - return primaryKey; + return id; } public void setPrimaryKey(Long aKey) { - primaryKey = aKey; + id = aKey; } /* diff --git a/security/impl/src/main/java/org/wamblee/security/authentication/User.java b/security/impl/src/main/java/org/wamblee/security/authentication/User.java index 82a77303..5e6666b7 100644 --- a/security/impl/src/main/java/org/wamblee/security/authentication/User.java +++ b/security/impl/src/main/java/org/wamblee/security/authentication/User.java @@ -20,11 +20,14 @@ import java.util.Set; import java.util.TreeSet; import javax.persistence.CascadeType; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; @@ -58,7 +61,7 @@ public class User implements Serializable, Comparable { @Id @GeneratedValue(strategy = GenerationType.AUTO) - private Long primaryKey; + private Long id; @Version private int version; @@ -77,6 +80,7 @@ public class User implements Serializable, Comparable { * Groups the user belongs to. */ @ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.EAGER) + @JoinTable(name = "SEC_USER_GROUP", joinColumns = { @JoinColumn(name = "USER_ID") }, inverseJoinColumns = { @JoinColumn(name = "GROUP_ID") }) private Set groups; /** @@ -115,7 +119,7 @@ public class User implements Serializable, Comparable { * */ public User(User aUser) { - primaryKey = aUser.primaryKey; + id = aUser.id; version = aUser.version; name = aUser.name; password = aUser.password; @@ -393,6 +397,6 @@ public class User implements Serializable, Comparable { } public Long getPrimaryKey() { - return primaryKey; + return id; } } diff --git a/security/impl/src/main/java/org/wamblee/security/authorization/AbstractAuthorizationRule.java b/security/impl/src/main/java/org/wamblee/security/authorization/AbstractAuthorizationRule.java index ebd52882..14ce4340 100644 --- a/security/impl/src/main/java/org/wamblee/security/authorization/AbstractAuthorizationRule.java +++ b/security/impl/src/main/java/org/wamblee/security/authorization/AbstractAuthorizationRule.java @@ -43,7 +43,7 @@ public abstract class AbstractAuthorizationRule implements AuthorizationRule { @Id @GeneratedValue(strategy = GenerationType.AUTO) - private Long primaryKey; + private Long id; @Version private int version; @@ -53,7 +53,7 @@ public abstract class AbstractAuthorizationRule implements AuthorizationRule { } public AbstractAuthorizationRule(AbstractAuthorizationRule aRule) { - primaryKey = aRule.primaryKey; + id = aRule.id; version = aRule.version; } } diff --git a/security/impl/src/main/java/org/wamblee/security/authorization/AbstractAuthorizationService.java b/security/impl/src/main/java/org/wamblee/security/authorization/AbstractAuthorizationService.java index e6534551..6cdb4ca2 100644 --- a/security/impl/src/main/java/org/wamblee/security/authorization/AbstractAuthorizationService.java +++ b/security/impl/src/main/java/org/wamblee/security/authorization/AbstractAuthorizationService.java @@ -50,7 +50,7 @@ public abstract class AbstractAuthorizationService implements AuthorizationServi @Id @GeneratedValue(strategy = GenerationType.AUTO) - private Long primaryKey; + private Long id; @Version private int version; @@ -69,7 +69,7 @@ public abstract class AbstractAuthorizationService implements AuthorizationServi } public AbstractAuthorizationService(AbstractAuthorizationService aSvc) { - primaryKey = aSvc.primaryKey; + id = aSvc.id; version = aSvc.version; name = aSvc.name; } diff --git a/security/impl/src/main/java/org/wamblee/security/authorization/AbstractOperationCondition.java b/security/impl/src/main/java/org/wamblee/security/authorization/AbstractOperationCondition.java index 69048ebd..f9333092 100644 --- a/security/impl/src/main/java/org/wamblee/security/authorization/AbstractOperationCondition.java +++ b/security/impl/src/main/java/org/wamblee/security/authorization/AbstractOperationCondition.java @@ -38,7 +38,7 @@ public abstract class AbstractOperationCondition implements OperationCondition { @Id @GeneratedValue(strategy = GenerationType.AUTO) - private Long primaryKey; + private Long id; @Version private int version; @@ -48,7 +48,7 @@ public abstract class AbstractOperationCondition implements OperationCondition { } public AbstractOperationCondition(AbstractOperationCondition aCondition) { - primaryKey = aCondition.primaryKey; + id = aCondition.id; version = aCondition.version; } } diff --git a/security/impl/src/main/java/org/wamblee/security/authorization/AbstractPathCondition.java b/security/impl/src/main/java/org/wamblee/security/authorization/AbstractPathCondition.java index 6ec48017..f131dea3 100644 --- a/security/impl/src/main/java/org/wamblee/security/authorization/AbstractPathCondition.java +++ b/security/impl/src/main/java/org/wamblee/security/authorization/AbstractPathCondition.java @@ -38,7 +38,7 @@ public abstract class AbstractPathCondition implements PathCondition { @Id @GeneratedValue(strategy = GenerationType.AUTO) - private Long primaryKey; + private Long id; @Version private int version; @@ -48,7 +48,7 @@ public abstract class AbstractPathCondition implements PathCondition { } public AbstractPathCondition(AbstractPathCondition aCondition) { - primaryKey = aCondition.primaryKey; + id = aCondition.id; version = aCondition.version; } } diff --git a/security/impl/src/main/java/org/wamblee/security/authorization/AbstractUserCondition.java b/security/impl/src/main/java/org/wamblee/security/authorization/AbstractUserCondition.java index e6bb53fc..96952075 100644 --- a/security/impl/src/main/java/org/wamblee/security/authorization/AbstractUserCondition.java +++ b/security/impl/src/main/java/org/wamblee/security/authorization/AbstractUserCondition.java @@ -40,7 +40,7 @@ public abstract class AbstractUserCondition implements UserCondition { @Id @GeneratedValue(strategy = GenerationType.AUTO) - private Long primaryKey; + private Long id; @Version private int version; @@ -50,7 +50,7 @@ public abstract class AbstractUserCondition implements UserCondition { } public AbstractUserCondition(AbstractUserCondition aCondition) { - primaryKey = aCondition.primaryKey; + id = aCondition.id; version = aCondition.version; } } diff --git a/security/impl/src/main/java/org/wamblee/security/authorization/DefaultAuthorizationService.java b/security/impl/src/main/java/org/wamblee/security/authorization/DefaultAuthorizationService.java index 8e449b9e..a142712e 100644 --- a/security/impl/src/main/java/org/wamblee/security/authorization/DefaultAuthorizationService.java +++ b/security/impl/src/main/java/org/wamblee/security/authorization/DefaultAuthorizationService.java @@ -21,12 +21,12 @@ import java.util.List; import javax.persistence.CascadeType; import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; -import javax.persistence.ManyToMany; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; import javax.persistence.OneToMany; import javax.persistence.OrderColumn; import javax.persistence.Transient; -import org.wamblee.security.authentication.User; import org.wamblee.security.authentication.UserAccessor; import org.wamblee.security.authentication.UserAdministration; @@ -48,6 +48,7 @@ public class DefaultAuthorizationService extends AbstractAuthorizationService { * List of ordered authorization rules. */ @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, targetEntity = AbstractAuthorizationRule.class) + @JoinTable(name = "SEC_AUTH_SVC_RULE", joinColumns = { @JoinColumn(name = "SVC_ID") }, inverseJoinColumns = { @JoinColumn(name = "RULE_ID") }) @OrderColumn(name = "RULE_INDEX") private List rules; @@ -75,7 +76,7 @@ public class DefaultAuthorizationService extends AbstractAuthorizationService { super(aName); rules = new ArrayList(); userAccessor = aAccessor; - userAdmin = aUserAdmin; + userAdmin = aUserAdmin; } /** @@ -84,19 +85,18 @@ public class DefaultAuthorizationService extends AbstractAuthorizationService { public DefaultAuthorizationService() { rules = new ArrayList(); userAccessor = null; - userAdmin = null; + userAdmin = null; } - @Override public void setUserAccessor(UserAccessor aUserAccessor) { userAccessor = aUserAccessor; } - + @Override public void setUserAdministration(UserAdministration aUserAdmin) { userAdmin = aUserAdmin; - for (AuthorizationRule rule: rules) { + for (AuthorizationRule rule : rules) { rule.setUserAdministration(userAdmin); } } @@ -198,7 +198,7 @@ public class DefaultAuthorizationService extends AbstractAuthorizationService { */ protected void setMappedRules(List aRules) { rules = aRules; - for (AuthorizationRule rule: rules) { + for (AuthorizationRule rule : rules) { rule.setUserAdministration(userAdmin); } } diff --git a/security/jpatest/src/test/java/org/wamblee/security/authentication/jpa/UserAdministrationTester.java b/security/jpatest/src/test/java/org/wamblee/security/authentication/jpa/UserAdministrationTester.java index 366ec6a9..634e10ed 100644 --- a/security/jpatest/src/test/java/org/wamblee/security/authentication/jpa/UserAdministrationTester.java +++ b/security/jpatest/src/test/java/org/wamblee/security/authentication/jpa/UserAdministrationTester.java @@ -28,6 +28,7 @@ import org.wamblee.security.authentication.UserSet; import org.wamblee.security.encryption.Md5HexMessageDigester; import org.wamblee.security.encryption.MessageDigester; import org.wamblee.support.persistence.JpaTester; +import org.wamblee.support.persistence.PersistenceUnitDescription; import org.wamblee.support.persistence.TransactionProxyFactory; /** @@ -38,12 +39,14 @@ import org.wamblee.support.persistence.TransactionProxyFactory; */ public class UserAdministrationTester { + private PersistenceUnitDescription persistenceUnit; private JpaTester jpaTester; private Cache userCache; private UserAdministration userAdmin; public UserAdministrationTester() { - jpaTester = new JpaTester(new SecurityPersistenceUnit()); + persistenceUnit = new SecurityPersistenceUnit(); + jpaTester = new JpaTester(persistenceUnit); } public void start() throws Exception { @@ -72,6 +75,9 @@ public class UserAdministrationTester { userAdmin = factory.getProxy(userAdminImpl); } + public PersistenceUnitDescription getPersistenceUnit() { + return persistenceUnit; + } public JpaTester getJpaTester() { return jpaTester; diff --git a/security/jpatest/src/test/java/org/wamblee/security/authorization/jpa/JpaAuthorizationServiceTest.java b/security/jpatest/src/test/java/org/wamblee/security/authorization/jpa/JpaAuthorizationServiceTest.java index afb0d405..d2053c2c 100644 --- a/security/jpatest/src/test/java/org/wamblee/security/authorization/jpa/JpaAuthorizationServiceTest.java +++ b/security/jpatest/src/test/java/org/wamblee/security/authorization/jpa/JpaAuthorizationServiceTest.java @@ -43,7 +43,7 @@ public class JpaAuthorizationServiceTest extends AuthorizationServiceTest { private static final String RULES_TABLE = "SEC_AUTH_RULE"; - private static final String SERVICE_RULES_TABLE = "SEC_AUTH_SVC_SEC_AUTH_RULE"; + private static final String SERVICE_RULES_TABLE = "SEC_AUTH_SVC_RULE"; private static final String OPERATIONCOND_TABLE = "SEC_OPERATION_CONDITION";