1 13 package com.tonbeller.jpivot.olap.query; 14 15 import java.util.List ; 16 17 import org.apache.log4j.Logger; 18 19 import com.tonbeller.jpivot.core.ModelSupport; 20 import com.tonbeller.jpivot.olap.model.Member; 21 import com.tonbeller.jpivot.olap.model.OlapException; 22 import com.tonbeller.jpivot.util.TreeNode; 23 24 27 public abstract class MdxOlapModel extends ModelSupport { 28 29 static Logger logger = Logger.getLogger(MdxOlapModel.class); 30 31 34 public abstract String getCurrentMdx(); 35 36 42 protected void quaxesFromBeans(Quax[] quaxes, QuaxBean[] quaxBeans) throws OlapException { 43 for (int i = 0; i < quaxes.length; i++) { 44 boolean qubonMode = quaxBeans[i].isQubonMode(); 45 46 quaxes[i].setQubonMode(qubonMode); 47 48 quaxes[i].setGenerateIndex(quaxBeans[i].getGenerateIndex()); 49 quaxes[i].setGenerateMode(quaxBeans[i].getGenerateMode()); 50 51 quaxes[i].setNHierExclude(quaxBeans[i].getNHierExclude()); 52 53 PositionNodeBean rootBean = quaxBeans[i].getPosTreeRoot(); 55 56 TreeNode rootNode = createPosTreeFromBean(rootBean); 57 quaxes[i].setPosTreeRoot(rootNode, true); 58 quaxes[i].changed(this, false); 59 60 quaxes[i].setHierarchizeNeeded(quaxBeans[i].isHierarchizeNeeded()); 61 62 } } 64 65 70 protected void restoreSort(SortRankBase sortExt, Memento memento) { 71 HandleSort: if (sortExt != null) { 72 String [] sortPosUniqueNames = memento.getSortPosMembers(); 73 if (sortPosUniqueNames != null) { 74 Member[] members = new Member[sortPosUniqueNames.length]; 75 for (int i = 0; i < members.length; i++) { 76 Member m = lookupMemberByUName(sortPosUniqueNames[i]); 77 if (m == null) { 78 logger.warn("sort position member not found " + sortPosUniqueNames[i]); 79 break HandleSort; 80 } 81 members[i] = m; 82 } 83 sortExt.setSortPosMembers(members); 84 sortExt.setQuaxToSort(memento.getQuaxToSort()); 85 sortExt.setSortMode(memento.getSortMode()); 86 sortExt.setSorting(memento.isSorting()); 87 sortExt.setTopBottomCount(memento.getTopBottomCount()); 88 } 89 } 90 } 91 92 97 private TreeNode createPosTreeFromBean(PositionNodeBean rootBean) throws OlapException { 98 ExpBean expBean = rootBean.getReference(); Object exp; 100 if (expBean == null) 101 exp = null; 102 else 103 exp = createExpFromBean(expBean); 104 TreeNode node = new TreeNode(exp); 105 PositionNodeBean[] beanChildren = rootBean.getChildren(); 106 if(beanChildren == null) 107 return node; for (int i = 0; i < beanChildren.length; i++) { 109 TreeNode childNode = createPosTreeFromBean(beanChildren[i]); 110 node.addChildNode(childNode); 111 } 112 return node; 113 } 114 115 122 protected void beanFromQuax(QuaxBean quaxBean, Quax quax) throws OlapException { 123 124 quaxBean.setOrdinal(quax.getOrdinal()); 125 quaxBean.setNDimension(quax.getNDimension()); 126 boolean qubonMode = quax.isQubonMode(); 127 quaxBean.setQubonMode(qubonMode); 128 PositionNodeBean posTreeRoot = createPosTreeBean(quax.getPosTreeRoot(), null); 129 quaxBean.setPosTreeRoot(posTreeRoot); 130 131 quaxBean.setHierarchizeNeeded(quax.isHierarchizeNeeded()); 132 quaxBean.setGenerateIndex(quax.getGenerateIndex()); 133 quaxBean.setGenerateMode(quax.getGenerateMode()); 134 quaxBean.setNHierExclude(quax.getNHierExclude()); 135 } 136 137 144 PositionNodeBean createPosTreeBean(TreeNode node, ExpBean reference) throws OlapException { 145 PositionNodeBean bean = new PositionNodeBean(); 146 bean.setReference(reference); 147 if (node == null) { 148 bean.setChildren( new PositionNodeBean[0]); 150 return bean; 151 } 152 List childrenList = node.getChildren(); 153 PositionNodeBean[] children = new PositionNodeBean[childrenList.size()]; 154 for (int i = 0; i < children.length; i++) { 155 TreeNode childNode = (TreeNode) childrenList.get(i); 156 ExpBean refBean = this.createBeanFromExp(childNode.getReference()); 157 children[i] = createPosTreeBean(childNode, refBean); 158 } 159 bean.setChildren(children); 160 return bean; 161 } 162 163 168 protected void storeSort(SortRankBase sortExt, Memento memento) { 169 Member[] sortPosMembers = sortExt.getSortPosMembers(); 170 if (sortPosMembers != null) { 171 String [] uniqueNames = new String [sortPosMembers.length]; 172 for (int i = 0; i < uniqueNames.length; i++) { 173 uniqueNames[i] = ((MDXMember) sortPosMembers[i]).getUniqueName(); 174 } 175 memento.setSortPosMembers(uniqueNames); 176 memento.setQuaxToSort(sortExt.getQuaxToSort()); 177 memento.setTopBottomCount(sortExt.getTopBottomCount()); 178 memento.setSortMode(sortExt.getSortMode()); 179 memento.setSorting(sortExt.isSorting()); 180 } 181 } 182 183 protected abstract Object createExpFromBean(ExpBean expBean) throws OlapException; 184 protected abstract ExpBean createBeanFromExp(Object exp) throws OlapException; 185 186 public abstract Member lookupMemberByUName(String uniqueName); 187 188 } | Popular Tags |