catch up with development

Signed-off-by: Ralf Mollik <ramollik@compex-commerce.com>
diff --git a/org.eclipse.osbp.xtext.datamartdsl/src/org/eclipse/osbp/xtext/datamartdsl/jvmmodel/DatamartDSLJvmModelInferrer.xtend b/org.eclipse.osbp.xtext.datamartdsl/src/org/eclipse/osbp/xtext/datamartdsl/jvmmodel/DatamartDSLJvmModelInferrer.xtend
index 115d7bb..6bbc6ba 100644
--- a/org.eclipse.osbp.xtext.datamartdsl/src/org/eclipse/osbp/xtext/datamartdsl/jvmmodel/DatamartDSLJvmModelInferrer.xtend
+++ b/org.eclipse.osbp.xtext.datamartdsl/src/org/eclipse/osbp/xtext/datamartdsl/jvmmodel/DatamartDSLJvmModelInferrer.xtend
@@ -25,6 +25,7 @@
 import java.util.Set
 import java.util.stream.Collectors
 import javax.inject.Inject
+import javax.swing.Timer
 import mondrian.rolap.RolapConnection
 import org.eclipse.osbp.bpm.api.IBPMEngine
 import org.eclipse.osbp.bpm.api.IBPMTaskClient
@@ -543,6 +544,8 @@
 				setInitializer([append('''new DatamartDtoMapper()''')])
 			]
 			type.members += field
+			field = definition.toField("clearCacheTimer", _typeReferenceBuilder.typeRef(Timer))
+			type.members += field
 		}
 		if (definition.source instanceof DatamartEntity) {
 			field = definition.toField("dateFilterAttributeProperties",
@@ -698,6 +701,16 @@
 	def void toOperations(JvmDeclaredType type, DatamartDefinition definition, DatamartPackage datamart) {
 		var JvmOperation operation
 
+		operation = definition.toMethod("getName", _typeReferenceBuilder.typeRef(String)) [
+				body = [
+					append('''
+						return "«definition.name»";
+					''')
+				]
+			]
+		operation.visibility = JvmVisibility::PUBLIC
+		type.members += operation
+
 		operation = definition.toMethod("getPrimaryListKeys",
 			_typeReferenceBuilder.typeRef(List, _typeReferenceBuilder.typeRef(Object))) [
 				parameters += definition.toParameter("columnId", _typeReferenceBuilder.typeRef(String))
@@ -754,11 +767,22 @@
 			body = [
 				append('''
 				«IF definition.source instanceof DatamartCube»
-					try {
-						«binderClassName».getPersistenceService().clearCubeCache(«binderClassName».getPersistenceService().getMondrianConnection(getPersistenceUnit(), "«((definition.source as DatamartCube).cubeRef.eContainer as CubePackage).fullyQualifiedName»"), "«(definition.source as DatamartCube).cubeRef.name»");
-					} catch (SQLException e) {
-						log.error("{}", e);
-					};
+					if(clearCacheTimer != null && clearCacheTimer.isRunning()) {
+						clearCacheTimer.restart();
+					} else {
+						clearCacheTimer = new Timer(50, new ActionListener(){
+							@Override
+							public void actionPerformed(ActionEvent event) {
+								try {
+									«binderClassName».getPersistenceService().clearCubeCache(«binderClassName».getPersistenceService().getMondrianConnection(getPersistenceUnit(), "«((definition.source as DatamartCube).cubeRef.eContainer as CubePackage).fullyQualifiedName»"), "«(definition.source as DatamartCube).cubeRef.name»");
+								} catch (SQLException e) {
+									log.error("{}", e);
+								}
+							}
+						});
+						clearCacheTimer.setRepeats(false);
+						clearCacheTimer.start();
+					}
 				«ENDIF»''')
 			]
 		])
@@ -1974,10 +1998,7 @@
 	}
 
 	def createSQLFilter(Expression element, DatamartEntity entity, DatamartAttributeBase attribute) {
-		var tableName = entity.entityRef.toTableName
-		if (entity.hasSuperType) {
-			tableName = entity.entityRef.superType.toTableName
-		}
+		var tableName = entity.entityRef.getEntityForAttribute(attribute.attributeRef).toTableName
 		var type = attribute.attributeRef.type
 		var filter = ""
 		if (type instanceof LDataType) {
@@ -2701,11 +2722,7 @@
 	 * 
 	 */
 	def getAttributeName(DatamartAttributeBase attribute, DatamartEntity entity) {
-		if (entity !== null) {
-			return '''«entity.getEntityAlias».«attribute.attributeRef.toColumnName»'''
-		} else {
-			return '''«(attribute.attributeRef.eContainer as LEntity).name».«attribute.attributeRef.toColumnName»'''
-		}
+		return '''«entity.entityRef.getEntityNameForAttribute(attribute.attributeRef)».«attribute.attributeRef.toColumnName»'''
 	}
 
 	/**
@@ -2978,16 +2995,14 @@
 	def createSelect(Map<String, Triple<String, Integer, Boolean>> attributes, DatamartDefinition definition, Map<String, DatamartEntity> entityMap) {
 		var selectString = ""
 		if (definition.source instanceof DatamartEntity){
-				if (!(definition.source as DatamartEntity).suppressAttributes){
-				selectString = attributes.entrySet.sortWith[e1, e2|return (e2.value.second - e1.value.second)].map [
-					if(it.value.third) {
-						"distinct " + it.key + " as \\\"" + it.value.first + "\\\""
-					} else {
-						it.key + " as \\\"" + it.value.first + "\\\""
-					}
-				].join(",")
-				selectString = '''«selectString»'''
-			}
+			selectString = attributes.entrySet.sortWith[e1, e2|return (e2.value.second - e1.value.second)].map [
+				if(it.value.third) {
+					"distinct " + it.key + " as \\\"" + it.value.first + "\\\""
+				} else {
+					it.key + " as \\\"" + it.value.first + "\\\""
+				}
+			].join(",")
+			selectString = '''«selectString»'''
 		}
 		datamartDtoMapper = "new DatamartDtoMapper()"
 		if (definition !== null) {
@@ -3140,23 +3155,34 @@
 	}
 
 	def aliasedColumnName(DatamartEntity entity, LAttribute attr, String beanPrefix, LAttribute parentBean) {
-		var name = ""
-		var entityRef = entity.entityRef
-		if (entityRef.hasSuperType) {
-			if (entityRef.superType.allAttributes.contains(attr) || parentBean !== null && entityRef.superType.allAttributes.contains(parentBean)) {
-				name = entityRef.superType.getName()
-			} else {
-				name = entityRef.getName()
-			}
-		} else {
-			name = entityRef.getName()
-		}
+		var name = getEntityNameForAttribute(entity.entityRef, attr, parentBean)
 		var alias = name
 		if (entity.eContainer instanceof DatamartNavigation) {
 			alias = '''«alias»_«(entity.eContainer as DatamartNavigation).joinRef.ref.name»'''
 		}
 		return '''«alias.shortenTo30Char».«attr.toColumnName.getBeanName(beanPrefix)»'''
 	}
+	
+	protected def String getEntityNameForAttribute(LEntity entityRef, LAttribute attr) {
+		 entityRef.getEntityForAttribute(attr, null).name
+	}
+	
+	protected def String getEntityNameForAttribute(LEntity entityRef, LAttribute attr, LAttribute parentBean) {
+		 entityRef.getEntityForAttribute(attr, parentBean).name
+	}
+	
+	protected def LEntity getEntityForAttribute(LEntity entityRef, LAttribute attr) {
+		 entityRef.getEntityForAttribute(attr, null)
+	}
+	
+	protected def LEntity getEntityForAttribute(LEntity entityRef, LAttribute attr, LAttribute parentBean) {
+		if (entityRef.hasSuperType) {
+			if (entityRef.superType.allAttributes.contains(attr) || parentBean !== null && entityRef.superType.allAttributes.contains(parentBean)) {
+				return entityRef.superType
+			}
+		}
+		entityRef
+	}
 
 	def void addAttribute(DatamartEntity datamartEntity, String beanPrefix, DatamartAttribute datamartAttr, boolean aggregated, boolean distinct,
 		String aggregateName, Integer columnWeight, Map<String, Triple<String, Integer, Boolean>> attributes,
@@ -3175,19 +3201,10 @@
 	private def void addAttribute(DatamartEntity datamartEntity, String beanPrefix, LAttribute attr, String attributeName, boolean aggregated, boolean distinct,
 		String aggregateName, Integer columnWeight, Map<String, Triple<String, Integer, Boolean>> attributes,
 		Map<String, LAttribute> typesMap, List<String> groupingList, LAttribute parentBean) {
-		var entity = datamartEntity.entityRef
+		var entityRef = datamartEntity.entityRef
 		var key = datamartEntity.aliasedColumnName(attr, beanPrefix, parentBean)
 		var newAttributeName = attributeName.getBeanName(beanPrefix)
-		var typesAttr = ""
-		if (entity.hasSuperType) {
-			if (entity.superType.allAttributes.contains(attr) || parentBean !== null && entity.superType.allAttributes.contains(parentBean)) {
-				typesAttr = '''«entity.superType.name».«newAttributeName»'''
-			} else {
-				typesAttr = '''«entity.name».«newAttributeName»'''
-			}
-		} else {
-			typesAttr = '''«entity.name».«newAttributeName»'''
-		}
+		var typesAttr = '''«entityRef.getEntityNameForAttribute(attr, parentBean)».«newAttributeName»'''
 		typesMap.put(typesAttr, attr);
 		if (aggregated) {
 			key = '''«aggregateName»(«key»)'''
@@ -3236,16 +3253,19 @@
 				}
 				join = '''«entity.getEntityAlias».«name»=«parent.getEntityAlias».«parent.entityRef.idAttributeName»'''
 			} else if (navigation instanceof DatamartOwner) {
-				join = '''«entity.getEntityAlias».«entity.entityRef.idAttributeName»=«parent.getEntityAlias».«name»'''
+				join = '''«entity.getEntityAlias».«entity.entityRef.idAttributeName»=«parent.entityRef.name».«name»'''
 			}
-			join = ''' on(«join»)'''
+			join = ''' on («join»)'''
 		}
 	}
 
 	def createSupertypeJoin(DatamartEntity entity) {
 		var subTypeAlias = entity.entityRef.name
+		if (entity.eContainer instanceof DatamartNavigation) {
+			subTypeAlias = '''«subTypeAlias»_«(entity.eContainer as DatamartNavigation).joinRef.ref.name»'''
+		}
 		var join = '''«subTypeAlias».«entity.entityRef.idAttributeName»=«entity.entityRef.superType.getEntityAlias(entity)».«entity.entityRef.superType.idAttributeName»'''
-		join = '''«entity.entityRef.persistenceInfo.schemaName.provideSchemaName»«entity.entityRef.toTableName» «subTypeAlias» on(«join»)'''
+		join = '''«entity.entityRef.persistenceInfo.schemaName.provideSchemaName»«entity.entityRef.toTableName» «subTypeAlias» on («join»)'''
 	}
 
 	/**
diff --git a/org.eclipse.osbp.xtext.datamartdsl/src/org/eclipse/osbp/xtext/datamartdsl/jvmmodel/DatamartModelGenerator.xtend b/org.eclipse.osbp.xtext.datamartdsl/src/org/eclipse/osbp/xtext/datamartdsl/jvmmodel/DatamartModelGenerator.xtend
index 2a74d4f..2dc5a42 100644
--- a/org.eclipse.osbp.xtext.datamartdsl/src/org/eclipse/osbp/xtext/datamartdsl/jvmmodel/DatamartModelGenerator.xtend
+++ b/org.eclipse.osbp.xtext.datamartdsl/src/org/eclipse/osbp/xtext/datamartdsl/jvmmodel/DatamartModelGenerator.xtend
@@ -16,6 +16,8 @@
 package org.eclipse.osbp.xtext.datamartdsl.jvmmodel
 
 import com.vaadin.ui.Notification
+import java.awt.event.ActionEvent
+import java.awt.event.ActionListener
 import java.math.BigDecimal
 import java.sql.Date
 import java.sql.DriverManager
@@ -111,6 +113,8 @@
 			,Locale
 			,ITranslator
 			,UUIDHist
+			,ActionListener
+			,ActionEvent
 		)
 		super.createAppendable(context, importManager, config)
 	}
diff --git a/org.eclipse.osbp.xtext.datamartdsl/xtend-gen/org/eclipse/osbp/xtext/datamartdsl/jvmmodel/DatamartModelGenerator.java b/org.eclipse.osbp.xtext.datamartdsl/xtend-gen/org/eclipse/osbp/xtext/datamartdsl/jvmmodel/DatamartModelGenerator.java
index b89c375..8fe2a76 100644
--- a/org.eclipse.osbp.xtext.datamartdsl/xtend-gen/org/eclipse/osbp/xtext/datamartdsl/jvmmodel/DatamartModelGenerator.java
+++ b/org.eclipse.osbp.xtext.datamartdsl/xtend-gen/org/eclipse/osbp/xtext/datamartdsl/jvmmodel/DatamartModelGenerator.java
@@ -14,6 +14,8 @@
 package org.eclipse.osbp.xtext.datamartdsl.jvmmodel;
 
 import com.vaadin.ui.Notification;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.math.BigDecimal;
 import java.sql.Date;
 import java.sql.DriverManager;
@@ -73,7 +75,7 @@
     TreeAppendable _xblockexpression = null;
     {
       this.setBuilder(context.eResource());
-      this._basicDslGeneratorUtils.addImportFor(this, importManager, this._typeReferenceBuilder, DriverManager.class, SQLException.class, List.class, DerivedAxis.class, DerivedPosition.class, DerivedMember.class, ResultSet.class, Statement.class, SqlCellSet.class, Axis.class, IPersistenceService.class, ProductConfiguration.class, IDataMart.EType.class, IDualData.class, SimpleDateFormatter.class, DatamartData.class, DatamartFilter.class, ReferenceCardinality.class, ReferencePolicy.class, User.class, HashMap.class, LinkedHashMap.class, IDataMart.class, IDto.class, DatamartDtoMapper.class, BPMTaskSummary.class, Notification.class, BigDecimal.class, Timestamp.class, Date.class, ResourceBundle.class, Locale.class, ITranslator.class, UUIDHist.class);
+      this._basicDslGeneratorUtils.addImportFor(this, importManager, this._typeReferenceBuilder, DriverManager.class, SQLException.class, List.class, DerivedAxis.class, DerivedPosition.class, DerivedMember.class, ResultSet.class, Statement.class, SqlCellSet.class, Axis.class, IPersistenceService.class, ProductConfiguration.class, IDataMart.EType.class, IDualData.class, SimpleDateFormatter.class, DatamartData.class, DatamartFilter.class, ReferenceCardinality.class, ReferencePolicy.class, User.class, HashMap.class, LinkedHashMap.class, IDataMart.class, IDto.class, DatamartDtoMapper.class, BPMTaskSummary.class, Notification.class, BigDecimal.class, Timestamp.class, Date.class, ResourceBundle.class, Locale.class, ITranslator.class, UUIDHist.class, ActionListener.class, ActionEvent.class);
       _xblockexpression = super.createAppendable(context, importManager, config);
     }
     return _xblockexpression;