Package org.hibernate.annotations.common.annotationfactory

Examples of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor


        element.elements( "named-query" );
    List namedQueries = new ArrayList();
    Iterator it = namedQueryElementList.listIterator();
    while ( it.hasNext() ) {
      Element subelement = (Element) it.next();
      AnnotationDescriptor ann = new AnnotationDescriptor(
          isNative ? NamedNativeQuery.class : NamedQuery.class
      );
      copyStringAttribute( ann, subelement, "name", false );
      Element queryElt = subelement.element( "query" );
      if ( queryElt == null ) {
        throw new AnnotationException( "No <query> element found." + SCHEMA_VALIDATION );
      }
      copyStringElement( queryElt, ann, "query" );
      List<Element> elements = subelement.elements( "hint" );
      List<QueryHint> queryHints = new ArrayList<QueryHint>( elements.size() );
      for ( Element hint : elements ) {
        AnnotationDescriptor hintDescriptor = new AnnotationDescriptor( QueryHint.class );
        String value = hint.attributeValue( "name" );
        if ( value == null ) {
          throw new AnnotationException( "<hint> without name. " + SCHEMA_VALIDATION );
        }
        hintDescriptor.setValue( "name", value );
        value = hint.attributeValue( "value" );
        if ( value == null ) {
          throw new AnnotationException( "<hint> without value. " + SCHEMA_VALIDATION );
        }
        hintDescriptor.setValue( "value", value );
        queryHints.add( (QueryHint) AnnotationFactory.create( hintDescriptor ) );
      }
      ann.setValue( "hints", queryHints.toArray( new QueryHint[queryHints.size()] ) );
      String clazzName = subelement.attributeValue( "result-class" );
      if ( StringHelper.isNotEmpty( clazzName ) ) {
View Full Code Here


    }
    else if ( defaults.canUseJavaAnnotations() && isJavaAnnotationPresent( TableGenerator.class ) ) {
      TableGenerator tableAnn = getJavaAnnotation( TableGenerator.class );
      if ( StringHelper.isNotEmpty( defaults.getSchema() )
          || StringHelper.isNotEmpty( defaults.getCatalog() ) ) {
        AnnotationDescriptor annotation = new AnnotationDescriptor( TableGenerator.class );
        annotation.setValue( "name", tableAnn.name() );
        annotation.setValue( "table", tableAnn.table() );
        annotation.setValue( "catalog", tableAnn.table() );
        if ( StringHelper.isEmpty( (String) annotation.valueOf( "catalog" ) )
            && StringHelper.isNotEmpty( defaults.getCatalog() ) ) {
          annotation.setValue( "catalog", defaults.getCatalog() );
        }
        annotation.setValue( "schema", tableAnn.table() );
        if ( StringHelper.isEmpty( (String) annotation.valueOf( "schema" ) )
            && StringHelper.isNotEmpty( defaults.getSchema() ) ) {
          annotation.setValue( "catalog", defaults.getSchema() );
        }
        annotation.setValue( "pkColumnName", tableAnn.pkColumnName() );
        annotation.setValue( "valueColumnName", tableAnn.valueColumnName() );
        annotation.setValue( "pkColumnValue", tableAnn.pkColumnValue() );
        annotation.setValue( "initialValue", tableAnn.initialValue() );
        annotation.setValue( "allocationSize", tableAnn.allocationSize() );
        annotation.setValue( "uniqueConstraints", tableAnn.uniqueConstraints() );
        return AnnotationFactory.create( annotation );
      }
      else {
        return tableAnn;
      }
View Full Code Here

      return null;
    }
  }

  public static TableGenerator buildTableGeneratorAnnotation(Element element, XMLContext.Default defaults) {
    AnnotationDescriptor ad = new AnnotationDescriptor( TableGenerator.class );
    copyStringAttribute( ad, element, "name", false );
    copyStringAttribute( ad, element, "table", false );
    copyStringAttribute( ad, element, "catalog", false );
    copyStringAttribute( ad, element, "schema", false );
    copyStringAttribute( ad, element, "pk-column-name", false );
    copyStringAttribute( ad, element, "value-column-name", false );
    copyStringAttribute( ad, element, "pk-column-value", false );
    copyIntegerAttribute( ad, element, "initial-value" );
    copyIntegerAttribute( ad, element, "allocation-size" );
    buildUniqueConstraints( ad, element );
    if ( StringHelper.isEmpty( (String) ad.valueOf( "schema" ) )
        && StringHelper.isNotEmpty( defaults.getSchema() ) ) {
      ad.setValue( "schema", defaults.getSchema() );
    }
    if ( StringHelper.isEmpty( (String) ad.valueOf( "catalog" ) )
        && StringHelper.isNotEmpty( defaults.getCatalog() ) ) {
      ad.setValue( "catalog", defaults.getCatalog() );
    }
    return AnnotationFactory.create( ad );
  }
View Full Code Here

    }
  }

  public static SequenceGenerator buildSequenceGeneratorAnnotation(Element element) {
    if ( element != null ) {
      AnnotationDescriptor ad = new AnnotationDescriptor( SequenceGenerator.class );
      copyStringAttribute( ad, element, "name", false );
      copyStringAttribute( ad, element, "sequence-name", false );
      copyIntegerAttribute( ad, element, "initial-value" );
      copyIntegerAttribute( ad, element, "allocation-size" );
      return AnnotationFactory.create( ad );
View Full Code Here

  }

  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 getJavaAnnotation( 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 getJavaAnnotation( 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 getJavaAnnotation( 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;
        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

          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() ? getJavaAnnotation( 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 = getJavaAnnotation( Entity.class );
          if ( javaAnn != null ) {
            entity.setValue( "name", javaAnn.name() );
          }
        }
        return AnnotationFactory.create( entity );
      }
      else {
View Full Code Here

TOP

Related Classes of org.hibernate.annotations.common.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.