Groovy Documentation

in.labulle.anycode.engine.groovy.directive
[Groovy] Class JpaDirective

java.lang.Object
  in.labulle.anycode.engine.groovy.directive.AnycodeDirective
      in.labulle.anycode.engine.groovy.directive.JavaDirective
          in.labulle.anycode.engine.groovy.directive.JpaDirective

class JpaDirective
extends JavaDirective

JPA Directive. It extends JavaDirective and provides some useful method to generate JPA related code.

Authors:
Jose Carreno


Method Summary
def annotation(IAttribute a)

Renders attribute's annotations(@OneToOne, @OneToMany...).

def attribute(IAttribute a)

Render JPA Attribute with its annotation.

protected def getOperationName(IOperation op)

Calculate operation's name.

def isFinderOperation(IOperation op)

Checks whether the given operation is a finder operation, i.e. : whether it begins with '@' prefix.

def isIdentifier(IAttribute a)

Checks whether the given attribute is identifier, i.e. : whether it has an stereotype named 'id'

def primaryKey(IClass c)

Generates a primary key based on entity class. 3 possibilities :

  • Class has more than one "id" stereotyped attribute, then a PK class is rendered
  • Class has exactly one "id" stereotyped attribute, then a JPA identifier will be generated based on this attribute.

def primaryKeyDataType(IClass c)

Generates a primary key datatype based on entity class. 3 possibilities :

  • Class has more than one "id" stereotyped attribute, then a PK class is rendered
  • Class has exactly one "id" stereotyped attribute, then a JPA identifier will be generated based on this attribute.

 
Methods inherited from class JavaDirective
attribute, classifierSignature, datatype, datatype, generalizations, getAttributeName, getDataTypeName, getDataTypeName, getOperationName, getter, operationImplementation, operationSignature, realizations, setter
 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Method Detail

annotation

def annotation(IAttribute a)
Renders attribute's annotations(@OneToOne, @OneToMany...).
Parameters:
a - attribute.
Returns:
Annotations as a GString or "" if attribute is simple (IAttribute.isRelation is false).


attribute

def attribute(IAttribute a)
Render JPA Attribute with its annotation. See annotation(IAttribute) for further details.
Parameters:
a - attribute to render.
Returns:
attribute full signature as a script as well as JPA annotations : [visibility] [datatype] [attribute name]. e.g. : private String myVar;.


getOperationName

protected def getOperationName(IOperation op)
Calculate operation's name. This is used to render the proper operation name even it is a finder method (isFinderOperation(IOperation)).
Parameters:
op - opearation
Returns:
operation's name.


isFinderOperation

def isFinderOperation(IOperation op)
Checks whether the given operation is a finder operation, i.e. : whether it begins with '@' prefix. The purpose of this method is to filter classifier operations and generate them in data access objects (DAO or repositories using Spring Data). This mechanism is borrowed from AndroMDA spring cartridge conventions.
Parameters:
op - operation
Returns:
true if operation starts with '@', false otherwise.


isIdentifier

def isIdentifier(IAttribute a)
Checks whether the given attribute is identifier, i.e. : whether it has an stereotype named 'id'
Parameters:
a - attribute.
Returns:
true is this attribute is part of the primary key of the entity, false otherwise.


primaryKey

def primaryKey(IClass c)
Generates a primary key based on entity class. 3 possibilities :
Parameters:
c - the class to render.
Returns:
primary key declaration as a GString.


primaryKeyDataType

def primaryKeyDataType(IClass c)
Generates a primary key datatype based on entity class. 3 possibilities :
Parameters:
c - the class to render.
Returns:
primary key's datatype as a GString.


 

Groovy Documentation