Package org.hibernate.annotationfactory

Examples of org.hibernate.annotationfactory.AnnotationDescriptor


  private Annotation getMarkerAnnotation(
      Class<? extends Annotation> clazz, Element element, XMLContext.Default defaults
  ) {
    Element subelement = element == null ? null : element.element( annotationToXml.get( clazz ) );
    if ( subelement != null ) {
      return AnnotationFactory.create( new AnnotationDescriptor( clazz ) );
    }
    else if ( defaults.canUseJavaAnnotations() ) {
      //TODO wonder whether it should be excluded so that user can undone it
      return super.getAnnotation( clazz );
    }
View Full Code Here


          addSqlResultsetMappingIfNeeded( current, results );
        }
      }
    }
    if ( results.size() > 0 ) {
      AnnotationDescriptor ad = new AnnotationDescriptor( SqlResultSetMappings.class );
      ad.setValue( "value", results.toArray( new SqlResultSetMapping[ results.size() ] ) );
      return AnnotationFactory.create( ad );
    }
    else {
      return null;
    }
View Full Code Here

    List resultsetElementList = element.elements( "sql-result-set-mapping" );
    List<SqlResultSetMapping> resultsets = new ArrayList<SqlResultSetMapping>();
    Iterator it = resultsetElementList.listIterator();
    while ( it.hasNext() ) {
      Element subelement = (Element) it.next();
      AnnotationDescriptor ann = new AnnotationDescriptor( SqlResultSetMapping.class );
      copyStringAttribute( ann, subelement, "name", true );
      List<Element> elements = subelement.elements( "entity-result" );
      List<EntityResult> entityResults = new ArrayList<EntityResult>( elements.size() );
      for ( Element entityResult : elements ) {
        AnnotationDescriptor entityResultDescriptor = new AnnotationDescriptor( EntityResult.class );
        String clazzName = entityResult.attributeValue( "entity-class" );
        if ( clazzName == null ) {
          throw new AnnotationException( "<entity-result> without entity-class. " + SCHEMA_VALIDATION );
        }
        Class clazz = null;
        try {
          clazz = ReflectHelper.classForName(
              XMLContext.buildSafeClassName( clazzName, defaults ),
              EJB3OverridenAnnotationReader.class
          );
        }
        catch (ClassNotFoundException e) {
          throw new AnnotationException( "Unable to find entity-class: " + clazzName, e );
        }
        entityResultDescriptor.setValue( "entityClass", clazz );
        copyStringAttribute( entityResultDescriptor, entityResult, "discriminator-column", false );
        List<FieldResult> fieldResults = new ArrayList<FieldResult>();
        for ( Element fieldResult : (List<Element>) entityResult.elements( "field-result" ) ) {
          AnnotationDescriptor fieldResultDescriptor = new AnnotationDescriptor( FieldResult.class );
          copyStringAttribute( fieldResultDescriptor, fieldResult, "name", true );
          copyStringAttribute( fieldResultDescriptor, fieldResult, "column", true );
          fieldResults.add( (FieldResult) AnnotationFactory.create( fieldResultDescriptor ) );
        }
        entityResultDescriptor.setValue(
            "fields", fieldResults.toArray( new FieldResult[ fieldResults.size() ] )
        );
        entityResults.add( (EntityResult) AnnotationFactory.create( entityResultDescriptor ) );
      }
      ann.setValue( "entities", entityResults.toArray( new EntityResult[ entityResults.size() ] ) );

      elements = subelement.elements( "column-result" );
      List<ColumnResult> columnResults = new ArrayList<ColumnResult>( elements.size() );
      for ( Element columnResult : elements ) {
        AnnotationDescriptor columnResultDescriptor = new AnnotationDescriptor( ColumnResult.class );
        copyStringAttribute( columnResultDescriptor, columnResult, "name", true );
        columnResults.add( (ColumnResult) AnnotationFactory.create( columnResultDescriptor ) );
      }
      ann.setValue( "columns", columnResults.toArray( new ColumnResult[ columnResults.size() ] ) );
      //FIXME there is never such a result-class, get rid of it?
View Full Code Here

    //   defined in the Annotation interface that do not have a default
    //   value.
    // - You can ignore in the descriptor those Annotation elements that
    //   have default values, or you can set them to override their
    //   default values.
    AnnotationDescriptor descriptor = new AnnotationDescriptor( TestAnnotation.class );
    descriptor.setValue( "booleanElement", false );
    descriptor.setValue( "stringElement", "abc" );
    descriptor.setValue( "someOtherElement", "xyz" );

    // Step 2: create the annotation from its descriptor.
    TestAnnotation ann = AnnotationFactory.create( descriptor );

    assertFalse( ann.booleanElement() );
View Full Code Here

          addNamedQueryIfNeeded( current, queries );
        }
      }
    }
    if ( queries.size() > 0 ) {
      AnnotationDescriptor ad = new AnnotationDescriptor( NamedQueries.class );
      ad.setValue( "value", queries.toArray( new NamedQuery[ queries.size() ] ) );
      return AnnotationFactory.create( ad );
    }
    else {
      return null;
    }
View Full Code Here

          addNamedNativeQueryIfNeeded( current, queries );
        }
      }
    }
    if ( queries.size() > 0 ) {
      AnnotationDescriptor ad = new AnnotationDescriptor( NamedNativeQueries.class );
      ad.setValue( "value", queries.toArray( new NamedNativeQuery[ queries.size() ] ) );
      return AnnotationFactory.create( ad );
    }
    else {
      return null;
    }
View Full Code Here

        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 );
      ann.setValue( "query", queryElt.getTextTrim() );
      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() && super.isAnnotationPresent( TableGenerator.class ) ) {
      TableGenerator tableAnn = super.getAnnotation( 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

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.