Package org.hibernate.cfg

Examples of org.hibernate.cfg.CollectionPropertyHolder


    }
    else {
      XClass elementClass;
      AnnotatedClassType classType;

      CollectionPropertyHolder holder = null;
      if ( BinderHelper.PRIMITIVE_NAMES.contains( collType.getName() ) ) {
        classType = AnnotatedClassType.NONE;
        elementClass = null;

        holder = PropertyHolderBuilder.buildPropertyHolder(
            collValue,
            collValue.getRole(),
            null,
            property,
            parentPropertyHolder,
            mappings
        );
      }
      else {
        elementClass = collType;
        classType = mappings.getClassType( elementClass );

        holder = PropertyHolderBuilder.buildPropertyHolder(
            collValue,
            collValue.getRole(),
            elementClass,
            property,
            parentPropertyHolder,
            mappings
        );

        // 'parentPropertyHolder' is the PropertyHolder for the owner of the collection
        // 'holder' is the CollectionPropertyHolder.
        // 'property' is the collection XProperty
        parentPropertyHolder.startingProperty( property );

        //force in case of attribute override
        boolean attributeOverride = property.isAnnotationPresent( AttributeOverride.class )
            || property.isAnnotationPresent( AttributeOverrides.class );
        // todo : force in the case of Convert annotation(s) with embedded paths (beyond key/value prefixes)?
        if ( isEmbedded || attributeOverride ) {
          classType = AnnotatedClassType.EMBEDDABLE;
        }
      }

      if ( AnnotatedClassType.EMBEDDABLE.equals( classType ) ) {
        EntityBinder entityBinder = new EntityBinder();
        PersistentClass owner = collValue.getOwner();
        boolean isPropertyAnnotated;
        //FIXME support @Access for collection of elements
        //String accessType = access != null ? access.value() : null;
        if ( owner.getIdentifierProperty() != null ) {
          isPropertyAnnotated = owner.getIdentifierProperty().getPropertyAccessorName().equals( "property" );
        }
        else if ( owner.getIdentifierMapper() != null && owner.getIdentifierMapper().getPropertySpan() > 0 ) {
          Property prop = (Property) owner.getIdentifierMapper().getPropertyIterator().next();
          isPropertyAnnotated = prop.getPropertyAccessorName().equals( "property" );
        }
        else {
          throw new AssertionFailure( "Unable to guess collection property accessor name" );
        }

        PropertyData inferredData;
        if ( isMap() ) {
          //"value" is the JPA 2 prefix for map values (used to be "element")
          if ( isHibernateExtensionMapping() ) {
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "element", elementClass );
          }
          else {
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "value", elementClass );
          }
        }
        else {
          if ( isHibernateExtensionMapping() ) {
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "element", elementClass );
          }
          else {
            //"collection&&element" is not a valid property name => placeholder
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "collection&&element", elementClass );
          }
        }
        //TODO be smart with isNullable
        boolean isNullable = true;
        Component component = AnnotationBinder.fillComponent(
            holder,
            inferredData,
            isPropertyAnnotated ? AccessType.PROPERTY : AccessType.FIELD,
            isNullable,
            entityBinder,
            false,
            false,
            true,
            mappings,
            inheritanceStatePerClass
        );

        collValue.setElement( component );

        if ( StringHelper.isNotEmpty( hqlOrderBy ) ) {
          String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName();
          String orderBy = adjustUserSuppliedValueCollectionOrderingFragment( hqlOrderBy );
          if ( orderBy != null ) {
            collValue.setOrderBy( orderBy );
          }
        }
      }
      else {
        holder.prepare( property );

        SimpleValueBinder elementBinder = new SimpleValueBinder();
        elementBinder.setMappings( mappings );
        elementBinder.setReturnedClassName( collType.getName() );
        if ( elementColumns == null || elementColumns.length == 0 ) {
          elementColumns = new Ejb3Column[1];
          Ejb3Column column = new Ejb3Column();
          column.setImplicit( false );
          //not following the spec but more clean
          column.setNullable( true );
          column.setLength( Ejb3Column.DEFAULT_COLUMN_LENGTH );
          column.setLogicalColumnName( Collection.DEFAULT_ELEMENT_COLUMN_NAME );
          //TODO create an EMPTY_JOINS collection
          column.setJoins( new HashMap<String, Join>() );
          column.setMappings( mappings );
          column.bind();
          elementColumns[0] = column;
        }
        //override the table
        for (Ejb3Column column : elementColumns) {
          column.setTable( collValue.getCollectionTable() );
        }
        elementBinder.setColumns( elementColumns );
        elementBinder.setType(
            property,
            elementClass,
            collValue.getOwnerEntityName(),
            holder.resolveElementAttributeConverterDefinition( elementClass )
        );
        elementBinder.setPersistentClassName( propertyHolder.getEntityName() );
        elementBinder.setAccessType( accessType );
        collValue.setElement( elementBinder.make() );
        String orderBy = adjustUserSuppliedValueCollectionOrderingFragment( hqlOrderBy );
View Full Code Here


          if ( isEmbedded || attributeOverride ) {
            classType = AnnotatedClassType.EMBEDDABLE;
          }
        }

        CollectionPropertyHolder holder = PropertyHolderBuilder.buildPropertyHolder(
            mapValue,
            StringHelper.qualify( mapValue.getRole(), "mapkey" ),
            keyXClass,
            property,
            propertyHolder,
            mappings
        );


        // 'propertyHolder' is the PropertyHolder for the owner of the collection
        // 'holder' is the CollectionPropertyHolder.
        // 'property' is the collection XProperty
        propertyHolder.startingProperty( property );
        holder.prepare( property );

        PersistentClass owner = mapValue.getOwner();
        AccessType accessType;
        // FIXME support @Access for collection of elements
        // String accessType = access != null ? access.value() : null;
        if ( owner.getIdentifierProperty() != null ) {
          accessType = owner.getIdentifierProperty().getPropertyAccessorName().equals( "property" )
              ? AccessType.PROPERTY
              : AccessType.FIELD;
        }
        else if ( owner.getIdentifierMapper() != null && owner.getIdentifierMapper().getPropertySpan() > 0 ) {
          Property prop = (Property) owner.getIdentifierMapper().getPropertyIterator().next();
          accessType = prop.getPropertyAccessorName().equals( "property" ) ? AccessType.PROPERTY
              : AccessType.FIELD;
        }
        else {
          throw new AssertionFailure( "Unable to guess collection property accessor name" );
        }

        if ( AnnotatedClassType.EMBEDDABLE.equals( classType ) ) {
          EntityBinder entityBinder = new EntityBinder();

          PropertyData inferredData;
          if ( isHibernateExtensionMapping() ) {
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "index", keyXClass );
          }
          else {
            //"key" is the JPA 2 prefix for map keys
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "key", keyXClass );
          }

          //TODO be smart with isNullable
          Component component = AnnotationBinder.fillComponent(
              holder,
              inferredData,
              accessType,
              true,
              entityBinder,
              false,
              false,
              true,
              mappings,
              inheritanceStatePerClass
          );
          mapValue.setIndex( component );
        }
        else {
          SimpleValueBinder elementBinder = new SimpleValueBinder();
          elementBinder.setMappings( mappings );
          elementBinder.setReturnedClassName( mapKeyType );

          Ejb3Column[] elementColumns = mapKeyColumns;
          if ( elementColumns == null || elementColumns.length == 0 ) {
            elementColumns = new Ejb3Column[1];
            Ejb3Column column = new Ejb3Column();
            column.setImplicit( false );
            column.setNullable( true );
            column.setLength( Ejb3Column.DEFAULT_COLUMN_LENGTH );
            column.setLogicalColumnName( Collection.DEFAULT_KEY_COLUMN_NAME );
            //TODO create an EMPTY_JOINS collection
            column.setJoins( new HashMap<String, Join>() );
            column.setMappings( mappings );
            column.bind();
            elementColumns[0] = column;
          }
          //override the table
          for (Ejb3Column column : elementColumns) {
            column.setTable( mapValue.getCollectionTable() );
          }
          elementBinder.setColumns( elementColumns );
          //do not call setType as it extract the type from @Type
          //the algorithm generally does not apply for map key anyway
          elementBinder.setKey(true);
          MapKeyType mapKeyTypeAnnotation = property.getAnnotation( MapKeyType.class );
          if ( mapKeyTypeAnnotation != null
              && !BinderHelper.isEmptyAnnotationValue( mapKeyTypeAnnotation.value() .type() ) ) {
            elementBinder.setExplicitType( mapKeyTypeAnnotation.value() );
          }
          else {
            elementBinder.setType(
                property,
                keyXClass,
                this.collection.getOwnerEntityName(),
                holder.keyElementAttributeConverterDefinition( keyXClass )
            );
          }
          elementBinder.setPersistentClassName( propertyHolder.getEntityName() );
          elementBinder.setAccessType( accessType );
          mapValue.setIndex( elementBinder.make() );
View Full Code Here

          if ( isEmbedded || attributeOverride ) {
            classType = AnnotatedClassType.EMBEDDABLE;
          }
        }

        CollectionPropertyHolder holder = PropertyHolderBuilder.buildPropertyHolder(
            mapValue,
            StringHelper.qualify( mapValue.getRole(), "mapkey" ),
            keyXClass,
            property,
            propertyHolder,
            mappings
        );


        // 'propertyHolder' is the PropertyHolder for the owner of the collection
        // 'holder' is the CollectionPropertyHolder.
        // 'property' is the collection XProperty
        propertyHolder.startingProperty( property );
        holder.prepare( property );

        PersistentClass owner = mapValue.getOwner();
        AccessType accessType;
        // FIXME support @Access for collection of elements
        // String accessType = access != null ? access.value() : null;
        if ( owner.getIdentifierProperty() != null ) {
          accessType = owner.getIdentifierProperty().getPropertyAccessorName().equals( "property" )
              ? AccessType.PROPERTY
              : AccessType.FIELD;
        }
        else if ( owner.getIdentifierMapper() != null && owner.getIdentifierMapper().getPropertySpan() > 0 ) {
          Property prop = (Property) owner.getIdentifierMapper().getPropertyIterator().next();
          accessType = prop.getPropertyAccessorName().equals( "property" ) ? AccessType.PROPERTY
              : AccessType.FIELD;
        }
        else {
          throw new AssertionFailure( "Unable to guess collection property accessor name" );
        }

        if ( AnnotatedClassType.EMBEDDABLE.equals( classType ) ) {
          EntityBinder entityBinder = new EntityBinder();

          PropertyData inferredData;
          if ( isHibernateExtensionMapping() ) {
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "index", keyXClass );
          }
          else {
            //"key" is the JPA 2 prefix for map keys
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "key", keyXClass );
          }

          //TODO be smart with isNullable
          Component component = AnnotationBinder.fillComponent(
              holder,
              inferredData,
              accessType,
              true,
              entityBinder,
              false,
              false,
              true,
              mappings,
              inheritanceStatePerClass
          );
          mapValue.setIndex( component );
        }
        else {
          SimpleValueBinder elementBinder = new SimpleValueBinder();
          elementBinder.setMappings( mappings );
          elementBinder.setReturnedClassName( mapKeyType );

          Ejb3Column[] elementColumns = mapKeyColumns;
          if ( elementColumns == null || elementColumns.length == 0 ) {
            elementColumns = new Ejb3Column[1];
            Ejb3Column column = new Ejb3Column();
            column.setImplicit( false );
            column.setNullable( true );
            column.setLength( Ejb3Column.DEFAULT_COLUMN_LENGTH );
            column.setLogicalColumnName( Collection.DEFAULT_KEY_COLUMN_NAME );
            //TODO create an EMPTY_JOINS collection
            column.setJoins( new HashMap<String, Join>() );
            column.setMappings( mappings );
            column.bind();
            elementColumns[0] = column;
          }
          //override the table
          for (Ejb3Column column : elementColumns) {
            column.setTable( mapValue.getCollectionTable() );
          }
          elementBinder.setColumns( elementColumns );
          //do not call setType as it extract the type from @Type
          //the algorithm generally does not apply for map key anyway
          elementBinder.setKey(true);
          MapKeyType mapKeyTypeAnnotation = property.getAnnotation( MapKeyType.class );
          if ( mapKeyTypeAnnotation != null
              && !BinderHelper.isEmptyAnnotationValue( mapKeyTypeAnnotation.value() .type() ) ) {
            elementBinder.setExplicitType( mapKeyTypeAnnotation.value() );
          }
          else {
            elementBinder.setType(
                property,
                keyXClass,
                this.collection.getOwnerEntityName(),
                holder.keyElementAttributeConverterDefinition( keyXClass )
            );
          }
          elementBinder.setPersistentClassName( propertyHolder.getEntityName() );
          elementBinder.setAccessType( accessType );
          mapValue.setIndex( elementBinder.make() );
View Full Code Here

    }
    else {
      XClass elementClass;
      AnnotatedClassType classType;

      CollectionPropertyHolder holder = null;
      if ( BinderHelper.PRIMITIVE_NAMES.contains( collType.getName() ) ) {
        classType = AnnotatedClassType.NONE;
        elementClass = null;

        holder = PropertyHolderBuilder.buildPropertyHolder(
            collValue,
            collValue.getRole(),
            null,
            property,
            parentPropertyHolder,
            mappings
        );
      }
      else {
        elementClass = collType;
        classType = mappings.getClassType( elementClass );

        holder = PropertyHolderBuilder.buildPropertyHolder(
            collValue,
            collValue.getRole(),
            elementClass,
            property,
            parentPropertyHolder,
            mappings
        );

        // 'parentPropertyHolder' is the PropertyHolder for the owner of the collection
        // 'holder' is the CollectionPropertyHolder.
        // 'property' is the collection XProperty
        parentPropertyHolder.startingProperty( property );

        //force in case of attribute override
        boolean attributeOverride = property.isAnnotationPresent( AttributeOverride.class )
            || property.isAnnotationPresent( AttributeOverrides.class );
        // todo : force in the case of Convert annotation(s) with embedded paths (beyond key/value prefixes)?
        if ( isEmbedded || attributeOverride ) {
          classType = AnnotatedClassType.EMBEDDABLE;
        }
      }

      if ( AnnotatedClassType.EMBEDDABLE.equals( classType ) ) {
        EntityBinder entityBinder = new EntityBinder();
        PersistentClass owner = collValue.getOwner();
        boolean isPropertyAnnotated;
        //FIXME support @Access for collection of elements
        //String accessType = access != null ? access.value() : null;
        if ( owner.getIdentifierProperty() != null ) {
          isPropertyAnnotated = owner.getIdentifierProperty().getPropertyAccessorName().equals( "property" );
        }
        else if ( owner.getIdentifierMapper() != null && owner.getIdentifierMapper().getPropertySpan() > 0 ) {
          Property prop = (Property) owner.getIdentifierMapper().getPropertyIterator().next();
          isPropertyAnnotated = prop.getPropertyAccessorName().equals( "property" );
        }
        else {
          throw new AssertionFailure( "Unable to guess collection property accessor name" );
        }

        PropertyData inferredData;
        if ( isMap() ) {
          //"value" is the JPA 2 prefix for map values (used to be "element")
          if ( isHibernateExtensionMapping() ) {
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "element", elementClass );
          }
          else {
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "value", elementClass );
          }
        }
        else {
          if ( isHibernateExtensionMapping() ) {
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "element", elementClass );
          }
          else {
            //"collection&&element" is not a valid property name => placeholder
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "collection&&element", elementClass );
          }
        }
        //TODO be smart with isNullable
        boolean isNullable = true;
        Component component = AnnotationBinder.fillComponent(
            holder,
            inferredData,
            isPropertyAnnotated ? AccessType.PROPERTY : AccessType.FIELD,
            isNullable,
            entityBinder,
            false,
            false,
            true,
            mappings,
            inheritanceStatePerClass
        );

        collValue.setElement( component );

        if ( StringHelper.isNotEmpty( hqlOrderBy ) ) {
          String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName();
          String orderBy = adjustUserSuppliedValueCollectionOrderingFragment( hqlOrderBy );
          if ( orderBy != null ) {
            collValue.setOrderBy( orderBy );
          }
        }
      }
      else {
        holder.prepare( property );

        SimpleValueBinder elementBinder = new SimpleValueBinder();
        elementBinder.setMappings( mappings );
        elementBinder.setReturnedClassName( collType.getName() );
        if ( elementColumns == null || elementColumns.length == 0 ) {
          elementColumns = new Ejb3Column[1];
          Ejb3Column column = new Ejb3Column();
          column.setImplicit( false );
          //not following the spec but more clean
          column.setNullable( true );
          column.setLength( Ejb3Column.DEFAULT_COLUMN_LENGTH );
          column.setLogicalColumnName( Collection.DEFAULT_ELEMENT_COLUMN_NAME );
          //TODO create an EMPTY_JOINS collection
          column.setJoins( new HashMap<String, Join>() );
          column.setMappings( mappings );
          column.bind();
          elementColumns[0] = column;
        }
        //override the table
        for (Ejb3Column column : elementColumns) {
          column.setTable( collValue.getCollectionTable() );
        }
        elementBinder.setColumns( elementColumns );
        elementBinder.setType(
            property,
            elementClass,
            collValue.getOwnerEntityName(),
            holder.resolveElementAttributeConverterDefinition( elementClass )
        );
        elementBinder.setPersistentClassName( propertyHolder.getEntityName() );
        elementBinder.setAccessType( accessType );
        collValue.setElement( elementBinder.make() );
        String orderBy = adjustUserSuppliedValueCollectionOrderingFragment( hqlOrderBy );
View Full Code Here

          if ( isEmbedded || attributeOverride ) {
            classType = AnnotatedClassType.EMBEDDABLE;
          }
        }

        CollectionPropertyHolder holder = PropertyHolderBuilder.buildPropertyHolder(
            mapValue,
            StringHelper.qualify( mapValue.getRole(), "mapkey" ),
            keyXClass,
            property,
            propertyHolder,
            mappings
        );


        // 'propertyHolder' is the PropertyHolder for the owner of the collection
        // 'holder' is the CollectionPropertyHolder.
        // 'property' is the collection XProperty
        propertyHolder.startingProperty( property );
        holder.prepare( property );

        PersistentClass owner = mapValue.getOwner();
        AccessType accessType;
        // FIXME support @Access for collection of elements
        // String accessType = access != null ? access.value() : null;
        if ( owner.getIdentifierProperty() != null ) {
          accessType = owner.getIdentifierProperty().getPropertyAccessorName().equals( "property" )
              ? AccessType.PROPERTY
              : AccessType.FIELD;
        }
        else if ( owner.getIdentifierMapper() != null && owner.getIdentifierMapper().getPropertySpan() > 0 ) {
          Property prop = (Property) owner.getIdentifierMapper().getPropertyIterator().next();
          accessType = prop.getPropertyAccessorName().equals( "property" ) ? AccessType.PROPERTY
              : AccessType.FIELD;
        }
        else {
          throw new AssertionFailure( "Unable to guess collection property accessor name" );
        }

        if ( AnnotatedClassType.EMBEDDABLE.equals( classType ) ) {
          EntityBinder entityBinder = new EntityBinder();

          PropertyData inferredData;
          if ( isHibernateExtensionMapping() ) {
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "index", keyXClass );
          }
          else {
            //"key" is the JPA 2 prefix for map keys
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "key", keyXClass );
          }

          //TODO be smart with isNullable
          Component component = AnnotationBinder.fillComponent(
              holder,
              inferredData,
              accessType,
              true,
              entityBinder,
              false,
              false,
              true,
              mappings,
              inheritanceStatePerClass
          );
          mapValue.setIndex( component );
        }
        else {
          SimpleValueBinder elementBinder = new SimpleValueBinder();
          elementBinder.setMappings( mappings );
          elementBinder.setReturnedClassName( mapKeyType );

          Ejb3Column[] elementColumns = mapKeyColumns;
          if ( elementColumns == null || elementColumns.length == 0 ) {
            elementColumns = new Ejb3Column[1];
            Ejb3Column column = new Ejb3Column();
            column.setImplicit( false );
            column.setNullable( true );
            column.setLength( Ejb3Column.DEFAULT_COLUMN_LENGTH );
            column.setLogicalColumnName( Collection.DEFAULT_KEY_COLUMN_NAME );
            //TODO create an EMPTY_JOINS collection
            column.setJoins( new HashMap<String, Join>() );
            column.setMappings( mappings );
            column.bind();
            elementColumns[0] = column;
          }
          //override the table
          for (Ejb3Column column : elementColumns) {
            column.setTable( mapValue.getCollectionTable() );
          }
          elementBinder.setColumns( elementColumns );
          //do not call setType as it extract the type from @Type
          //the algorithm generally does not apply for map key anyway
          elementBinder.setKey(true);
          MapKeyType mapKeyTypeAnnotation = property.getAnnotation( MapKeyType.class );
          if ( mapKeyTypeAnnotation != null
              && !BinderHelper.isEmptyAnnotationValue( mapKeyTypeAnnotation.value() .type() ) ) {
            elementBinder.setExplicitType( mapKeyTypeAnnotation.value() );
          }
          else {
            elementBinder.setType(
                property,
                keyXClass,
                this.collection.getOwnerEntityName(),
                holder.keyElementAttributeConverterDefinition( keyXClass )
            );
          }
          elementBinder.setPersistentClassName( propertyHolder.getEntityName() );
          elementBinder.setAccessType( accessType );
          mapValue.setIndex( elementBinder.make() );
View Full Code Here

    }
    else {
      XClass elementClass;
      AnnotatedClassType classType;

      CollectionPropertyHolder holder = null;
      if ( BinderHelper.PRIMITIVE_NAMES.contains( collType.getName() ) ) {
        classType = AnnotatedClassType.NONE;
        elementClass = null;

        holder = PropertyHolderBuilder.buildPropertyHolder(
            collValue,
            collValue.getRole(),
            null,
            property,
            parentPropertyHolder,
            mappings
        );
      }
      else {
        elementClass = collType;
        classType = mappings.getClassType( elementClass );

        holder = PropertyHolderBuilder.buildPropertyHolder(
            collValue,
            collValue.getRole(),
            elementClass,
            property,
            parentPropertyHolder,
            mappings
        );

        // 'parentPropertyHolder' is the PropertyHolder for the owner of the collection
        // 'holder' is the CollectionPropertyHolder.
        // 'property' is the collection XProperty
        parentPropertyHolder.startingProperty( property );

        //force in case of attribute override
        boolean attributeOverride = property.isAnnotationPresent( AttributeOverride.class )
            || property.isAnnotationPresent( AttributeOverrides.class );
        // todo : force in the case of Convert annotation(s) with embedded paths (beyond key/value prefixes)?
        if ( isEmbedded || attributeOverride ) {
          classType = AnnotatedClassType.EMBEDDABLE;
        }
      }

      if ( AnnotatedClassType.EMBEDDABLE.equals( classType ) ) {
        EntityBinder entityBinder = new EntityBinder();
        PersistentClass owner = collValue.getOwner();
        boolean isPropertyAnnotated;
        //FIXME support @Access for collection of elements
        //String accessType = access != null ? access.value() : null;
        if ( owner.getIdentifierProperty() != null ) {
          isPropertyAnnotated = owner.getIdentifierProperty().getPropertyAccessorName().equals( "property" );
        }
        else if ( owner.getIdentifierMapper() != null && owner.getIdentifierMapper().getPropertySpan() > 0 ) {
          Property prop = (Property) owner.getIdentifierMapper().getPropertyIterator().next();
          isPropertyAnnotated = prop.getPropertyAccessorName().equals( "property" );
        }
        else {
          throw new AssertionFailure( "Unable to guess collection property accessor name" );
        }

        PropertyData inferredData;
        if ( isMap() ) {
          //"value" is the JPA 2 prefix for map values (used to be "element")
          if ( isHibernateExtensionMapping() ) {
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "element", elementClass );
          }
          else {
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "value", elementClass );
          }
        }
        else {
          if ( isHibernateExtensionMapping() ) {
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "element", elementClass );
          }
          else {
            //"collection&&element" is not a valid property name => placeholder
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "collection&&element", elementClass );
          }
        }
        //TODO be smart with isNullable
        boolean isNullable = true;
        Component component = AnnotationBinder.fillComponent(
            holder,
            inferredData,
            isPropertyAnnotated ? AccessType.PROPERTY : AccessType.FIELD,
            isNullable,
            entityBinder,
            false,
            false,
            true,
            mappings,
            inheritanceStatePerClass
        );

        collValue.setElement( component );

        if ( StringHelper.isNotEmpty( hqlOrderBy ) ) {
          String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName();
          String orderBy = adjustUserSuppliedValueCollectionOrderingFragment( hqlOrderBy );
          if ( orderBy != null ) {
            collValue.setOrderBy( orderBy );
          }
        }
      }
      else {
        holder.prepare( property );

        SimpleValueBinder elementBinder = new SimpleValueBinder();
        elementBinder.setMappings( mappings );
        elementBinder.setReturnedClassName( collType.getName() );
        if ( elementColumns == null || elementColumns.length == 0 ) {
          elementColumns = new Ejb3Column[1];
          Ejb3Column column = new Ejb3Column();
          column.setImplicit( false );
          //not following the spec but more clean
          column.setNullable( true );
          column.setLength( Ejb3Column.DEFAULT_COLUMN_LENGTH );
          column.setLogicalColumnName( Collection.DEFAULT_ELEMENT_COLUMN_NAME );
          //TODO create an EMPTY_JOINS collection
          column.setJoins( new HashMap<String, Join>() );
          column.setMappings( mappings );
          column.bind();
          elementColumns[0] = column;
        }
        //override the table
        for (Ejb3Column column : elementColumns) {
          column.setTable( collValue.getCollectionTable() );
        }
        elementBinder.setColumns( elementColumns );
        elementBinder.setType(
            property,
            elementClass,
            collValue.getOwnerEntityName(),
            holder.resolveElementAttributeConverterDefinition( elementClass )
        );
        elementBinder.setPersistentClassName( propertyHolder.getEntityName() );
        elementBinder.setAccessType( accessType );
        collValue.setElement( elementBinder.make() );
        String orderBy = adjustUserSuppliedValueCollectionOrderingFragment( hqlOrderBy );
View Full Code Here

    }
    else {
      XClass elementClass;
      AnnotatedClassType classType;

      CollectionPropertyHolder holder = null;
      if ( BinderHelper.PRIMITIVE_NAMES.contains( collType.getName() ) ) {
        classType = AnnotatedClassType.NONE;
        elementClass = null;

        holder = PropertyHolderBuilder.buildPropertyHolder(
            collValue,
            collValue.getRole(),
            null,
            property,
            parentPropertyHolder,
            mappings
        );
      }
      else {
        elementClass = collType;
        classType = mappings.getClassType( elementClass );

        holder = PropertyHolderBuilder.buildPropertyHolder(
            collValue,
            collValue.getRole(),
            elementClass,
            property,
            parentPropertyHolder,
            mappings
        );

        // 'parentPropertyHolder' is the PropertyHolder for the owner of the collection
        // 'holder' is the CollectionPropertyHolder.
        // 'property' is the collection XProperty
        parentPropertyHolder.startingProperty( property );

        //force in case of attribute override
        boolean attributeOverride = property.isAnnotationPresent( AttributeOverride.class )
            || property.isAnnotationPresent( AttributeOverrides.class );
        // todo : force in the case of Convert annotation(s) with embedded paths (beyond key/value prefixes)?
        if ( isEmbedded || attributeOverride ) {
          classType = AnnotatedClassType.EMBEDDABLE;
        }
      }

      if ( AnnotatedClassType.EMBEDDABLE.equals( classType ) ) {
        EntityBinder entityBinder = new EntityBinder();
        PersistentClass owner = collValue.getOwner();
        boolean isPropertyAnnotated;
        //FIXME support @Access for collection of elements
        //String accessType = access != null ? access.value() : null;
        if ( owner.getIdentifierProperty() != null ) {
          isPropertyAnnotated = owner.getIdentifierProperty().getPropertyAccessorName().equals( "property" );
        }
        else if ( owner.getIdentifierMapper() != null && owner.getIdentifierMapper().getPropertySpan() > 0 ) {
          Property prop = (Property) owner.getIdentifierMapper().getPropertyIterator().next();
          isPropertyAnnotated = prop.getPropertyAccessorName().equals( "property" );
        }
        else {
          throw new AssertionFailure( "Unable to guess collection property accessor name" );
        }

        PropertyData inferredData;
        if ( isMap() ) {
          //"value" is the JPA 2 prefix for map values (used to be "element")
          if ( isHibernateExtensionMapping() ) {
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "element", elementClass );
          }
          else {
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "value", elementClass );
          }
        }
        else {
          if ( isHibernateExtensionMapping() ) {
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "element", elementClass );
          }
          else {
            //"collection&&element" is not a valid property name => placeholder
            inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "collection&&element", elementClass );
          }
        }
        //TODO be smart with isNullable
        boolean isNullable = true;
        Component component = AnnotationBinder.fillComponent(
            holder,
            inferredData,
            isPropertyAnnotated ? AccessType.PROPERTY : AccessType.FIELD,
            isNullable,
            entityBinder,
            false,
            false,
            true,
            mappings,
            inheritanceStatePerClass
        );

        collValue.setElement( component );

        if ( StringHelper.isNotEmpty( hqlOrderBy ) ) {
          String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName();
          String orderBy = adjustUserSuppliedValueCollectionOrderingFragment( hqlOrderBy );
          if ( orderBy != null ) {
            collValue.setOrderBy( orderBy );
          }
        }
      }
      else {
        holder.prepare( property );

        SimpleValueBinder elementBinder = new SimpleValueBinder();
        elementBinder.setMappings( mappings );
        elementBinder.setReturnedClassName( collType.getName() );
        if ( elementColumns == null || elementColumns.length == 0 ) {
          elementColumns = new Ejb3Column[1];
          Ejb3Column column = new Ejb3Column();
          column.setImplicit( false );
          //not following the spec but more clean
          column.setNullable( true );
          column.setLength( Ejb3Column.DEFAULT_COLUMN_LENGTH );
          column.setLogicalColumnName( Collection.DEFAULT_ELEMENT_COLUMN_NAME );
          //TODO create an EMPTY_JOINS collection
          column.setJoins( new HashMap<String, Join>() );
          column.setMappings( mappings );
          column.bind();
          elementColumns[0] = column;
        }
        //override the table
        for (Ejb3Column column : elementColumns) {
          column.setTable( collValue.getCollectionTable() );
        }
        elementBinder.setColumns( elementColumns );
        elementBinder.setType(
            property,
            elementClass,
            collValue.getOwnerEntityName(),
            holder.resolveElementAttributeConverterDefinition( elementClass )
        );
        elementBinder.setPersistentClassName( propertyHolder.getEntityName() );
        elementBinder.setAccessType( accessType );
        collValue.setElement( elementBinder.make() );
        String orderBy = adjustUserSuppliedValueCollectionOrderingFragment( hqlOrderBy );
View Full Code Here

TOP

Related Classes of org.hibernate.cfg.CollectionPropertyHolder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.