1 package org.apache.ojb.broker.util; 2 3 17 18 import java.sql.ResultSet ; 19 import java.sql.SQLException ; 20 21 import org.apache.commons.lang.StringUtils; 22 23 29 public class SqlHelper 30 { 31 32 public static final String OJB_CLASS_COLUMN = "OJB_CLAZZ"; 33 34 44 public static final class PathInfo 45 { 46 public String column; 47 public String prefix; 48 public String suffix; 49 public final String path; 51 PathInfo(String aPath, String aPrefix, String aColumn, String aSuffix) 52 { 53 path = aPath; 54 column = aColumn; 55 prefix = aPrefix; 56 suffix = aSuffix; 57 } 58 } 59 60 69 public static String cleanPath(String aPath) 70 { 71 return splitPath(aPath).column; 72 } 73 74 89 public static PathInfo splitPath(String aPath) 90 { 91 String prefix = null; 92 String suffix = null; 93 String colName = aPath; 94 95 if (aPath == null) 96 { 97 return new PathInfo(null, null, null, null); 98 } 99 100 int braceBegin = aPath.lastIndexOf("("); 102 int braceEnd = aPath.indexOf(")"); 103 int opPos = StringUtils.indexOfAny(aPath, "+-/*"); 104 105 if (braceBegin >= 0 && braceEnd >= 0 && braceEnd > braceBegin) 106 { 107 int colBegin; 108 int colEnd; 109 String betweenBraces; 110 111 betweenBraces = aPath.substring(braceBegin + 1, braceEnd).trim(); 112 colBegin = betweenBraces.indexOf(" "); 114 colEnd = betweenBraces.indexOf(","); 116 colEnd = colEnd > 0 ? colEnd : betweenBraces.length(); 117 prefix = aPath.substring(0, braceBegin + 1) + betweenBraces.substring(0, colBegin + 1); 118 colName = betweenBraces.substring(colBegin + 1, colEnd); 119 suffix = betweenBraces.substring(colEnd) + aPath.substring(braceEnd); 120 } 121 else if (opPos >= 0) 122 { 123 colName = aPath.substring(0, opPos).trim(); 124 suffix = aPath.substring(opPos); 125 } 126 127 return new PathInfo(aPath, prefix, colName.trim(), suffix); 128 } 129 130 135 public static String getOjbClassName(ResultSet rs) 136 { 137 try 138 { 139 return rs.getString(OJB_CLASS_COLUMN); 140 } 141 catch (SQLException e) 142 { 143 return null; 144 } 145 } 146 147 } 148 | Popular Tags |