blob: d7f2dc0a78e528b58c8d49bc638355b9944716d8 [file] [log] [blame]
@GenModel(fileExtensions="entity", modelDirectory="/org.eclipse.osbp.dsl.entity.xtext/emf-gen", editDirectory="/org.eclipse.osbp.dsl.entity.xtext.edit/src", childCreationExtenders="true")
@GenModel(modelName="Entity")
@GenModel(prefix="OSBPEntity")
@GenModel(suppressEMFModelTags="true")
@GenModel(loadInitialization="false")
@GenModel(literalsInterface="true")
@GenModel(copyrightText="Copyright (c) 2011, 2016 - Lunifera GmbH (Gross Enzersdorf), Loetz GmbH&Co.KG (Heidelberg)
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0
which accompanies this distribution, and is available at
https://www.eclipse.org/legal/epl-2.0/
SPDX-License-Identifier: EPL-2.0
Based on ideas from Xtext, Xtend, Xcore
Contributors:
Florian Pirchner - Initial implementation
")
@Ecore(nsURI="http://osbp.eclipse.org/dsl/entity/v1")
@Ecore(nsPrefix="entity")
@Ecore(rootPackage="entity")
package org.eclipse.osbp.dsl.semantic.entity
import java.util.List
import org.eclipse.emf.ecore.InternalEObject
import org.eclipse.osbp.dsl.semantic.common.types.LAttribute
import org.eclipse.osbp.dsl.semantic.common.types.LClass
import org.eclipse.osbp.dsl.semantic.common.types.LEnumLiteral
import org.eclipse.osbp.dsl.semantic.common.types.LDateType
import org.eclipse.osbp.dsl.semantic.common.types.LFeature
import org.eclipse.osbp.dsl.semantic.common.types.LFeaturesHolder
import org.eclipse.osbp.dsl.semantic.common.types.LLazyResolver
import org.eclipse.osbp.dsl.semantic.common.types.LReference
import org.eclipse.osbp.dsl.semantic.common.types.LResultFilters
import org.eclipse.osbp.dsl.semantic.common.types.LScalarType
import org.eclipse.osbp.dsl.semantic.common.types.LType
import org.eclipse.osbp.dsl.semantic.common.types.LTypedPackage
import org.eclipse.xtext.xtype.XImportSection
class LEntityModel {
contains XImportSection importSection
contains LTypedPackage[] packages
}
/**
* A bean is an embeddable element that may become added to a entity using the @embedd annotation.
*/
class LBean extends LClass, LScalarType, LFeaturesHolder {
contains LBeanFeature[] features
refers LBean superType opposite subTypes
refers LBean[] subTypes opposite superType
boolean beanOnTab
/**
* Returns all features of type LOperation
*/
op OperationsList getOperations() {
features.filter(typeof(LOperation)).toList
}
/**
* Returns all features of type LBeanReference
*/
op BeanReferenceList getReferences() {
features.filter(typeof(LBeanReference)).toList
}
/**
* Returns all features of type LBeanAttribute
*/
op BeanAttributeList getAttributes() {
features.filter(typeof(LBeanAttribute)).toList
}
/**
* Returns all features of the holder and from super types
*/
op BeanFeatureList getAllFeatures() {
val List<LBeanFeature> result = newArrayList()
collectAllOSBPFeatures(result)
return result
}
/**
* Returns all attributes of the holder and from super types
*/
op BeanAttributeList getAllAttributes() {
val List<LBeanFeature> result = newArrayList()
collectAllOSBPFeatures(result)
return result.filter(typeof(LBeanAttribute)).toList
}
/**
* Returns all references of the holder and from super types
*/
op BeanReferenceList getAllReferences() {
val List<LBeanFeature> result = newArrayList()
collectAllOSBPFeatures(result)
return result.filter(typeof(LBeanReference)).toList
}
op void collectAllOSBPFeatures(LBean current, BeanFeatureList result) {
if (current === null) {
return
}
// collect from current feature
result.addAll(current.features)
// call for super class
current.superType.collectAllOSBPFeatures(result)
}
}
/**
* Represents a JPA entity.
*/
class LEntity extends LClass, LFeaturesHolder {
boolean cacheable
boolean historized
boolean timedependent
LDateType timedependentDateType
boolean mappedSuperclass
contains LEntityPersistenceInfo persistenceInfo
contains LEntityInheritanceStrategy inheritanceStrategy
contains LEntityFeature[] features
contains LIndex[] indexes
refers LEntity superType opposite subTypes
refers LEntity[] subTypes opposite superType
String persistenceUnit
contains LEntitySuperIndex[*] superIndex
/**
* Returns all features of type LOperation
*/
op OperationsList getOperations() {
features.filter(typeof(LOperation)).toList
}
/**
* Returns all features of type LEntityReference
*/
op EntityReferenceList getReferences() {
features.filter(typeof(LEntityReference)).toList
}
/**
* Returns all features of type LEntityAttribute
*/
op EntityAttributeList getAttributes() {
features.filter(typeof(LEntityAttribute)).toList
}
/**
* Returns all features of the holder and from super types
*/
op EntityFeatureList getAllFeatures() {
val List<LEntityFeature> result = newArrayList()
collectAllOSBPFeatures(result)
return result
}
/**
* Returns all attributes of the holder and from super types
*/
op EntityAttributeList getAllAttributes() {
val List<LEntityFeature> result = newArrayList()
collectAllOSBPFeatures(result)
return result.filter(typeof(LEntityAttribute)).toList
}
/**
* Returns all references of the holder and from super types
*/
op EntityReferenceList getAllReferences() {
val List<LEntityFeature> result = newArrayList()
collectAllOSBPFeatures(result)
return result.filter(typeof(LEntityReference)).toList
}
op void collectAllOSBPFeatures(LEntity current, EntityFeatureList result) {
if (current === null) {
return
}
// collect from current feature
result.addAll(current.features)
// call for super class
current.superType.collectAllOSBPFeatures(result)
}
op void collectNormalOSBPFeatures(LEntity current, EntityFeatureList result) {
if (current === null) {
return
}
// collect from current feature
result.addAll(current.features.filter[it.normalAttribute])
// call for super class
current.superType.collectNormalOSBPFeatures(result)
}
op LEntityAttribute getPrimaryKeyAttribute() {
return allFeatures.filter(typeof(LEntityAttribute)).findFirst [
return it.id || it.uuid
]
}
op String getIdAttributeName() {
return getPrimaryKeyAttribute()?.name
}
op LScalarType getIdAttributeType() {
var tp = getPrimaryKeyAttribute()?.^type
if (tp !== null) {
if (tp.eIsProxy) {
return (tp as InternalEObject).eResolveProxy as LScalarType
}
}
return getPrimaryKeyAttribute()?.^type
}
op LEntityAttribute getCurrentAttribute() {
return allFeatures.filter(typeof(LEntityAttribute)).findFirst [
return it.histCurrentAttribute
]
}
op LEntityAttribute getVersionAttribute() {
return allFeatures.filter(typeof(LEntityAttribute)).findFirst [
return it.version
]
}
op String getVersionAttributeName() {
return getVersionAttribute()?.name
}
op LScalarType getVersionAttributeType() {
var tp = getVersionAttribute()?.^type
if (tp !== null) {
if (tp.eIsProxy) {
return (tp as InternalEObject).eResolveProxy as LScalarType
}
}
return getVersionAttribute()?.^type
}
op EntityFeatureList getNormalFeatures() {
val List<LEntityFeature> result = newArrayList()
collectNormalOSBPFeatures(result)
return result
}
/**
* Checks this entity and its parents, whether it is historized.
*/
op boolean isHistorizedWithParent() {
var entity = this;
while (entity !== null) {
if (entity.historized) {
return true
}
entity = entity.superType
}
return false
}
/**
* Checks this entity and its parents, whether it is timedependent.
*/
op boolean isTimedependentWithParent() {
var entity = this;
while (entity !== null) {
if (entity.timedependent) {
return true
}
entity = entity.superType
}
return false
}
op boolean isHistorizedOrTimedependentWithParent() {
return isHistorizedWithParent || isTimedependentWithParent
}
}
class LEntitySuperIndex extends LLazyResolver {
String name
contains LNestedFeature[*] attributes
}
class LNestedFeature extends LLazyResolver {
refers LFeature feature
contains LNestedFeature tail
}
type InternalEObject wraps InternalEObject
class LEntityPersistenceInfo extends LLazyResolver {
String schemaName
String tableName
}
class LEntityColumnPersistenceInfo extends LLazyResolver {
String columnName
}
interface LEntityInheritanceStrategy extends LLazyResolver {
}
class LTablePerClassStrategy extends LEntityInheritanceStrategy {
String discriminatorColumn
LDiscriminatorType discriminatorType
String discriminatorValue
}
class LTablePerSubclassStrategy extends LEntityInheritanceStrategy {
String discriminatorColumn
LDiscriminatorType discriminatorType
String discriminatorValue
}
enum LDiscriminatorType {
INHERIT
, STRING
, CHAR
, INTEGER
}
class LEntityFeature extends LFeature {
contains LEntityColumnPersistenceInfo persistenceInfo
op LEntity getEntity() {
return eContainer as LEntity
}
op boolean isCascading() {
return cascadeMergePersist || cascadeRemove || cascadeRefresh
}
}
class LKanbanStateDetail {
contains LKanbanEnumInfo[] infos
}
class LKanbanEnumInfo {
refers LEnumLiteral literal
String i18nKey
}
class LEntityAttribute extends LEntityFeature, LAttribute {
// in case that a bean has a reference to entity
// kanban attributes
boolean asKanbanState
boolean onKanbanCard
contains LKanbanStateDetail onKanbanCardStates
boolean asKanbanOrdering
boolean decentKanbanOrder
// other attributes
refers LBeanReference ^opposite
derived String typedName get {
var result = new StringBuilder
if (name !== null) {
result.append = name
} else {
result.append = "empty"
}
result.append = " : "
if (^type !== null) {
result.append = ^type.name
} else {
result.append = "undefined"
}
return result.toString
}
}
class LEntityReference extends LEntityFeature, LReference {
refers LEntity ^type
refers LEntityReference ^opposite
// reference filters may be used by UI to filter unwanted references
contains LResultFilters resultFilters
int filterDepth
}
class LBeanFeature extends LFeature {
op LBean getBean() {
return eContainer as LBean
}
op boolean isCascading() {
return cascadeMergePersist || cascadeRemove
}
}
class LBeanAttribute extends LBeanFeature, LAttribute {
derived String typedName get {
var result = new StringBuilder
if (name !== null) {
result.append = name
} else {
result.append = "empty"
}
result.append = " : "
if (^type !== null) {
result.append = ^type.name
} else {
result.append = "undefined"
}
return result.toString
}
}
class LBeanReference extends LBeanFeature, LReference {
// can be entity or bean
refers LType ^type
refers LFeature ^opposite
// reference filters may be used by UI to filter unwanted references
contains LResultFilters resultFilters
}
class LIndex {
boolean ^unique
String name
refers LEntityFeature[] features
}
/**
* Overwrites LOperation to add bean and entity feature as supertype
*/
class LOperation extends org.eclipse.osbp.dsl.semantic.common.types.LOperation, LBeanFeature, LEntityFeature {
}
type OperationsList wraps java.util.List<LOperation>
type EntityFeatureList wraps java.util.List<LEntityFeature>
type EntityReferenceList wraps java.util.List<LEntityReference>
type EntityAttributeList wraps java.util.List<LEntityAttribute>
type BeanFeatureList wraps java.util.List<LBeanFeature>
type BeanReferenceList wraps java.util.List<LBeanReference>
type BeanAttributeList wraps java.util.List<LBeanAttribute>