blob: 0ed030cac4ae8eab3c6931982c17673f908fdcec [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 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.sql;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import org.olap4j.Axis;
import org.olap4j.CellSet;
import org.olap4j.CellSetAxis;
import org.olap4j.CellSetAxisMetaData;
import org.olap4j.Position;
import org.olap4j.metadata.Hierarchy;
public class SqlCellSetAxis implements CellSetAxis {
private final CellSet fCellSet;
private final Axis fAxis;
private final List<Position> fPositions;
private Hierarchy fHierarchy;
public Hierarchy getHierarchy() {
return fHierarchy;
}
public SqlCellSetAxis(CellSet cellSet, int axisOrdinal) {
fCellSet = cellSet;
fAxis = Axis.Factory.forOrdinal(axisOrdinal);
fPositions = new ArrayList<Position>();
fHierarchy = null;
}
public SqlCellSetAxis(CellSet cellSet, int axisOrdinal, String type, String name, String label) {
this(cellSet, axisOrdinal);
addPosition(axisOrdinal, 0, type, name, label);
}
public void addPosition(int axis, int ordinal, String type, String name, String label) {
for (Position pos : fPositions){
if (pos.getOrdinal() == ordinal) {
if (axis == 1) { // the row values must be qualified for later decomposition
if (pos.getMembers().size() == 0) {
pos.getMembers().add(new SqlMember(type, "["+name+"]", label, fHierarchy));
}
else {
((SqlMember)pos.getMembers().get(0)).appendLevel(type, name);
}
}
else {
pos.getMembers().add(new SqlMember(type, name, label, fHierarchy));
}
return;
}
}
if (fHierarchy == null) {
fHierarchy = new SqlHierarchy();
}
fPositions.add(new SqlPosition(ordinal, type, name, label, fHierarchy));
}
@Override
public Axis getAxisOrdinal() {
return fAxis;
}
@Override
public CellSet getCellSet() {
return fCellSet;
}
@Override
public int getPositionCount() {
return fPositions.size();
}
@Override
public List<Position> getPositions() {
return fPositions;
}
@Override
public ListIterator<Position> iterator() {
return getPositions().listIterator();
}
/* ============== NOT NEEDED NOW ============== */
@Override
public CellSetAxisMetaData getAxisMetaData() {
// TODO Auto-generated method stub
return null;
}
}