FileDocCategorySizeDatePackage
DumpMapping.javaAPI DocGlassfish v2 API12640Fri May 04 22:34:44 BST 2007com.sun.jdo.api.persistence.model.util

DumpMapping

public class DumpMapping extends Object
DumpMapping.java

Fields Summary
private static Model
model
Constructors Summary
Methods Summary
public static voiddumpClassLoaderCache(java.io.PrintStream stream)
Print out the cache of classLoaders to the specified PrintStream.

param
stream PrintStream used to dump the info

		stream.println("ClassLoader cache (class names -> ClassLoaders)"); //NOI18N
		for (Iterator i = model.getClassLoaderCache().entrySet().iterator(); 
			 i.hasNext();)
		{
			Map.Entry entry = (Map.Entry)i.next();
			String className = (String)entry.getKey();
			ClassLoader classLoader = (ClassLoader)entry.getValue();
			stream.println("\t" + className + " ->\t" + classLoader);  //NOI18N
		}
	
public static voiddumpMappingCache(java.io.PrintStream stream)
Print out the cache of MappingClassElements to the specified PrintStream.

param
stream PrintStream used to dump the info

		// initialize the model reference
		setModel(Model.RUNTIME);
	
		stream.println("Mapping cache (class names -> MappingClassElements)"); // NOI18N
		for (Iterator i = model.getMappingCache().entrySet().iterator(); 
			 i.hasNext();)
		{
			Map.Entry entry = (Map.Entry)i.next();
			String className = (String)entry.getKey();
			MappingClassElement mce =  (MappingClassElement)entry.getValue();
			String mceRepr = mce.getClass() + "@" + // NOI18N
				Integer.toHexString(System.identityHashCode(mce));
			stream.println("\t" + className + " ->\t" + mceRepr); //NOI18N
		}
	
static java.lang.StringgetObjectIdentityTypeRepr(int objectIdentityType)

		String repr;
		switch (objectIdentityType)
		{
		case PersistenceClassElement.APPLICATION_IDENTITY:
			return "APPLICATION_IDENTITY";  //NOI18N
		case PersistenceClassElement.DATABASE_IDENTITY:
			return "DATABASE_IDENTITY_IDENTITY";  //NOI18N
		case PersistenceClassElement.UNMANAGED_IDENTITY:
			return "UNMANAGED_IDENTITY";  //NOI18N
		default:
			return "UNKNOWN";  //NOI18N
		}
	
static java.lang.StringgetPersistenceTypeRepr(int persistenceType)

		String repr;
		switch (persistenceType)
		{
		case PersistenceFieldElement.PERSISTENT:
			return "PERSISTENT";  //NOI18N
		case PersistenceFieldElement.DERIVED:
			return "DERIVED";  //NOI18N
		case PersistenceFieldElement.TRANSIENT:
			return "TRANSIENT";  //NOI18N
		default:
			return "UNKNOWN";  //NOI18N
		}
	
public static voidmain(java.lang.String[] args)

		for (int i = 0; i < args.length; i++)
		{
			String className = args[i];
			println(0, "\nClass " + className + ":");  //NOI18N

			try
			{
				MappingClassElementImpl mce = (MappingClassElementImpl)model.getMappingClass(className);
				if (mce != null)
				{
					printPersistenceClassElement(mce.getPersistenceElement());
					printMappingClassElement(mce);
				}
				else
				{
					println(0, "Cannot find mapping info for class " + className + " (getMappingClass returns null)");  //NOI18N
				}
			}
			catch (Exception e)
			{
				println(0, "Problems during accessing mapping info for class " + className);  //NOI18N
				e.printStackTrace();
			}
		}
	
public static voidprintConcurrencyGroupElements(int tabs, ConcurrencyGroupElement[] groups)

		if ((groups != null) && (groups.length > 0))
		{
			println(tabs, "--> concurrency groups");  //NOI18N
			for (int i = 0; i < groups.length; i++)
			{
				ConcurrencyGroupElement cg = groups[i];
				println(tabs, "[" + i + "] " + cg.getClass());  //NOI18N
				println(tabs+1, "name           = " + cg.getName());  //NOI18N
				println(tabs+1, "declaringClass = " + cg.getDeclaringClass());  //NOI18N
				println(tabs+1, "fields         = " + cg.getFields());  //NOI18N
			}
			println(tabs, "<-- concurrency groups");  //NOI18N
		}
	
public static voidprintMappingClassElement(MappingClassElement mce)

		println(0, "\n--> MappingClassElement");  //NOI18N
		
		println(1, "databaseRoot = " + mce.getDatabaseRoot());  //NOI18N
		printMappingTableElements(1, mce.getTables());
		printMappingFieldElements(1, mce.getFields());

		println(0, "<-- MappingClassElement");  //NOI18N
	
public static voidprintMappingFieldElements(int tabs, java.util.ArrayList fields)

		final int count = ((fields != null) ? fields.size() : 0);

		if (count > 0)
		{
			println(tabs, "--> fields ");  //NOI18N
			for (int i = 0; i < count; i++)
			{
				MappingFieldElementImpl mfe = (MappingFieldElementImpl) fields.get(i);
				
				println(tabs, "[" + i + "] " + mfe.getClass());  //NOI18N
				println(tabs+1, "name            = " + mfe.getName());  //NOI18N
				println(tabs+1, "fetchGroup      = " + mfe.getFetchGroup());  //NOI18N
				println(tabs+1, "columns         = " + mfe.getColumns());  //NOI18N
				
				if (!(mfe instanceof MappingRelationshipElement))
				{
					println(tabs+1, "columnObjects	 = " + mfe.getColumnObjects());  //NOI18N
				}
				else
				{
					MappingRelationshipElementImpl mre = (MappingRelationshipElementImpl) mfe;

					ArrayList columnObjects = mre.getColumnObjects();
					int colCount = 
						((columnObjects != null) ? columnObjects.size() : 0);
					if (colCount > 0)
					{
						println(tabs+1, "--> columnsObjects ");  //NOI18N
						for (int j = 0; j < colCount; j++)
						{
							ColumnPairElement fce = (ColumnPairElement) columnObjects.get(j);
							ColumnElement rce = (fce!=null)?fce.getReferencedColumn():null;
							println(tabs+1, "[" + j + "] " + fce + " -> " + rce);  //NOI18N
						}
						println(tabs+1, "<-- columnsObjects ");  //NOI18N
					}
					
					println(tabs+1, "associatedColumns = " + mre.getAssociatedColumns());  //NOI18N

					ArrayList associatedColumnObjects = mre.getAssociatedColumnObjects();
					colCount = ((associatedColumnObjects != null) ? 
						associatedColumnObjects.size() : 0);
					if (colCount > 0)
					{
						println(tabs+1, "--> associatedColumnObjects ");  //NOI18N
						for (int j = 0; j < colCount; j++)
						{
							ColumnPairElement fce = (ColumnPairElement) associatedColumnObjects.get(j);
							ColumnElement rce = (fce!=null)?fce.getReferencedColumn():null;
							println(tabs+1, "[" + j + "] " + fce + " -> " + rce);  //NOI18N
						}
						println(tabs+1, "<-- associatedColumnObjects ");  //NOI18N
					}
				}
			}
			println(tabs, "<-- fields ");  //NOI18N
		}

	
public static voidprintMappingRefKeyElements(int tabs, java.util.ArrayList refKeys)

		final int count = ((refKeys != null) ? refKeys.size() : 0);

		if (count > 0)
		{
			println(tabs, "--> tables ");  //NOI18N
			for (int i = 0; i < count; i++)
			{
				MappingReferenceKeyElement mrke = (MappingReferenceKeyElement)refKeys.get(i);

				println(tabs, "[" + i + "] " + mrke.getClass());  //NOI18N

				println(tabs+1, "table           = " + mrke.getDeclaringTable());  //NOI18N
				println(tabs+1, "pairs           = " + mrke.getColumnPairNames());  //NOI18N
			}
			println(tabs, "<-- tables ");  //NOI18N
		}
	 
public static voidprintMappingTableElements(int tabs, java.util.ArrayList tables)

		final int count = ((tables != null) ? tables.size() : 0);

		if (count > 0)
		{
			println(tabs, "--> tables ");  //NOI18N
			for (int i = 0; i < count; i++)
			{
				MappingTableElementImpl mte = (MappingTableElementImpl) tables.get(i);

				println(tabs, "[" + i + "] " + mte.getClass());  //NOI18N

				println(tabs+1, "table           = " + mte.getTable());  //NOI18N
				println(tabs+1, "tableObject     = " + mte.getTableObject());  //NOI18N
				println(tabs+1, "key             = " + mte.getKey());  //NOI18N
				println(tabs+1, "keyObjects      = " + mte.getKeyObjects());  //NOI18N
				printMappingRefKeyElements(tabs+1, mte.getReferencingKeys());
			}
			println(tabs, "<-- tables ");  //NOI18N
		}
	 
public static voidprintPersistenceClassElement(PersistenceClassElement pce)

		println(0, "\n--> PersistenceClassElement ");  //NOI18N
		println(1, "package  = " + pce.getPackage());  //NOI18N
		println(1, "name     = " + pce.getName());  //NOI18N
		println(1, "identity = " + getObjectIdentityTypeRepr(pce.getObjectIdentityType()));  //NOI18N
		println(1, "keyClass = " + pce.getKeyClass());  //NOI18N

		printPersistenceFieldElements(1, pce.getFields());
		printConcurrencyGroupElements(1, pce.getConcurrencyGroups());

		println(0, "<-- PersistenceClassElement\n ");  //NOI18N
	
public static voidprintPersistenceFieldElements(int tabs, PersistenceFieldElement[] fields)

		if ((fields != null) && (fields.length > 0))
		{
			println(tabs, "--> fields ");  //NOI18N
			for (int i = 0; i < fields.length; i++)
			{
				PersistenceFieldElement pfe = fields[i];
				
				println(tabs, "[" + i + "] " + pfe.getClass());  //NOI18N
				println(tabs+1, "name             = " + pfe.getName());  //NOI18N
				println(tabs+1, "declaringClass   = " + pfe.getDeclaringClass());  //NOI18N
				println(tabs+1, "fieldNumber      = " + pfe.getFieldNumber());  //NOI18N
				println(tabs+1, "persistenceType  = " + getPersistenceTypeRepr(pfe.getPersistenceType()));  //NOI18N
				println(tabs+1, "read / write     = " + pfe.isReadSensitive() + " / " + pfe.isWriteSensitive());  //NOI18N
				println(tabs+1, "isKey            = " + pfe.isKey());  //NOI18N
				
				if (pfe instanceof RelationshipElement)
				{
					RelationshipElement re = (RelationshipElement) pfe;
					
					println(tabs+1, "bounds          = " + re.getLowerBound() + " / " +  re.getUpperBound());  //NOI18N
					println(tabs+1, "deleteAction    = " + re.getDeleteAction());  //NOI18N
					println(tabs+1, "updateAction    = " + re.getUpdateAction());  //NOI18N
					println(tabs+1, "collectionClass = " + re.getCollectionClass());  //NOI18N
					println(tabs+1, "elementClass	 = " + re.getElementClass());  //NOI18N
					println(tabs+1, "isPrefetch      = " + re.isPrefetch());  //NOI18N
				}
				printConcurrencyGroupElements(tabs+1, pfe.getConcurrencyGroups());
			}
			println(tabs, "<-- fields ");			  //NOI18N
		}
	
static voidprintln(int indent, java.lang.String text)

		for (int i = 0; i < indent; i++)
		{
			System.out.print("\t");  //NOI18N
		}
		
		System.out.println(text);
	
public static voidsetModel(Model newModel)
Sets the internal model reference used by the DumpMapping methods to the specified Model instance.

param
newModel the Model instance to be used by DumpMapping

		model = newModel;