Search in sources :

Example 21 with ComponentType

use of org.hibernate.type.ComponentType in project jbosstools-hibernate by jbosstools.

the class TypeFacadeTest method testIsComponentType.

@Test
public void testIsComponentType() {
    IType typeFacade = null;
    ClassType classType = new ClassType();
    typeFacade = FACADE_FACTORY.createType(classType);
    Assert.assertFalse(typeFacade.isComponentType());
    MetadataBuildingOptions mdbo = new MetadataBuilderImpl.MetadataBuildingOptionsImpl(new StandardServiceRegistryBuilder().build());
    MetadataImplementor mdi = (MetadataImplementor) new MetadataBuilderImpl(new MetadataSources()).build();
    ComponentType componentType = new ComponentType(null, new ComponentMetamodel(new Component(mdi, new RootClass(null)), mdbo));
    typeFacade = FACADE_FACTORY.createType(componentType);
    Assert.assertTrue(typeFacade.isComponentType());
}
Also used : RootClass(org.hibernate.mapping.RootClass) ComponentType(org.hibernate.type.ComponentType) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ComponentMetamodel(org.hibernate.tuple.component.ComponentMetamodel) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) ClassType(org.hibernate.type.ClassType) Component(org.hibernate.mapping.Component) MetadataBuilderImpl(org.hibernate.boot.internal.MetadataBuilderImpl) IType(org.jboss.tools.hibernate.runtime.spi.IType) MetadataBuildingOptions(org.hibernate.boot.spi.MetadataBuildingOptions) Test(org.junit.Test)

Example 22 with ComponentType

use of org.hibernate.type.ComponentType in project BroadleafCommerce by BroadleafCommerce.

the class DynamicEntityDaoImpl method buildComponentProperties.

protected void buildComponentProperties(Class<?> targetClass, ForeignKey foreignField, ForeignKey[] additionalForeignFields, String[] additionalNonPersistentProperties, MergedPropertyType mergedPropertyType, Map<String, FieldMetadata> fields, String idProperty, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String ceilingEntityFullyQualifiedClassname, String propertyName, Type type, Class<?> returnedClass, List<Class<?>> parentClasses, Boolean isParentExcluded, String prefix, String parentPrefix) {
    String[] componentProperties = ((ComponentType) type).getPropertyNames();
    List<String> componentPropertyNames = Arrays.asList(componentProperties);
    Type[] componentTypes = ((ComponentType) type).getSubtypes();
    List<Type> componentPropertyTypes = Arrays.asList(componentTypes);
    String tempPrefix = "";
    int pos = prefix.indexOf(".");
    final int prefixLength = prefix.length();
    if (pos > 0 && pos < prefixLength - 1) {
        // only use part of the prefix if it's more than one layer deep
        tempPrefix = prefix.substring(pos + 1, prefixLength);
    }
    Map<String, FieldMetadata> componentPresentationAttributes = metadata.getFieldMetadataForTargetClass(targetClass, returnedClass, this, tempPrefix + propertyName + ".");
    if (isParentExcluded) {
        for (String key : componentPresentationAttributes.keySet()) {
            LOG.debug("buildComponentProperties:Excluding " + key + " because the parent was excluded");
            componentPresentationAttributes.get(key).setExcluded(true);
        }
    }
    PersistentClass persistentClass = getPersistentClass(targetClass.getName());
    Property property;
    try {
        property = persistentClass.getProperty(propertyName);
    } catch (MappingException e) {
        property = persistentClass.getProperty(prefix + propertyName);
    }
    Iterator componentPropertyIterator = ((org.hibernate.mapping.Component) property.getValue()).getPropertyIterator();
    List<Property> componentPropertyList = new ArrayList<>();
    while (componentPropertyIterator.hasNext()) {
        componentPropertyList.add((Property) componentPropertyIterator.next());
    }
    Map<String, FieldMetadata> newFields = new HashMap<>();
    buildProperties(targetClass, foreignField, additionalForeignFields, additionalNonPersistentProperties, mergedPropertyType, componentPresentationAttributes, componentPropertyList, newFields, componentPropertyNames, componentPropertyTypes, idProperty, populateManyToOneFields, includeFields, excludeFields, configurationKey, ceilingEntityFullyQualifiedClassname, parentClasses, propertyName + ".", isParentExcluded, true, parentPrefix + prefix);
    Map<String, FieldMetadata> convertedFields = new HashMap<>();
    for (String key : newFields.keySet()) {
        final FieldMetadata fieldMetadata = newFields.get(key);
        convertedFields.put(propertyName + "." + key, fieldMetadata);
        if (isForeignKey(fieldMetadata)) {
            setOriginatingFieldForForeignKey(propertyName, key, fieldMetadata);
        }
    }
    fields.putAll(convertedFields);
}
Also used : ComponentType(org.hibernate.type.ComponentType) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MappingException(org.hibernate.MappingException) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType) PersistencePerspectiveItemType(org.broadleafcommerce.common.presentation.client.PersistencePerspectiveItemType) SupportedFieldType(org.broadleafcommerce.common.presentation.client.SupportedFieldType) ComponentType(org.hibernate.type.ComponentType) Type(org.hibernate.type.Type) Iterator(java.util.Iterator) Component(org.springframework.stereotype.Component) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass)

Aggregations

ComponentType (org.hibernate.type.ComponentType)22 Component (org.hibernate.mapping.Component)9 Type (org.hibernate.type.Type)9 Test (org.junit.Test)9 RootClass (org.hibernate.mapping.RootClass)8 ComponentMetamodel (org.hibernate.tuple.component.ComponentMetamodel)8 ClassType (org.hibernate.type.ClassType)8 IType (org.jboss.tools.hibernate.runtime.spi.IType)8 ManyToOneType (org.hibernate.type.ManyToOneType)5 MetadataSources (org.hibernate.boot.MetadataSources)4 MetadataBuilderImpl (org.hibernate.boot.internal.MetadataBuilderImpl)4 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)4 MetadataBuildingOptions (org.hibernate.boot.spi.MetadataBuildingOptions)4 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)4 CollectionType (org.hibernate.type.CollectionType)3 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 Iterator (java.util.Iterator)2 OneToOneType (org.hibernate.type.OneToOneType)2