Package org.hibernate.mapping

Examples of org.hibernate.mapping.Value


      Value value,
      Collection collection,
      String targetPropertyName,
      PersistentClass associatedClass,
      Mappings mappings) {
    Value element = collection.getElement();
    String fromAndWhere = null;
    if ( !( element instanceof OneToMany ) ) {
      String referencedPropertyName = null;
      if ( element instanceof ToOne ) {
        referencedPropertyName = ( (ToOne) element ).getReferencedPropertyName();
      }
      else if ( element instanceof DependantValue ) {
        //TODO this never happen I think
        if ( propertyName != null ) {
          referencedPropertyName = collection.getReferencedPropertyName();
        }
        else {
          throw new AnnotationException( "SecondaryTable JoinColumn cannot reference a non primary key" );
        }
      }
      Iterator referencedEntityColumns;
      if ( referencedPropertyName == null ) {
        referencedEntityColumns = associatedClass.getIdentifier().getColumnIterator();
      }
      else {
        Property referencedProperty = associatedClass.getRecursiveProperty( referencedPropertyName );
        referencedEntityColumns = referencedProperty.getColumnIterator();
      }
      String alias = "$alias$";
      StringBuilder fromAndWhereSb = new StringBuilder( " from " )
          .append( associatedClass.getTable().getName() )
              //.append(" as ") //Oracle doesn't support it in subqueries
          .append( " " )
          .append( alias ).append( " where " );
      Iterator collectionTableColumns = element.getColumnIterator();
      while ( collectionTableColumns.hasNext() ) {
        Column colColumn = (Column) collectionTableColumns.next();
        Column refColumn = (Column) referencedEntityColumns.next();
        fromAndWhereSb.append( alias ).append( '.' ).append( refColumn.getQuotedName() )
            .append( '=' ).append( colColumn.getQuotedName() ).append( " and " );
View Full Code Here


    }
    return followers;
  }

  private Iterator getSubPropertyIterator(PersistentClass pc, String reducedName) {
    Value value = pc.getRecursiveProperty( reducedName ).getValue();
    Iterator parentPropIter;
    if ( value instanceof Component ) {
      Component comp = (Component) value;
      parentPropIter = comp.getPropertyIterator();
    }
View Full Code Here

            .getName() + "]"
    );
    final Member member = memberResolver.resolveMember( attributeContext );
    LOG.trace( "    Determined member [" + member + "]" );

    final Value value = attributeContext.getPropertyMapping().getValue();
    final org.hibernate.type.Type type = value.getType();
    LOG.trace( "    Determined type [name=" + type.getName() + ", class=" + type.getClass().getName() + "]" );

    if ( type.isAnyType() ) {
      // ANY mappings are currently not supported in the JPA metamodel; see HHH-6589
      if ( context.isIgnoreUnsupported() ) {
        return null;
      }
      else {
        throw new UnsupportedOperationException( "ANY not supported" );
      }
    }
    else if ( type.isAssociationType() ) {
      // collection or entity
      if ( type.isEntityType() ) {
        // entity
        return new SingularAttributeMetadataImpl<X, Y>(
            attributeContext.getPropertyMapping(),
            attributeContext.getOwnerType(),
            member,
            determineSingularAssociationAttributeType( member )
        );
      }
      // collection
      if ( value instanceof Collection ) {
        final Collection collValue = (Collection) value;
        final Value elementValue = collValue.getElement();
        final org.hibernate.type.Type elementType = elementValue.getType();

        // First, determine the type of the elements and use that to help determine the
        // collection type)
        final Attribute.PersistentAttributeType elementPersistentAttributeType;
        final Attribute.PersistentAttributeType persistentAttributeType;
        if ( elementType.isAnyType() ) {
          if ( context.isIgnoreUnsupported() ) {
            return null;
          }
          else {
            throw new UnsupportedOperationException( "collection of any not supported yet" );
          }
        }
        final boolean isManyToMany = isManyToMany( member );
        if ( elementValue instanceof Component ) {
          elementPersistentAttributeType = Attribute.PersistentAttributeType.EMBEDDED;
          persistentAttributeType = Attribute.PersistentAttributeType.ELEMENT_COLLECTION;
        }
        else if ( elementType.isAssociationType() ) {
          elementPersistentAttributeType = isManyToMany ?
              Attribute.PersistentAttributeType.MANY_TO_MANY :
              Attribute.PersistentAttributeType.ONE_TO_MANY;
          persistentAttributeType = elementPersistentAttributeType;
        }
        else {
          elementPersistentAttributeType = Attribute.PersistentAttributeType.BASIC;
          persistentAttributeType = Attribute.PersistentAttributeType.ELEMENT_COLLECTION;
        }

        final Attribute.PersistentAttributeType keyPersistentAttributeType;

        // Finally, we determine the type of the map key (if needed)
        if ( value instanceof Map ) {
          final Value keyValue = ( (Map) value ).getIndex();
          final org.hibernate.type.Type keyType = keyValue.getType();

          if ( keyType.isAnyType() ) {
            if ( context.isIgnoreUnsupported() ) {
              return null;
            }
View Full Code Here

      final Property property = associatedClass.getRecursiveProperty( columns[0].getMappedBy() );
      Iterator mappedByColumns;
      if ( property.getValue() instanceof Collection ) {
        Collection collection = ( (Collection) property.getValue() );
        Value element = collection.getElement();
        if ( element == null ) {
          throw new AnnotationException(
              "Illegal use of mappedBy on both sides of the relationship: "
                  + associatedClass.getEntityName() + "." + mappedByProperty
          );
        }
        mappedByColumns = element.getColumnIterator();
      }
      else {
        mappedByColumns = property.getValue().getColumnIterator();
      }
      while ( mappedByColumns.hasNext() ) {
View Full Code Here

    hasSequentialSelects = hasDeferred;

    // DISCRIMINATOR

    if ( persistentClass.isPolymorphic() ) {
      Value discrimValue = persistentClass.getDiscriminator();
      if (discrimValue==null) {
        throw new MappingException("discriminator mapping required for single table polymorphic persistence");
      }
      forceDiscriminator = persistentClass.isForceDiscriminator();
      Selectable selectable = (Selectable) discrimValue.getColumnIterator().next();
      if ( discrimValue.hasFormula() ) {
        Formula formula = (Formula) selectable;
        discriminatorFormula = formula.getFormula();
        discriminatorFormulaTemplate = formula.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
        discriminatorColumnName = null;
        discriminatorColumnReaders = null;
        discriminatorColumnReaderTemplate = null;
        discriminatorAlias = "clazz_";
      }
      else {
        Column column = (Column) selectable;
        discriminatorColumnName = column.getQuotedName( factory.getDialect() );
        discriminatorColumnReaders = column.getReadExpr( factory.getDialect() );
        discriminatorColumnReaderTemplate = column.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
        discriminatorAlias = column.getAlias( factory.getDialect(), persistentClass.getRootTable() );
        discriminatorFormula = null;
        discriminatorFormulaTemplate = null;
      }
      discriminatorType = persistentClass.getDiscriminator().getType();
      if ( persistentClass.isDiscriminatorValueNull() ) {
        discriminatorValue = NULL_DISCRIMINATOR;
        discriminatorSQLValue = InFragment.NULL;
        discriminatorInsertable = false;
      }
      else if ( persistentClass.isDiscriminatorValueNotNull() ) {
        discriminatorValue = NOT_NULL_DISCRIMINATOR;
        discriminatorSQLValue = InFragment.NOT_NULL;
        discriminatorInsertable = false;
      }
      else {
        discriminatorInsertable = persistentClass.isDiscriminatorInsertable() && !discrimValue.hasFormula();
        try {
          DiscriminatorType dtype = (DiscriminatorType) discriminatorType;
          discriminatorValue = dtype.stringToObject( persistentClass.getDiscriminatorValue() );
          discriminatorSQLValue = dtype.objectToSQLString( discriminatorValue, factory.getDialect() );
        }
View Full Code Here

      // If this is not a persistent property, with the same access type as currently checked,
      // it's not audited as well.
      // If the property was already defined by the subclass, is ignored by superclasses
      if ((persistentProperties.contains(property.getName()) && (!auditedPropertiesHolder
          .contains(property.getName())))) {
        Value propertyValue = persistentPropertiesSource.getProperty(property.getName()).getValue();
        if (propertyValue instanceof Component) {
          this.addFromComponentProperty(property, accessType, (Component)propertyValue, allClassAudited);
        } else {
          this.addFromNotComponentProperty(property, accessType, allClassAudited);
        }
View Full Code Here

    }
  }

  public void bindDiscriminatorValue() {
    if ( StringHelper.isEmpty( discriminatorValue ) ) {
      Value discriminator = persistentClass.getDiscriminator();
      if ( discriminator == null ) {
        persistentClass.setDiscriminatorValue( name );
      }
      else if ( "character".equals( discriminator.getType().getName() ) ) {
        throw new AnnotationException(
            "Using default @DiscriminatorValue for a discriminator of type CHAR is not safe"
        );
      }
      else if ( "integer".equals( discriminator.getType().getName() ) ) {
        persistentClass.setDiscriminatorValue( String.valueOf( name.hashCode() ) );
      }
      else {
        persistentClass.setDiscriminatorValue( name ); //Spec compliant
      }
View Full Code Here

    }
  }

  public void bindDiscriminatorValue() {
    if ( StringHelper.isEmpty( discriminatorValue ) ) {
      Value discriminator = persistentClass.getDiscriminator();
      if ( discriminator == null ) {
        persistentClass.setDiscriminatorValue( name );
      }
      else if ( "character".equals( discriminator.getType().getName() ) ) {
        throw new AnnotationException(
            "Using default @DiscriminatorValue for a discriminator of type CHAR is not safe"
        );
      }
      else if ( "integer".equals( discriminator.getType().getName() ) ) {
        persistentClass.setDiscriminatorValue( String.valueOf( name.hashCode() ) );
      }
      else {
        persistentClass.setDiscriminatorValue( name ); //Spec compliant
      }
View Full Code Here

      final Property property = associatedClass.getRecursiveProperty( columns[0].getMappedBy() );
      Iterator mappedByColumns;
      if ( property.getValue() instanceof Collection ) {
        Collection collection = ( (Collection) property.getValue() );
        Value element = collection.getElement();
        if ( element == null ) {
          throw new AnnotationException(
              "Illegal use of mappedBy on both sides of the relationship: "
                  + associatedClass.getEntityName() + "." + mappedByProperty
          );
        }
        mappedByColumns = element.getColumnIterator();
      }
      else {
        mappedByColumns = property.getValue().getColumnIterator();
      }
      while ( mappedByColumns.hasNext() ) {
View Full Code Here

        throw new AnnotationException(
            "Map key property not found: " + collType + "." + mapKeyPropertyName
        );
      }
      org.hibernate.mapping.Map map = (org.hibernate.mapping.Map) this.collection;
      Value indexValue = createFormulatedValue( mapProperty.getValue(), map, targetPropertyName, associatedClass );
      map.setIndex( indexValue );
    }
    else {
      //this is a true Map mapping
      //TODO ugly copy/pastle from CollectionBinder.bindManyToManySecondPass
View Full Code Here

TOP

Related Classes of org.hibernate.mapping.Value

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.