com.sap.gateway.v4.rt.jdbc.hana.edm.HanaEdmProvider Maven / Gradle / Ivy
package com.sap.gateway.v4.rt.jdbc.hana.edm;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.sap.gateway.v4.rt.jdbc.edm.JDBCEdmProvider;
import com.sap.gateway.v4.rt.jdbc.hana.util.HANAODataArtifact;
import com.sap.gateway.v4.rt.jdbc.util.DBODataArtifact;
public class HanaEdmProvider extends JDBCEdmProvider{
final static Logger logger = LoggerFactory.getLogger(HanaEdmProvider.class);
/*
@Override
public String getReferentialConstraintsSQL(DBODataArtifact doa){
HANAODataArtifact hoa = (HANAODataArtifact) doa;
String hanaArtifactName = hoa.getArtifactName();
StringBuffer sqlStatement = new StringBuffer();
if(!hoa.isSynonym())
sqlStatement.append("SELECT COLUMN_NAME,REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME FROM \"SYS\".\"REFERENTIAL_CONSTRAINTS\" WHERE TABLE_NAME = '").append(hanaArtifactName).append("' ORDER BY REFERENCED_TABLE_NAME");
else {
String actualArtifactName = hoa.getActualArtifactName();
String actualArtifactSchema = hoa.getActualArtifactSchema();
sqlStatement.append("SELECT COLUMN_NAME,REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME FROM \"SYS\".\"REFERENTIAL_CONSTRAINTS\" WHERE TABLE_NAME = '").append(actualArtifactName).append("' AND SCHEMA_NAME = '").append(actualArtifactSchema).append("' ORDER BY REFERENCED_TABLE_NAME");
}
return sqlStatement.toString();
}
@Override
public String getColumnMetadataSQL(DBODataArtifact doa){
HANAODataArtifact hoa = (HANAODataArtifact) doa;
String hanaArtifactName = hoa.getArtifactName();
StringBuffer sqlStatement = new StringBuffer();
if(!hoa.isSynonym()) {
sqlStatement.append("SELECT COLUMN_NAME,DATA_TYPE_NAME,DEFAULT_VALUE,LENGTH,SCALE,IS_NULLABLE,COMMENTS,POSITION FROM TABLE_COLUMNS WHERE TABLE_NAME = '").append(hanaArtifactName);
sqlStatement.append("' UNION ALL SELECT COLUMN_NAME,DATA_TYPE_NAME,DEFAULT_VALUE,LENGTH,SCALE,IS_NULLABLE,COMMENTS,POSITION FROM VIEW_COLUMNS WHERE VIEW_NAME = '").append(hanaArtifactName).append("' ORDER BY POSITION");
return sqlStatement.toString();
}
else {
String actualArtifactName = hoa.getActualArtifactName();
String actualArtifactSchema = hoa.getActualArtifactSchema();
sqlStatement.append("SELECT COLUMN_NAME,DATA_TYPE_NAME,DEFAULT_VALUE,LENGTH,SCALE,IS_NULLABLE,COMMENTS,POSITION FROM TABLE_COLUMNS WHERE TABLE_NAME = '").append(actualArtifactName).append("' AND SCHEMA_NAME = '").append(actualArtifactSchema);
sqlStatement.append("' UNION ALL SELECT COLUMN_NAME,DATA_TYPE_NAME,DEFAULT_VALUE,LENGTH,SCALE,IS_NULLABLE,COMMENTS,POSITION FROM VIEW_COLUMNS WHERE VIEW_NAME = '").append(actualArtifactName).append("' AND SCHEMA_NAME = '").append(actualArtifactSchema).append("' ORDER BY POSITION");
return sqlStatement.toString();
}
}
@Override
public String getIntegrityConstraintsSQL(DBODataArtifact doa) {
HANAODataArtifact hoa = (HANAODataArtifact) doa;
String hanaArtifactName = hoa.getArtifactName();
StringBuffer sqlStatement = new StringBuffer();
if(!hoa.isSynonym())
sqlStatement.append("SELECT COLUMN_NAME FROM \"SYS\".\"CONSTRAINTS\" WHERE TABLE_NAME = '").append(hanaArtifactName).append("' AND IS_PRIMARY_KEY = 'TRUE'");
else {
String hanaActualArtifactName = hoa.getActualArtifactName();
String hanaActualArtifactSchema = hoa.getActualArtifactSchema();
sqlStatement.append("SELECT COLUMN_NAME FROM \"SYS\".\"CONSTRAINTS\" WHERE TABLE_NAME = '").append(hanaActualArtifactName).append("' AND SCHEMA_NAME = '").append(hanaActualArtifactSchema).append("' AND IS_PRIMARY_KEY = 'TRUE'");
}
return sqlStatement.toString();
}
@Override
protected HashMap> getTypeIdentifiedArtifacts(List artifactList) {
List toBeExposedAsFunction = new ArrayList();
List toBeExposedAsAction = new ArrayList();
List toBeExposedAsEntityType = new ArrayList();
String[] aggregateFunctions = {"sum","count","min","max","avg"};
String synonymSQL = "SELECT OBJECT_NAME,OBJECT_SCHEMA FROM SYNONYMS WHERE SYNONYM_NAME = ";
String calcViewSQL = "SELECT CATALOG_NAME,"+
"CUBE_NAME,"+
"COLUMNOBJECT_NAME,"+
"COLUMN_NAME," +
"MEASURE_AGGREGATOR,"+
"MEASURE_AGGREGATABLE "+
"from \"_SYS_BI\".\"BIMC_DIMENSION_VIEW_HDI\"" +
" where COLUMNOBJECT_NAME = ";
Statement stmt = null;
try {
stmt = conn.createStatement();
ResultSet rs;
for(DBODataArtifact artifact : artifactList) {
HANAODataArtifact hoa = (HANAODataArtifact) artifact;
HashMap measureAggregateFunctions = new HashMap();
String name = hoa.getArtifactName();
String schema = getSchemaName();
synonymSQL += "'" + name + "'";
rs = stmt.executeQuery(synonymSQL);
if(rs.next()) {
hoa.setIsSynonym(true);
name = rs.getString("OBJECT_NAME");
schema = rs.getString("OBJECT_SCHEMA");
hoa.setActualArtifactName(name);
hoa.setActualArtifactSchema(schema);
}
calcViewSQL = calcViewSQL + "'" + schema + '.' + name + "'";
String calcViewParameterDetailsSQL = getFunctionParameterDetailsSQL(hoa);
rs = stmt.executeQuery(calcViewSQL);
if(rs.next()) {
if(!rs.getObject("CUBE_NAME").equals("$ATTRIBUTE$")) {
do{
if(rs.getObject("MEASURE_AGGREGATOR") != null) {
Integer mAggregator = (Integer) rs.getObject("MEASURE_AGGREGATOR");
measureAggregateFunctions.put(rs.getObject("COLUMN_NAME").toString(),aggregateFunctions[mAggregator]);
}
}while(rs.next());
hoa.setAggregateFunctionsData(measureAggregateFunctions);
rs = stmt.executeQuery(calcViewParameterDetailsSQL);
if(rs.next())
toBeExposedAsFunction.add(hoa);
}
}
toBeExposedAsEntityType.add(hoa);
}
}
catch(SQLException e) {
logger.error(e.getMessage(),e);
return new HashMap>();
}
HashMap> typeIdentifiedArtifacts = new HashMap>();
typeIdentifiedArtifacts.put("entityType", toBeExposedAsEntityType);
typeIdentifiedArtifacts.put("function", toBeExposedAsFunction);
typeIdentifiedArtifacts.put("action", toBeExposedAsAction);
return typeIdentifiedArtifacts;
}
@Override
public String getFunctionParameterDetailsSQL(DBODataArtifact doa) {
HANAODataArtifact hoa = (HANAODataArtifact) doa;
String hanaArtifactName = hoa.getArtifactName();
String actualArtifactName = hoa.getActualArtifactName();
String actualSchemaName = hoa.getActualArtifactSchema();
String baseParametersSQL = "select" +
" VARIABLE_NAME,COLUMN_TYPE_D,COLUMN_SQL_TYPE,MANDATORY,DESCRIPTION,DEFAULT_VALUE,\"ORDER\"" +
" from \"_SYS_BI\".\"BIMC_VARIABLE_VIEW_HDI\"" +
" where QUALIFIED_NAME = ";
if(hoa.isSynonym()) {
return baseParametersSQL + "'" + actualSchemaName + '.' + actualArtifactName + "'" + "order by \"ORDER\"";
}
return baseParametersSQL + "'" + schemaName + "." + hanaArtifactName + "'" + "ORDER BY \"ORDER\"";
}
@Override
public HashMap getDBODataTypeMapping()
{
HashMap typeMapping = new HashMap();
typeMapping.put("INTEGER", EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
typeMapping.put("CHAR", EdmPrimitiveTypeKind.String.getFullQualifiedName());
typeMapping.put("VARCHAR", EdmPrimitiveTypeKind.String.getFullQualifiedName());
typeMapping.put("NVARCHAR", EdmPrimitiveTypeKind.String.getFullQualifiedName());
typeMapping.put("ALPHANUM", EdmPrimitiveTypeKind.String.getFullQualifiedName());
typeMapping.put("SHORTTEXT", EdmPrimitiveTypeKind.String.getFullQualifiedName());
typeMapping.put("BIGINT", EdmPrimitiveTypeKind.Int64.getFullQualifiedName());
typeMapping.put("TINYINT", EdmPrimitiveTypeKind.Byte.getFullQualifiedName());
typeMapping.put("DECIMAL", EdmPrimitiveTypeKind.Decimal.getFullQualifiedName());
typeMapping.put("DOUBLE", EdmPrimitiveTypeKind.Double.getFullQualifiedName());
typeMapping.put("TIME", EdmPrimitiveTypeKind.TimeOfDay.getFullQualifiedName());
typeMapping.put("DATE", EdmPrimitiveTypeKind.Date.getFullQualifiedName());
typeMapping.put("TIMESTAMP", EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName());
typeMapping.put("SECONDDATE", EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName());
typeMapping.put("BOOLEAN", EdmPrimitiveTypeKind.Boolean.getFullQualifiedName());
typeMapping.put("SMALLINT", EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
return typeMapping;
}
*/
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy