1 package org.hibernate.cfg; 3 4 import java.util.Map ; 5 import java.util.HashMap ; 6 import java.lang.reflect.AnnotatedElement ; 7 import javax.persistence.Column; 8 import javax.persistence.AttributeOverride; 9 import javax.persistence.AttributeOverrides; 10 11 import org.hibernate.mapping.Collection; 12 import org.hibernate.mapping.Component; 13 import org.hibernate.mapping.PersistentClass; 14 15 20 public final class PropertyHolderBuilder { 21 private PropertyHolderBuilder() {} 22 23 public static PropertyHolder buildPropertyHolder(PersistentClass persistentClass, Map <String , Column[]> columnOverride) { 24 return (PropertyHolder) new ClassPropertyHolder(persistentClass, columnOverride); 25 } 26 27 34 public static PropertyHolder buildPropertyHolder(Component component, String path, Map <String , Column[]> columnOverride) { 35 return (PropertyHolder) new ComponentPropertyHolder(component, path, columnOverride); 36 } 37 38 39 public static PropertyHolder buildPropertyHolder(Collection collection, String path) { 40 return new CollectionPropertyHolder( collection, path ); 41 } 42 43 public static PropertyHolder buildPropertyHolder(PersistentClass persistentClass) { 44 return buildPropertyHolder( persistentClass, new HashMap <String , Column[]>() ); 45 } 46 47 public static Map <String , Column[]> buildColumnOverride(AnnotatedElement element) { 48 AttributeOverride singleOverride = element.getAnnotation(AttributeOverride.class); 49 AttributeOverrides multipleOverrides = element.getAnnotation(AttributeOverrides.class); 50 AttributeOverride[] overrides; 51 if (singleOverride != null) { 52 overrides = new AttributeOverride[] { singleOverride }; 53 } 54 else if (multipleOverrides != null) { 55 overrides = multipleOverrides.value(); 56 } 57 else { 58 overrides = null; 59 } 60 Map <String , Column[]> columnOverride = new HashMap <String , Column[]>(); 61 if (overrides != null) { 63 for ( AttributeOverride depAttr : overrides ) { 64 columnOverride.put( depAttr.name(), new Column[] { depAttr.column() } ); 65 } 66 } 67 return columnOverride; 68 } 69 } 70 | Popular Tags |