PowerDesigner——配置模板(二)

在上一篇文章的基础上,这篇文章再对具有多对多或者一对多关系的实体的模板补充!

一、删除多对多,多对一,一对多关系下的get,set方法(删除如下代码)

PowerDesigner——配置模板(二)_第1张图片


代码如下:
.if (%implInterface%)
.// Get collection
.set_value(_operationName, get%.FU:roleName%, new)
.set_value(_operationSignature, get%.FU:roleName%, new)
.set_value(_memberName, %roleName%, new)
 .if (%endClassHasOperation% == false)
 
public %implInterface% %_operationName%() \
{
   if (%_memberName% == null)
      %_memberName% = new %implClass%();
   return %_memberName%;
}
 .endif(\n\n)
.// Get iterator
.set_value(_operationName, getIterator%.FU:roleName%, new)
.set_value(_operationSignature, getIterator%.FU:roleName%, new)
.set_value(_memberName, %roleName%, new)
 .if (%endClassHasOperation% == false)

public java.util.Iterator %_operationName%() \
{
   if (%_memberName% == null)
      %_memberName% = new %implClass%();
   return %_memberName%.iterator();
}

 .endif(\n\n)

.// Set collection
.set_value(_operationName, set%.FU:roleName%, new)
.set_value(_operationSignature, set%.FU:roleName%@%implInterface%, new)
.set_value(_paramName, new%.FU:roleName%, new)
.set_value(_memberName, %roleName%, new)
 .if (%endClassHasOperation% == false)

public void %_operationName%(%implInterface% %_paramName%) \
{
   removeAll%.FU:roleName%();
   for (java.util.Iterator iter = %_paramName%.iterator(); iter.hasNext();)
      add%.FU:roleName%((%Classifier.qualifiedCode%)iter.next());
}
 .endif(\n\n)
.// Add object
.set_value(_operationName, add%.FU:roleName%, new)
.set_value(_operationSignature, add%.FU:roleName%@%Classifier.qualifiedCode%, new)
.set_value(_paramName, new%.FU:Classifier.Code%, new)
.set_value(_memberName, %roleName%, new)
 .if (%endClassHasOperation% == false)

public void %_operationName%(%Classifier.qualifiedCode% %_paramName%) \
{
   if (%_paramName% == null)
      return;
   if (this.%_memberName% == null)
      this.%_memberName% = new %implClass%();
   if (!this.%_memberName%.contains(%_paramName%))\n
  .if (%endNavigability%) and (%endMultiple% == false)
   {
      this.%_memberName%.add(%_paramName%);
      %_paramName%.set%.FU:endRoleName%(this);      
   }
  .elsif (%endNavigability%) and (%endMultiple%) and (%endClassHasImplementation%)
   {
      this.%_memberName%.add(%_paramName%);
      %_paramName%.add%.FU:endRoleName%(this);      
   }
  .else
      this.%_memberName%.add(%_paramName%);
  .endif(\n)
}
 .endif(\n\n)
.// Remove object
.set_value(_operationName, remove%.FU:roleName%, new)
.set_value(_operationSignature, remove%.FU:roleName%@%Classifier.qualifiedCode%, new)
.set_value(_paramName, old%.FU:Classifier.Code%, new)
.set_value(_memberName, %roleName%, new)
 .if (%endClassHasOperation% == false)

public void %_operationName%(%Classifier.qualifiedCode% %_paramName%) \
{
   if (%_paramName% == null)
      return;
   if (this.%_memberName% != null)
      if (this.%_memberName%.contains(%_paramName%))\n
  .if (%endNavigability%) and (%endMultiple% == false)
      {
         this.%_memberName%.remove(%_paramName%);
         %_paramName%.set%.FU:endRoleName%((%EndClassifier.qualifiedCode%)null);
      }
  .elsif (%endNavigability%) and (%endMultiple%) and (%endClassHasImplementation%)
      {
         this.%_memberName%.remove(%_paramName%);
         %_paramName%.remove%.FU:endRoleName%(this);
      }
  .else
         this.%_memberName%.remove(%_paramName%);
  .endif(\n)     
}
 .endif(\n\n)
.// Remove all objects
.set_value(_operationName, removeAll%.FU:roleName%, new)
.set_value(_operationSignature, removeAll%.FU:roleName%, new)
.set_value(_memberName, %roleName%, new)
.set_value(_tempObjName, old%.FU:Classifier.Code%, new)
 .if (%endClassHasOperation% == false)

public void %_operationName%() \
{
   if (%_memberName% != null)\n
  .if (%endNavigability%) and (%endMultiple% == false)
   {
      %Classifier.qualifiedCode% %_tempObjName%;
      for (java.util.Iterator iter = getIterator%.FU:roleName%(); iter.hasNext();)
      {
         %_tempObjName% = (%Classifier.qualifiedCode%)iter.next();
         iter.remove();
         %_tempObjName%.set%.FU:endRoleName%((%EndClassifier.qualifiedCode%)null);
      }
   }
  .elsif (%endNavigability%) and (%endMultiple%) and (%endClassHasImplementation%)
   {
      %Classifier.qualifiedCode% %_tempObjName%;
      for (java.util.Iterator iter = getIterator%.FU:roleName%(); iter.hasNext();)
      {
         %_tempObjName% = (%Classifier.qualifiedCode%)iter.next();
         iter.remove();
         %_tempObjName%.remove%.FU:endRoleName%(this);
      }
   }
  .else
      %_memberName%.clear();
  .endif(\n)
}
 .endif(\n)
.else
 .if (%isGenAssocDefaultAccessors%)
.// Default accessors
.// Get array
.set_value(_operationName, get%.FU:roleName%, new)
.set_value(_operationSignature, get%.FU:roleName%, new)
.set_value(_memberName, %roleName%, new)
  .if (%endClassHasOperation% == false)

public %Classifier.qualifiedCode%\[\] %_operationName%() \
{
   return %_memberName%;
}
  .endif(\n\n)
.// Set array
.set_value(_operationName, set%.FU:roleName%, new)
.set_value(_operationSignature, set%.FU:roleName%@%Classifier.qualifiedCode%#, new)
.set_value(_paramName, new%.FU:roleName%, new)
.set_value(_memberName, %roleName%, new)
  .if (%endClassHasOperation% == false)

public void %_operationName%(%Classifier.qualifiedCode%\[\] %_paramName%) \
{
   this.%_memberName% = %_paramName%;
}
  .endif(\n\n)
 .endif
.endif


二、删除多对多,多对一,一对多关系下的get,set方法(删除如下代码)



代码如下:
.if ((%endNavigability%) and(%endContainerType%) and (%endMultiple%)) or (%isGenAssocDefaultAccessors%)
.// Parent getter
.set_value(_operationName, get%.FU:roleName%, new)
.set_value(_operationSignature, get%.FU:roleName%, new)
.if (%endClassHasOperation% == false)

public %Classifier.qualifiedCode% get%.FU:roleName%() \
{
   return %roleName%;
}
.endif(\n\n)
.// Parent setter
.set_value(_operationName, set%.FU:roleName%)
.set_value(_operationSignature, set%.FU:roleName%@%Classifier.qualifiedCode%)
.if (%endClassHasOperation% == false)

public void set%.FU:roleName%(%Classifier.qualifiedCode% new%.FU:Classifier.Code%) \
{\n
   .if (%endNavigability%)
      .if (%endContainerType%) and (%endMultiple%)
   if (this.%roleName% == null || !this.%roleName%.equals(new%.FU:Classifier.Code%))
   {
      if (this.%roleName% != null)
      {
         %Classifier.qualifiedCode% old%.FU:Classifier.Code% = this.%roleName%;
         this.%roleName% = null;
         old%.FU:Classifier.Code%.remove%.FU:endRoleName%(this);
      }
      if (new%.FU:Classifier.Code% != null)
      {
         this.%roleName% = new%.FU:Classifier.Code%;
         this.%roleName%.add%.FU:endRoleName%(this);
      }
   }
      .elsif (%endMultiple% == false)
   if (this.%roleName% == null || !this.%roleName%.equals(new%.FU:Classifier.Code%))
   {
      if (this.%roleName% != null)
         this.%roleName%.set%.FU:endRoleName%(null);
      this.%roleName% = new%.FU:Classifier.Code%;
      if (this.%roleName% != null)
         this.%roleName%.set%.FU:endRoleName%(this);
   }
      .else
   this.%roleName% = new%.FU:Classifier.Code%;
      .endif(\n)
   .else
   this.%roleName% = new%.FU:Classifier.Code%;
   .endif(\n)
}
.endif(\n\n)
.endif



三、删除多对一,一对多,多对多关系实体中,实体“一”一方的关系,

PowerDesigner——配置模板(二)_第2张图片
代码如下:
[%roleBTags%\n]\
.if (%roleBContainerType%)
@ManyToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY, targetEntity = %roleBCollectionType%.class)
@JoinColumn(name = "accountId", nullable = false, insertable = false, updatable = false)
[%roleBVisibility% ]%roleBContainerType%%roleBCollectionType% %roleBCode%[ = %.A:RoleBInitialValue%];
.else
[%roleBVisibility% ][%roleBFlags% ]%ClassB.qualifiedCode%\[\] %roleBCode%[ = %.A:RoleBInitialValue%];
.endif


四、删除多对一,一对多,多对多关系实体中,实体“多”一方的关系,
PowerDesigner——配置模板(二)_第3张图片


代码如下:
[%roleBTags%\n]\
@ManyToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY, targetEntity = %roleBContainerType%.class)
@JoinColumn(name = "accountId", nullable = false, insertable = false, updatable = false)
//test
[%roleBVisibility% ][%roleBFlags% ]%ClassB.qualifiedCode% %roleBCode%[ = %.A:RoleBInitialValue%];

总结:
善于借助工具,能够帮助我们更加快速高效的开发!

你可能感兴趣的:(PowerDesigner——配置模板(二))