Package org.tentackle.wurblet
Class ModelWurblet
- java.lang.Object
-
- org.wurbelizer.wurblet.AbstractWurblet
-
- 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.AbstractWurbletExtendedAbstractWurbletproviding 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
-
-
Constructor Summary
Constructors Constructor Description ModelWurblet()Creates a wurblet.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendCommaSeparated(java.lang.StringBuilder builder, java.lang.String appendStr)Adds a string to a comma separated list.java.lang.StringcreateDeclaredArgsForSelectOrDeleteMethod(org.tentackle.model.Relation relation)Creates the method argument declaration for the select or delete method.java.lang.StringcreateListRelationDeleteMethodName(org.tentackle.model.Relation relation)Creates the method name to select a relation.java.lang.StringcreateRelationSelectMethodName(org.tentackle.model.Relation relation)Creates the method name to select a relation.java.lang.StringderiveClassNameForEntity(org.tentackle.model.Entity otherEntity)Applies the semantics ofAbstractWurblet.getClassName()to another entity.
Example:java.util.List<java.lang.String>getArgs()Gets the wurblet arguments.org.tentackle.model.EntitygetEntity()Gets the model entity.java.lang.StringgetMethodName()Gets the methodname.
From the guardname or from arg "--method=<.....>" if present.org.tentackle.model.ModelDefaultsgetModelDefaults()Gets the optional model defaults.java.lang.StringgetModelDirName()Gets the name of the model directory.java.lang.StringgetModelName()Gets the name of the modelfile.java.lang.StringgetOption(java.lang.String option)Gets the option if set.
Options come in two flavours: without a value.java.util.List<java.lang.String>getOptionArgs()Gets the wurblet options.
The options got the leading '--' removed.java.lang.StringgetPdoClassName()Gets the pdo class from the source.
Looks for annotations@DomainObjectService,@PersistentObjectServiceand interface extensions.java.util.List<java.lang.String>getWurbletArgs()Gets the wurblet arguments.
All arguments except the options.booleanisAttributeDerived(org.tentackle.model.Attribute attribute)Checks whether attribute is derived from a superclass.booleanisGenerified()Returns whether the class is defined using java generics.booleanisIdAttribute(org.tentackle.model.Attribute attribute)Checks whether attribute is the pdo ID.booleanisIdOrSerialAttribute(org.tentackle.model.Attribute attribute)Checks whether attribute is the pdo ID or serial.booleanisInterface()Returns whether wurblet is defined within an interface.
Only valid if isPdo() returns non-null.booleanisPartOfInheritanceHierarchy()Returns whether the entity is part of an inheritance tree.booleanisPdo()Returns whether this is a pdo.booleanisRemote()Returns true if --remote option set.booleanisSerialAttribute(org.tentackle.model.Attribute attribute)Checks whether attribute is the pdo serial.booleanisSetGetRequired(org.tentackle.model.Attribute attribute)Determines whether setter/getter need to be used to access an attribute.java.util.List<org.tentackle.model.Entity>orderByInheritanceLevelAndClassId(java.util.List<org.tentackle.model.Entity> entities)Sorts the given list of entities by inheritance level plus classid.voidprependCommaSeparated(java.lang.StringBuilder builder, java.lang.String prependStr)Prepends a string to a comma separated list.voidrun()voidsetRemote(boolean remote)Sets the remote option explicitly.
-
-
-
Method Detail
-
getModelDirName
public java.lang.String getModelDirName()
Gets the name of the model directory.- Returns:
- the model dir name
-
getModelDefaults
public org.tentackle.model.ModelDefaults getModelDefaults()
Gets the optional model defaults.- Returns:
- the defaults, null if none
-
getPdoClassName
public java.lang.String getPdoClassName() throws org.wurbelizer.wurbel.WurbelExceptionGets the pdo class from the source.
Looks for annotations@DomainObjectService,@PersistentObjectServiceand 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 this is a pdo.- Returns:
- true if pdo
-
isInterface
public boolean isInterface()
Returns whether wurblet is defined within an interface.
Only valid if isPdo() returns non-null.- 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:
- truf 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
-
getMethodName
public java.lang.String getMethodName() throws org.wurbelizer.wurbel.WurbelExceptionGets the methodname.
From the guardname or from arg "--method=<.....>" if present.- Returns:
- the method name
- Throws:
org.wurbelizer.wurbel.WurbelException- if no guardname
-
getModelName
public java.lang.String getModelName() throws org.wurbelizer.wurbel.WurbelExceptionGets the name of the modelfile.- Returns:
- the name
- Throws:
org.wurbelizer.wurbel.WurbelException- if model could not be determined
-
deriveClassNameForEntity
public java.lang.String deriveClassNameForEntity(org.tentackle.model.Entity otherEntity) throws org.wurbelizer.wurbel.WurbelExceptionApplies the semantics ofAbstractWurblet.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
public java.util.List<org.tentackle.model.Entity> orderByInheritanceLevelAndClassId(java.util.List<org.tentackle.model.Entity> entities)
Sorts the given list of entities by inheritance level plus classid.- Parameters:
entities- the entities- Returns:
- the sorted entities (same reference as argument)
-
getEntity
public org.tentackle.model.Entity getEntity()
Gets the model entity.- Returns:
- the entity
-
getArgs
public java.util.List<java.lang.String> getArgs()
Gets the wurblet arguments.- Returns:
- the wurblet args
-
getOptionArgs
public java.util.List<java.lang.String> getOptionArgs()
Gets the wurblet options.
The options got the leading '--' removed.- Returns:
- the option args
-
getOption
public java.lang.String getOption(java.lang.String option)
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
public java.util.List<java.lang.String> getWurbletArgs()
Gets the wurblet arguments.
All arguments except the options.- Returns:
- the wurblet args
-
createRelationSelectMethodName
public java.lang.String createRelationSelectMethodName(org.tentackle.model.Relation relation)
Creates the method name to select a relation.- Parameters:
relation- the relation- Returns:
- the method name
-
createListRelationDeleteMethodName
public java.lang.String createListRelationDeleteMethodName(org.tentackle.model.Relation relation)
Creates the method name to select a relation.- Parameters:
relation- the relation- Returns:
- the method name
-
createDeclaredArgsForSelectOrDeleteMethod
public java.lang.String createDeclaredArgsForSelectOrDeleteMethod(org.tentackle.model.Relation relation) throws org.tentackle.model.ModelExceptionCreates the method argument declaration for the select or delete method.- Parameters:
relation- the relation- Returns:
- the argument declaration
- Throws:
org.tentackle.model.ModelException- if failed
-
run
public void run() throws org.wurbelizer.wurbel.WurbelExceptionOverridden to load the map file.
- Specified by:
runin interfaceorg.wurbelizer.wurblet.Wurblet- Overrides:
runin classorg.wurbelizer.wurblet.AbstractWurblet- Throws:
org.wurbelizer.wurbel.WurbelException- if running the wurblet failed
-
isIdAttribute
public boolean isIdAttribute(org.tentackle.model.Attribute attribute)
Checks whether attribute is the pdo ID.- Parameters:
attribute- the attribute- Returns:
- true if pdo id
-
isSerialAttribute
public boolean isSerialAttribute(org.tentackle.model.Attribute attribute)
Checks whether attribute is the pdo serial.- Parameters:
attribute- the attribute- Returns:
- true if pdo serial
-
isIdOrSerialAttribute
public boolean isIdOrSerialAttribute(org.tentackle.model.Attribute attribute)
Checks whether attribute is the pdo ID or serial.- Parameters:
attribute- the attribute- Returns:
- true if pdo id or serial
-
isAttributeDerived
public boolean isAttributeDerived(org.tentackle.model.Attribute attribute)
Checks whether attribute is derived from a superclass.- Parameters:
attribute- the attribute- Returns:
- true if derived from superclass
-
isSetGetRequired
public boolean isSetGetRequired(org.tentackle.model.Attribute attribute)
Determines whether setter/getter need to be used to access an attribute.- Parameters:
attribute- the attribute- Returns:
- true if use set/get
-
appendCommaSeparated
public void appendCommaSeparated(java.lang.StringBuilder builder, java.lang.String appendStr)Adds a string to a comma separated list.- Parameters:
builder- the string builderappendStr- the string to append
-
prependCommaSeparated
public void prependCommaSeparated(java.lang.StringBuilder builder, java.lang.String prependStr)Prepends a string to a comma separated list.- Parameters:
builder- the string builderprependStr- the string to prepend
-
-