Package org.hibernate.annotations.common.reflection

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


          inferredData, cascadeDeleteEnabled, Nullability.NO_CONSTRAINT,
          propertyHolder, new EntityBinder(), true, mappings );
      collValue.setElement( any );
    }
    else {
      XClass elementClass;
      AnnotatedClassType classType;
//      Map<String, javax.persistence.Column[]> columnOverrides = PropertyHolderBuilder.buildColumnOverride(
//          property, StringHelper.qualify( collValue.getRole(), "element" )
//      );
      //FIXME the "element" is lost
View Full Code Here


  }

  //TODO execute it lazily to be order safe
  public void setType(XProperty property, XClass returnedClass) {
    if ( returnedClass == null ) return; //we cannot guess anything
    XClass returnedClassOrElement = returnedClass;
    boolean isArray = false;
    if ( property.isArray() ) {
      returnedClassOrElement = property.getElementClass();
      isArray = true;
    }
    Properties typeParameters = this.typeParameters;
    typeParameters.clear();
    String type = BinderHelper.ANNOTATION_STRING_DEFAULT;
    if ( property.isAnnotationPresent( Temporal.class ) ) {
      Temporal ann = property.getAnnotation( Temporal.class );
      boolean isDate;
      if ( mappings.getReflectionManager().equals( returnedClassOrElement, Date.class ) ) {
        isDate = true;
      }
      else if ( mappings.getReflectionManager().equals( returnedClassOrElement, Calendar.class ) ) {
        isDate = false;
      }
      else {
        throw new AnnotationException(
            "@Temporal should only be set on a java.util.Date or java.util.Calendar property: "
                + StringHelper.qualify( persistentClassName, propertyName )
        );
      }

      switch ( ann.value() ) {
        case DATE:
          type = isDate ? "date" : "calendar_date";
          break;
        case TIME:
          type = "time";
          if ( !isDate ) {
            throw new NotYetImplementedException(
                "Calendar cannot persist TIME only"
                    + StringHelper.qualify( persistentClassName, propertyName )
            );
          }
          break;
        case TIMESTAMP:
          type = isDate ? "timestamp" : "calendar";
          break;
        default:
          throw new AssertionFailure( "Unknown temporal type: " + ann.value() );
      }
    }
    else if ( property.isAnnotationPresent( Lob.class ) ) {

      if ( mappings.getReflectionManager().equals( returnedClassOrElement, java.sql.Clob.class ) ) {
        type = "clob";
      }
      else if ( mappings.getReflectionManager().equals( returnedClassOrElement, java.sql.Blob.class ) ) {
        type = "blob";
      }
      else if ( mappings.getReflectionManager().equals( returnedClassOrElement, String.class ) ) {
        type = StringClobType.class.getName();
      }
      else if ( mappings.getReflectionManager().equals( returnedClassOrElement, Character.class ) && isArray ) {
        type = CharacterArrayClobType.class.getName();
      }
      else if ( mappings.getReflectionManager().equals( returnedClassOrElement, char.class ) && isArray ) {
        type = PrimitiveCharacterArrayClobType.class.getName();
      }
      else if ( mappings.getReflectionManager().equals( returnedClassOrElement, Byte.class ) && isArray ) {
        type = ByteArrayBlobType.class.getName();
      }
      else if ( mappings.getReflectionManager().equals( returnedClassOrElement, byte.class ) && isArray ) {
        type = PrimitiveByteArrayBlobType.class.getName();
      }
      else if ( mappings.getReflectionManager()
          .toXClass( Serializable.class )
          .isAssignableFrom( returnedClassOrElement ) ) {
        type = SerializableToBlobType.class.getName();
        //typeParameters = new Properties();
        typeParameters.setProperty(
            SerializableToBlobType.CLASS_NAME,
            returnedClassOrElement.getName()
        );
      }
      else {
        type = "blob";
      }
    }
    //implicit type will check basic types and Serializable classes
    if ( columns == null ) {
      throw new AssertionFailure( "SimpleValueBinder.setColumns should be set before SimpleValueBinder.setType" );
    }
    if ( BinderHelper.ANNOTATION_STRING_DEFAULT.equals( type ) ) {
      if ( returnedClassOrElement.isEnum() ) {
        type = EnumType.class.getName();
        typeParameters = new Properties();
        typeParameters.setProperty( EnumType.ENUM, returnedClassOrElement.getName() );
        String schema = columns[0].getTable().getSchema();
        schema = schema == null ? "" : schema;
        String catalog = columns[0].getTable().getCatalog();
        catalog = catalog == null ? "" : catalog;
        typeParameters.setProperty( EnumType.SCHEMA, schema );
View Full Code Here

  protected List<XClass> orderAndFillHierarchy(List<XClass> original) {
    //TODO remove embeddable
    List<XClass> copy = new ArrayList<XClass>( original );
    //for each class, copy all the relevant hierarchy
    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( MappedSuperclass.class ) ) {
          copy.add( superClass );
        }
        superClass = superClass.getSuperclass();
      }
    }
    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

   *
   * @param persistentClass the mapped class
   * @return the configuration object
   */
  public AnnotationConfiguration addAnnotatedClass(Class persistentClass) throws MappingException {
    XClass persistentXClass = reflectionManager.toXClass( persistentClass );
    try {
      annotatedClasses.add( persistentXClass );
      return this;
    }
    catch (MappingException me) {
View Full Code Here

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

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

    // First reading the access types for the persistent properties.
    readPersistentPropertiesAccess();

        // Retrieve classes and properties that are explicitly marked for auditing process by any superclass
        // of currently mapped entity or itself.
        XClass clazz = persistentPropertiesSource.getXClass();
        readAuditOverrides(clazz);

        // Adding all properties from the given class.
        addPropertiesFromClass(clazz);
  }
View Full Code Here

    private void readAuditOverrides(XClass clazz) {
        /* TODO: Code to remove with @Audited.auditParents - start. */
        Audited allClassAudited = clazz.getAnnotation(Audited.class);
        if (allClassAudited != null && allClassAudited.auditParents().length > 0) {
            for (Class c : allClassAudited.auditParents()) {
                XClass parentClass = reflectionManager.toXClass(c);
                checkSuperclass(clazz, parentClass);
                if (!overriddenNotAuditedClasses.contains(parentClass)) {
                    // If the class has not been marked as not audited by the subclass.
                    overriddenAuditedClasses.add(parentClass);
                }
            }
        }
        /* TODO: Code to remove with @Audited.auditParents - finish. */
        List<AuditOverride> auditOverrides = computeAuditOverrides(clazz);
        for (AuditOverride auditOverride : auditOverrides) {
            if (auditOverride.forClass() != void.class) {
                XClass overrideClass = reflectionManager.toXClass(auditOverride.forClass());
                checkSuperclass(clazz, overrideClass);
                String propertyName = auditOverride.name();
                if (!StringTools.isEmpty(propertyName)) {
                    // Override @Audited annotation on property level.
                    XProperty property = getProperty(overrideClass, propertyName);
                    if (auditOverride.isAudited()) {
                        if (!overriddenNotAuditedProperties.contains(property)) {
                            // If the property has not been marked as not audited by the subclass.
                            overriddenAuditedProperties.add(property);
                        }
                    } else {
                        if (!overriddenAuditedProperties.contains(property)) {
                            // If the property has not been marked as audited by the subclass.
                            overriddenNotAuditedProperties.add(property);
                        }
                    }
                } else {
                    // Override @Audited annotation on class level.
                    if (auditOverride.isAudited()) {
                        if (!overriddenNotAuditedClasses.contains(overrideClass)) {
                            // If the class has not been marked as not audited by the subclass.
                            overriddenAuditedClasses.add(overrideClass);
                        }
                    } else {
                        if (!overriddenAuditedClasses.contains(overrideClass)) {
                            // If the class has not been marked as audited by the subclass.
                            overriddenNotAuditedClasses.add(overrideClass);
                        }
                    }
                }
            }
        }
        XClass superclass = clazz.getSuperclass();
        if (!clazz.isInterface() && !Object.class.getName().equals(superclass.getName())) {
            readAuditOverrides(superclass);
        }
    }
View Full Code Here

    //look in the class
    addFromProperties(clazz.getDeclaredProperties("field"), "field", fieldAccessedPersistentProperties, allClassAudited);
    addFromProperties(clazz.getDeclaredProperties("property"), "property", propertyAccessedPersistentProperties, allClassAudited);
   
    if(allClassAudited != null || !auditedPropertiesHolder.isEmpty()) {
      XClass superclazz = clazz.getSuperclass();
      if (!clazz.isInterface() && !"java.lang.Object".equals(superclazz.getName())) {
        addPropertiesFromClass(superclazz);
      }
    }
  }
View Full Code Here

* @author Emmanuel Bernard
*/
public class DeepGenericsInheritance extends TestCase {
  public void test2StepsGenerics() throws Exception {
    JavaReflectionManager factory = new JavaReflectionManager();
    XClass subclass2 = factory.toXClass( Subclass2.class );
    XClass dummySubclass = factory.toXClass( DummySubclass.class );
    XClass superclass = subclass2.getSuperclass();
    XClass supersuperclass = superclass.getSuperclass();
    assertTrue( supersuperclass.getDeclaredProperties( "field" ).get( 1 ).isTypeResolved() );
    assertEquals( dummySubclass, supersuperclass.getDeclaredProperties( "field" ).get( 1 ).getType() );

  }
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.