Refine search
@Override public void setIdentifier(Object entity, Serializable id, EntityMode entityMode, SharedSessionContractImplementor session) { final Object[] extractedValues = mappedIdentifierType.getPropertyValues( id, entityMode ); final Object[] injectionValues = new Object[extractedValues.length]; final PersistenceContext persistenceContext = session.getPersistenceContext(); for ( int i = 0; i < virtualIdComponent.getSubtypes().length; i++ ) { final Type virtualPropertyType = virtualIdComponent.getSubtypes()[i]; final Type idClassPropertyType = mappedIdentifierType.getSubtypes()[i]; if ( virtualPropertyType.isEntityType() && !idClassPropertyType.isEntityType() ) { if ( session == null ) { throw new AssertionError( virtualIdComponent.getPropertyNames()[i] ); virtualIdComponent.setPropertyValues( entity, injectionValues, entityMode );
@Override public boolean isEqual(final Object x, final Object y) throws HibernateException { if ( x == y ) { return true; } // null value and empty component are considered equivalent for ( int i = 0; i < propertySpan; i++ ) { if ( !propertyTypes[i].isEqual( getPropertyValue( x, i ), getPropertyValue( y, i ) ) ) { return false; } } return true; }
@Override public int getPropertyIndex(String name) { String[] names = getPropertyNames(); for ( int i = 0, max = names.length; i < max; i++ ) { if ( names[i].equals( name ) ) { return i; } } throw new PropertyNotFoundException( "Unable to locate property named " + name + " on " + getReturnedClass().getName() ); }
@Override public Object getIdentifier(Object entity, EntityMode entityMode, SharedSessionContractImplementor session) { Object id = mappedIdentifierType.instantiate( entityMode ); final Object[] propertyValues = virtualIdComponent.getPropertyValues( entity, entityMode ); mappedIdentifierType.setPropertyValues( id, propertyValues, entityMode ); return id; }
@Override public void setIdentifier(Object entity, Serializable id, EntityMode entityMode, SharedSessionContractImplementor session) { virtualIdComponent.setPropertyValues( entity, mappedIdentifierType.getPropertyValues( id, session ), entityMode ); } }
@Override public Object instantiate(Object parent, SharedSessionContractImplementor session) throws HibernateException { final boolean useParent = parent != null && //TODO: Yuck! This is not quite good enough, it's a quick //hack around the problem of having a to-one association //that refers to an embedded component: super.getReturnedClass().isInstance( parent ); return useParent ? parent : super.instantiate( parent, session ); } }
private void handleComponentType(ComponentType componentType, String property, String entityName) { for (int i = 0; i < componentType.getSubtypes().length; i++) { Type subtype = componentType.getSubtypes()[i]; String subProperty = property + "." + componentType.getPropertyNames()[i]; if (subtype instanceof EntityType && RiotFile.class.isAssignableFrom(subtype.getReturnedClass())) { fileQueries.add(String.format("select %1$s.id from %2$s where %1$s is not null", subProperty, entityName)); } else if (subtype.isComponentType()) { handleComponentType((ComponentType) subtype, subProperty, entityName); } } }
|| type instanceof TimeType || type instanceof BinaryType || (type.isAssociationType() && !type.isCollectionType()) || type instanceof AttributeConverterTypeAdapter) else if (type.isAssociationType() && type.isCollectionType()) ComponentType embed = (ComponentType)type; knownEmbeddedtypes.add(type.getReturnedClass().getName()); String [] names = embed.getPropertyNames(); Type [] types = embed.getSubtypes(); for (int n = 0; n < names.length; n++) registerEntityField(type.getReturnedClass(), names[n], types[n]);
private ComponentType buildComponentType(SessionFactory sessionFactory, String entityName, String propertyName) { EntityType entityType = (EntityType) entityTypes.get(entityName); if (null != entityType) { Type propertyType = (Type) entityType.getPropertyTypes().get(propertyName); if (null != propertyType) { return (ComponentType) propertyType; } } ClassMetadata cm = sessionFactory.getClassMetadata(entityName); org.hibernate.type.ComponentType hcType = (org.hibernate.type.ComponentType) cm .getPropertyType(propertyName); String[] propertyNames = hcType.getPropertyNames(); ComponentType cType = new ComponentType(hcType.getReturnedClass()); Map<String, Type> propertyTypes = cType.getPropertyTypes(); for (int j = 0; j < propertyNames.length; j++) { org.hibernate.type.Type type = cm.getPropertyType(propertyName + "." + propertyNames[j]); if (type.isEntityType()) { propertyTypes.put(propertyNames[j], buildEntityType(sessionFactory, type.getName())); } else if (type.isComponentType()) { propertyTypes.put(propertyNames[j], buildComponentType(sessionFactory, entityName, propertyName + "." + propertyNames[j])); } else if (type.isCollectionType()) { propertyTypes.put( propertyNames[j], buildCollectionType(sessionFactory, defaultCollectionClass(type), entityName + "." + propertyName + "." + propertyNames[j])); } } return cType; }
private void findComponentProperties(Type[] propertyTypes, Set<Class<?>> typesToRegister) { if (propertyTypes == null) { return; } for (Type propertyType : propertyTypes) { if (propertyType instanceof ComponentType) { typesToRegister.add(propertyType.getReturnedClass()); findComponentProperties(((ComponentType)propertyType).getSubtypes(), typesToRegister); } } } }
private void collectEmbeddedCollectionColumns(ComponentType componentType, String dotName, List<String> embeddedCollections) { for ( String propertyName : componentType.getPropertyNames() ) { Type type = componentType.getSubtypes()[componentType.getPropertyIndex( propertyName )]; if ( type.isCollectionType() ) { embeddedCollections.add( dotName + "." + propertyName ); } else if ( type.isComponentType() ) { collectEmbeddedCollectionColumns( (ComponentType) type, dotName + "." + propertyName, embeddedCollections ); } } }
ComponentCollectionCriteriaInfoProvider(QueryableCollection persister) { this.persister = persister; if (!persister.getElementType().isComponentType()) { throw new IllegalArgumentException("persister for role "+persister.getRole()+" is not a collection-of-component"); } ComponentType componentType = (ComponentType)persister.getElementType(); String[] names = componentType.getPropertyNames(); Type[] types = componentType.getSubtypes(); for (int i = 0; i < names.length; i++) { subTypes.put(names[i], types[i]); } }
@Override public Member resolveMember(AttributeContext attributeContext) { final EmbeddedTypeDescriptor embeddableType = (EmbeddedTypeDescriptor<?>) attributeContext.getOwnerType(); final String attributeName = attributeContext.getPropertyMapping().getName(); final Getter getter = embeddableType.getHibernateType() .getComponentTuplizer() .getGetter( embeddableType.getHibernateType().getPropertyIndex( attributeName ) ); return PropertyAccessMapImpl.GetterImpl.class.isInstance( getter ) ? new MapMember( attributeName, attributeContext.getPropertyMapping().getType().getReturnedClass() ) : getter.getMember(); } };
@Override public Object getIdentifier(Object entity, EntityMode entityMode, SharedSessionContractImplementor session) { final Object id = mappedIdentifierType.instantiate( entityMode ); final Object[] propertyValues = virtualIdComponent.getPropertyValues( entity, entityMode ); final Type[] subTypes = virtualIdComponent.getSubtypes(); final Type[] copierSubTypes = mappedIdentifierType.getSubtypes(); final int length = subTypes.length; for ( int i = 0; i < length; i++ ) { if ( propertyValues[i] == null ) { throw new HibernateException( "No part of a composite identifier may be null" ); } //JPA 2 @MapsId + @IdClass points to the pk of the entity if ( subTypes[i].isAssociationType() && !copierSubTypes[i].isAssociationType() ) { propertyValues[i] = determineEntityId( propertyValues[i], (AssociationType) subTypes[i], session, sessionFactory ); } } mappedIdentifierType.setPropertyValues( id, propertyValues, entityMode ); return id; }
private int getNumberOfParametersCoveredBy(Type[] subtypes) { int numberOfParameters = 0; for ( Type type : subtypes ) { if ( type.isComponentType() ) { numberOfParameters = numberOfParameters + getNumberOfParametersCoveredBy( ((ComponentType) type).getSubtypes() ); } else { numberOfParameters++; } } return numberOfParameters; }
if ( type != null && type.isComponentType() ) { if ( !"=".equals( op ) && !"<>".equals( op ) ) { throw new AuditException( "Component-based criterion is not supported for op: " + op ); for ( int i = 0; i < componentType.getPropertyNames().length; i++ ) { final Object componentValue = componentType.getPropertyValue( value, i, session ); parameters.addWhereWithParam( alias, propertyName + "_" + componentType.getPropertyNames()[ i ], op, componentValue
@Override public boolean isDeleteCascaded(ManagedType<?> ownerType, String elementCollectionPath, String attributeName) { Type elementType = getCollectionPersister(ownerType, elementCollectionPath).getElementType(); if (!(elementType instanceof ComponentType)) { // This can only happen for collection/join table target attributes, where it is irrelevant return false; } ComponentType componentType = (ComponentType) elementType; String subAttribute = attributeName.substring(elementCollectionPath.length() + 1); // Component types only store direct properties, so we have to go deeper String[] propertyParts = subAttribute.split("\\."); int propertyIndex = 0; for (; propertyIndex < propertyParts.length - 1; propertyIndex++) { int index = componentType.getPropertyIndex(propertyParts[propertyIndex]); Type propertyType = componentType.getSubtypes()[index]; if (propertyType instanceof ComponentType) { componentType = (ComponentType) propertyType; } else { // The association property is just as good as the id property of the association for our purposes // So we stop here and query the association property instead break; } } try { return (boolean) DO_CASCADE_METHOD.invoke(componentType.getCascadeStyle(propertyIndex), DELETE_CASCADE); } catch (Exception ex) { throw new RuntimeException("Could not access orphan removal information. Please report your version of hibernate so we can provide support for it!", ex); } }
for ( int i = 0; i < virtualIdComponent.getSubtypes().length; i++ ) { if ( virtualIdComponent.getSubtypes()[i].isEntityType() && !mappedIdClassComponentType.getSubtypes()[i].isEntityType() ) { wereAllEquivalent = false; break;
private Type associationPropertyType(Type type, String property) { if ( type instanceof ComponentType ) { ComponentType componentType = (ComponentType) type; return componentType.getSubtypes()[componentType.getPropertyIndex( property )]; } else if ( type instanceof EntityType ) { OgmEntityPersister persister = getPersister( type.getName() ); return persister.getPropertyType( property ); } throw new UnsupportedOperationException( "Unrecognized property type: " + type ); }
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 = "";