Package org.hibernate.mapping

Examples of org.hibernate.mapping.RootClass


      }
      else if ( "typedef".equals( elementName ) ) {
        bindTypeDef( element, mappings );
      }
      else if ( "class".equals( elementName ) ) {
        RootClass rootclass = new RootClass();
        bindRootClass( element, rootclass, mappings, inheritedMetas );
        mappings.addClass( rootclass );
      }
      else if ( "subclass".equals( elementName ) ) {
        PersistentClass superModel = getSuperclass( mappings, element );
View Full Code Here


        subclassAndSingleTableStrategy,
        idPropertiesIfIdClass
    );

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

  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

            "Unable to define @Version on an embedded class: "
                + propertyHolder.getEntityName()
        );
      }
      log.trace( "{} 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 );
      log.trace(
          "Version name: {}, unsavedValue: {}", rootClass.getVersion().getName(),
          ( ( SimpleValue ) rootClass.getVersion().getValue() ).getNullValue()
      );
    }
    else {
      final boolean forcePersist = property.isAnnotationPresent( MapsId.class )
          || property.isAnnotationPresent( Id.class );
View Full Code Here

      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

      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

        subclassAndSingleTableStrategy,
        idPropertiesIfIdClass
    );

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

  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

            "Unable to define @Version on an embedded class: "
                + propertyHolder.getEntityName()
        );
      }
      log.trace( "{} is a version property", inferredData.getPropertyName() );
      RootClass rootClass = ( RootClass ) propertyHolder.getPersistentClass();
      propertyBinder.setColumns( columns );
      Property prop = propertyBinder.makePropertyValueAndBind();
      propertyBinder.getSimpleValueBinder().setVersion( true );
      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 );
      log.trace(
          "Version name: {}, unsavedValue: {}", rootClass.getVersion().getName(),
          ( ( SimpleValue ) rootClass.getVersion().getValue() ).getNullValue()
      );
    }
    else {
      final boolean forcePersist = property.isAnnotationPresent( MapsId.class )
          || property.isAnnotationPresent( Id.class );
View Full Code Here

      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

TOP

Related Classes of org.hibernate.mapping.RootClass

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.