Examples of RootClass


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 ( traceEnabled ) {
        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.setOptimisticLockStyle( OptimisticLockStyle.VERSION );
      if ( traceEnabled ) {
        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(), persistentClassName, null );
      value.setAccessType( propertyAccessor );
      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

      }
      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

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

    setCacheConcurrencyStrategy( clazz, concurrencyStrategy, region, true );
  }

  void setCacheConcurrencyStrategy(String clazz, String concurrencyStrategy, String region, boolean includeLazy)
      throws MappingException {
    RootClass rootClass = getRootClassMapping( clazz );
    if ( rootClass == null ) {
      throw new MappingException( "Cannot cache an unknown entity: " + clazz );
    }
    rootClass.setCacheConcurrencyStrategy( concurrencyStrategy );
    rootClass.setCacheRegionName( region );
    rootClass.setLazyPropertiesCacheable( includeLazy );
  }
View Full Code Here

Examples of org.hibernate.mapping.RootClass

    //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.type ) ) {
      persistentClass = new SingleTableSubclass( superEntity );
    }
    else if ( InheritanceType.JOINED.equals( inheritanceState.type ) ) {
      persistentClass = new JoinedSubclass( superEntity );
    }
    else if ( InheritanceType.TABLE_PER_CLASS.equals( inheritanceState.type ) ) {
      persistentClass = new UnionSubclass( superEntity );
    }
    else {
      throw new AssertionFailure( "Unknown inheritance type: " + inheritanceState.type );
    }
    Proxy proxyAnn = annotatedClass.getAnnotation( Proxy.class );
    BatchSize sizeAnn = annotatedClass.getAnnotation( BatchSize.class );
    Where whereAnn = annotatedClass.getAnnotation( Where.class );
    Entity entityAnn = annotatedClass.getAnnotation( Entity.class );
    org.hibernate.annotations.Entity hibEntityAnn = annotatedClass.getAnnotation(
        org.hibernate.annotations.Entity.class
    );
    org.hibernate.annotations.Cache cacheAnn = annotatedClass.getAnnotation(
        org.hibernate.annotations.Cache.class
    );
    EntityBinder entityBinder = new EntityBinder(
        entityAnn, hibEntityAnn, clazzToProcess, persistentClass, mappings
    );
    entityBinder.setDiscriminatorValue( discrimValue );
    entityBinder.setBatchSize( sizeAnn );
    entityBinder.setProxy( proxyAnn );
    entityBinder.setWhere( whereAnn );
    entityBinder.setCache( cacheAnn );
    entityBinder.setInheritanceState( inheritanceState );
    Filter filterAnn = annotatedClass.getAnnotation( Filter.class );
    if ( filterAnn != null ) {
      entityBinder.addFilter( filterAnn.name(), filterAnn.condition() );
    }
    Filters filtersAnn = annotatedClass.getAnnotation( Filters.class );
    if ( filtersAnn != null ) {
      for (Filter filter : filtersAnn.value()) {
        entityBinder.addFilter( filter.name(), filter.condition() );
      }
    }
    entityBinder.bindEntity();

    if ( inheritanceState.hasTable() ) {
      Check checkAnn = annotatedClass.getAnnotation( Check.class );
      String constraints = checkAnn == null ?
          null :
          checkAnn.constraints();
      entityBinder.bindTable(
          schema, catalog, table, uniqueConstraints,
          constraints, inheritanceState.hasDenormalizedTable() ?
          superEntity.getTable() :
          null
      );
    }
    else {
      if ( annotatedClass.isAnnotationPresent( Table.class ) ) {
        log.warn( "Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy: " + clazzToProcess
            .getName() );
      }
    }
//    Map<String, Column[]> columnOverride = PropertyHolderBuilder.buildHierarchyColumnOverride(
//        clazzToProcess,
//        persistentClass.getClassName()
//    );
    PropertyHolder propertyHolder = PropertyHolderBuilder.buildPropertyHolder(
        clazzToProcess,
        persistentClass,
        entityBinder, mappings
    );

    javax.persistence.SecondaryTable secTabAnn = annotatedClass.getAnnotation(
        javax.persistence.SecondaryTable.class
    );
    javax.persistence.SecondaryTables secTabsAnn = annotatedClass.getAnnotation(
        javax.persistence.SecondaryTables.class
    );
    entityBinder.firstLevelSecondaryTablesBinding( secTabAnn, secTabsAnn );

    OnDelete onDeleteAnn = annotatedClass.getAnnotation( OnDelete.class );
    boolean onDeleteAppropriate = false;
    if ( InheritanceType.JOINED.equals( inheritanceState.type ) && inheritanceState.hasParents ) {
      onDeleteAppropriate = true;
      final JoinedSubclass jsc = (JoinedSubclass) persistentClass;
      if ( persistentClass.getEntityPersisterClass() == null ) {
        persistentClass.getRootClass().setEntityPersisterClass( JoinedSubclassEntityPersister.class );
      }
      SimpleValue key = new DependantValue( jsc.getTable(), jsc.getIdentifier() );
      jsc.setKey( key );
      ForeignKey fk = annotatedClass.getAnnotation( ForeignKey.class );
      if ( fk != null && !BinderHelper.isDefault( fk.name() ) ) {
        key.setForeignKeyName( fk.name() );
      }
      if ( onDeleteAnn != null ) {
        key.setCascadeDeleteEnabled( OnDeleteAction.CASCADE.equals( onDeleteAnn.action() ) );
      }
      else {
        key.setCascadeDeleteEnabled( false );
      }
      //we are never in a second pass at that stage, so queue it
      SecondPass sp = new JoinedSubclassFkSecondPass( jsc, inheritanceJoinedColumns, key, mappings );
      mappings.addSecondPass( sp );
      mappings.addSecondPass( new CreateKeySecondPass( jsc ) );

    }
    else if ( InheritanceType.SINGLE_TABLE.equals( inheritanceState.type ) ) {
      if ( inheritanceState.hasParents ) {
        if ( persistentClass.getEntityPersisterClass() == null ) {
          persistentClass.getRootClass().setEntityPersisterClass( SingleTableEntityPersister.class );
        }
      }
      else {
        if ( inheritanceState.hasSons || !discriminatorColumn.isImplicit() ) {
          //need a discriminator column
          bindDiscriminatorToPersistentClass(
              (RootClass) persistentClass,
              discriminatorColumn,
              entityBinder.getSecondaryTables(),
              propertyHolder
          );
          entityBinder.bindDiscriminatorValue();//bind it again since the type might have changed
        }
      }
    }
    else if ( InheritanceType.TABLE_PER_CLASS.equals( inheritanceState.type ) ) {
      if ( inheritanceState.hasParents ) {
        if ( persistentClass.getEntityPersisterClass() == null ) {
          persistentClass.getRootClass().setEntityPersisterClass( UnionSubclassEntityPersister.class );
        }
      }
    }
    if ( onDeleteAnn != null && !onDeleteAppropriate ) {
      log.warn(
          "Inapropriate use of @OnDelete on entity, annotation ignored: {}", propertyHolder.getEntityName()
      );
    }

    //try to find class level generators
    HashMap<String, IdGenerator> classGenerators = buildLocalGenerators( annotatedClass, mappings );

    // check properties
    List<PropertyData> elements =
        getElementsToProcess(
            clazzToProcess, inheritanceStatePerClass, propertyHolder, entityBinder, mappings
        );
    if ( elements == null ) {
      throw new AnnotationException( "No identifier specified for entity: " + propertyHolder.getEntityName() );
    }
    final boolean subclassAndSingleTableStrategy = inheritanceState.type == InheritanceType.SINGLE_TABLE
        && inheritanceState.hasParents;
    //process idclass if any
    Set<String> idProperties = new HashSet<String>();
    IdClass idClass = null;
    if ( !inheritanceState.hasParents ) {
      //look for idClass
      XClass current = inheritanceState.clazz;
      InheritanceState state = inheritanceState;
      do {
        current = state.clazz;
        if ( current.isAnnotationPresent( IdClass.class ) ) {
          idClass = current.getAnnotation( IdClass.class );
          break;
        }
        state = InheritanceState.getSuperclassInheritanceState(
            current, inheritanceStatePerClass, mappings.getReflectionManager()
        );
      }
      while ( state != null );
    }
    if ( idClass != null ) {
      XClass compositeClass = mappings.getReflectionManager().toXClass( idClass.value() );
      boolean isComponent = true;
      boolean propertyAnnotated = entityBinder.isPropertyAnnotated( compositeClass );
      String propertyAccessor = entityBinder.getPropertyAccessor( compositeClass );
      String generatorType = "assigned";
      String generator = BinderHelper.ANNOTATION_STRING_DEFAULT;
      PropertyData inferredData = new PropertyPreloadedData(
          entityBinder.getPropertyAccessor(), "id", compositeClass
      );
      HashMap<String, IdGenerator> localGenerators = new HashMap<String, IdGenerator>();
      boolean ignoreIdAnnotations = entityBinder.isIgnoreIdAnnotations();
      entityBinder.setIgnoreIdAnnotations( true );
      bindId(
          generatorType,
          generator,
          inferredData,
          null,
          propertyHolder,
          localGenerators,
          isComponent,
          propertyAnnotated,
          propertyAccessor, entityBinder,
          true,
          false, mappings
      );
      inferredData = new PropertyPreloadedData(
          propertyAccessor, "_identifierMapper", compositeClass
      );
      Component mapper = fillComponent(
          propertyHolder,
          inferredData,
          propertyAnnotated,
          propertyAccessor, false,
          entityBinder,
          true, true,
          false, mappings
      );
      entityBinder.setIgnoreIdAnnotations( ignoreIdAnnotations );
      persistentClass.setIdentifierMapper( mapper );
      Property property = new Property();
      property.setName( "_identifierMapper" );
      property.setNodeName( "id" );
      property.setUpdateable( false );
      property.setInsertable( false );
      property.setValue( mapper );
      property.setPropertyAccessorName( "embedded" );
      persistentClass.addProperty( property );
      entityBinder.setIgnoreIdAnnotations( true );

      Iterator properties = mapper.getPropertyIterator();
      while ( properties.hasNext() ) {
        idProperties.add( ( (Property) properties.next() ).getName() );
      }
    }
    Set<String> missingIdProperties = new HashSet<String>( idProperties );
    for (PropertyData propertyAnnotatedElement : elements) {
      String propertyName = propertyAnnotatedElement.getPropertyName();
      if ( !idProperties.contains( propertyName ) ) {
        processElementAnnotations(
            propertyHolder,
            subclassAndSingleTableStrategy ?
                Nullability.FORCED_NULL :
                Nullability.NO_CONSTRAINT,
            propertyAnnotatedElement.getProperty(),
            propertyAnnotatedElement, classGenerators, entityBinder,
            false, false, false, mappings
        );
      }
      else {
        missingIdProperties.remove( propertyName );
      }
    }

    if ( missingIdProperties.size() != 0 ) {
      StringBuilder missings = new StringBuilder();
      for (String property : missingIdProperties) {
        missings.append( property ).append( ", " );
      }
      throw new AnnotationException(
          "Unable to find properties ("
              + missings.substring( 0, missings.length() - 2 )
              + ") in entity annotated with @IdClass:" + persistentClass.getEntityName()
      );
    }

    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

            "Unable to define @Version on an embedded class: "
                + propertyHolder.getEntityName()
        );
      }
      log.debug( "{} is a version property", inferredData.getPropertyName() );
      RootClass rootClass = (RootClass) propertyHolder.getPersistentClass();
      PropertyBinder propBinder = new PropertyBinder();
      propBinder.setName( inferredData.getPropertyName() );
      propBinder.setReturnedClassName( inferredData.getTypeName() );
      propBinder.setLazy( false );
      propBinder.setPropertyAccessorName( inferredData.getDefaultAccess() );
      propBinder.setColumns( columns );
      propBinder.setHolder( propertyHolder ); //PropertyHolderBuilder.buildPropertyHolder(rootClass)
      propBinder.setProperty( property );
      propBinder.setReturnedClass( inferredData.getPropertyClass() );

      propBinder.setMappings( mappings );
      Property prop = propBinder.bind();
      rootClass.setVersion( prop );
      SimpleValue simpleValue = (SimpleValue) prop.getValue();
      if ( !simpleValue.isTypeSpecified() ) simpleValue.setTypeName( "integer" );
      simpleValue.setNullValue( "undefined" );
      rootClass.setOptimisticLockMode( Versioning.OPTIMISTIC_LOCK_VERSION );
      log.debug(
          "Version name: {}, unsavedValue: {}", rootClass.getVersion().getName(),
          ( (SimpleValue) rootClass.getVersion().getValue() ).getNullValue()
      );
    }
    else if ( property.isAnnotationPresent( ManyToOne.class ) ) {
      ManyToOne ann = property.getAnnotation( ManyToOne.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 == null ?
        null :
        rootClass.getClassName();
    SimpleValue id;
    if ( isComposite ) {
      id = fillComponent(
          propertyHolder, inferredData, isPropertyAnnotated, propertyAccessor,
          false, entityBinder, isEmbedded, isIdentifierMapper, false, mappings
      );
      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 {
      for (Ejb3Column column : columns) {
        column.forceNotNull(); //this is an id
      }
      SimpleValueBinder value = new SimpleValueBinder();
      value.setPropertyName( inferredData.getPropertyName() );
      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( inferredData.getPropertyName() );
      binder.setValue( id );
      binder.setPropertyAccessorName( inferredData.getDefaultAccess() );
      binder.setProperty( inferredData.getProperty() );
      Property prop = binder.make();
      rootClass.setIdentifierProperty( prop );
    }
  }
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.