Package org.hibernate.annotationfactory

Examples of org.hibernate.annotationfactory.AnnotationDescriptor


  private AnnotationProxy ann;
  private AnnotationDescriptor descriptor;

  public void setUp() {
    descriptor = new AnnotationDescriptor( TestAnnotation.class );
    descriptor.setValue( "stringElement", "x" );
    descriptor.setValue( "booleanElement", false );
    descriptor.setValue( "someOtherElement", "y" );
    ann = new AnnotationProxy( descriptor );
  }
View Full Code Here


    ann = new AnnotationProxy( descriptor );
  }

  public void testConstructionFailsIfYouDoNotAssignValuesToAllTheElementsWithoutADefault() {
    try {
      AnnotationDescriptor desc = new AnnotationDescriptor( TestAnnotation.class );
      desc.setValue( "stringElement", "x" );
      desc.setValue( "booleanElement", false );
      new AnnotationProxy( desc );
      fail();
    }
    catch (Exception e) {
      assertEquals( "No value provided for someOtherElement", e.getMessage() );
View Full Code Here

    }
  }

  public void testConstructionFailsIfYouDefineElementsThatAreNotInTheAnnotationInterface() {
    try {
      AnnotationDescriptor desc = new AnnotationDescriptor( Deprecated.class );
      desc.setValue( "wrongElement", "xxx" );
      new AnnotationProxy( desc );
      fail();
    }
    catch (Exception e) {
      assertTrue( e.getMessage().contains( "unknown elements" ) );
View Full Code Here

    assertEquals( ann.annotationType(), invoke( ann, "annotationType" ) );
    assertEquals( ann.toString(), invoke( ann, "toString" ) );
  }

  public void testThrowsARuntimeExceptionIfYouUseAnElementWhichIsNotInTheAnnotationInterface() {
    AnnotationDescriptor elements = new AnnotationDescriptor( TestAnnotation.class );
    elements.setValue( "anOddElement", "x" );
    try {
      new AnnotationProxy( elements );
      fail();
    }
    catch (RuntimeException e) {
View Full Code Here

    private void processEventAnnotations(List<Annotation> annotationList, XMLContext.Default defaults) {
    boolean eventElement = false;
    for ( Element element : elementsForProperty ) {
      String elementName = element.getName();
      if ( "pre-persist".equals( elementName ) ) {
        AnnotationDescriptor ad = new AnnotationDescriptor( PrePersist.class );
        annotationList.add( AnnotationFactory.create( ad ) );
        eventElement = true;
      }
      else if ( "pre-remove".equals( elementName ) ) {
        AnnotationDescriptor ad = new AnnotationDescriptor( PreRemove.class );
        annotationList.add( AnnotationFactory.create( ad ) );
        eventElement = true;
      }
      else if ( "pre-update".equals( elementName ) ) {
        AnnotationDescriptor ad = new AnnotationDescriptor( PreUpdate.class );
        annotationList.add( AnnotationFactory.create( ad ) );
        eventElement = true;
      }
      else if ( "post-persist".equals( elementName ) ) {
        AnnotationDescriptor ad = new AnnotationDescriptor( PostPersist.class );
        annotationList.add( AnnotationFactory.create( ad ) );
        eventElement = true;
      }
      else if ( "post-remove".equals( elementName ) ) {
        AnnotationDescriptor ad = new AnnotationDescriptor( PostRemove.class );
        annotationList.add( AnnotationFactory.create( ad ) );
        eventElement = true;
      }
      else if ( "post-update".equals( elementName ) ) {
        AnnotationDescriptor ad = new AnnotationDescriptor( PostUpdate.class );
        annotationList.add( AnnotationFactory.create( ad ) );
        eventElement = true;
      }
      else if ( "post-load".equals( elementName ) ) {
        AnnotationDescriptor ad = new AnnotationDescriptor( PostLoad.class );
        annotationList.add( AnnotationFactory.create( ad ) );
        eventElement = true;
      }
    }
    if ( ! eventElement && defaults.canUseJavaAnnotations() ) {
View Full Code Here

          throw new AnnotationException(
              "Unable to find " + element.getPath() + ".class: " + className, e
          );
        }
      }
      AnnotationDescriptor ad = new AnnotationDescriptor( EntityListeners.class );
      ad.setValue( "value", entityListenerClasses.toArray( new Class[ entityListenerClasses.size() ] ) );
      return AnnotationFactory.create( ad );
    }
    else if ( defaults.canUseJavaAnnotations() ) {
      return super.getAnnotation( EntityListeners.class );
    }
View Full Code Here

        );
    final Class<JoinTable> annotationType = JoinTable.class;
    if ( defaultToJoinTable
        && ( StringHelper.isNotEmpty( defaults.getCatalog() )
          || StringHelper.isNotEmpty( defaults.getSchema() ) ) ) {
      AnnotationDescriptor ad = new AnnotationDescriptor( annotationType );
      if ( defaults.canUseJavaAnnotations() ) {
        JoinTable table = super.getAnnotation( annotationType );
        if ( table != null ) {
          ad.setValue( "name", table.name() );
          ad.setValue( "schema", table.schema() );
          ad.setValue( "catalog", table.catalog() );
          ad.setValue( "uniqueConstraints", table.uniqueConstraints() );
          ad.setValue( "joinColumns", table.joinColumns() );
          ad.setValue( "inverseJoinColumns", table.inverseJoinColumns() );
        }
      }
      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 );
    }
    else if ( defaults.canUseJavaAnnotations() ) {
      return super.getAnnotation( annotationType );
View Full Code Here

  private void getJoinTable(List<Annotation> annotationList, Element tree, XMLContext.Default defaults) {
    Element subelement = tree == null ? null : tree.element( "join-table" );
    final Class<JoinTable> annotationType = JoinTable.class;
    if ( subelement != null ) {
      //ignore java annotation, an element is defined
      AnnotationDescriptor annotation = new AnnotationDescriptor( annotationType );
      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 );
      annotation.setValue( "joinColumns", getJoinColumns( subelement, false ) );
      annotation.setValue( "inverseJoinColumns", getJoinColumns( subelement, true ) );
      annotationList.add( AnnotationFactory.create( annotation ) );
    }
  }
View Full Code Here

      Class<? extends Annotation> annotationType, List<Annotation> annotationList, XMLContext.Default defaults
  ) {
    String xmlName = annotationToXml.get( annotationType );
    for ( Element element : elementsForProperty ) {
      if ( xmlName.equals( element.getName() ) ) {
        AnnotationDescriptor ad = new AnnotationDescriptor( annotationType );
        String className = element.attributeValue( "target-entity" );
        if ( className != null ) {
          Class clazz;
          try {
            clazz = ReflectHelper.classForName(
                XMLContext.buildSafeClassName( className, defaults ),
                this.getClass()
            );
          }
          catch (ClassNotFoundException e) {
            throw new AnnotationException(
                "Unable to find " + element.getPath() + "target-entity: " + className, e
            );
          }
          ad.setValue( "targetEntity", clazz );
        }
        getFetchType( ad, element );
        getCascades( ad, element, defaults );
        getJoinTable( annotationList, element, defaults );
        buildJoinColumns( annotationList, element, defaults );
View Full Code Here

  private void getOrderBy(List<Annotation> annotationList, Element element, XMLContext.Default defaults) {
    Element subelement = element != null ? element.element( "order-by" ) : null;
    if ( subelement != null ) {
      String orderByString = subelement.getTextTrim();
      AnnotationDescriptor ad = new AnnotationDescriptor( OrderBy.class );
      if ( StringHelper.isNotEmpty( orderByString ) ) ad.setValue( "value", orderByString );
      annotationList.add( 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.