List of usage examples for org.hibernate.mapping Component getComponentClassName
public String getComponentClassName()
From source file:com.mysema.query.jpa.codegen.HibernateDomainExporter.java
License:Apache License
private void handleProperty(EntityType entityType, Class<?> cl, org.hibernate.mapping.Property p) throws NoSuchMethodException, ClassNotFoundException { if (p.isBackRef()) { return;/*from ww w.jav a 2 s .co m*/ } Class<?> clazz = Object.class; try { clazz = p.getType().getReturnedClass(); } catch (MappingException e) { // ignore } Type propertyType = getType(cl, clazz, p.getName()); if (p.isComposite()) { EntityType embeddedType = createEmbeddableType(propertyType); Iterator<?> properties = ((Component) p.getValue()).getPropertyIterator(); while (properties.hasNext()) { handleProperty(embeddedType, embeddedType.getJavaClass(), (org.hibernate.mapping.Property) properties.next()); } propertyType = embeddedType; } else if (propertyType.getCategory() == TypeCategory.ENTITY || p.getValue() instanceof ManyToOne) { propertyType = createEntityType(propertyType); } else if (propertyType.getCategory() == TypeCategory.CUSTOM) { propertyType = createEmbeddableType(propertyType); } else if (p.getValue() instanceof org.hibernate.mapping.Collection) { org.hibernate.mapping.Collection collection = (org.hibernate.mapping.Collection) p.getValue(); if (collection.getElement() instanceof OneToMany) { String entityName = ((OneToMany) collection.getElement()).getReferencedEntityName(); if (entityName != null) { Type componentType = typeFactory.create(Class.forName(entityName)); propertyType = new SimpleType(propertyType, componentType); } } else if (collection.getElement() instanceof Component) { Component component = (Component) collection.getElement(); Class<?> embeddedClass = Class.forName(component.getComponentClassName()); EntityType embeddedType = createEmbeddableType(embeddedClass); Iterator<?> properties = component.getPropertyIterator(); while (properties.hasNext()) { handleProperty(embeddedType, embeddedClass, (org.hibernate.mapping.Property) properties.next()); } } } AnnotatedElement annotated = getAnnotatedElement(cl, p.getName()); Property property = createProperty(entityType, p.getName(), propertyType, annotated); entityType.addProperty(property); }
From source file:com.querydsl.jpa.codegen.HibernateDomainExporter.java
License:Apache License
private void handleProperty(EntityType entityType, Class<?> cl, org.hibernate.mapping.Property p) throws NoSuchMethodException, ClassNotFoundException { if (p.isBackRef()) { return;/* w w w . ja va 2 s. co m*/ } Class<?> clazz = Object.class; try { clazz = p.getType().getReturnedClass(); } catch (MappingException e) { // ignore } Type propertyType = getType(cl, clazz, p.getName()); try { propertyType = getPropertyType(p, propertyType); } catch (MappingException e) { // ignore } AnnotatedElement annotated = getAnnotatedElement(cl, p.getName()); propertyType = getTypeOverride(propertyType, annotated); if (propertyType == null) { return; } if (p.isComposite()) { EntityType embeddedType = createEmbeddableType(propertyType); Iterator<?> properties = ((Component) p.getValue()).getPropertyIterator(); while (properties.hasNext()) { handleProperty(embeddedType, embeddedType.getJavaClass(), (org.hibernate.mapping.Property) properties.next()); } propertyType = embeddedType; } else if (propertyType.getCategory() == TypeCategory.ENTITY || p.getValue() instanceof ManyToOne) { propertyType = createEntityType(propertyType); } else if (propertyType.getCategory() == TypeCategory.CUSTOM) { propertyType = createEmbeddableType(propertyType); } else if (p.getValue() instanceof org.hibernate.mapping.Collection) { org.hibernate.mapping.Collection collection = (org.hibernate.mapping.Collection) p.getValue(); if (collection.getElement() instanceof OneToMany) { String entityName = ((OneToMany) collection.getElement()).getReferencedEntityName(); if (entityName != null) { if (collection.isMap()) { Type keyType = typeFactory .get(Class.forName(propertyType.getParameters().get(0).getFullName())); Type valueType = typeFactory.get(Class.forName(entityName)); propertyType = new SimpleType(propertyType, normalize(propertyType.getParameters().get(0), keyType), normalize(propertyType.getParameters().get(1), valueType)); } else { Type componentType = typeFactory.get(Class.forName(entityName)); propertyType = new SimpleType(propertyType, normalize(propertyType.getParameters().get(0), componentType)); } } } else if (collection.getElement() instanceof Component) { Component component = (Component) collection.getElement(); Class<?> embeddedClass = Class.forName(component.getComponentClassName()); EntityType embeddedType = createEmbeddableType(embeddedClass); Iterator<?> properties = component.getPropertyIterator(); while (properties.hasNext()) { handleProperty(embeddedType, embeddedClass, (org.hibernate.mapping.Property) properties.next()); } } } Property property = createProperty(entityType, p.getName(), propertyType, annotated); entityType.addProperty(property); }
From source file:gov.nih.nci.system.util.ClassCache.java
License:BSD License
@SuppressWarnings("unchecked") private Map<String, List<Object>> processIfAssociationType(Property property, String fieldName, Configuration cfg) {/*w ww . j a v a 2 s.c o m*/ Map<String, List<Object>> associationPsFields = new HashMap<String, List<Object>>(); org.hibernate.mapping.Set childAssociationType = (org.hibernate.mapping.Set) property.getValue(); Object element = childAssociationType.getElement(); Class<? extends Value> elementClass = childAssociationType.getElement().getClass(); if (Component.class.isAssignableFrom(elementClass)) { Component associationComponent = (Component) element; Iterator<Property> propertiesIterator = associationComponent.getPropertyIterator(); String assoChildCompClassName = associationComponent.getComponentClassName(); String key = fieldName + "<" + assoChildCompClassName + ">"; List<Object> isoPersistentFields = new ArrayList<Object>(); while (propertiesIterator.hasNext()) { Property tempProperty = propertiesIterator.next(); List<Object> tempPersistentFields = getPersistentFieldsForISOObject(tempProperty); Class<? extends Value> tempPropertyClass = tempProperty.getValue().getClass(); if (Component.class.isAssignableFrom(tempPropertyClass)) { Map<String, List<Object>> nestedComponent = new HashMap<String, List<Object>>(); nestedComponent.put(tempProperty.getName(), tempPersistentFields); isoPersistentFields.add(nestedComponent); } else { isoPersistentFields.addAll(tempPersistentFields); } } associationPsFields.put(key, isoPersistentFields); } else if (element instanceof ManyToOne) { ManyToOne manyToOne = (ManyToOne) childAssociationType.getElement(); String many2OnePClassName = manyToOne.getReferencedEntityName(); if (!many2OnePClassName.startsWith("_xxEntityxx_gov_nih_nci_cacoresdk_domain_other_datatype")) { return associationPsFields; } PersistentClass many2OnePClass = cfg.getClassMapping(many2OnePClassName); Map<String, List<Object>> map = getISOPropertiesForObject(many2OnePClass, cfg); Iterator<String> keyItr = map.keySet().iterator(); String key = fieldName + "<" + many2OnePClass.getClassName() + ">"; List<Object> isoPersistentFields = new ArrayList<Object>(); isoPersistentFields.add(map); associationPsFields.put(key, isoPersistentFields); } else if (element instanceof OneToMany) { OneToMany oneToMany = (OneToMany) element;//prop.getValue(); String oneToManyPClassName = oneToMany.getReferencedEntityName(); if (!oneToManyPClassName.startsWith("_xxEntityxx_gov_nih_nci_cacoresdk_domain_other_datatype")) { return associationPsFields; } PersistentClass oneToManyPClass = cfg.getClassMapping(oneToManyPClassName); Map<String, List<Object>> map = getISOPropertiesForObject(oneToManyPClass, cfg); Iterator<String> keyItr = map.keySet().iterator(); String key = fieldName + "<" + oneToMany.getAssociatedClass().getClassName() + ">"; List<Object> isoPersistentFields = new ArrayList<Object>(); isoPersistentFields.add(map); associationPsFields.put(key, isoPersistentFields); } else { log.info("ignoring :::" + elementClass.getName()); } return associationPsFields; }
From source file:org.compass.gps.device.hibernate.embedded.CompassEventListener.java
License:Apache License
private CompassHolder initCompassHolder(Configuration cfg) { Properties compassProperties = new Properties(); //noinspection unchecked Properties props = cfg.getProperties(); for (Map.Entry entry : props.entrySet()) { String key = (String) entry.getKey(); if (key.startsWith(COMPASS_PREFIX)) { compassProperties.put(entry.getKey(), entry.getValue()); }//from w w w . j a v a 2 s. c o m if (key.startsWith(COMPASS_GPS_INDEX_PREFIX)) { compassProperties.put(entry.getKey(), entry.getValue()); } } if (compassProperties.isEmpty()) { if (log.isDebugEnabled()) { log.debug("No Compass properties defined, disabling Compass"); } return null; } if (compassProperties.getProperty(CompassEnvironment.CONNECTION) == null) { if (log.isDebugEnabled()) { log.debug("No Compass [" + CompassEnvironment.CONNECTION + "] property defined, disabling Compass"); } return null; } processCollections = compassProperties.getProperty(COMPASS_PROCESS_COLLECTIONS, "true") .equalsIgnoreCase("true"); CompassConfiguration compassConfiguration = CompassConfigurationFactory.newConfiguration(); CompassSettings settings = compassConfiguration.getSettings(); settings.addSettings(compassProperties); String configLocation = (String) compassProperties.get(COMPASS_CONFIG_LOCATION); if (configLocation != null) { compassConfiguration.configure(configLocation); } boolean atleastOneClassAdded = false; for (Iterator it = cfg.getClassMappings(); it.hasNext();) { PersistentClass clazz = (PersistentClass) it.next(); Class<?> mappedClass = clazz.getMappedClass(); for (Iterator propIt = clazz.getPropertyIterator(); propIt.hasNext();) { Property prop = (Property) propIt.next(); Value value = prop.getValue(); if (value instanceof Component) { Component component = (Component) value; try { atleastOneClassAdded |= compassConfiguration.tryAddClass( ClassUtils.forName(component.getComponentClassName(), settings.getClassLoader())); } catch (ClassNotFoundException e) { log.warn("Failed to load component class [" + component.getComponentClassName() + "]", e); } } } Value idValue = clazz.getIdentifierProperty().getValue(); if (idValue instanceof Component) { Component component = (Component) idValue; try { atleastOneClassAdded |= compassConfiguration.tryAddClass( ClassUtils.forName(component.getComponentClassName(), settings.getClassLoader())); } catch (ClassNotFoundException e) { log.warn("Failed to load component class [" + component.getComponentClassName() + "]", e); } } atleastOneClassAdded |= compassConfiguration.tryAddClass(mappedClass); } if (!atleastOneClassAdded) { if (log.isDebugEnabled()) { log.debug("No searchable class mappings found in Hibernate class mappings, disabling Compass"); } return null; } CompassHolder compassHolder = new CompassHolder(); compassHolder.compassProperties = compassProperties; compassHolder.commitBeforeCompletion = settings .getSettingAsBoolean(CompassEnvironment.Transaction.COMMIT_BEFORE_COMPLETION, false); String transactionFactory = (String) compassProperties.get(CompassEnvironment.Transaction.FACTORY); if (transactionFactory == null) { String hibernateTransactionStrategy = cfg.getProperty(Environment.TRANSACTION_STRATEGY); if (CMTTransactionFactory.class.getName().equals(hibernateTransactionStrategy) || JTATransactionFactory.class.getName().equals(hibernateTransactionStrategy)) { // hibernate is configured with JTA, automatically configure Compass to use its JTASync (by default) compassHolder.hibernateControlledTransaction = false; compassConfiguration.setSetting(CompassEnvironment.Transaction.FACTORY, JTASyncTransactionFactory.class.getName()); } else { // Hibernate JDBC transaction manager, let Compass use the local transaction manager compassHolder.hibernateControlledTransaction = true; // if the settings is configured to use local transaciton, disable thread bound setting since // we are using Hibernate to managed transaction scope (using the transaction to holder map) and not thread locals if (settings .getSetting(CompassEnvironment.Transaction.DISABLE_THREAD_BOUND_LOCAL_TRANSATION) == null) { settings.setBooleanSetting(CompassEnvironment.Transaction.DISABLE_THREAD_BOUND_LOCAL_TRANSATION, true); } } } else if (LocalTransactionFactory.class.getName().equals(transactionFactory)) { compassHolder.hibernateControlledTransaction = true; // if the settings is configured to use local transaciton, disable thread bound setting since // we are using Hibernate to managed transaction scope (using the transaction to holder map) and not thread locals if (settings.getSetting(CompassEnvironment.Transaction.DISABLE_THREAD_BOUND_LOCAL_TRANSATION) == null) { settings.setBooleanSetting(CompassEnvironment.Transaction.DISABLE_THREAD_BOUND_LOCAL_TRANSATION, true); } } else { // Hibernate is not controlling the transaction (using JTA Sync or XA), don't commit/rollback // with Hibernate transaction listeners compassHolder.hibernateControlledTransaction = false; } compassHolder.indexSettings = new Properties(); for (Map.Entry entry : compassProperties.entrySet()) { String key = (String) entry.getKey(); if (key.startsWith(COMPASS_GPS_INDEX_PREFIX)) { compassHolder.indexSettings.put(key.substring(COMPASS_GPS_INDEX_PREFIX.length()), entry.getValue()); } } String mirrorFilterClass = compassHolder.compassProperties.getProperty(COMPASS_MIRROR_FILTER); if (mirrorFilterClass != null) { try { compassHolder.mirrorFilter = (HibernateMirrorFilter) ClassUtils .forName(mirrorFilterClass, compassConfiguration.getSettings().getClassLoader()) .newInstance(); } catch (Exception e) { throw new CompassException("Failed to create mirror filter [" + mirrorFilterClass + "]", e); } } compassHolder.compass = compassConfiguration.buildCompass(); return compassHolder; }
From source file:org.eclipse.emf.teneo.hibernate.HbDataStore.java
License:Open Source License
/** * Sets the emf component tuplizer (if it is an eclass) or the hibernate * component tuplizer/*from w w w . ja va2s.c o m*/ */ protected void setComponentTuplizer(Component component, Configuration cfg) { // check if the eclass exists // todo: change recognizing a component to using metadata! EClass eClass = ERuntime.INSTANCE.getEClass(component.getComponentClass()); if (eClass == null) { eClass = getEntityNameStrategy().toEClass(component.getComponentClassName()); } if (eClass != null) { if (log.isDebugEnabled()) { log.debug("Found " + eClass.getName() + " as a component"); } } else { eClass = HbUtil.getEClassFromMeta(component); if (eClass == null) { return; } } // is a valid eclass component.addTuplizer(EntityMode.MAP, getHbContext().getEMFComponentTuplizerClass(cfg).getName()); component.addTuplizer(EntityMode.POJO, getHbContext().getEMFComponentTuplizerClass(cfg).getName()); HbHelper.INSTANCE.registerDataStoreByComponent(this, component); }
From source file:org.eclipse.emf.teneo.hibernate.HbHelper.java
License:Open Source License
/** Register the datastore also for the components */ void registerDataStoreByComponent(HbDataStore ds, Component component) { if (log.isDebugEnabled()) { log.debug("Datastore: " + ds.getName() + " registered for component: " + component.getComponentClassName()); }//from w w w . ja va 2s. c o m dataStoreByPersistentClass.put(component, ds); }
From source file:org.eclipse.emf.teneo.hibernate.HbHelper.java
License:Open Source License
/** Return the datastore on the basis of the component */ public HbDataStore getDataStore(Component component) { final HbDataStore ds = dataStoreByPersistentClass.get(component); if (ds == null) { throw new HbMapperException("No datastore for pc " + component.getComponentClassName()); }//from w w w. j av a 2 s.c om return ds; }
From source file:org.eclipse.emf.teneo.hibernate.tuplizer.EMFComponentTuplizer.java
License:Open Source License
private EClass getEClass(Component component) { if (eClass == null) { final HbDataStore ds = HbHelper.INSTANCE.getDataStore(component); eClass = ds.getEntityNameStrategy().toEClass(component.getComponentClassName()); if (eClass == null) { eClass = ERuntime.INSTANCE.getEClass(component.getComponentClass()); }/*w ww . j ava2 s .c o m*/ if (eClass == null) { eClass = HbUtil.getEClassFromMeta(component); } } if (eClass == null) { throw new HbMapperException("No eclass found for entityname: " + component.getComponentClassName()); } return eClass; }
From source file:org.eclipse.emf.teneo.hibernate.tuplizer.EMFComponentTuplizer.java
License:Open Source License
/** Returns the correct accessor on the basis of the type of property */ public PropertyAccessor getPropertyAccessor(Property mappedProperty, Component comp) { final HbDataStore ds = HbHelper.INSTANCE.getDataStore(comp); return HbUtil.getPropertyAccessor(mappedProperty, ds, comp.getComponentClassName(), getEClass(comp)); }
From source file:org.jboss.tools.hibernate.ui.diagram.editors.model.SpecialRootClass.java
License:Open Source License
@SuppressWarnings("unchecked") private void generate() { if (property == null) { return;/* w ww. ja v a2 s . c om*/ } Component component = null; if (property.getValue() instanceof Collection) { Collection collection = (Collection) property.getValue(); component = (Component) collection.getElement(); } else if (property.getValue() instanceof Component) { component = (Component) property.getValue(); } if (component != null) { setClassName(component.getComponentClassName()); setEntityName(component.getComponentClassName()); PersistentClass ownerClass = component.getOwner(); if (component.getParentProperty() != null) { parentProperty = new Property(); parentProperty.setName(component.getParentProperty()); parentProperty.setPersistentClass(ownerClass); } Iterator<Property> iterator = component.getPropertyIterator(); while (iterator.hasNext()) { Property property = iterator.next(); if (property != null) { addProperty(property); } } } }