@CompileStatic @GroovyASTTransformation(phase: CompilePhase.CANONICALIZATION) class GormEntityTransformation extends AbstractASTTransformation implements CompilationUnitAware, ASTTransformation, TransformWithPriority
An AST transformation that adds the following features:
- An id and version (if not already present)
- A toString() method (if not already present)
- Associations and association methods (addTo*, removeFrom*) etc.
- Association id getter methods ('userId' for 'user' association)
- Adds the GormEntity and GormValidateable traits
- Named query methods
| Modifiers | Name | Description |
|---|---|---|
static Parameter[] |
ADD_TO_PARAMETERS |
|
static java.lang.String |
DEFAULT_ID_TYPE_LONG |
The DEFAULT_ID_TYPE_PROPERTY value that gives every entity a Long id. |
static java.lang.String |
DEFAULT_ID_TYPE_NATIVE |
The DEFAULT_ID_TYPE_PROPERTY value that defers to the GORM implementation the entity is mapped with. |
static java.lang.String |
DEFAULT_ID_TYPE_PROPERTY |
The system property, published by the Grails Gradle plugin from
grails { gorm { defaultIdType = '...' }}, that selects the type of the id
property injected into an entity that declares none of its own. |
static AnnotationNode |
JPA_ENTITY_ANNOTATION_NODE |
|
protected static ClassNode |
JPA_ENTITY_CLASS_NODE |
|
static AnnotationNode |
JPA_ID_ANNOTATION_NODE |
|
static AnnotationNode |
JPA_TRANSIENT_ANNOTATION_NODE |
|
static AnnotationNode |
JPA_VERSION_ANNOTATION_NODE |
|
static ClassNode |
SERIALIZABLE_CLASS_NODE |
|
protected CompilationUnit |
compilationUnit |
| Fields inherited from class | Fields |
|---|---|
class AbstractASTTransformation |
RETENTION_CLASSNODE |
| Constructor and description |
|---|
GormEntityTransformation() |
| Type Params | Return Type | Name and description |
|---|---|---|
|
ListExpression |
getOrCreateListProperty(ClassNode classNode, java.lang.String name) |
|
protected void |
injectIdProperty(ClassNode classNode, SourceUnit sourceUnit, GormEntityTraitProvider traitProvider) |
|
protected void |
injectVersionProperty(ClassNode classNode) |
|
int |
priority() |
|
protected java.lang.Class<?> |
resolveIdentityType(ClassNode classNode, SourceUnit sourceUnit, GormEntityTraitProvider traitProvider)The type of the id injected into an entity that declares none. |
|
protected GormEntityTraitProvider |
resolveTraitProvider(ClassNode classNode, SourceUnit source)Resolves, at compile time, the GORM implementation an entity is mapped with, from the entity's mapWith property and the GormEntityTraitProviders on the compilation classpath. |
|
void |
setCompilationUnit(CompilationUnit compilationUnit) |
|
void |
visit(ASTNode[] astNodes, SourceUnit sourceUnit) |
|
void |
visit(ClassNode classNode, SourceUnit sourceUnit) |
| Methods inherited from class | Name |
|---|---|
class AbstractASTTransformation |
addError, checkPropertyList, checkPropertyList, checkPropertyList, deemedInternalName, equals, getAnnotationName, getClass, getMemberClassList, getMemberClassValue, getMemberClassValue, getMemberIntValue, getMemberStringList, getMemberStringValue, getMemberStringValue, getMemberValue, hasAnnotation, hashCode, memberHasValue, notify, notifyAll, shouldSkip, shouldSkip, shouldSkipOnDescriptorUndefinedAware, shouldSkipUndefinedAware, shouldSkipUndefinedAware, toString, tokenize, visit, wait, wait, wait |
The DEFAULT_ID_TYPE_PROPERTY value that gives every entity a Long id. The
default where the property is unset.
The DEFAULT_ID_TYPE_PROPERTY value that defers to the GORM implementation the entity is mapped with.
The system property, published by the Grails Gradle plugin from
grails { gorm { defaultIdType = '...' }}, that selects the type of the id
property injected into an entity that declares none of its own.
DEFAULT_ID_TYPE_LONG, the default, injects Long for every entity as every
earlier release did. DEFAULT_ID_TYPE_NATIVE asks the GORM implementation the entity is
mapped with for its own default, through
GormEntityTraitProvider.getDefaultIdentityType, so a Mongo entity is given a
String id while a Hibernate entity keeps Long.
An entity that declares an id keeps the type it declares either way.
The type of the id injected into an entity that declares none.
Long unless the build opted into native identity types through
DEFAULT_ID_TYPE_PROPERTY, in which case the GORM implementation the entity is mapped
with supplies its own default. An entity that resolved to no implementation - because several
are on the classpath and it does not say which it means, or because it is mapped with Hibernate
- keeps Long.
classNode - the entitysourceUnit - the source unit, warned against where the property states a value that is not
recognisedtraitProvider - the resolved implementation, or null where none appliesnull Resolves, at compile time, the GORM implementation an entity is mapped with, from the entity's
mapWith property and the GormEntityTraitProviders on the compilation classpath.
The result decides both the entity trait the class is given and, where the build has opted
into native identity types, the type of the injected id.
classNode - the entitysource - the source unit, warned against where the implementation is ambiguousnull where none applies and the entity
falls back to the datastore-neutral GormEntity trait and a Long id