Package org.tentackle.persist.wurblet
Class DbModelWurblet
java.lang.Object
org.wurbelizer.wurblet.AbstractWurblet
org.wurbelizer.wurblet.AbstractJavaWurblet
org.tentackle.wurblet.ModelWurblet
org.tentackle.persist.wurblet.DbModelWurblet
- All Implemented Interfaces:
org.wurbelizer.wurblet.Wurblet
- Direct Known Subclasses:
AssertRemote,ClassVariables,DbDeleteBy,DbIsReferencing,DbSelectList,DbSelectUnique,DbUpdateBy,Declare,MethodCache,MethodsImpl,PdoCache,PdoDeleteBy,PdoIsReferencing,PdoRelations,PdoSelectList,PdoSelectUnique,PdoUpdateBy,RemoteMethod
Base class for persistence wurblets.
The following wurblet options are supported:
- --context=<key>: defines the context id (--context= turns off default context).
- --tracked: return a TrackedList instead of List (useful if [TRACKED] not given in model).
- --attracked: same as --tracked but generate is...Modified per attribute.
- --fulltracked: same as --attracked but keep last persisted values as well.
- --untracked: disable [TRACKED, ATTRACKED or FULLTRACKED] from model.
ModelWurblet.- Author:
- harald
-
Field Summary
Fields inherited from class org.wurbelizer.wurblet.AbstractWurblet
configuration, container, out, phase, source -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionUtility method to generate argument list.Adds a string to a comma separated list.Utility method to always get a non-null string.voidAsserts that SQL statements can be executed for that entity.voidAsserts that entity can be selected from the database.Builds the string of invocation parameters.buildInvocationParameters(boolean limit, boolean offset) Builds the string of invocation parameters.Builds the string of method parameters.buildMethodParameters(boolean limit, boolean offset) Builds the string of method parameters.createJdbcGetterName(org.tentackle.model.Attribute attribute) Creates the "getXXXX" method name for ResultSetWrapper.createJdbcSetterName(org.tentackle.sql.DataType<?> dataType) Creates the "setXXXX" method name for PreparedStatementWrapper.Creates the java code forJoinedSelects.Creates optional JDBC-set parameters code for joins with extra arguments.Creates the order by clause.createOrderBy(List<WurbletArgument> sortKeys) Creates the order by clause.createRelationArgString(org.tentackle.model.Relation relation) Creates the argument string for select or delete statement of a relation.createRelationDeleteCode(org.tentackle.model.Relation relation) Creates the java code to delete a relation.createRelationLinkCode(org.tentackle.model.Relation relation) Creates the java code to set the link of a relation.createRelationSelectCode(org.tentackle.model.Relation relation) Creates the java code to select a relation.createRelationSetFirstArgMethodName(org.tentackle.model.Relation relation) Creates the set-first-arg method name (useful only in object relations).createRelationUpdateReferenceCode(org.tentackle.model.Relation relation) Creates the java code to update the reference of a relation.
The pdo name is fixed"me()".createRelationUpdateReferenceCode(org.tentackle.model.Relation relation, String pdo, boolean blunt) Creates the java code to update the reference of a relation.createRelationWurbletArgString(org.tentackle.model.Relation relation) Creates the wurblet argument string for select or delete statement of a relation.Creates the relop code for prepared statements.
The code assumes a StringBuilder and begins with".append(".Creates the name of a statement id.
Because statement ids are final, the name is in uppercase.createWhereSetPars(org.tentackle.model.Attribute attr, String argument) Creates the java code to set a single-column parameter in a PreparedStatementWrapper.Creates the java code to set a parameter in a PreparedStatementWrapper.
Works for single- and multi-column data types.org.tentackle.model.AttributeGets the context attribute.List<org.tentackle.model.AttributeSorting>Goes up the inheritance tree until a default sorting is found.Gets the default sorting keys.List<org.tentackle.model.Relation>The TT persistence layer provides an optimized select for a single eager relations via a LeftJoin.Gets the select/where expression.Gets the expression arguments.Gets the extra arguments.
Those are not part of the expression and not sorting arguments.org.tentackle.model.AttributegetFirstMethodAttribute(org.tentackle.model.Relation relation) Gets the method attribute for a relation.getJdbcCode(org.tentackle.model.Attribute attribute, String modelCode) Creates java code applicable to the JDBC layer from model variable access code.
Applies .toExternal() if attribute is an application specific type.Gets the consolidated relation paths for the join arguments.Gets the method arguments.getModelCode(org.tentackle.model.Attribute attribute, String jdbcCode) Creates java code applicable to the application model from JDBC variable access code.
Applies .toInternal() if attribute is an application specific type.Gets the sorting arguments.booleanisAbstractJoinPath(List<JoinPath> paths) Returns whether joins with delegates of abstract classes are used.
The casts of such joins are "unchecked" and need a SuppressWarnings to avoid Xlint warnings.booleanReturns whether argument grouping is enabled.
By default, the grouping separator '|' just improves readability.
Some wurblet, however, need extra arguments separated from the main expression.booleanReturns whether the entity is attracked or fulltracked.booleanReturns whether SQL statements can be executed for that entity.booleanReturns whether the entity is fulltracked.booleanReturns whether expression arguments may contain paths to other entities.booleanDetermines whether one the wurblet arguments refer to a value returned by a PDO's method.booleanisRelationTransient(org.tentackle.model.Relation relation) Returns whether the relation is transient.booleanReturns whether the entity is tracked.booleanReturns whether default sorting is configured for the entity.booleanReturns whether there are load joins.booleanReturns whether sorting is configured for this wurblet.Prepends a string to a comma separated list.voidrun()Methods inherited from class org.tentackle.wurblet.ModelWurblet
appendCommaSeparated, assertSupportedByBackends, createAccessorCode, createComponentInfo, createDeclaredArgsForSelectOrDeleteMethod, createListRelationDeleteMethodName, createRelationSelectMethodName, deriveClassNameForEntity, getAnnotationOptions, getArgs, getBackends, getColumnName, getColumnNameConstant, getEffectiveDataType, getEmbeddedTableAttributes, getEntity, getMethodName, getModelDefaults, getModelDirName, getModelName, getNonPrimitiveJavaType, getOption, getOptionArgs, getPdoClassName, getWurbletArgs, isAttributeDerived, isGenerified, isIdAttribute, isIdOrSerialAttribute, isInterface, isMuteOptionSet, isPartOfInheritanceHierarchy, isPdo, isRemote, isSerialAttribute, orderByInheritanceLevelAndClassId, prependCommaSeparated, setRemoteMethods inherited from class org.wurbelizer.wurblet.AbstractJavaWurblet
getClassName, getPackageName, getSuperClassName, isAbstract, isClass, isFinal, isPrivate, isProtected, isPublic, isRecord, toStringMethods inherited from class org.wurbelizer.wurblet.AbstractWurblet
cleanup, getConfiguration, getContainer, getGuardName, getPhase, process, setConfiguration, setContainer, setPhase
-
Constructor Details
-
DbModelWurblet
public DbModelWurblet()
-
-
Method Details
-
isArgumentGroupingEnabled
public boolean isArgumentGroupingEnabled()Returns whether argument grouping is enabled.
By default, the grouping separator '|' just improves readability.
Some wurblet, however, need extra arguments separated from the main expression. This is true for the PdoUpdateBy or DbUpdateBy wurblets, for example. Grouping is turned on via the wurblet option "groupArgs".- Returns:
- true if grouping enabled
-
isPathAllowed
public boolean isPathAllowed()Returns whether expression arguments may contain paths to other entities.- Returns:
- true if allowed, false if not
-
run
public void run() throws org.wurbelizer.wurbel.WurbelException- Specified by:
runin interfaceorg.wurbelizer.wurblet.Wurblet- Overrides:
runin classModelWurblet- Throws:
org.wurbelizer.wurbel.WurbelException
-
isTracked
public boolean isTracked()Returns whether the entity is tracked.- Returns:
- true if tracked (TRACKED, ATTRACKED or FULLTRACKED)
-
isAttracked
public boolean isAttracked()Returns whether the entity is attracked or fulltracked.- Returns:
- true if attracked (ATTRACKED or FULLTRACKED)
-
isFullTracked
public boolean isFullTracked()Returns whether the entity is fulltracked.- Returns:
- true if FULLTRACKED
-
getContextAttribute
public org.tentackle.model.Attribute getContextAttribute()Gets the context attribute.- Returns:
- the context attribute, null if none
-
isEntityPersistable
public boolean isEntityPersistable()Returns whether SQL statements can be executed for that entity.- Returns:
- true if persistable
-
assertEntityIsPersistable
public void assertEntityIsPersistable() throws org.wurbelizer.wurbel.WurbelExceptionAsserts that SQL statements can be executed for that entity.- Throws:
org.wurbelizer.wurbel.WurbelException- if not
-
assertEntityNotEmbedded
public void assertEntityNotEmbedded() throws org.wurbelizer.wurbel.WurbelExceptionAsserts that entity can be selected from the database.- Throws:
org.wurbelizer.wurbel.WurbelException- if not
-
getMethodArguments
Gets the method arguments.- Returns:
- the method arguments
-
getExpressionArguments
Gets the expression arguments.- Returns:
- the arguments used within the expression
-
getExtraArguments
Gets the extra arguments.
Those are not part of the expression and not sorting arguments.- Returns:
- the extra arguments
-
getExpression
Gets the select/where expression.- Returns:
- the expression
-
getSortingArguments
Gets the sorting arguments.- Returns:
- the sorting arguments, empty if no "order by"
-
isWithSorting
public boolean isWithSorting()Returns whether sorting is configured for this wurblet.- Returns:
- true if sorting defined in args
-
getDefaultSorting
Goes up the inheritance tree until a default sorting is found.- Returns:
- the sorting, null if none
-
getDefaultSortKeys
Gets the default sorting keys.- Returns:
- the sorting keys, empty if no "order by"
- Throws:
org.wurbelizer.wurbel.WurbelException- if failed
-
isWithDefaultSorting
public boolean isWithDefaultSorting()Returns whether default sorting is configured for the entity.- Returns:
- true if sorting enabled
-
getJoinPaths
Gets the consolidated relation paths for the join arguments.- Returns:
- the join paths
-
isWithJoins
public boolean isWithJoins()Returns whether there are load joins.- Returns:
- true if with load joins
-
createRelopCode
Creates the relop code for prepared statements.
The code assumes a StringBuilder and begins with".append(".- Parameters:
arg- the wurblet argument- Returns:
- the java code
- Throws:
org.wurbelizer.wurbel.WurbelException
-
createOrderBy
public String createOrderBy(List<WurbletArgument> sortKeys) throws org.wurbelizer.wurbel.WurbelException Creates the order by clause.- Parameters:
sortKeys- the sorting keys- Returns:
- the order by clause, null if unsorted
- Throws:
org.wurbelizer.wurbel.WurbelException- if failed
-
createOrderBy
Creates the order by clause.- Returns:
- the order by clause, null if unsorted
- Throws:
org.wurbelizer.wurbel.WurbelException- if failed
-
isAbstractJoinPath
public boolean isAbstractJoinPath(List<JoinPath> paths) throws org.wurbelizer.wurbel.WurbelException Returns whether joins with delegates of abstract classes are used.
The casts of such joins are "unchecked" and need a SuppressWarnings to avoid Xlint warnings.- Returns:
- true if join paths involve delegates of abstract classes
- Throws:
org.wurbelizer.wurbel.WurbelException- if failed
-
createJoins
Creates the java code forJoinedSelects.- Returns:
- the generated java code
- Throws:
org.wurbelizer.wurbel.WurbelException- if failed
-
createWhereSetPars
public String createWhereSetPars(WurbletArgument arg) throws org.wurbelizer.wurbel.WurbelException, org.tentackle.model.ModelException Creates the java code to set a parameter in a PreparedStatementWrapper.
Works for single- and multi-column data types.- Parameters:
arg- the wurblet argument- Returns:
- the java code
- Throws:
org.wurbelizer.wurbel.WurbelException- if malformed or illegal wurblet argumentorg.tentackle.model.ModelException- if getting the jdbc java code failed
-
createWhereSetPars
public String createWhereSetPars(org.tentackle.model.Attribute attr, String argument) throws org.wurbelizer.wurbel.WurbelException Creates the java code to set a single-column parameter in a PreparedStatementWrapper.- Parameters:
attr- the model attributeargument- the argument string- Returns:
- the created java code
- Throws:
org.wurbelizer.wurbel.WurbelException- if failed
-
createJoinSetPars
public String createJoinSetPars() throws org.wurbelizer.wurbel.WurbelException, org.tentackle.model.ModelExceptionCreates optional JDBC-set parameters code for joins with extra arguments.- Returns:
- the optional code, empty if none
- Throws:
org.wurbelizer.wurbel.WurbelException- if failedorg.tentackle.model.ModelException
-
createStatementId
Creates the name of a statement id.
Because statement ids are final, the name is in uppercase.- Returns:
- the id string
- Throws:
org.wurbelizer.wurbel.WurbelException- if guardname could not be determined
-
buildMethodParameters
public String buildMethodParameters(boolean limit, boolean offset) throws org.wurbelizer.wurbel.WurbelException Builds the string of method parameters.- Parameters:
limit- optional limit rowsoffset- optional skip rows- Returns:
- the method parameters
- Throws:
org.wurbelizer.wurbel.WurbelException- if failed
-
buildMethodParameters
Builds the string of method parameters.- Returns:
- the method parameters
- Throws:
org.wurbelizer.wurbel.WurbelException- if failed
-
buildInvocationParameters
public String buildInvocationParameters(boolean limit, boolean offset) throws org.wurbelizer.wurbel.WurbelException Builds the string of invocation parameters.- Parameters:
limit- optional limit rowsoffset- optional skip rows- Returns:
- the invocation parameters
- Throws:
org.wurbelizer.wurbel.WurbelException- if failed
-
isPdoProvidingArguments
public boolean isPdoProvidingArguments()Determines whether one the wurblet arguments refer to a value returned by a PDO's method.- Returns:
- true if at least one argument is something like "getBlah()"
-
buildInvocationParameters
Builds the string of invocation parameters.- Returns:
- the invocation parameters
- Throws:
org.wurbelizer.wurbel.WurbelException- if failed
-
acs
Adds a string to a comma separated list.- Parameters:
str- the stringappendStr- the string to append- Returns:
- the new string
-
pcs
Prepends a string to a comma separated list.- Parameters:
str- the string builderprependStr- the string to prepend- Returns:
- the new string
-
aas
Utility method to generate argument list.- Parameters:
str- the argument string- Returns:
- comma + str if str not empty or null, the empty string otherwise
-
as
Utility method to always get a non-null string.- Parameters:
str- the source string- Returns:
- the string or the empty string if str is null
-
createJdbcSetterName
Creates the "setXXXX" method name for PreparedStatementWrapper.- Parameters:
dataType- the datatype- Returns:
- the method name
-
createJdbcGetterName
public String createJdbcGetterName(org.tentackle.model.Attribute attribute) throws org.wurbelizer.wurbel.WurbelException Creates the "getXXXX" method name for ResultSetWrapper.- Parameters:
attribute- the model attribute- Returns:
- the method name
- Throws:
org.wurbelizer.wurbel.WurbelException- if type is misconfigured
-
getModelCode
public String getModelCode(org.tentackle.model.Attribute attribute, String jdbcCode) throws org.wurbelizer.wurbel.WurbelException Creates java code applicable to the application model from JDBC variable access code.
Applies .toInternal() if attribute is an application specific type. Otherwise, jdbcCode is returned unchanged.- Parameters:
attribute- the attributejdbcCode- the jdbc code- Returns:
- the code the model code
- Throws:
org.wurbelizer.wurbel.WurbelException- if some model error
-
getJdbcCode
public String getJdbcCode(org.tentackle.model.Attribute attribute, String modelCode) throws org.wurbelizer.wurbel.WurbelException Creates java code applicable to the JDBC layer from model variable access code.
Applies .toExternal() if attribute is an application specific type. Otherwise, modelCode is returned unchanged.- Parameters:
attribute- the attributemodelCode- the jdbc code- Returns:
- the code the model code
- Throws:
org.wurbelizer.wurbel.WurbelException- if some model error
-
isRelationTransient
public boolean isRelationTransient(org.tentackle.model.Relation relation) Returns whether the relation is transient.- Parameters:
relation- the relation- Returns:
- true if transient modifier required
-
createRelationArgString
Creates the argument string for select or delete statement of a relation.- Parameters:
relation- the relation.- Returns:
- the arg string
-
createRelationWurbletArgString
Creates the wurblet argument string for select or delete statement of a relation.- Parameters:
relation- the relation.- Returns:
- the arg string
-
createRelationSelectCode
Creates the java code to select a relation.- Parameters:
relation- the relation- Returns:
- the java code
-
createRelationUpdateReferenceCode
public String createRelationUpdateReferenceCode(org.tentackle.model.Relation relation, String pdo, boolean blunt) Creates the java code to update the reference of a relation.- Parameters:
relation- the relationpdo- the PDO nameblunt- use the blunt setter method, if provided- Returns:
- the java code
-
createRelationUpdateReferenceCode
Creates the java code to update the reference of a relation.
The pdo name is fixed"me()".- Parameters:
relation- the relation- Returns:
- the java code
-
createRelationSetFirstArgMethodName
public String createRelationSetFirstArgMethodName(org.tentackle.model.Relation relation) throws org.tentackle.model.ModelException Creates the set-first-arg method name (useful only in object relations).- Parameters:
relation- the relation- Returns:
- the set-method name
- Throws:
org.tentackle.model.ModelException- if unexpected method args
-
getFirstMethodAttribute
public org.tentackle.model.Attribute getFirstMethodAttribute(org.tentackle.model.Relation relation) throws org.tentackle.model.ModelException Gets the method attribute for a relation.- Parameters:
relation- the relation- Returns:
- the attribute
- Throws:
org.tentackle.model.ModelException- if no method args found or missing attribute
-
createRelationDeleteCode
Creates the java code to delete a relation.- Parameters:
relation- the relation- Returns:
- the java code
-
createRelationLinkCode
Creates the java code to set the link of a relation.- Parameters:
relation- the relation- Returns:
- the java code
-
getEagerRelations
public List<org.tentackle.model.Relation> getEagerRelations() throws org.tentackle.model.ModelExceptionThe TT persistence layer provides an optimized select for a single eager relations via a LeftJoin.- Returns:
- the eager relations, empty list if no optimization possible or no eager relations at all
- Throws:
org.tentackle.model.ModelException
-