FileDocCategorySizeDatePackage
Printer.javaAPI DocHibernate 3.2.53010Sat Feb 19 05:58:24 GMT 2005org.hibernate.pretty

Printer

public final class Printer extends Object
Renders entities to a nicely readable string.
author
Gavin King

Fields Summary
private org.hibernate.engine.SessionFactoryImplementor
factory
private static final Log
log
Constructors Summary
public Printer(org.hibernate.engine.SessionFactoryImplementor factory)

		this.factory = factory;
	
Methods Summary
public java.lang.StringtoString(java.lang.Object entity, org.hibernate.EntityMode entityMode)

param
entity an actual entity object, not a proxy!


	         	 
	        

		// todo : this call will not work for anything other than pojos!
		ClassMetadata cm = factory.getClassMetadata( entity.getClass() );

		if ( cm==null ) return entity.getClass().getName();

		Map result = new HashMap();

		if ( cm.hasIdentifierProperty() ) {
			result.put(
				cm.getIdentifierPropertyName(),
				cm.getIdentifierType().toLoggableString( cm.getIdentifier( entity, entityMode ), factory )
			);
		}

		Type[] types = cm.getPropertyTypes();
		String[] names = cm.getPropertyNames();
		Object[] values = cm.getPropertyValues( entity, entityMode );
		for ( int i=0; i<types.length; i++ ) {
			if ( !names[i].startsWith("_") ) {
				String strValue = values[i]==LazyPropertyInitializer.UNFETCHED_PROPERTY ?
					values[i].toString() :
					types[i].toLoggableString( values[i], factory );
				result.put( names[i], strValue );
			}
		}
		return cm.getEntityName() + result.toString();
	
public java.lang.StringtoString(org.hibernate.type.Type[] types, java.lang.Object[] values)

		List list = new ArrayList( types.length * 5 );
		for ( int i=0; i<types.length; i++ ) {
			if ( types[i]!=null ) list.add( types[i].toLoggableString( values[i], factory ) );
		}
		return list.toString();
	
public java.lang.StringtoString(java.util.Map namedTypedValues)

		Map result = new HashMap();
		Iterator iter = namedTypedValues.entrySet().iterator();
		while ( iter.hasNext() ) {
			Map.Entry me = (Map.Entry) iter.next();
			TypedValue tv = (TypedValue) me.getValue();
			result.put( me.getKey(), tv.getType().toLoggableString( tv.getValue(), factory ) );
		}
		return result.toString();
	
public voidtoString(java.util.Iterator iter, org.hibernate.EntityMode entityMode)

		if ( !log.isDebugEnabled() || !iter.hasNext() ) return;
		log.debug("listing entities:");
		int i=0;
		while ( iter.hasNext() ) {
			if (i++>20) {
				log.debug("more......");
				break;
			}
			log.debug( toString( iter.next(), entityMode ) );
		}