Package org.hibernate.annotationfactory

Examples of org.hibernate.annotationfactory.AnnotationDescriptor


  }

  private DiscriminatorColumn getDiscriminatorColumn(Element tree, XMLContext.Default defaults) {
    Element element = tree != null ? tree.element( "discriminator-column" ) : null;
    if ( element != null ) {
      AnnotationDescriptor ad = new AnnotationDescriptor( DiscriminatorColumn.class );
      copyStringAttribute( ad, element, "name", false );
      copyStringAttribute( ad, element, "column-definition", false );
      String value = element.attributeValue( "discriminator-type" );
      DiscriminatorType type = DiscriminatorType.STRING;
      if ( value != null ) {
        if ( "STRING".equals( value ) ) {
          type = DiscriminatorType.STRING;
        }
        else if ( "CHAR".equals( value ) ) {
          type = DiscriminatorType.CHAR;
        }
        else if ( "INTEGER".equals( value ) ) {
          type = DiscriminatorType.INTEGER;
        }
        else {
          throw new AnnotationException(
              "Unknown DiscrimiatorType in XML: " + value + " (" + SCHEMA_VALIDATION + ")"
          );
        }
      }
      ad.setValue( "discriminatorType", type );
      copyIntegerAttribute( ad, element, "length" );
      return AnnotationFactory.create( ad );
    }
    else if ( defaults.canUseJavaAnnotations() ) {
      return super.getAnnotation( DiscriminatorColumn.class );
View Full Code Here


  }

  private DiscriminatorValue getDiscriminatorValue(Element tree, XMLContext.Default defaults) {
    Element element = tree != null ? tree.element( "discriminator-value" ) : null;
    if ( element != null ) {
      AnnotationDescriptor ad = new AnnotationDescriptor( DiscriminatorValue.class );
      copyStringElement( element, ad, "value" );
      return AnnotationFactory.create( ad );
    }
    else if ( defaults.canUseJavaAnnotations() ) {
      return super.getAnnotation( DiscriminatorValue.class );
View Full Code Here

  }

  private Inheritance getInheritance(Element tree, XMLContext.Default defaults) {
    Element element = tree != null ? tree.element( "inheritance" ) : null;
    if ( element != null ) {
      AnnotationDescriptor ad = new AnnotationDescriptor( Inheritance.class );
      Attribute attr = element.attribute( "strategy" );
      InheritanceType strategy = InheritanceType.SINGLE_TABLE;
      if ( attr != null ) {
        String value = attr.getValue();
        if ( "SINGLE_TABLE".equals( value ) ) {
          strategy = InheritanceType.SINGLE_TABLE;
        }
        else if ( "JOINED".equals( value ) ) {
          strategy = InheritanceType.JOINED;
        }
        else if ( "TABLE_PER_CLASS".equals( value ) ) {
          strategy = InheritanceType.TABLE_PER_CLASS;
        }
        else {
          throw new AnnotationException(
              "Unknown InheritanceType in XML: " + value + " (" + SCHEMA_VALIDATION + ")"
          );
        }
      }
      ad.setValue( "strategy", strategy );
      return AnnotationFactory.create( ad );
    }
    else if ( defaults.canUseJavaAnnotations() ) {
      return super.getAnnotation( Inheritance.class );
    }
View Full Code Here

  private IdClass getIdClass(Element tree, XMLContext.Default defaults) {
    Element element = tree == null ? null : tree.element( "id-class" );
    if ( element != null ) {
      Attribute attr = element.attribute( "class" );
      if ( attr != null ) {
        AnnotationDescriptor ad = new AnnotationDescriptor( IdClass.class );
        Class clazz = null;
        try {
          clazz = ReflectHelper.classForName(
              XMLContext.buildSafeClassName( attr.getValue(), defaults ),
              this.getClass()
          );
        }
        catch (ClassNotFoundException e) {
          throw new AnnotationException( "Unable to find id-class: " + attr.getValue(), e );
        }
        ad.setValue( "value", clazz );
        return AnnotationFactory.create( ad );
      }
      else {
        throw new AnnotationException( "id-class without class. " + SCHEMA_VALIDATION );
      }
View Full Code Here

        PrimaryKeyJoinColumns annotations = super.getAnnotation( PrimaryKeyJoinColumns.class );
        columns = annotations != null ? annotations.value() : columns;
      }
    }
    if ( columns.length > 0 ) {
      AnnotationDescriptor ad = new AnnotationDescriptor( PrimaryKeyJoinColumns.class );
      ad.setValue( "value", columns );
      return AnnotationFactory.create( ad );
    }
    else {
      return null;
    }
View Full Code Here

    if ( tree == null ) {
      return defaults.canUseJavaAnnotations() ? super.getAnnotation( Entity.class ) : null;
    }
    else {
      if ( "entity".equals( tree.getName() ) ) {
        AnnotationDescriptor entity = new AnnotationDescriptor( Entity.class );
        copyStringAttribute( entity, tree, "name", false );
        if ( defaults.canUseJavaAnnotations()
            && StringHelper.isEmpty( (String) entity.valueOf( "name" ) ) ) {
          Entity javaAnn = super.getAnnotation( Entity.class );
          if ( javaAnn != null ) entity.setValue( "name", javaAnn.name() );
        }
        return AnnotationFactory.create( entity );
      }
      else {
        return null; //this is not an entity
View Full Code Here

    if ( tree == null ) {
      return defaults.canUseJavaAnnotations() ? super.getAnnotation( MappedSuperclass.class ) : null;
    }
    else {
      if ( "mapped-superclass".equals( tree.getName() ) ) {
        AnnotationDescriptor entity = new AnnotationDescriptor( MappedSuperclass.class );
        return AnnotationFactory.create( entity );
      }
      else {
        return null; //this is not an entity
      }
View Full Code Here

    if ( tree == null ) {
      return defaults.canUseJavaAnnotations() ? super.getAnnotation( Embeddable.class ) : null;
    }
    else {
      if ( "embeddable".equals( tree.getName() ) ) {
        AnnotationDescriptor entity = new AnnotationDescriptor( Embeddable.class );
        return AnnotationFactory.create( entity );
      }
      else {
        return null; //this is not an entity
      }
View Full Code Here

    Element subelement = tree == null ? null : tree.element( "table" );
    if ( subelement == null ) {
      //no element but might have some default or some annotation
      if ( StringHelper.isNotEmpty( defaults.getCatalog() )
          || StringHelper.isNotEmpty( defaults.getSchema() ) ) {
        AnnotationDescriptor annotation = new AnnotationDescriptor( Table.class );
        if ( defaults.canUseJavaAnnotations() ) {
          Table table = super.getAnnotation( Table.class );
          if ( table != null ) {
            annotation.setValue( "name", table.name() );
            annotation.setValue( "schema", table.schema() );
            annotation.setValue( "catalog", table.catalog() );
            annotation.setValue( "uniqueConstraints", table.uniqueConstraints() );
          }
        }
        if ( StringHelper.isEmpty( (String) annotation.valueOf( "schema" ) )
            && StringHelper.isNotEmpty( defaults.getSchema() ) ) {
          annotation.setValue( "schema", defaults.getSchema() );
        }
        if ( StringHelper.isEmpty( (String) annotation.valueOf( "catalog" ) )
            && StringHelper.isNotEmpty( defaults.getCatalog() ) ) {
          annotation.setValue( "catalog", defaults.getCatalog() );
        }
        return AnnotationFactory.create( annotation );
      }
      else if ( defaults.canUseJavaAnnotations() ) {
        return super.getAnnotation( Table.class );
      }
      else {
        return null;
      }
    }
    else {
      //ignore java annotation, an element is defined
      AnnotationDescriptor annotation = new AnnotationDescriptor( Table.class );
      copyStringAttribute( annotation, subelement, "name", false );
      copyStringAttribute( annotation, subelement, "catalog", false );
      if ( StringHelper.isNotEmpty( defaults.getCatalog() )
          && StringHelper.isEmpty( (String) annotation.valueOf( "catalog" ) ) ) {
        annotation.setValue( "catalog", defaults.getCatalog() );
      }
      copyStringAttribute( annotation, subelement, "schema", false );
      if ( StringHelper.isNotEmpty( defaults.getSchema() )
          && StringHelper.isEmpty( (String) annotation.valueOf( "schema" ) ) ) {
        annotation.setValue( "schema", defaults.getSchema() );
      }
      buildUniqueConstraints( annotation, subelement );
      return AnnotationFactory.create( annotation );
    }
  }
View Full Code Here

    List<Element> elements = tree == null ?
        new ArrayList<Element>() :
        (List<Element>) tree.elements( "secondary-table" );
    List<SecondaryTable> secondaryTables = new ArrayList<SecondaryTable>( 3 );
    for ( Element element : elements ) {
      AnnotationDescriptor annotation = new AnnotationDescriptor( SecondaryTable.class );
      copyStringAttribute( annotation, element, "name", false );
      copyStringAttribute( annotation, element, "catalog", false );
      if ( StringHelper.isNotEmpty( defaults.getCatalog() )
          && StringHelper.isEmpty( (String) annotation.valueOf( "catalog" ) ) ) {
        annotation.setValue( "catalog", defaults.getCatalog() );
      }
      copyStringAttribute( annotation, element, "schema", false );
      if ( StringHelper.isNotEmpty( defaults.getSchema() )
          && StringHelper.isEmpty( (String) annotation.valueOf( "schema" ) ) ) {
        annotation.setValue( "schema", defaults.getSchema() );
      }
      buildUniqueConstraints( annotation, element );
      annotation.setValue( "pkJoinColumns", buildPrimaryKeyJoinColumns( element ) );
      secondaryTables.add( (SecondaryTable) AnnotationFactory.create( annotation ) );
    }
    /*
     * You can't have both secondary table in XML and Java,
     * since there would be no way to "remove" a secondary table
     */
    if ( secondaryTables.size() == 0 && defaults.canUseJavaAnnotations() ) {
      SecondaryTable secTableAnn = super.getAnnotation( SecondaryTable.class );
      overridesDefaultInSecondaryTable( secTableAnn, defaults, secondaryTables );
      SecondaryTables secTablesAnn = super.getAnnotation( SecondaryTables.class );
      if ( secTablesAnn != null ) {
        for ( SecondaryTable table : secTablesAnn.value() ) {
          overridesDefaultInSecondaryTable( table, defaults, secondaryTables );
        }
      }
    }
    if ( secondaryTables.size() > 0 ) {
      AnnotationDescriptor descriptor = new AnnotationDescriptor( SecondaryTables.class );
      descriptor.setValue( "value", secondaryTables.toArray( new SecondaryTable[secondaryTables.size()] ) );
      return AnnotationFactory.create( descriptor );
    }
    else {
      return null;
    }
View Full Code Here

TOP

Related Classes of org.hibernate.annotationfactory.AnnotationDescriptor

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.