ArchitectureJdoRules

A library of architecture tests to ensure coding conventions are followed for classes annotated with the JDO javax.jdo.annotations.PersistenceCapable annotation.

API

ArchitectureJdoRules.java
class ArchitectureJdoRules {
  ArchRule every_logicalTypeName_and_jdo_discriminator_must_be_same()
  ArchRule every_jdo_PersistenceCapable_must_be_annotated_with_DomainObject_nature_of_ENTITY()     (1)
  ArchRule every_jdo_PersistenceCapable_must_be_annotated_with_Version()     (2)
  ArchRule every_jdo_PersistenceCapable_must_be_annotated_as_XmlJavaAdapter_PersistentEntityAdapter()     (3)
  ArchRule every_jdo_PersistenceCapable_must_implement_Comparable()     (4)
  ArchRule every_jdo_PersistenceCapable_must_be_annotated_as_Uniques_or_Unique()     (5)
  ArchRule every_jdo_PersistenceCapable_with_DATASTORE_identityType_must_be_annotated_as_DataStoreIdentity()     (6)
  ArchRule every_jdo_PersistenceCapable_must_have_schema()     (7)
  DescribedPredicate<JavaAnnotation<?>> PersistenceCapable_schema()
  DescribedPredicate<JavaAnnotation<?>> PersistenceCapable_with_DATASTORE_identityType()
  ArchRule every_injected_field_of_jdo_PersistenceCapable_must_be_annotated_with_NotPersistent()     (8)
  DescribedPredicate<JavaClass> areEntities()
  DescribedPredicate<? super JavaClass> areSubtypeEntities()
}
1 every_jdo_PersistenceCapable_must_be_annotated_with_DomainObject_nature_of_ENTITY()

This rule requires that classes annotated with the JDO javax.jdo.annotations.PersistenceCapable annotation must also be annotated with the Apache Causeway DomainObject annotation specifying that its DomainObject#nature() nature is an org.apache.causeway.applib.annotation.Nature#ENTITY entity .

2 every_jdo_PersistenceCapable_must_be_annotated_with_Version()

This rule requires that classes annotated with the JDO javax.jdo.annotations.PersistenceCapable annotation must also be annotated with the JDO javax.jdo.annotations.Version annotation (in support of optimistic locking checks).

3 every_jdo_PersistenceCapable_must_be_annotated_as_XmlJavaAdapter_PersistentEntityAdapter()

This rule requires that classes annotated with the JDO javax.jdo.annotations.PersistenceCapable annotation must also be annotated with the Apache Causeway javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter annotation with a value of org.apache.causeway.applib.jaxb.PersistentEntityAdapter .class .

4 every_jdo_PersistenceCapable_must_implement_Comparable()

This rule requires that classes annotated with the JDO javax.jdo.annotations.PersistenceCapable annotation must also implement Comparable .

5 every_jdo_PersistenceCapable_must_be_annotated_as_Uniques_or_Unique()

This rule requires that classes annotated with the JDO javax.jdo.annotations.PersistenceCapable annotation and is not a subtype entity, must also be annotated with the JDO javax.jdo.annotations.Uniques or javax.jdo.annotations.Unique constraints.

6 every_jdo_PersistenceCapable_with_DATASTORE_identityType_must_be_annotated_as_DataStoreIdentity()

This rule requires that classes annotated with the JDO javax.jdo.annotations.PersistenceCapable annotation must also be annotated with the JDO javax.jdo.annotations.Uniques or javax.jdo.annotations.Unique constraints.

7 every_jdo_PersistenceCapable_must_have_schema()

This rule requires that classes annotated with the JDO javax.jdo.annotations.PersistenceCapable annotation must have the javax.jdo.annotations.PersistenceCapable#schema() schema attribute set.

8 every_injected_field_of_jdo_PersistenceCapable_must_be_annotated_with_NotPersistent()

This rule requires that injected fields in classes annotated with the JDO PersistenceCapable annotation must also be annotated with JDO javax.jdo.annotations.NotPersistent annotation.

Members

every_jdo_PersistenceCapable_must_be_annotated_with_DomainObject_nature_of_ENTITY()

This rule requires that classes annotated with the JDO javax.jdo.annotations.PersistenceCapable annotation must also be annotated with the Apache Causeway DomainObject annotation specifying that its DomainObject#nature() nature is an org.apache.causeway.applib.annotation.Nature#ENTITY entity .

every_jdo_PersistenceCapable_must_be_annotated_with_Version()

This rule requires that classes annotated with the JDO javax.jdo.annotations.PersistenceCapable annotation must also be annotated with the JDO javax.jdo.annotations.Version annotation (in support of optimistic locking checks).

The rule does not apply to any entities that are subtype entities where there is a supertype entity.

every_jdo_PersistenceCapable_must_be_annotated_as_XmlJavaAdapter_PersistentEntityAdapter()

This rule requires that classes annotated with the JDO javax.jdo.annotations.PersistenceCapable annotation must also be annotated with the Apache Causeway javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter annotation with a value of org.apache.causeway.applib.jaxb.PersistentEntityAdapter .class .

Tnis is so that entities can be transparently referenced from XML-style view models.

every_jdo_PersistenceCapable_must_implement_Comparable()

This rule requires that classes annotated with the JDO javax.jdo.annotations.PersistenceCapable annotation must also implement Comparable .

This is so that entities have a natural ordering and can safely be added to parented collections of type java.util.SortedSet .

every_jdo_PersistenceCapable_must_be_annotated_as_Uniques_or_Unique()

This rule requires that classes annotated with the JDO javax.jdo.annotations.PersistenceCapable annotation and is not a subtype entity, must also be annotated with the JDO javax.jdo.annotations.Uniques or javax.jdo.annotations.Unique constraints.

This is so that entities will have an alternative business key in addition to the system-defined surrogate key.

every_jdo_PersistenceCapable_with_DATASTORE_identityType_must_be_annotated_as_DataStoreIdentity()

This rule requires that classes annotated with the JDO javax.jdo.annotations.PersistenceCapable annotation must also be annotated with the JDO javax.jdo.annotations.Uniques or javax.jdo.annotations.Unique constraints.

This is so that entities will have an alternative business key in addition to the system-defined surrogate key.

The rule does not apply to any entities that are subtype entities where there is a supertype entity.

every_jdo_PersistenceCapable_must_have_schema()

This rule requires that classes annotated with the JDO javax.jdo.annotations.PersistenceCapable annotation must have the javax.jdo.annotations.PersistenceCapable#schema() schema attribute set.

This is so that entity tables are organised into an appropriate structure (ideally mirroring that of the entities).

every_injected_field_of_jdo_PersistenceCapable_must_be_annotated_with_NotPersistent()

This rule requires that injected fields in classes annotated with the JDO PersistenceCapable annotation must also be annotated with JDO javax.jdo.annotations.NotPersistent annotation.

The rationale here is that injected services are managed by the runtime and are not/cannot be persisted.

In fact, JDO is tolerant to such fields and will not trip up. So another more pragmatic reason is that, if using JDO type-safe queries, then the injected fields will not appear incorrectly in the generated Q classes.