use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class BinderHelper method shallowCopy.
/**
* create a property copy reusing the same value
*/
public static Property shallowCopy(Property property) {
Property clone = new Property();
clone.setCascade(property.getCascade());
clone.setInsertable(property.isInsertable());
clone.setLazy(property.isLazy());
clone.setName(property.getName());
clone.setNaturalIdentifier(property.isNaturalIdentifier());
clone.setOptimisticLocked(property.isOptimisticLocked());
clone.setOptional(property.isOptional());
clone.setPersistentClass(property.getPersistentClass());
clone.setPropertyAccessorName(property.getPropertyAccessorName());
clone.setSelectable(property.isSelectable());
clone.setUpdateable(property.isUpdateable());
clone.setValue(property.getValue());
return clone;
}
use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class LazyAttributesMetadata method from.
/**
* Build a LazyFetchGroupMetadata based on the attributes defined for the
* PersistentClass
*
* @param mappedEntity The entity definition
*
* @return The built LazyFetchGroupMetadata
*/
public static LazyAttributesMetadata from(PersistentClass mappedEntity) {
final Map<String, LazyAttributeDescriptor> lazyAttributeDescriptorMap = new LinkedHashMap<>();
final Map<String, Set<String>> fetchGroupToAttributesMap = new HashMap<>();
int i = -1;
int x = 0;
final Iterator itr = mappedEntity.getPropertyClosureIterator();
while (itr.hasNext()) {
i++;
final Property property = (Property) itr.next();
if (property.isLazy()) {
final LazyAttributeDescriptor lazyAttributeDescriptor = LazyAttributeDescriptor.from(property, i, x++);
lazyAttributeDescriptorMap.put(lazyAttributeDescriptor.getName(), lazyAttributeDescriptor);
final Set<String> attributeSet = fetchGroupToAttributesMap.computeIfAbsent(lazyAttributeDescriptor.getFetchGroupName(), k -> new LinkedHashSet<>());
attributeSet.add(lazyAttributeDescriptor.getName());
}
}
if (lazyAttributeDescriptorMap.isEmpty()) {
return new LazyAttributesMetadata(mappedEntity.getEntityName());
}
for (Map.Entry<String, Set<String>> entry : fetchGroupToAttributesMap.entrySet()) {
entry.setValue(Collections.unmodifiableSet(entry.getValue()));
}
return new LazyAttributesMetadata(mappedEntity.getEntityName(), Collections.unmodifiableMap(lazyAttributeDescriptorMap), Collections.unmodifiableMap(fetchGroupToAttributesMap));
}
use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class CopyIdentifierComponentSecondPass method createSimpleProperty.
private Property createSimpleProperty(PersistentClass referencedPersistentClass, boolean isExplicitReference, Map<String, Ejb3JoinColumn> columnByReferencedName, AtomicInteger index, Property referencedProperty) {
Property property = new Property();
property.setName(referencedProperty.getName());
//FIXME set optional?
//property.setOptional( property.isOptional() );
property.setPersistentClass(component.getOwner());
property.setPropertyAccessorName(referencedProperty.getPropertyAccessorName());
SimpleValue value = new SimpleValue(buildingContext.getMetadataCollector(), component.getTable());
property.setValue(value);
final SimpleValue referencedValue = (SimpleValue) referencedProperty.getValue();
value.setTypeName(referencedValue.getTypeName());
value.setTypeParameters(referencedValue.getTypeParameters());
final Iterator<Selectable> columns = referencedValue.getColumnIterator();
if (joinColumns[0].isNameDeferred()) {
joinColumns[0].copyReferencedStructureAndCreateDefaultJoinColumns(referencedPersistentClass, columns, value);
} else {
//FIXME take care of Formula
while (columns.hasNext()) {
final Selectable selectable = columns.next();
if (!Column.class.isInstance(selectable)) {
log.debug("Encountered formula definition; skipping");
continue;
}
final Column column = (Column) selectable;
final Ejb3JoinColumn joinColumn;
String logicalColumnName = null;
if (isExplicitReference) {
final String columnName = column.getName();
logicalColumnName = buildingContext.getMetadataCollector().getLogicalColumnName(referencedPersistentClass.getTable(), columnName);
//JPA 2 requires referencedColumnNames to be case insensitive
joinColumn = columnByReferencedName.get(logicalColumnName.toLowerCase(Locale.ROOT));
} else {
joinColumn = columnByReferencedName.get("" + index.get());
index.getAndIncrement();
}
if (joinColumn == null && !joinColumns[0].isNameDeferred()) {
throw new AnnotationException(isExplicitReference ? "Unable to find column reference in the @MapsId mapping: " + logicalColumnName : "Implicit column reference in the @MapsId mapping fails, try to use explicit referenceColumnNames: " + referencedEntityName);
}
final String columnName = joinColumn == null || joinColumn.isNameDeferred() ? "tata_" + column.getName() : joinColumn.getName();
value.addColumn(new Column(columnName));
if (joinColumn != null) {
joinColumn.linkWithValue(value);
}
column.setValue(value);
}
}
return property;
}
use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class SortTest method testSortedSetDefinitionInHbmXml.
@Test
public void testSortedSetDefinitionInHbmXml() {
final PersistentClass entityMapping = metadata().getEntityBinding(Search.class.getName());
final Property sortedSetProperty = entityMapping.getProperty("searchResults");
final Collection sortedSetMapping = assertTyping(Collection.class, sortedSetProperty.getValue());
assertTrue("SortedSet mapping not interpreted as sortable", sortedSetMapping.isSorted());
final Property sortedMapProperty = entityMapping.getProperty("tokens");
final Collection sortedMapMapping = assertTyping(Collection.class, sortedMapProperty.getValue());
assertTrue("SortedMap mapping not interpreted as sortable", sortedMapMapping.isSorted());
}
Aggregations