Package org.hibernate.mapping

Examples of org.hibernate.mapping.Any


  public static Any buildAnyValue(String anyMetaDefName, Ejb3JoinColumn[] columns, javax.persistence.Column metaColumn, PropertyData inferredData,
                  boolean cascadeOnDelete, Nullability nullability, PropertyHolder propertyHolder,
                  EntityBinder entityBinder, boolean optional, ExtendedMappings mappings) {
    //All FK columns should be in the same table
    Any value = new Any( columns[0].getTable() );
    AnyMetaDef metaAnnDef = inferredData.getProperty().getAnnotation( AnyMetaDef.class );

    if ( metaAnnDef != null ) {
      //local has precedence over general and can be mapped for future reference if named
      bindAnyMetaDefs( inferredData.getProperty(), mappings );
    }
    else {
      metaAnnDef = mappings.getAnyMetaDef( anyMetaDefName );
    }
    if ( metaAnnDef != null ) {
      value.setIdentifierType( metaAnnDef.idType() );
      value.setMetaType( metaAnnDef.metaType() );

      HashMap values = new HashMap();
      org.hibernate.type.Type metaType = TypeFactory.heuristicType( value.getMetaType() );
      for (MetaValue metaValue : metaAnnDef.metaValues()) {
        try {
          Object discrim = ( (org.hibernate.type.DiscriminatorType) metaType ).stringToObject( metaValue
              .value() );
          String entityName = metaValue.targetEntity().getName();
          values.put( discrim, entityName );
        }
        catch (ClassCastException cce) {
          throw new MappingException( "metaType was not a DiscriminatorType: "
              + metaType.getName() );
        }
        catch (Exception e) {
          throw new MappingException( "could not interpret metaValue", e );
        }
      }
      if ( !values.isEmpty() ) value.setMetaValues( values );
    }
    else {
      throw new AnnotationException( "Unable to find @AnyMetaDef for an @(ManyTo)Any mapping: "
          + StringHelper.qualify( propertyHolder.getPath(), inferredData.getPropertyName() ) );
    }

    value.setCascadeDeleteEnabled( cascadeOnDelete );
    if ( !optional ) {
      for (Ejb3JoinColumn column : columns) {
        column.setNullable( false );
      }
    }

    Ejb3Column[] metaColumns = Ejb3Column.buildColumnFromAnnotation( new javax.persistence.Column[] { metaColumn }, null,
        nullability, propertyHolder, inferredData, entityBinder.getSecondaryTables(), mappings );
    //set metaColumn to the right table
    for (Ejb3Column column : metaColumns) {
      column.setTable( value.getTable() );
    }
    //meta column
    for (Ejb3Column column : metaColumns) {
      column.linkWithValue( value );
    }
View Full Code Here


    org.hibernate.annotations.Any anyAnn = inferredData.getProperty().getAnnotation( org.hibernate.annotations.Any.class );
    if ( anyAnn == null ) {
      throw new AssertionFailure( "Missing @Any annotation: "
          + StringHelper.qualify( propertyHolder.getPath(), inferredData.getPropertyName() ) );
    }
    Any value = BinderHelper.buildAnyValue( anyAnn.metaDef(), columns, anyAnn.metaColumn(), inferredData,
        cascadeOnDelete, nullability, propertyHolder, entityBinder, anyAnn.optional(), mappings );

    PropertyBinder binder = new PropertyBinder();
    binder.setName( inferredData.getPropertyName() );
    binder.setValue( value );
View Full Code Here

    final Table tbl = new Table();
    final RootClass rootClass = new RootClass();

    ValueVisitor vv = new ValueVisitorValidator();
   
    new Any( mappings, tbl ).accept(vv);
    new Array( mappings, rootClass ).accept(vv);
    new Bag( mappings, rootClass ).accept(vv);
    new Component( mappings, rootClass ).accept(vv);
    new DependantValue( mappings, tbl, null ).accept(vv);
    new IdentifierBag( mappings, rootClass ).accept(vv);
View Full Code Here

      if ( "many-to-one".equals( name ) ) {
        value = new ManyToOne( table );
        bindManyToOne( subnode, (ManyToOne) value, propertyName, true, mappings );
      }
      else if ( "any".equals( name ) ) {
        value = new Any( table );
        bindAny( subnode, (Any) value, true, mappings );
      }
      else if ( "property".equals( name ) ) {
        value = new SimpleValue( table );
        bindSimpleValue( subnode, (SimpleValue) value, true, propertyName, mappings );
View Full Code Here

          relativePath = subpath.substring( component.getOwner().getEntityName().length() + 1 );
        }
        bindOneToOne( subnode, (OneToOne) value, relativePath, isNullable, mappings );
      }
      else if ( "any".equals( name ) ) {
        value = new Any( component.getTable() );
        bindAny( subnode, (Any) value, isNullable, mappings );
      }
      else if ( "property".equals( name ) || "key-property".equals( name ) ) {
        value = new SimpleValue( component.getTable() );
        String relativePath;
View Full Code Here

      else if ( "many-to-one".equals( name ) ) {
        value = new ManyToOne( table );
        bindManyToOne( subnode, (ManyToOne) value, propertyName, nullable, mappings );
      }
      else if ( "any".equals( name ) ) {
        value = new Any( table );
        bindAny( subnode, (Any) value, nullable, mappings );
      }
      else if ( "one-to-one".equals( name ) ) {
        value = new OneToOne( table, persistentClass );
        bindOneToOne( subnode, (OneToOne) value, propertyName, true, mappings );
View Full Code Here

            inheritedMetas
          );
        map.setIndex( component );
      }
      else if ( "index-many-to-any".equals( name ) ) {
        Any any = new Any( map.getCollectionTable() );
        bindAny( subnode, any, map.isOneToMany(), mappings );
        map.setIndex( any );
      }
    }
View Full Code Here

            mappings,
            inheritedMetas
          );
      }
      else if ( "many-to-any".equals( name ) ) {
        Any element = new Any( collection.getCollectionTable() );
        collection.setElement( element );
        bindAny( subnode, element, true, mappings );
      }
      else if ( "cache".equals( name ) ) {
        collection.setCacheConcurrencyStrategy( subnode.attributeValue( "usage" ) );
View Full Code Here

      throw new AssertionFailure(
          "Missing @Any annotation: "
              + BinderHelper.getPath( propertyHolder, inferredData )
      );
    }
    Any value = BinderHelper.buildAnyValue(
        anyAnn.metaDef(), columns, anyAnn.metaColumn(), inferredData,
        cascadeOnDelete, nullability, propertyHolder, entityBinder, anyAnn.optional(), mappings
    );

    PropertyBinder binder = new PropertyBinder();
View Full Code Here

      PropertyData inferredData = new PropertyInferredData(null, property, "unsupported", mappings.getReflectionManager() );
      //override the table
      for (Ejb3Column column : inverseJoinColumns) {
        column.setTable( collValue.getCollectionTable() );
      }
      Any any = BinderHelper.buildAnyValue( anyAnn.metaDef(), inverseJoinColumns, anyAnn.metaColumn(),
          inferredData, cascadeDeleteEnabled, Nullability.NO_CONSTRAINT,
          propertyHolder, new EntityBinder(), true, mappings );
      collValue.setElement( any );
    }
    else {
View Full Code Here

TOP

Related Classes of org.hibernate.mapping.Any

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.