| @GenModel(fileExtensions="entity", modelDirectory= "/org.eclipse.osbp.dsl.entity.xtext/src-gen", editDirectory="/org.eclipse.osbp.dsl.entity.xtext.edit/src", childCreationExtenders="true") |
| @GenModel(modelName="Entity") |
| @GenModel(prefix="OSBPEntity") |
| @GenModel(suppressEMFModelTags="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 v1.0 |
| which accompanies this distribution, and is available at |
| http://www.eclipse.org/legal/epl-v10.html |
| |
| 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.xtext.common.types.JvmTypeReference |
| 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.LConstraint |
| 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.LScalarType |
| import org.eclipse.osbp.dsl.semantic.common.types.LType |
| import org.eclipse.osbp.dsl.semantic.common.types.LTypedPackage |
| import org.eclipse.osbp.dsl.semantic.common.types.LResultFilters |
| |
| class LEntityModel { |
| 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 |
| contains transient JvmTypeReference superTypeJvm |
| refers LBean[] subTypes opposite superType |
| /** |
| * 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 |
| contains transient JvmTypeReference superTypeJvm |
| refers LEntity[] subTypes opposite superType |
| String persistenceUnit |
| /** |
| * 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) |
| } |
| } |
| |
| 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 |
| } |
| } |
| |
| class LEntityAttribute extends LEntityFeature, LAttribute { |
| // in case that a bean has a reference to entity |
| 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 |
| contains transient JvmTypeReference typeJvm |
| refers LEntityReference ^opposite |
| |
| // reference filters may be used by UI to filter unwanted references |
| contains LResultFilters resultFilters |
| } |
| |
| class LBeanFeature extends LFeature { |
| op LBean getBean() { |
| return eContainer as LBean |
| } |
| } |
| |
| 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 |
| contains transient JvmTypeReference typeJvm |
| // 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> |
| |
| |
| |
| |
| |
| |
| |
| |