blob: d60ed7c9e62cd0f43b6818b45a7329e1cd37a5a6 [file] [log] [blame]
/**
*
* 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 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*
*/
package org.eclipse.osbp.xtext.datamart.common.olap;
import java.math.BigDecimal;
import org.eclipse.osbp.xtext.datamart.common.sql.SqlCell;
import org.olap4j.OlapException;
import mondrian.olap.Cell;
public class DerivedCell {
private org.olap4j.Cell olapCell;
private mondrian.olap.Cell mondrianCell;
private Object value = null;
private String formattedValue = "";
public DerivedCell(org.olap4j.Cell olapCell) {
this.olapCell = olapCell;
}
public DerivedCell(Cell mondrianCell) {
super();
this.mondrianCell = mondrianCell;
}
public DerivedCell(Object value, String formattedValue) {
super();
this.value = value;
this.formattedValue = formattedValue;
}
public Object getValue(){
if (olapCell!=null){
if(olapCell.getValue() instanceof BigDecimal) {
try {
return olapCell.getDoubleValue();
} catch (OlapException e) {
return 0.0;
}
}
return olapCell.getValue();
} else if (mondrianCell!=null){
value = mondrianCell.getValue();
if(value instanceof BigDecimal) {
return ((BigDecimal)value).doubleValue();
}
return value;
} else {
return value;
}
}
public String getFormattedValue(){
if (olapCell!=null){
return olapCell.getFormattedValue();
} else if (mondrianCell!=null){
return mondrianCell.getFormattedValue();
} else {
return formattedValue;
}
}
public boolean isId() {
if (olapCell!=null){
if (olapCell instanceof SqlCell) {
return ((SqlCell)olapCell).isId();
}
}
return false;
}
public String getIdType() {
if (olapCell!=null){
if (olapCell instanceof SqlCell) {
return ((SqlCell)olapCell).getType().toString();
}
}
return "";
}
}