Package org.hibernate.annotations.common.reflection

Examples of org.hibernate.annotations.common.reflection.XClass


    /*
    * Iterate the class hierarchy top down. This allows to override the default analyzer for the properties if the class holds one
    */
    for ( int index = hierarchy.size() - 1; index >= 0; index-- ) {
      XClass currentClass = hierarchy.get( index );

      initializeClassLevelAnnotations( currentClass, propertiesMetadata, isRoot, prefix, context );

      // rejecting non properties (ie regular methods) because the object is loaded from Hibernate,
      // so indexing a non property does not make sense
      List<XProperty> methods = currentClass.getDeclaredProperties( XClass.ACCESS_PROPERTY );
      for ( XProperty method : methods ) {
        initializeMemberLevelAnnotations(
            method, propertiesMetadata, isRoot, prefix, processedClasses, context
        );
      }

      List<XProperty> fields = currentClass.getDeclaredProperties( XClass.ACCESS_FIELD );
      for ( XProperty field : fields ) {
        initializeMemberLevelAnnotations(
            field, propertiesMetadata, isRoot, prefix, processedClasses, context
        );
      }
View Full Code Here


        potentialLevel = Integer.MAX_VALUE;
      }
      maxLevel = potentialLevel > maxLevel ? maxLevel : potentialLevel;
      level++;

      XClass elementClass;
      if ( void.class == embeddedAnn.targetElement() ) {
        elementClass = member.getElementClass();
      }
      else {
        elementClass = reflectionManager.toXClass( embeddedAnn.targetElement() );
      }
      if ( maxLevel == Integer.MAX_VALUE //infinite
          && processedClasses.contains( elementClass ) ) {
        throw new SearchException(
            "Circular reference. Duplicate use of "
                + elementClass.getName()
                + " in root entity " + beanXClass.getName()
                + "#" + buildEmbeddedPrefix( prefix, embeddedAnn, member )
        );
      }
      if ( level <= maxLevel ) {
View Full Code Here

  }

  public static InheritanceState getInheritanceStateOfSuperEntity(
      XClass clazz, Map<XClass, InheritanceState> states
  ) {
    XClass superclass = clazz;
    do {
      superclass = superclass.getSuperclass();
      InheritanceState currentState = states.get( superclass );
      if ( currentState != null && !currentState.isEmbeddableSuperclass() ) {
        return currentState;
      }
    }
    while ( superclass != null && !Object.class.getName().equals( superclass.getName() ) );
    return null;
  }
View Full Code Here

    while ( superclass != null && !Object.class.getName().equals( superclass.getName() ) );
    return null;
  }

  public static InheritanceState getSuperclassInheritanceState(XClass clazz, Map<XClass, InheritanceState> states) {
    XClass superclass = clazz;
    do {
      superclass = superclass.getSuperclass();
      InheritanceState currentState = states.get( superclass );
      if ( currentState != null ) {
        return currentState;
      }
    }
    while ( superclass != null && !Object.class.getName().equals( superclass.getName() ) );
    return null;
  }
View Full Code Here

    }
    return elementsToProcess;
  }

  private AccessType determineDefaultAccessType() {
    XClass xclass = clazz;
    while ( xclass != null && !Object.class.getName().equals( xclass.getName() ) ) {
      if ( xclass.isAnnotationPresent( Entity.class ) || xclass.isAnnotationPresent( MappedSuperclass.class ) ) {
        for ( XProperty prop : xclass.getDeclaredProperties( AccessType.PROPERTY.getType() ) ) {
          final boolean isEmbeddedId = prop.isAnnotationPresent( EmbeddedId.class );
          if ( prop.isAnnotationPresent( Id.class ) || isEmbeddedId ) {
            return AccessType.PROPERTY;
          }
        }
        for ( XProperty prop : xclass.getDeclaredProperties( AccessType.FIELD.getType() ) ) {
          final boolean isEmbeddedId = prop.isAnnotationPresent( EmbeddedId.class );
          if ( prop.isAnnotationPresent( Id.class ) || isEmbeddedId ) {
            return AccessType.FIELD;
          }
        }
      }
      xclass = xclass.getSuperclass();
    }
    throw new AnnotationException( "No identifier specified for entity: " + clazz );
  }
View Full Code Here

  }

  private void getMappedSuperclassesTillNextEntityOrdered() {

    //ordered to allow proper messages on properties subclassing
    XClass currentClassInHierarchy = clazz;
    InheritanceState superclassState;
    do {
      classesToProcessForMappedSuperclass.add( 0, currentClassInHierarchy );
      XClass superClass = currentClassInHierarchy;
      do {
        superClass = superClass.getSuperclass();
        superclassState = inheritanceStatePerClass.get( superClass );
      }
      while ( superClass != null
          && !mappings.getReflectionManager().equals( superClass, Object.class ) && superclassState == null );
View Full Code Here

    }
    return override;
  }

  private void buildHierarchyColumnOverride(XClass element) {
    XClass current = element;
    Map<String, Column[]> columnOverride = new HashMap<String, Column[]>();
    Map<String, JoinColumn[]> joinColumnOverride = new HashMap<String, JoinColumn[]>();
    Map<String, JoinTable> joinTableOverride = new HashMap<String, JoinTable>();
    while ( current != null && !mappings.getReflectionManager().toXClass( Object.class ).equals( current ) ) {
      if ( current.isAnnotationPresent( Entity.class ) || current.isAnnotationPresent( MappedSuperclass.class )
          || current.isAnnotationPresent( Embeddable.class ) ) {
        //FIXME is embeddable override?
        Map<String, Column[]> currentOverride = buildColumnOverride( current, getPath() );
        Map<String, JoinColumn[]> currentJoinOverride = buildJoinColumnOverride( current, getPath() );
        Map<String, JoinTable> currentJoinTableOverride = buildJoinTableOverride( current, getPath() );
        currentOverride.putAll( columnOverride ); //subclasses have precedence over superclasses
        currentJoinOverride.putAll( joinColumnOverride ); //subclasses have precedence over superclasses
        currentJoinTableOverride.putAll( joinTableOverride ); //subclasses have precedence over superclasses
        columnOverride = currentOverride;
        joinColumnOverride = currentJoinOverride;
        joinTableOverride = currentJoinTableOverride;
      }
      current = current.getSuperclass();
    }

    holderColumnOverride = columnOverride.size() > 0 ? columnOverride : null;
    holderJoinColumnOverride = joinColumnOverride.size() > 0 ? joinColumnOverride : null;
    holderJoinTableOverride = joinTableOverride.size() > 0 ? joinTableOverride : null;
View Full Code Here

    }

    protected void syncAnnotatedClasses() {
      final Iterator<XClass> itr = annotatedClasses.iterator();
      while ( itr.hasNext() ) {
        final XClass annotatedClass = itr.next();
        if ( annotatedClass.isAnnotationPresent( Entity.class ) ) {
          annotatedClassesByEntityNameMap.put( annotatedClass.getName(), annotatedClass );
          continue;
        }

        if ( !annotatedClass.isAnnotationPresent( javax.persistence.MappedSuperclass.class ) ) {
          itr.remove();
        }
      }
    }
View Full Code Here

      // order the hierarchy
      List<XClass> workingCopy = new ArrayList<XClass>( copy );
      List<XClass> newList = new ArrayList<XClass>( copy.size() );
      while ( workingCopy.size() > 0 ) {
        XClass clazz = workingCopy.get( 0 );
        orderHierarchy( workingCopy, newList, copy, clazz );
      }
      return newList;
    }
View Full Code Here

      return newList;
    }

    private void insertMappedSuperclasses(List<XClass> original, List<XClass> copy) {
      for ( XClass clazz : original ) {
        XClass superClass = clazz.getSuperclass();
        while ( superClass != null
            && !reflectionManager.equals( superClass, Object.class )
            && !copy.contains( superClass ) ) {
          if ( superClass.isAnnotationPresent( Entity.class )
              || superClass.isAnnotationPresent( javax.persistence.MappedSuperclass.class ) ) {
            copy.add( superClass );
          }
          superClass = superClass.getSuperclass();
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.hibernate.annotations.common.reflection.XClass

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.