1 23 24 28 29 package com.sun.jdo.api.persistence.model.util; 30 31 import java.util.*; 32 import java.io.PrintStream ; 33 34 import com.sun.jdo.api.persistence.model.*; 35 import com.sun.jdo.api.persistence.model.mapping.*; 36 import com.sun.jdo.api.persistence.model.mapping.impl.*; 37 import com.sun.jdo.api.persistence.model.jdo.*; 38 39 import org.netbeans.modules.dbschema.ColumnElement; 40 import org.netbeans.modules.dbschema.ColumnPairElement; 41 42 public class DumpMapping 43 { 44 public static Model model = Model.RUNTIME; 45 46 49 public static void dumpMappingCache (PrintStream stream) 50 { 51 stream.println("Mapping cache (class names -> MappingClassElements)"); for (Iterator i = model.getMappingCache().entrySet().iterator(); 53 i.hasNext();) 54 { 55 Map.Entry entry = (Map.Entry)i.next(); 56 String className = (String )entry.getKey(); 57 MappingClassElement mce = (MappingClassElement)entry.getValue(); 58 String mceRepr = mce.getClass() + "@" + Integer.toHexString(System.identityHashCode(mce)); 60 stream.println("\t" + className + " ->\t" + mceRepr); } 62 } 63 64 67 public static void dumpClassLoaderCache (PrintStream stream) 68 { 69 stream.println("ClassLoader cache (class names -> ClassLoaders)"); for (Iterator i = model.getClassLoaderCache().entrySet().iterator(); 71 i.hasNext();) 72 { 73 Map.Entry entry = (Map.Entry)i.next(); 74 String className = (String )entry.getKey(); 75 ClassLoader classLoader = (ClassLoader )entry.getValue(); 76 stream.println("\t" + className + " ->\t" + classLoader); } 78 } 79 80 public static void main(String [] args) 81 { 82 for (int i = 0; i < args.length; i++) 83 { 84 String className = args[i]; 85 println(0, "\nClass " + className + ":"); 87 try 88 { 89 MappingClassElementImpl mce = (MappingClassElementImpl)model.getMappingClass(className); 90 if (mce != null) 91 { 92 printPersistenceClassElement(mce.getPersistenceElement()); 93 printMappingClassElement(mce); 94 } 95 else 96 { 97 println(0, "Cannot find mapping info for class " + className + " (getMappingClass returns null)"); } 99 } 100 catch (Exception e) 101 { 102 println(0, "Problems during accessing mapping info for class " + className); e.printStackTrace(); 104 } 105 } 106 } 107 108 110 public static void printPersistenceClassElement(PersistenceClassElement pce) 111 { 112 println(0, "\n--> PersistenceClassElement "); println(1, "package = " + pce.getPackage()); println(1, "name = " + pce.getName()); println(1, "identity = " + getObjectIdentityTypeRepr(pce.getObjectIdentityType())); println(1, "keyClass = " + pce.getKeyClass()); 118 printPersistenceFieldElements(1, pce.getFields()); 119 printConcurrencyGroupElements(1, pce.getConcurrencyGroups()); 120 121 println(0, "<-- PersistenceClassElement\n "); } 123 124 125 public static void printPersistenceFieldElements(int tabs, PersistenceFieldElement[] fields) 126 { 127 if ((fields != null) && (fields.length > 0)) 128 { 129 println(tabs, "--> fields "); for (int i = 0; i < fields.length; i++) 131 { 132 PersistenceFieldElement pfe = fields[i]; 133 134 println(tabs, "[" + i + "] " + pfe.getClass()); println(tabs+1, "name = " + pfe.getName()); println(tabs+1, "declaringClass = " + pfe.getDeclaringClass()); println(tabs+1, "fieldNumber = " + pfe.getFieldNumber()); println(tabs+1, "persistenceType = " + getPersistenceTypeRepr(pfe.getPersistenceType())); println(tabs+1, "read / write = " + pfe.isReadSensitive() + " / " + pfe.isWriteSensitive()); println(tabs+1, "isKey = " + pfe.isKey()); 142 if (pfe instanceof RelationshipElement) 143 { 144 RelationshipElement re = (RelationshipElement) pfe; 145 146 println(tabs+1, "bounds = " + re.getLowerBound() + " / " + re.getUpperBound()); println(tabs+1, "deleteAction = " + re.getDeleteAction()); println(tabs+1, "updateAction = " + re.getUpdateAction()); println(tabs+1, "collectionClass = " + re.getCollectionClass()); println(tabs+1, "elementClass = " + re.getElementClass()); println(tabs+1, "isPrefetch = " + re.isPrefetch()); } 153 printConcurrencyGroupElements(tabs+1, pfe.getConcurrencyGroups()); 154 } 155 println(tabs, "<-- fields "); } 157 } 158 159 public static void printConcurrencyGroupElements(int tabs, ConcurrencyGroupElement[] groups) 160 { 161 if ((groups != null) && (groups.length > 0)) 162 { 163 println(tabs, "--> concurrency groups"); for (int i = 0; i < groups.length; i++) 165 { 166 ConcurrencyGroupElement cg = groups[i]; 167 println(tabs, "[" + i + "] " + cg.getClass()); println(tabs+1, "name = " + cg.getName()); println(tabs+1, "declaringClass = " + cg.getDeclaringClass()); println(tabs+1, "fields = " + cg.getFields()); } 172 println(tabs, "<-- concurrency groups"); } 174 } 175 176 178 public static void printMappingClassElement(MappingClassElement mce) 179 { 180 println(0, "\n--> MappingClassElement"); 182 println(1, "databaseRoot = " + mce.getDatabaseRoot()); printMappingTableElements(1, mce.getTables()); 184 printMappingFieldElements(1, mce.getFields()); 185 186 println(0, "<-- MappingClassElement"); } 188 189 public static void printMappingTableElements(int tabs, ArrayList tables) 190 { 191 final int count = ((tables != null) ? tables.size() : 0); 192 193 if (count > 0) 194 { 195 println(tabs, "--> tables "); for (int i = 0; i < count; i++) 197 { 198 MappingTableElementImpl mte = (MappingTableElementImpl) tables.get(i); 199 200 println(tabs, "[" + i + "] " + mte.getClass()); 202 println(tabs+1, "table = " + mte.getTable()); println(tabs+1, "tableObject = " + mte.getTableObject()); println(tabs+1, "key = " + mte.getKey()); println(tabs+1, "keyObjects = " + mte.getKeyObjects()); printMappingRefKeyElements(tabs+1, mte.getReferencingKeys()); 207 } 208 println(tabs, "<-- tables "); } 210 } 211 212 public static void printMappingRefKeyElements(int tabs, ArrayList refKeys) 213 { 214 final int count = ((refKeys != null) ? refKeys.size() : 0); 215 216 if (count > 0) 217 { 218 println(tabs, "--> tables "); for (int i = 0; i < count; i++) 220 { 221 MappingReferenceKeyElement mrke = (MappingReferenceKeyElement)refKeys.get(i); 222 223 println(tabs, "[" + i + "] " + mrke.getClass()); 225 println(tabs+1, "table = " + mrke.getDeclaringTable()); println(tabs+1, "pairs = " + mrke.getColumnPairNames()); } 228 println(tabs, "<-- tables "); } 230 } 231 232 public static void printMappingFieldElements(int tabs, ArrayList fields) 233 { 234 final int count = ((fields != null) ? fields.size() : 0); 235 236 if (count > 0) 237 { 238 println(tabs, "--> fields "); for (int i = 0; i < count; i++) 240 { 241 MappingFieldElementImpl mfe = (MappingFieldElementImpl) fields.get(i); 242 243 println(tabs, "[" + i + "] " + mfe.getClass()); println(tabs+1, "name = " + mfe.getName()); println(tabs+1, "fetchGroup = " + mfe.getFetchGroup()); println(tabs+1, "columns = " + mfe.getColumns()); 248 if (!(mfe instanceof MappingRelationshipElement)) 249 { 250 println(tabs+1, "columnObjects = " + mfe.getColumnObjects()); } 252 else 253 { 254 MappingRelationshipElementImpl mre = (MappingRelationshipElementImpl) mfe; 255 256 ArrayList columnObjects = mre.getColumnObjects(); 257 int colCount = 258 ((columnObjects != null) ? columnObjects.size() : 0); 259 if (colCount > 0) 260 { 261 println(tabs+1, "--> columnsObjects "); for (int j = 0; j < colCount; j++) 263 { 264 ColumnPairElement fce = (ColumnPairElement) columnObjects.get(j); 265 ColumnElement rce = (fce!=null)?fce.getReferencedColumn():null; 266 println(tabs+1, "[" + j + "] " + fce + " -> " + rce); } 268 println(tabs+1, "<-- columnsObjects "); } 270 271 println(tabs+1, "associatedColumns = " + mre.getAssociatedColumns()); 273 ArrayList associatedColumnObjects = mre.getAssociatedColumnObjects(); 274 colCount = ((associatedColumnObjects != null) ? 275 associatedColumnObjects.size() : 0); 276 if (colCount > 0) 277 { 278 println(tabs+1, "--> associatedColumnObjects "); for (int j = 0; j < colCount; j++) 280 { 281 ColumnPairElement fce = (ColumnPairElement) associatedColumnObjects.get(j); 282 ColumnElement rce = (fce!=null)?fce.getReferencedColumn():null; 283 println(tabs+1, "[" + j + "] " + fce + " -> " + rce); } 285 println(tabs+1, "<-- associatedColumnObjects "); } 287 } 288 } 289 println(tabs, "<-- fields "); } 291 292 } 293 294 296 static String getObjectIdentityTypeRepr(int objectIdentityType) 297 { 298 String repr; 299 switch (objectIdentityType) 300 { 301 case PersistenceClassElement.APPLICATION_IDENTITY: 302 return "APPLICATION_IDENTITY"; case PersistenceClassElement.DATABASE_IDENTITY: 304 return "DATABASE_IDENTITY_IDENTITY"; case PersistenceClassElement.UNMANAGED_IDENTITY: 306 return "UNMANAGED_IDENTITY"; default: 308 return "UNKNOWN"; } 310 } 311 312 static String getPersistenceTypeRepr(int persistenceType) 313 { 314 String repr; 315 switch (persistenceType) 316 { 317 case PersistenceFieldElement.PERSISTENT: 318 return "PERSISTENT"; case PersistenceFieldElement.DERIVED: 320 return "DERIVED"; case PersistenceFieldElement.TRANSIENT: 322 return "TRANSIENT"; default: 324 return "UNKNOWN"; } 326 } 327 328 static void println(int indent, String text) 329 { 330 for (int i = 0; i < indent; i++) 331 { 332 System.out.print("\t"); } 334 335 System.out.println(text); 336 } 337 } 338 | Popular Tags |