1 21 package oracle.toplink.essentials.internal.helper; 23 import java.util.regex.Pattern ; 24 import java.util.Hashtable ; 25 26 27 31 public class JDK15Platform implements JDKPlatform { 32 33 37 public java.util.Map getQueryCacheMap() { 38 return new java.util.concurrent.ConcurrentHashMap (); 39 } 40 41 45 protected static Hashtable patternCache = new Hashtable (); 46 47 52 public int conformLike(Object left, Object right) { 53 if ((left == null) && (right == null)) { 54 return JavaPlatform.TRUE; 55 } else if ((left == null) || (right == null)) { 56 return JavaPlatform.FALSE; 57 } 58 if (left instanceof String && right instanceof String ) { 59 Pattern pattern = (Pattern )patternCache.get(right); 62 if (pattern == null) { 63 String convertedRight = ((String )right).replaceAll("\\?", "\\\\?"); 66 convertedRight = convertedRight.replaceAll("\\*", "\\\\*"); 67 convertedRight = convertedRight.replaceAll("\\.", "\\\\."); 68 convertedRight = convertedRight.replaceAll("\\[", "\\\\["); 69 convertedRight = convertedRight.replaceAll("\\)", "\\\\)"); 70 convertedRight = convertedRight.replaceAll("\\(", "\\\\("); 71 convertedRight = convertedRight.replaceAll("\\{", "\\\\{"); 72 convertedRight = convertedRight.replaceAll("\\+", "\\\\+"); 73 convertedRight = convertedRight.replaceAll("\\^", "\\\\^"); 74 convertedRight = convertedRight.replaceAll("\\|", "\\\\|"); 75 76 convertedRight = convertedRight.replaceAll("([^\\\\])%", "$1.*"); 79 80 convertedRight = convertedRight.replaceAll("([^\\\\])_", "$1."); 82 83 convertedRight = convertedRight.replaceAll("^%", ".*"); 85 convertedRight = convertedRight.replaceAll("^_", "."); 86 87 convertedRight = convertedRight.replaceAll("\\\\%", "%"); 89 90 convertedRight = convertedRight.replaceAll("\\\\_", "_"); 92 93 pattern = Pattern.compile(convertedRight); 94 if (patternCache.size() > 100) { 96 patternCache.remove(patternCache.keySet().iterator().next()); 97 } 98 patternCache.put(right, pattern); 99 } 100 boolean match = pattern.matcher((String )left).matches(); 101 if (match) { 102 return JavaPlatform.TRUE; 103 } else { 104 return JavaPlatform.FALSE; 105 } 106 } 107 return JavaPlatform.UNDEFINED; 108 } 109 110 114 public long getTimeInMillis(java.util.Calendar calendar) { 115 return calendar.getTimeInMillis(); 116 } 117 118 122 public void setTimeInMillis(java.util.Calendar calendar, long millis) { 123 calendar.setTimeInMillis(millis); 124 } 125 126 130 public void setExceptionCause(Throwable exception, Throwable cause) { 131 if (exception.getCause() == null) { 132 exception.initCause(cause); 133 } 134 } 135 136 143 public boolean shouldPrintInternalException() { 144 return false; 145 } 146 } 147 | Popular Tags |