Package org.hibernate.annotations.common.annotationfactory

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


    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 = getJavaAnnotation( SecondaryTable.class );
      overridesDefaultInSecondaryTable( secTableAnn, defaults, secondaryTables );
      SecondaryTables secTablesAnn = getJavaAnnotation( 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


  ) {
    if ( secTableAnn != null ) {
      //handle default values
      if ( StringHelper.isNotEmpty( defaults.getCatalog() )
          || StringHelper.isNotEmpty( defaults.getSchema() ) ) {
        AnnotationDescriptor annotation = new AnnotationDescriptor( SecondaryTable.class );
        annotation.setValue( "name", secTableAnn.name() );
        annotation.setValue( "schema", secTableAnn.schema() );
        annotation.setValue( "catalog", secTableAnn.catalog() );
        annotation.setValue( "uniqueConstraints", secTableAnn.uniqueConstraints() );
        annotation.setValue( "pkJoinColumns", secTableAnn.pkJoinColumns() );
        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() );
        }
        secondaryTables.add( (SecondaryTable) AnnotationFactory.create( annotation ) );
      }
      else {
        secondaryTables.add( secTableAnn );
View Full Code Here

      Iterator it = columnNamesElements.listIterator();
      while ( it.hasNext() ) {
        Element columnNameElt = (Element) it.next();
        columnNames[columnNameIndex++] = columnNameElt.getTextTrim();
      }
      AnnotationDescriptor ucAnn = new AnnotationDescriptor( UniqueConstraint.class );
      copyStringAttribute( ucAnn, subelement, "name", false );
      ucAnn.setValue( "columnNames", columnNames );
      uniqueConstraints[ucIndex++] = AnnotationFactory.create( ucAnn );
    }
    annotation.setValue( "uniqueConstraints", uniqueConstraints );
  }
View Full Code Here

    PrimaryKeyJoinColumn[] pkJoinColumns = new PrimaryKeyJoinColumn[pkJoinColumnElementList.size()];
    int index = 0;
    Iterator pkIt = pkJoinColumnElementList.listIterator();
    while ( pkIt.hasNext() ) {
      Element subelement = (Element) pkIt.next();
      AnnotationDescriptor pkAnn = new AnnotationDescriptor( PrimaryKeyJoinColumn.class );
      copyStringAttribute( pkAnn, subelement, "name", false );
      copyStringAttribute( pkAnn, subelement, "referenced-column-name", false );
      copyStringAttribute( pkAnn, subelement, "column-definition", false );
      pkJoinColumns[index++] = AnnotationFactory.create( pkAnn );
    }
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 getJavaAnnotation( 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 = getJavaAnnotation( 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 getJavaAnnotation( annotationType );
View Full Code Here

    final Class<JoinTable> annotationType = JoinTable.class;
    if ( subelement == null ) {
      return 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 ) );
    return 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 );
        addTargetClass( element, ad, "target-entity", defaults );
        getFetchType( ad, element );
        getCascades( ad, element, defaults );
        getJoinTable( annotationList, element, defaults );
        buildJoinColumns( annotationList, element );
View Full Code Here

  }

  private void buildMapKeyJoinColumns(List<Annotation> annotationList, Element element) {
    MapKeyJoinColumn[] joinColumns = getMapKeyJoinColumns( element );
    if ( joinColumns.length > 0 ) {
      AnnotationDescriptor ad = new AnnotationDescriptor( MapKeyJoinColumns.class );
      ad.setValue( "value", joinColumns );
      annotationList.add( AnnotationFactory.create( ad ) );
    }
  }
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.