1 13 package com.tonbeller.jpivot.xmla; 14 15 import com.tonbeller.jpivot.olap.mdxparse.Exp; 16 import com.tonbeller.jpivot.olap.mdxparse.FunCall; 17 import com.tonbeller.jpivot.olap.mdxparse.Literal; 18 import com.tonbeller.jpivot.olap.mdxparse.ParsedQuery; 19 import com.tonbeller.jpivot.olap.mdxparse.QueryAxis; 20 import com.tonbeller.jpivot.olap.model.Member; 21 import com.tonbeller.jpivot.olap.model.Position; 22 import com.tonbeller.jpivot.olap.navi.SortRank; 23 import com.tonbeller.jpivot.olap.query.SortRankBase; 24 25 28 public class XMLA_SortRank extends SortRankBase implements SortRank { 29 30 36 public boolean isSortable(Position position) { 37 Member[] members = position.getMembers(); 38 for (int i = 0; i < members.length; i++) 39 if (members[i].getLevel().getHierarchy().getDimension().isMeasure()) 40 return true; 41 return false; 42 } 43 44 47 public void addSortToQuery() { 48 if (sorting && sortPosMembers != null) { 49 XMLA_Model model = (XMLA_Model) getModel(); 50 ParsedQuery pq = ((XMLA_QueryAdapter)model.getQueryAdapter()).getParsedQuery(); 51 52 switch (sortMode) { 53 case com.tonbeller.jpivot.olap.navi.SortRank.ASC : 54 case com.tonbeller.jpivot.olap.navi.SortRank.DESC : 55 case com.tonbeller.jpivot.olap.navi.SortRank.BASC : 56 case com.tonbeller.jpivot.olap.navi.SortRank.BDESC : 57 orderAxis(pq); 59 break; 60 case com.tonbeller.jpivot.olap.navi.SortRank.TOPCOUNT : 61 topBottomAxis(pq, "TopCount"); 62 break; 63 case com.tonbeller.jpivot.olap.navi.SortRank.BOTTOMCOUNT : 64 topBottomAxis(pq, "BottomCount"); 65 break; 66 default : 67 return; } 69 } 70 } 71 72 77 private void orderAxis(ParsedQuery pq) { 78 QueryAxis[] queryAxes = pq.getAxes(); 80 QueryAxis qa = queryAxes[quaxToSort.getOrdinal()]; 81 Exp setForAx = qa.getExp(); 82 83 Exp[] args = new Exp[3]; 86 args[0] = setForAx; Exp sortExp; 89 if (sortPosMembers.length > 1) { 90 sortExp = new FunCall("()", (XMLA_Member[]) sortPosMembers, FunCall.TypeParentheses); 91 } else { 92 sortExp = (XMLA_Member) sortPosMembers[0]; 93 } 94 args[1] = sortExp; 95 args[2] = Literal.createString(sortMode2String(sortMode)); 96 FunCall order = new FunCall("Order", args, FunCall.TypeFunction); 97 qa.setExp(order); 98 } 99 100 105 private void topBottomAxis(ParsedQuery pq, String function) { 106 108 QueryAxis[] queryAxes = pq.getAxes(); 109 QueryAxis qa = queryAxes[quaxToSort.getOrdinal()]; 110 Exp setForAx = qa.getExp(); 111 Exp sortExp; 112 if (sortPosMembers.length > 1) { 114 sortExp = new FunCall("()", (XMLA_Member[]) sortPosMembers, FunCall.TypeParentheses); 115 } else { 116 sortExp = (XMLA_Member) sortPosMembers[0]; 117 } 118 119 Exp[] args = new Exp[3]; 120 args[0] = setForAx; args[1] = Literal.create(new Integer (topBottomCount)); 122 args[2] = sortExp; 123 FunCall topbottom = new FunCall(function, args, FunCall.TypeFunction); 124 qa.setExp(topbottom); 125 } 126 127 128 132 static private String sortMode2String(int sortMode) { 133 switch (sortMode) { 134 case com.tonbeller.jpivot.olap.navi.SortRank.ASC : 135 return "ASC"; 136 case com.tonbeller.jpivot.olap.navi.SortRank.DESC : 137 return "DESC"; 138 case com.tonbeller.jpivot.olap.navi.SortRank.BASC : 139 return "BASC"; 140 case com.tonbeller.jpivot.olap.navi.SortRank.BDESC : 141 return "BDESC"; 142 default : 143 return ""; } 145 } 146 147 } | Popular Tags |