Examples of RootClass


Examples of org.hibernate.mapping.RootClass

        Session session = mockSession();
        Logger logger = mockLogger();

        replay();

        RootClass persistentClass = new RootClass();
        Property idProperty = new Property();
        idProperty.setName("id");
        persistentClass.setIdentifierProperty(idProperty);

        HibernateEntityValueEncoder<SampleEntity> encoder = new HibernateEntityValueEncoder<SampleEntity>(
                SampleEntity.class, persistentClass, session, access, typeCoercer, logger);

        try
View Full Code Here

Examples of org.hibernate.mapping.RootClass

    this.isXToMany = xToMany;
  }

  private Property bind(Property prop) {
    if (isId) {
      final RootClass rootClass = ( RootClass ) holder.getPersistentClass();
      //if an xToMany, it as to be wrapped today.
      //FIXME this pose a problem as the PK is the class instead of the associated class which is not really compliant with the spec
      if ( isXToMany || entityBinder.wrapIdsInEmbeddedComponents() ) {
        Component identifier = (Component) rootClass.getIdentifier();
        if (identifier == null) {
          identifier = AnnotationBinder.createComponent( holder, new PropertyPreloadedData(null, null, null), true, false, mappings );
          rootClass.setIdentifier( identifier );
          identifier.setNullValue( "undefined" );
          rootClass.setEmbeddedIdentifier( true );
          rootClass.setIdentifierMapper( identifier );
        }
        //FIXME is it good enough?
        identifier.addProperty( prop );
      }
      else {
        rootClass.setIdentifier( ( KeyValue ) getValue() );
        if (embedded) {
          rootClass.setEmbeddedIdentifier( true );
        }
        else {
          rootClass.setIdentifierProperty( prop );
          final org.hibernate.mapping.MappedSuperclass superclass = BinderHelper.getMappedSuperclassOrNull(
              declaringClass,
              inheritanceStatePerClass,
              mappings
          );
          if (superclass != null) {
            superclass.setDeclaredIdentifierProperty(prop);
          }
          else {
            //we know the property is on the actual entity
            rootClass.setDeclaredIdentifierProperty( prop );
          }
        }
      }
    }
    else {
View Full Code Here

Examples of org.hibernate.mapping.RootClass

        subclassAndSingleTableStrategy,
        idPropertiesIfIdClass
    );

    if ( !inheritanceState.hasParents() ) {
      final RootClass rootClass = ( RootClass ) persistentClass;
      mappings.addSecondPass( new CreateKeySecondPass( rootClass ) );
    }
    else {
      superEntity.addSubclass( ( Subclass ) persistentClass );
    }
View Full Code Here

Examples of org.hibernate.mapping.RootClass

  private static PersistentClass makePersistentClass(InheritanceState inheritanceState, PersistentClass superEntity) {
    //we now know what kind of persistent entity it is
    PersistentClass persistentClass;
    //create persistent class
    if ( !inheritanceState.hasParents() ) {
      persistentClass = new RootClass();
    }
    else if ( InheritanceType.SINGLE_TABLE.equals( inheritanceState.getType() ) ) {
      persistentClass = new SingleTableSubclass( superEntity );
    }
    else if ( InheritanceType.JOINED.equals( inheritanceState.getType() ) ) {
View Full Code Here

Examples of org.hibernate.mapping.RootClass

        );
      }
      if ( LOG.isTraceEnabled() ) {
        LOG.tracev( "{0} is a version property", inferredData.getPropertyName() );
      }
      RootClass rootClass = ( RootClass ) propertyHolder.getPersistentClass();
      propertyBinder.setColumns( columns );
      Property prop = propertyBinder.makePropertyValueAndBind();
      setVersionInformation( property, propertyBinder );
      rootClass.setVersion( prop );

      //If version is on a mapped superclass, update the mapping
      final org.hibernate.mapping.MappedSuperclass superclass = BinderHelper.getMappedSuperclassOrNull(
          inferredData.getDeclaringClass(),
          inheritanceStatePerClass,
          mappings
      );
      if ( superclass != null ) {
        superclass.setDeclaredVersion( prop );
      }
      else {
        //we know the property is on the actual entity
        rootClass.setDeclaredVersion( prop );
      }

      SimpleValue simpleValue = ( SimpleValue ) prop.getValue();
      simpleValue.setNullValue( "undefined" );
      rootClass.setOptimisticLockMode( Versioning.OPTIMISTIC_LOCK_VERSION );
      if ( LOG.isTraceEnabled() ) {
        LOG.tracev( "Version name: {0}, unsavedValue: {1}", rootClass.getVersion().getName(),
            ( (SimpleValue) rootClass.getVersion().getValue() ).getNullValue() );
      }
    }
    else {
      final boolean forcePersist = property.isAnnotationPresent( MapsId.class )
          || property.isAnnotationPresent( Id.class );
View Full Code Here

Examples of org.hibernate.mapping.RootClass

      throw new AnnotationException(
          "Unable to define/override @Id(s) on a subclass: "
              + propertyHolder.getEntityName()
      );
    }
    RootClass rootClass = ( RootClass ) persistentClass;
    String persistentClassName = rootClass.getClassName();
    SimpleValue id;
    final String propertyName = inferredData.getPropertyName();
    HashMap<String, IdGenerator> localGenerators = new HashMap<String, IdGenerator>();
    if ( isComposite ) {
      id = fillComponent(
          propertyHolder, inferredData, baseInferredData, propertyAccessor,
          false, entityBinder, isEmbedded, isIdentifierMapper, false, mappings, inheritanceStatePerClass
      );
      Component componentId = ( Component ) id;
      componentId.setKey( true );
      if ( rootClass.getIdentifier() != null ) {
        throw new AnnotationException( componentId.getComponentClassName() + " must not have @Id properties when used as an @EmbeddedId" );
      }
      if ( componentId.getPropertySpan() == 0 ) {
        throw new AnnotationException( componentId.getComponentClassName() + " has no persistent id property" );
      }
      //tuplizers
      XProperty property = inferredData.getProperty();
      setupComponentTuplizer( property, componentId );
    }
    else {
      //TODO I think this branch is never used. Remove.

      for ( Ejb3Column column : columns ) {
        column.forceNotNull(); //this is an id
      }
      SimpleValueBinder value = new SimpleValueBinder();
      value.setPropertyName( propertyName );
      value.setReturnedClassName( inferredData.getTypeName() );
      value.setColumns( columns );
      value.setPersistentClassName( persistentClassName );
      value.setMappings( mappings );
      value.setType( inferredData.getProperty(), inferredData.getClassOrElement() );
      id = value.make();
    }
    rootClass.setIdentifier( id );
    BinderHelper.makeIdGenerator( id, generatorType, generatorName, mappings, localGenerators );
    if ( isEmbedded ) {
      rootClass.setEmbeddedIdentifier( inferredData.getPropertyClass() == null );
    }
    else {
      PropertyBinder binder = new PropertyBinder();
      binder.setName( propertyName );
      binder.setValue( id );
      binder.setAccessType( inferredData.getDefaultAccess() );
      binder.setProperty( inferredData.getProperty() );
      Property prop = binder.makeProperty();
      rootClass.setIdentifierProperty( prop );
      //if the id property is on a superclass, update the metamodel
      final org.hibernate.mapping.MappedSuperclass superclass = BinderHelper.getMappedSuperclassOrNull(
          inferredData.getDeclaringClass(),
          inheritanceStatePerClass,
          mappings
      );
      if ( superclass != null ) {
        superclass.setDeclaredIdentifierProperty( prop );
      }
      else {
        //we know the property is on the actual entity
        rootClass.setDeclaredIdentifierProperty( prop );
      }
    }
  }
View Full Code Here

Examples of org.hibernate.mapping.RootClass

    this.isXToMany = xToMany;
  }

  private Property bind(Property prop) {
    if (isId) {
      final RootClass rootClass = ( RootClass ) holder.getPersistentClass();
      //if an xToMany, it as to be wrapped today.
      //FIXME this pose a problem as the PK is the class instead of the associated class which is not really compliant with the spec
      if ( isXToMany || entityBinder.wrapIdsInEmbeddedComponents() ) {
        Component identifier = (Component) rootClass.getIdentifier();
        if (identifier == null) {
          identifier = AnnotationBinder.createComponent( holder, new PropertyPreloadedData(null, null, null), true, false );
          rootClass.setIdentifier( identifier );
          identifier.setNullValue( "undefined" );
          rootClass.setEmbeddedIdentifier( true );
        }
        //FIXME is it good enough?
        identifier.addProperty( prop );
      }
      else {
        rootClass.setIdentifier( ( KeyValue ) getValue() );
        if (embedded) {
          rootClass.setEmbeddedIdentifier( true );
        }
        else {
          rootClass.setIdentifierProperty( prop );
          final org.hibernate.mapping.MappedSuperclass superclass = BinderHelper.getMappedSuperclassOrNull(
              declaringClass,
              inheritanceStatePerClass,
              mappings
          );
          if (superclass != null) {
            superclass.setDeclaredIdentifierProperty(prop);
          }
          else {
            //we know the property is on the actual entity
            rootClass.setDeclaredIdentifierProperty( prop );
          }
        }
      }
    }
    else {
View Full Code Here

Examples of org.hibernate.mapping.RootClass

    }
    persistentClass.setDynamicInsert( dynamicInsert );
    persistentClass.setDynamicUpdate( dynamicUpdate );

    if ( persistentClass instanceof RootClass ) {
      RootClass rootClass = (RootClass) persistentClass;
      boolean mutable = true;
      //priority on @Immutable, then @Entity.mutable()
      if ( annotatedClass.isAnnotationPresent( Immutable.class ) ) {
        mutable = false;
      }
      else {
        org.hibernate.annotations.Entity entityAnn =
            annotatedClass.getAnnotation( org.hibernate.annotations.Entity.class );
        if ( entityAnn != null ) {
          mutable = entityAnn.mutable();
        }
      }
      rootClass.setMutable( mutable );
      rootClass.setExplicitPolymorphism( isExplicitPolymorphism( polymorphismType ) );
      if ( StringHelper.isNotEmpty( where ) ) rootClass.setWhere( where );
      if ( cacheConcurrentStrategy != null ) {
        rootClass.setCacheConcurrencyStrategy( cacheConcurrentStrategy );
        rootClass.setCacheRegionName( cacheRegion );
        rootClass.setLazyPropertiesCacheable( cacheLazyProperty );
      }
      rootClass.setForceDiscriminator( annotatedClass.isAnnotationPresent( ForceDiscriminator.class ) );
    }
    else {
      if ( explicitHibernateEntityAnnotation ) {
        log.warn( "@org.hibernate.annotations.Entity used on a non root entity: ignored for {}",
            annotatedClass.getName() );
View Full Code Here

Examples of org.hibernate.mapping.RootClass

      boolean cacheLazyProperty) throws MappingException {
    caches.add( new CacheHolder( entityName, concurrencyStrategy, region, true, cacheLazyProperty ) );
  }

  private void applyCacheConcurrencyStrategy(CacheHolder holder) {
    RootClass rootClass = getRootClassMapping( holder.role );
    if ( rootClass == null ) {
      throw new MappingException( "Cannot cache an unknown entity: " + holder.role );
    }
    rootClass.setCacheConcurrencyStrategy( holder.usage );
    rootClass.setCacheRegionName( holder.region );
    rootClass.setLazyPropertiesCacheable( holder.cacheLazy );
  }
View Full Code Here

Examples of org.hibernate.mapping.RootClass

        subclassAndSingleTableStrategy,
        idPropertiesIfIdClass
    );

    if ( !inheritanceState.hasParents() ) {
      final RootClass rootClass = (RootClass) persistentClass;
      mappings.addSecondPass( new CreateKeySecondPass( rootClass ) );
    }
    else {
      superEntity.addSubclass( (Subclass) persistentClass );
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.