Package org.tentackle.wurblet
Class ModelWurblet
java.lang.Object
org.wurbelizer.wurblet.AbstractWurblet
org.wurbelizer.wurblet.AbstractJavaWurblet
org.tentackle.wurblet.ModelWurblet
- All Implemented Interfaces:
org.wurbelizer.wurblet.Wurblet
- Direct Known Subclasses:
AttributeNames
,ColumnLengths
,ColumnNames
,DomainMethods
,Methods
,ModelComment
,Relations
,UniqueDomainKey
public class ModelWurblet
extends org.wurbelizer.wurblet.AbstractJavaWurblet
Extended
AbstractJavaWurblet
providing basic functionality for the persistent object model.
The following wurblet options are parsed:
- --method=<method-name>: optional name of the generated method. Defaults to the wurblet tag.
- --model=<mapping>: optional model mapping. Derived from source file, if missing.
- --remote: force generating remote code. Taken from model-defaults, if missing.
- --noremote: don't generate remote code. Taken from model-defaults, if missing.
AbstractWurblet
.- Author:
- harald
-
Field Summary
Fields inherited from class org.wurbelizer.wurblet.AbstractWurblet
configuration, container, out, phase, source
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
appendCommaSeparated
(StringBuilder builder, String appendStr) Adds a string to a comma separated list.void
assertSupportedByBackends
(String feature, Function<org.tentackle.sql.Backend, Boolean> backendValidator) Checks that all backends support a given feature.
The feature validator is aConsumer
that must return false or throw aRuntimeException
if unsupported.createAccessorCode
(Entity entity, String path, boolean createSetter) Creates the java code to access an attribute or column.
Relations are separated by dots.createComponentInfo
(Entity component) Creates the component info for a given component.Creates the method argument declaration for the select or delete method.createListRelationDeleteMethodName
(Relation relation) Creates the method name to select a relation.createRelationSelectMethodName
(Relation relation) Creates the method name to select a relation.deriveClassNameForEntity
(Entity otherEntity) Applies the semantics ofAbstractJavaWurblet.getClassName()
to another entity.
Example:determinePackageName
(String className) Determines the package name of a class from the source contents.
This is done by scanning the import statements.
Rather costly.getAnnotationOptions
(List<String> annotations, String annotationType) Returns the annotation options for all annotation strings provided by the model and a given annotation type.getArgs()
Gets the wurblet arguments.Collection
<org.tentackle.sql.Backend> Gets the backends that will be used.
Useful if a feature is used that may not be supported by all backends.getColumnName
(Attribute attribute, int columnIndex) Gets the column name.getColumnNameConstant
(Attribute attribute, int columnIndex) Gets the name of the string constant for a database column name.org.tentackle.sql.DataType
<?> getEffectiveDataType
(Attribute attribute) Gets the effective datatype.
The effective type may be different if type is a Convertible.Determines all embedded attributes for the table of the entity.Gets the model entity.Gets the methodname.
From the guardname or from arg "--method=<.....>" if present.Gets the optional model defaults.Gets the name of the model directory.Gets the name of the modelfile.getNonPrimitiveJavaType
(Attribute attribute) Gets the non-primitive java type string of an attribute.Gets the option if set.
Options come in two flavours: without a value.Gets the wurblet options.
The options got the leading '--' removed.Gets the pdo/operation class from the source.
Looks for annotations@DomainObjectService, @PersistentObjectService, @DomainOperationService, @PersistentOperationService
and interface extensions.Gets the wurblet arguments.
All arguments except the options.boolean
isAttributeDerived
(Attribute attribute) Checks whether attribute is derived from a superclass.boolean
Returns whether the class is defined using java generics.boolean
isIdAttribute
(Attribute attribute) Checks whether attribute is the pdo ID.boolean
isIdOrSerialAttribute
(Attribute attribute) Checks whether attribute is the pdo ID or serial.boolean
Returns whether wurblet is defined within an interface.
Only valid if isPdo() returns non-null.boolean
isMuteOptionSet
(Entity entity) Returns whether at least one of the mapped attributes has the [MUTE]-option set.boolean
Returns whether wurblet located within an operation.boolean
Returns whether the entity is part of an inheritance tree.boolean
isPdo()
Returns whether wurblet located within a pdo.boolean
isRemote()
Returns true if --remote option set.boolean
isSerialAttribute
(Attribute attribute) Checks whether attribute is the pdo serial.orderByInheritanceLevelAndClassId
(List<Entity> entities) Sorts the given list of entities by inheritance level plus classid.void
prependCommaSeparated
(StringBuilder builder, String prependStr) Prepends a string to a comma separated list.void
run()
void
setRemote
(boolean remote) Sets the remote option explicitly.Methods inherited from class org.wurbelizer.wurblet.AbstractJavaWurblet
getClassName, getPackageName, getSuperClassName, isAbstract, isClass, isFinal, isPrivate, isProtected, isPublic, isRecord, toString
Methods inherited from class org.wurbelizer.wurblet.AbstractWurblet
cleanup, getConfiguration, getContainer, getGuardName, getPhase, process, setConfiguration, setContainer, setPhase
-
Constructor Details
-
ModelWurblet
public ModelWurblet()Creates a wurblet.
-
-
Method Details
-
getModelDirName
Gets the name of the model directory.- Returns:
- the model dir name
-
getModelDefaults
Gets the optional model defaults.- Returns:
- the defaults, null if none
-
getPdoClassName
Gets the pdo/operation class from the source.
Looks for annotations@DomainObjectService, @PersistentObjectService, @DomainOperationService, @PersistentOperationService
and interface extensions.- Returns:
- the pdo name
- Throws:
org.wurbelizer.wurbel.WurbelException
- if pdo class cannot be determined from the source file
-
isPdo
public boolean isPdo()Returns whether wurblet located within a pdo.- Returns:
- true for PDOs, false for low-level objects
-
isOperation
public boolean isOperation()Returns whether wurblet located within an operation.- Returns:
- true if operation
-
isInterface
public boolean isInterface()Returns whether wurblet is defined within an interface.
Only valid if isPdo() returns non-null.- Overrides:
isInterface
in classorg.wurbelizer.wurblet.AbstractJavaWurblet
- Returns:
- true if interface
-
isRemote
public boolean isRemote()Returns true if --remote option set.- Returns:
- true if remote
-
setRemote
public void setRemote(boolean remote) Sets the remote option explicitly.- Parameters:
remote
- true if remoting enabled
-
isPartOfInheritanceHierarchy
public boolean isPartOfInheritanceHierarchy()Returns whether the entity is part of an inheritance tree.- Returns:
- true if part of an inheritance tree
-
isGenerified
public boolean isGenerified()Returns whether the class is defined using java generics.Generics are used in abstract inheritable classes. Final concrete PDO classes must not use generics. Otherwise, the generated wurblet code will not compile.
- Returns:
- true if class is generified
-
isMuteOptionSet
Returns whether at least one of the mapped attributes has the [MUTE]-option set.- Parameters:
entity
- the entity- Returns:
- true if not all attributes mapped to the Java entity
-
getMethodName
Gets the methodname.
From the guardname or from arg "--method=<.....>" if present.- Returns:
- the method name
- Throws:
org.wurbelizer.wurbel.WurbelException
- if no guardname
-
getModelName
Gets the name of the modelfile.- Returns:
- the name
- Throws:
org.wurbelizer.wurbel.WurbelException
- if model could not be determined
-
deriveClassNameForEntity
public String deriveClassNameForEntity(Entity otherEntity) throws org.wurbelizer.wurbel.WurbelException Applies the semantics ofAbstractJavaWurblet.getClassName()
to another entity.
Example:getEntity() -> Firma getClassName() -> "MyFirmaPersistenceImpl" Assumed that otherEntity = Kontakt (which is a superclass of Firma, for example), then: deriveClassNameForEntity(otherEntity) -> "MyKontaktPersistenceImpl"
- Parameters:
otherEntity
- the other entity- Returns:
- the derived classname
- Throws:
org.wurbelizer.wurbel.WurbelException
- if this classname does not contain the entity name as a substring
-
orderByInheritanceLevelAndClassId
Sorts the given list of entities by inheritance level plus classid.- Parameters:
entities
- the entities- Returns:
- the sorted entities (same reference as argument)
-
getEntity
Gets the model entity.- Returns:
- the entity
-
getArgs
Gets the wurblet arguments.- Returns:
- the wurblet args
-
getOptionArgs
Gets the wurblet options.
The options got the leading '--' removed.- Returns:
- the option args
-
getOption
Gets the option if set.
Options come in two flavours:- without a value. Example: --remote
- with a value. Example: --model=modlog.map
- Parameters:
option
- the option- Returns:
- the empty string (case 1), the value (case 2) or null if option not set
-
getWurbletArgs
Gets the wurblet arguments.
All arguments except the options.- Returns:
- the wurblet args
-
createRelationSelectMethodName
Creates the method name to select a relation.- Parameters:
relation
- the relation- Returns:
- the method name
-
createListRelationDeleteMethodName
Creates the method name to select a relation.- Parameters:
relation
- the relation- Returns:
- the method name
-
createDeclaredArgsForSelectOrDeleteMethod
Creates the method argument declaration for the select or delete method.- Parameters:
relation
- the relation- Returns:
- the argument declaration
- Throws:
ModelException
- if failed
-
getEffectiveDataType
public org.tentackle.sql.DataType<?> getEffectiveDataType(Attribute attribute) throws org.wurbelizer.wurbel.WurbelException Gets the effective datatype.
The effective type may be different if type is a Convertible.- Parameters:
attribute
- the attribute- Returns:
- the data type
- Throws:
org.wurbelizer.wurbel.WurbelException
-
getColumnName
public String getColumnName(Attribute attribute, int columnIndex) throws org.wurbelizer.wurbel.WurbelException Gets the column name.- Parameters:
attribute
- the attributecolumnIndex
- the column index, -1 if without suffix- Returns:
- the column name
- Throws:
org.wurbelizer.wurbel.WurbelException
- if failed
-
getColumnNameConstant
public String getColumnNameConstant(Attribute attribute, int columnIndex) throws org.wurbelizer.wurbel.WurbelException Gets the name of the string constant for a database column name.- Parameters:
attribute
- the attributecolumnIndex
- the column index within the attribute, -1 if without suffix- Returns:
- the constant CN_...
- Throws:
org.wurbelizer.wurbel.WurbelException
-
getAnnotationOptions
Returns the annotation options for all annotation strings provided by the model and a given annotation type.- Parameters:
annotations
- the annotations of the model- Returns:
- the annotation options matching the annotation type (without package name)
-
getEmbeddedTableAttributes
Determines all embedded attributes for the table of the entity.- Returns:
- the list of embedded attributes, empty if none
- Throws:
org.wurbelizer.wurbel.WurbelException
- if failed
-
run
public void run() throws org.wurbelizer.wurbel.WurbelExceptionOverridden to load the map file.
- Specified by:
run
in interfaceorg.wurbelizer.wurblet.Wurblet
- Overrides:
run
in classorg.wurbelizer.wurblet.AbstractWurblet
- Throws:
org.wurbelizer.wurbel.WurbelException
- if running the wurblet failed
-
getBackends
Gets the backends that will be used.
Useful if a feature is used that may not be supported by all backends.- Returns:
- the backends, never null but may be empty
-
assertSupportedByBackends
public void assertSupportedByBackends(String feature, Function<org.tentackle.sql.Backend, Boolean> backendValidator) throws org.wurbelizer.wurbel.WurbelExceptionChecks that all backends support a given feature.
The feature validator is aConsumer
that must return false or throw aRuntimeException
if unsupported.- Parameters:
feature
- a string describing the featurebackendValidator
- the feature validator- Throws:
org.wurbelizer.wurbel.WurbelException
- if some validator failed
-
isIdAttribute
Checks whether attribute is the pdo ID.- Parameters:
attribute
- the attribute- Returns:
- true if pdo id
-
isSerialAttribute
Checks whether attribute is the pdo serial.- Parameters:
attribute
- the attribute- Returns:
- true if pdo serial
-
isIdOrSerialAttribute
Checks whether attribute is the pdo ID or serial.- Parameters:
attribute
- the attribute- Returns:
- true if pdo id or serial
-
isAttributeDerived
Checks whether attribute is derived from a superclass.- Parameters:
attribute
- the attribute- Returns:
- true if derived from superclass
-
appendCommaSeparated
Adds a string to a comma separated list.- Parameters:
builder
- the string builderappendStr
- the string to append
-
prependCommaSeparated
Prepends a string to a comma separated list.- Parameters:
builder
- the string builderprependStr
- the string to prepend
-
createComponentInfo
public ComponentInfo createComponentInfo(Entity component) throws org.wurbelizer.wurbel.WurbelException Creates the component info for a given component.- Parameters:
component
- the component of the wurblet's entity- Returns:
- the info
- Throws:
org.wurbelizer.wurbel.WurbelException
- if failed
-
createAccessorCode
public String createAccessorCode(Entity entity, String path, boolean createSetter) throws org.wurbelizer.wurbel.WurbelException Creates the java code to access an attribute or column.
Relations are separated by dots. For multi-column types, the column is separated from the attribute by a hash.- Parameters:
entity
- the entity where the path beginspath
- the accessor pathcreateSetter
- true if create setter, else getter- Returns:
- the java code without the trailing braces
- Throws:
org.wurbelizer.wurbel.WurbelException
- if failed
-
getNonPrimitiveJavaType
Gets the non-primitive java type string of an attribute.- Parameters:
attribute
- the attribute- Returns:
- the java type as a string
- Throws:
ModelException
- if type conversion failed
-
determinePackageName
Determines the package name of a class from the source contents.
This is done by scanning the import statements.
Rather costly. Use only if there is no other way to determine the package (by rule, for example).- Parameters:
className
- the simple classname- Returns:
- the package name (never null)
- Throws:
org.wurbelizer.wurbel.WurbelException
- if package could not be determined
-