1 24 25 package org.objectweb.cjdbc.common.sql.metadata; 26 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 30 import org.objectweb.cjdbc.common.log.Trace; 31 32 41 public final class MetadataContainer extends HashMap 42 { 43 private static final long serialVersionUID = 564436668119294938L; 44 45 private final String line = System 46 .getProperty("line.separator"); 47 private String url; 48 49 54 public MetadataContainer(String url) 55 { 56 this.url = url; 57 } 58 59 67 public boolean isCompatible(MetadataContainer container, Trace logger) 68 { 69 if (keySet() == null) 70 return container.keySet() == null; 71 Iterator keys = keySet().iterator(); 72 boolean isCompatible = true; 73 String key; 74 Object value1; 75 Object value2; 76 String log; 77 while (keys.hasNext()) 78 { 79 key = (String ) keys.next(); 80 value1 = get(key); 81 value2 = container.get(key); 82 if (!value1.equals(value2)) 83 { 84 isCompatible = false; 85 log = "Metadata key [" + key + "] is not compatible. (Backends are: [" 86 + url + "] and [" + container.getUrl() + "] ; Values are:[" 87 + value1 + "] and [" + value2 + "])"; 88 if (logger != null) 89 logger.warn(log); 90 else 91 System.err.println(log); 92 } 93 } 94 return isCompatible; 95 } 96 97 100 public String toString() 101 { 102 if (keySet() == null) 103 return "no metadata"; 104 StringBuffer buffer = new StringBuffer (); 105 Iterator keys = keySet().iterator(); 106 String element; 107 while (keys.hasNext()) 108 { 109 element = (String ) keys.next(); 110 buffer.append(element + " : " + this.get(element) + line); 111 } 112 return buffer.toString(); 113 } 114 115 120 public String getUrl() 121 { 122 return url; 123 } 124 125 134 public static String getContainerKey(String methodName, 135 Class [] parametersType, Object [] arguments) 136 { 137 if (parametersType == null) 138 { return methodName; 140 } 141 else 142 { StringBuffer key = new StringBuffer (methodName); 144 key.append('('); 145 for (int i = 0; i < parametersType.length; i++) 146 { 147 Class c = parametersType[i]; 148 if (c != null) 149 key.append(c.getName()); 150 else 151 key.append("null"); 152 key.append('='); 153 Object arg = arguments[i]; 154 if (arg != null) 155 key.append(arg.toString()); 156 else 157 key.append("null"); 158 key.append(','); 159 } 160 key.setCharAt(key.length() - 1, ')'); 162 return key.toString(); 163 } 164 } 165 } | Popular Tags |