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());
}
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);
}
Aggregations