| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * 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 |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| */ |
| package org.eclipse.osbp.xtext.datamart.common; |
| |
| import org.eclipse.osbp.dsl.semantic.entity.LEntity; |
| import org.eclipse.osbp.dsl.semantic.entity.LEntityAttribute; |
| import org.eclipse.osbp.ui.api.datamart.IDataMart; |
| import org.eclipse.osbp.utils.entityhelper.DataType; |
| import org.eclipse.osbp.ui.api.datamart.IDataMart.EType; |
| |
| public class DatamartDefinitionUtil { |
| |
| public static String getEntityNameForIdColumnName(String columnName) { |
| if (isEntityIdColumnName(columnName)) { |
| return columnName.substring(IDataMart.DATAMART_ID_COLUMN_PREFIX.length(), columnName.length()-IDataMart.DATAMART_ID_COLUMN_POSTFIX.length()); |
| } |
| else { |
| return null; |
| } |
| } |
| |
| public static boolean isEntityIdColumnName(String columnName) { |
| return columnName.startsWith(IDataMart.DATAMART_ID_COLUMN_PREFIX) && columnName.endsWith(IDataMart.DATAMART_ID_COLUMN_POSTFIX); |
| } |
| |
| public static String getEntityIdColumnName(LEntity entityRef) { |
| LEntityAttribute idAttribute = getEntityIdAttribute(entityRef); |
| if (idAttribute == null) { |
| return null; |
| } |
| else { |
| return entityRef.getName()+"."+idAttribute.getName(); |
| } |
| } |
| |
| public static String getEntityIdAliasName(LEntity entityRef) { |
| LEntityAttribute idAttribute = getEntityIdAttribute(entityRef); |
| if (idAttribute == null) { |
| return null; |
| } |
| else { |
| return IDataMart.DATAMART_ID_COLUMN_PREFIX+entityRef.getName()+IDataMart.DATAMART_ID_COLUMN_POSTFIX; |
| } |
| } |
| |
| public static LEntityAttribute getEntityIdAttribute(LEntity entityRef) { |
| for (LEntityAttribute attribute : entityRef.getAllAttributes()) { |
| if (attribute.isId() || attribute.isUuid()) { |
| return attribute; |
| } |
| } |
| return null; |
| } |
| |
| public static String getEntityIdDatatype(LEntity entityRef) { |
| for (LEntityAttribute attribute : entityRef.getAllAttributes()) { |
| if (attribute.isId() || attribute.isUuid()) { |
| return attribute.getType().getName(); |
| } |
| } |
| return null; |
| } |
| |
| public static EType getEntityIdEType(LEntity entityRef) { |
| for (LEntityAttribute attribute : entityRef.getAllAttributes()) { |
| if (attribute.isId() || attribute.isUuid()) { |
| return (new DataType()).getBasicType(attribute); |
| } |
| } |
| return null; |
| } |
| } |