/*
 * Created on Sep 15, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package edu.wustl.common.util.dbManager;

import java.util.Iterator;

import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.mapping.Column;
import net.sf.hibernate.mapping.Property;
import net.sf.hibernate.mapping.Table;
import edu.wustl.common.util.logger.Logger;


/**
 * @author kapil_kaveeshwar
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class HibernateMetaData
{
	private static Configuration cfg; 
	public static void initHibernateMetaData(Configuration configuration)
	{
		cfg = configuration;
	}
	
	public static String getTableName(Class classObj)
	{
		Table tbl = cfg.getClassMapping(classObj).getTable();
		if(tbl!=null)
			return tbl.getName();
		return "";
	}
	
	public static String getColumnName(Class classObj, String attributeName)
	{
		Logger.out.debug("classObj, String attributeName "+classObj+" "+attributeName);
		Iterator it = cfg.getClassMapping(classObj).getPropertyIterator();
		while(it.hasNext())
		{
			Property property = (Property)it.next();
			
			Logger.out.debug("property.getName() "+property.getName());
			if(property!=null && property.getName().equals(attributeName))
			{
				//System.out.println("property.getColumnSpan() "+property.getColumnSpan());
				Iterator colIt = property.getColumnIterator();
				while(colIt.hasNext())
				{
					Column col = (Column)colIt.next();
					return col.getName();
				}
			}
		}
		
		
		Property property = cfg.getClassMapping(classObj).getIdentifierProperty();
		Logger.out.debug("property.getName() "+property.getName());
		if(property.getName().equals(attributeName))
		{
			Iterator colIt = property.getColumnIterator();//y("systemIdentifier").getColumnIterator();
			while(colIt.hasNext())
			{
				Column col = (Column)colIt.next();
				return col.getName();
				//System.out.println(col.getName());
			}
		}
		
		return "";
	}
}

@@ -1199,16 +1199,23 @@
 Property
+Closure
 Iterator
@@ -1219,16 +1219,16 @@
 tor();%0D%0A
-
 %09%09while(
@@ -1361,16 +1361,114 @@
 me());%0D%0A
+%09%09%09//System.out.println();%0D%0A%09%09%09//System.out.print(%22property.getName() %22+property.getName()+%22 %22);%0D%0A
 %09%09%09if(pr
@@ -1696,24 +1696,24 @@
 ())%0D%0A%09%09%09%09%7B%0D%0A
-
 %09%09%09%09%09Column 
@@ -1737,24 +1737,74 @@
 It.next();%0D%0A
+%09%09%09%09%09//System.out.println(%22col %22+col.getName());%0D%0A
 %09%09%09%09%09return 

use of getPropertyClosureIterator instead of getPropertyIterator