1 22 23 package org.xquark.extractor.algebra; 24 25 import java.sql.Types ; 26 import java.util.List ; 27 28 import org.xquark.extractor.xfunctions.XfCast; 29 import org.xquark.jdbc.typing.DbType; 30 31 32 37 public final class FormatDateTime { 38 39 private static final String RCSRevision = "$Revision: 1.8 $"; 40 private static final String RCSName = "$Name: $"; 41 42 public FormatDateTime() { 43 } 44 45 public static void formatDateTimes(Expression algebraTree) 46 { 47 TopLevelProjectsVisitor tlpv = new TopLevelProjectsVisitor(); 49 tlpv.reinit(); 50 algebraTree.accept(tlpv); 51 List projectList = tlpv.getProjectList(); 52 UnOpProject project = null; 53 for (int i = 0; i < projectList.size(); i++) { 54 project = (UnOpProject)projectList.get(i); 55 formatDateTimes(project); 56 } 57 } 59 60 private static void formatDateTimes(UnOpProject project) 61 { 62 64 List itemList = project.getItemList(); 65 Expression item = null; 66 SqlTypeAtom type = null; 67 DbType stringType = new DbType(Types.CHAR); 68 String itemName = null; 69 for (int i = 0; i < itemList.size(); i++) { 70 item = (Expression)itemList.get(i); 71 type = (SqlTypeAtom)item.getType(); 72 if (type.isDataTime()) { 73 itemName = item.getName(); 74 if (item instanceof RenameItem) { 75 item = ((RenameItem)item).getOperand(); 76 } 77 item = new XfCast(item,stringType); 78 if (null != itemName) { 79 item = new RenameItem(item, itemName); 80 } 81 project.setItem(i, item); 82 } 83 } 84 } 86 87 88 89 90 91 92 93 94 95 96 97 } 98 | Popular Tags |