templates.Entity.xpt Maven / Gradle / Ivy
?IMPORT dom?
?IMPORT core?
?EXTENSION extensions::File?
?EXTENSION extensions::EntityExtension?
?EXTENSION extensions::SimpleTypeExtension?
?EXTENSION extensions::Properties?
?EXTENSION extensions::Names?
?EXTENSION org::eclipse::xtend::util::stdlib::cloning?
?EXTENSION org::eclipse::xtend::util::stdlib::uid?
?EXTENSION org::openxma::dsl::common::extensions::LogUtil?
/**
* main entry point for persistence generator
*/
?DEFINE main FOR Model?
?LET getEntities() AS entities?
?EXPAND genInterface FOREACH entities?
?EXPAND manInterface FOREACH entities?
?EXPAND genClass FOREACH entities?
?EXPAND manClass FOREACH entities?
?EXPAND compositeIdClass FOREACH entities.select(e|e.identifier==null && !e.attributeGroups.select(e|e.key).isEmpty)?
?EXPAND attributeProperties FOREACH entities?
?ENDLET?
?ENDDEFINE?
/**
* Generates the interface of the given entity
*/
?DEFINE genInterface FOR Entity?
?info("Write "+getGenInterfaceFileName())?
?FILE getGenInterfaceFileName()-?
package ?getPackageName(false)?;
?addImports()-?
?EXPAND Documentation::documentation FOR this-?
public interface ?getGenInterfaceName()??IF superType != null? extends ?superType.getFullyQualifiedName(false)? ?ENDIF? {
?FOREACH attributes.select(e|!e.reference) AS attribute?
?EXPAND Features::accessor FOR attribute-?
?EXPAND Features::mutator FOR attribute-?
?ENDFOREACH-?
?FOREACH attributes.select(e|e.reference) AS attribute?
?EXPAND Features::accessor FOR attribute-?
?EXPAND Features::mutator FOR attribute-?
?ENDFOREACH-?
?IF key!=null && (superType==null || superType.key==null) && identifier==null && (superType == null || superType.identifier==null)-?
?getFullyQualifiedCompositeIdentifierName()? ?key.getAccessorMethodName()?();
?ENDIF-?
?EXPAND genOperationInterface FOR this-?
}
?ENDFILE?
?ENDDEFINE?
/**
* Generates the manual interface of the given entity
*/
?DEFINE manInterface FOR Entity?
?info("Write "+getInterfaceFileName())?
?FILE getInterfaceFileName() OUTLET_JAVA-?
package ?getPackageName(false)?;
?EXPAND Documentation::documentation FOR this-?
public interface ?name? extends ?getGenInterfaceName()? {
?EXPAND manOperationInterface FOR this-?
}
?ENDFILE?
?ENDDEFINE?
/**
* Generates the implementation of the given entity
*/
?DEFINE genClass FOR Entity?
?info("Write "+getGenClassFileName())?
?FILE getGenClassFileName()-?
package ?getPackageName(true)?;
?addImports()-?
?EXPAND Documentation::documentation FOR this-?
public abstract class ?getGenClassName()??IF superType != null? extends ?superType.getQualifiedClassName()??ENDIF? implements ?getQualifiedInterfaceName()? {
?EXPAND Features::attributes FOR this-?
?EXPAND Features::properties FOR this-?
?IF key!=null && (superType==null || superType.key==null) && identifier==null && (superType == null || superType.identifier==null)-?
public ?getCompositeIdentifierName()? ?key.getAccessorMethodName()?() {
return new ?getCompositeIdentifierName()?(?FOREACH key.attributes.attribute AS feature SEPARATOR ","??feature.name??ENDFOREACH?);
}
?ENDIF-?
?IF isIdentifiable() && (superType == null || !superType.isIdentifiable())-?
?EXPAND equalsHashCode FOR this-?
?ENDIF-?
?EXPAND Features::toString FOR this-?
?EXPAND genOperationImpl FOR this-?
}
?ENDFILE?
?ENDDEFINE?
/**
* Generates the manual implementation of the given entity
*/
?DEFINE manClass FOR Entity?
?info("Write "+getClassFileName())?
?FILE getClassFileName() OUTLET_JAVA-?
package ?getPackageName(true)?;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
?addImports()-?
?EXPAND Documentation::documentation FOR this-?
@Component("?name.toFirstLower()?Prototype")
@Scope("prototype")
public class ?getClassName()? extends ?getGenClassName()? {
?FOREACH attributes.select(e|e.derived) AS derivedAttribute-?
?IF !derivedAttribute.readOnly-?
/**
* @param ?derivedAttribute.name? the ?derivedAttribute.name? to set
*/
public void ?getMutatorMethodName()?(?derivedAttribute.getImplementationType()? ?derivedAttribute.name?) {
}
?ENDIF-?
/**
* @return the ?derivedAttribute.name?
*/
public ?derivedAttribute.getImplementationType()? ?derivedAttribute.getAccessorMethodName()?() {
return null;
}
?ENDFOREACH-?
?EXPAND manOperationImpl FOR this-?
}
?ENDFILE?
?ENDDEFINE?
/**
* Generates default hashCode & equals implementation
*/
?DEFINE equalsHashCode FOR Entity?
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
?IF identifier!=null-?
result = prime * result + ((?identifier.getAccessorMethodName()?() == null) ? 0 : ?identifier.getAccessorMethodName()?().hashCode());
?ELSEIF key!=null-?
result = prime * result + ((get?getCompositeIdentifierName()?() == null) ? 0 : get?getCompositeIdentifierName()?().hashCode());
?ENDIF-?
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof ?name?)) {
return false;
}
?name? other = (?name?) obj;
?IF identifier!=null-?
if (?identifier.getAccessorMethodName()?() == null) {
if (other.?identifier.getAccessorMethodName()?() != null) {
return false;
}
} else if (!?identifier.getAccessorMethodName()?().equals(other.?identifier.getAccessorMethodName()?())) {
return false;
}
?ELSEIF key!=null-?
if (get?getCompositeIdentifierName()?() == null) {
if (((?getClassName()?)other).get?getCompositeIdentifierName()?() != null) {
return false;
}
} else if (!get?getCompositeIdentifierName()?().equals(((?getClassName()?)other).get?getCompositeIdentifierName()?())) {
return false;
}
?ENDIF-?
return true;
}
?ENDDEFINE?
/**
* Creates a dto for each dataView
*/
?DEFINE compositeIdClass FOR Entity?
?info("Write "+getCompositeIdentifierClassFileName())?
?FILE getCompositeIdentifierClassFileName()?
package ?getPackageName(true)?;
import java.io.Serializable;
import org.springframework.util.Assert;
?addImports()-?
/**
* Represents a composite identifier for entity ?name?
.
*/
public class ?getCompositeIdentifierName()? implements Serializable {
?EXPAND Features::serialVersionUID FOR this-?
?EXPAND Features::attribute FOREACH key.attributes.attribute-?
?EXPAND Features::properties FOREACH key.attributes.attribute-?
public ?getCompositeIdentifierName()?() {
}
public ?getCompositeIdentifierName()?(?EXPAND Features::methodParameter FOREACH key.attributes.attribute SEPARATOR ","?) {
?FOREACH key.attributes.attribute AS field-?
Assert.notNull(?field.name?, "parameter '?field.name?' must not be null");
?ENDFOREACH-?
?FOREACH key.attributes.attribute AS field-?
this.?field.name?=?field.name?;
?ENDFOREACH-?
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
?FOREACH key.attributes.attribute AS feature-?
result = prime * result + ((?feature.name? == null) ? 0 : ?feature.name?.hashCode());
?ENDFOREACH-?
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
?getCompositeIdentifierName()? other = (?getCompositeIdentifierName()?) obj;
?FOREACH key.attributes.attribute AS feature-?
if (?feature.name? == null) {
if (other.?feature.name? != null) {
return false;
}
} else if (!?feature.name?.equals(other.?feature.name?)) {
return false;
}
?ENDFOREACH-?
return true;
}
@Override
public String toString() {
return new StringBuilder("?name? [")
?FOREACH key.attributes.attribute AS feature ITERATOR iterator-?
.append("?feature.name?=").append(?feature.name?)?IF !iterator.lastIteration?.append(",")?ENDIF?
?ENDFOREACH-?
.append("]")
.toString();
}
}
?ENDFILE?
?ENDDEFINE?
?DEFINE attributeProperties FOR Entity?
?FILE getPropertyFileName() OUTLET_GENERATED_RESOURCES-?
?FOREACH allAttributes AS attribute ITERATOR it-?
?FOREACH attribute.attributProperties.typeSelect(AttributeTextProperty).select(e|e.labelText != null) AS atp-?
?attribute.name?.title = ?toUnicode(atp)?
?ENDFOREACH-?
?FOREACH attribute.attributProperties.typeSelect(AttributeTextProperty).select(e|e.tooltipText != null) AS atp-?
?attribute.name?.description = ?atp.tooltipText?
?ENDFOREACH-?
?ENDFOREACH?
?ENDFILE?
?ENDDEFINE?
/**
* defines a hook for generating additional operations for the GENERATED entity INTERFACE
*/
?DEFINE genOperationInterface FOR Entity??ENDDEFINE?
/**
* defines a hook for generating additional operations for the GENERATED entity IMPLEMENTATION
*/
?DEFINE genOperationImpl FOR Entity??ENDDEFINE?
/**
* defines a hook for generating additional operations for the MANUAL service INTERFACE
*/
?DEFINE manOperationInterface FOR Entity??ENDDEFINE?
/**
* defines a hook for generating additional operations for the MANUAL entity IMPLEMENTATION
*/
?DEFINE manOperationImpl FOR Entity??ENDDEFINE?