1 9 package org.jboss.portal.setup.impl.dl.dbloader.hibernate; 10 11 import org.jboss.portal.setup.impl.dl.dbloader.ColumnMetaData; 12 import org.jboss.portal.setup.PortalSetupException; 13 import org.hibernate.type.LiteralType; 14 import org.hibernate.type.NullableType; 15 import org.hibernate.type.Type; 16 import org.hibernate.type.TypeFactory; 17 import org.hibernate.tool.hbm2ddl.ColumnMetadata; 18 import org.hibernate.dialect.Dialect; 19 import org.hibernate.mapping.Column; 20 import org.hibernate.cfg.Configuration; 21 import org.hibernate.MappingException; 22 import org.hibernate.HibernateException; 23 24 25 import javax.sound.sampled.EnumControl ; 26 import java.sql.Types ; 27 28 29 35 public class HibernateColumnMetaData extends ColumnMetaData 36 { 37 private String m_dbTypeName; 38 private LiteralType m_literalType; 39 private int m_size = -1; 40 41 public String getDbTypeName() 42 { 43 return m_dbTypeName; 44 } 45 46 public HibernateColumnMetaData(String columnName, String javaType, int columnSize) 47 { 48 super(columnName, javaType, columnSize); 49 } 50 51 public int getSize() 52 { 53 return m_size; 54 } 55 56 public LiteralType getLiteralType() 57 { 58 return m_literalType; 59 } 60 61 void setColumnTypeValues(ColumnMetadata md, Dialect dialect, Column column, Configuration cfg) throws PortalSetupException 62 { 63 m_dbTypeName = column.getSqlType(); 65 try 66 { 67 m_literalType = (LiteralType)TypeFactory.heuristicType(getJavaType()); 68 int sqlTypeFromLiteral = ((NullableType)m_literalType).sqlType(); 69 String dbString = dialect.getTypeName(sqlTypeFromLiteral); 70 int firstParent = dbString.indexOf('('); 71 if (firstParent > 0) 72 { 73 m_dbTypeName = dbString.substring(0, firstParent); 74 int lastparent = dbString.indexOf(')'); 75 String length = dbString.substring(firstParent, lastparent); 76 try 77 { 78 m_size = Integer.parseInt(length); 79 } 80 catch (Throwable th) 81 { 82 } 84 } 85 else 86 { 87 m_dbTypeName = dbString; 88 } 89 90 } 91 catch (MappingException me) 92 { 93 throw new PortalSetupException("failed to resolve data literal type"); 94 } 95 catch (HibernateException he) 96 { 97 throw new PortalSetupException("failed to resolve data literal type"); 98 } 99 100 } 101 102 int getSqlTypeIndex() 103 { 104 return m_literalType == null ? -1 : ((NullableType)m_literalType).sqlType(); 105 } 106 107 108 } 109 | Popular Tags |