Examples of Formula


Examples of org.hibernate.annotations.Formula

    joinColumns = buildExplicitJoinColumns(property, inferredData);


    if ( property.isAnnotationPresent( Column.class ) || property.isAnnotationPresent( Formula.class ) ) {
      Column ann = property.getAnnotation( Column.class );
      Formula formulaAnn = property.getAnnotation( Formula.class );
      columns = Ejb3Column.buildColumnFromAnnotation(
          new Column[] { ann }, formulaAnn, nullability, propertyHolder, inferredData,
          entityBinder.getSecondaryTables(), mappings
      );
    }
View Full Code Here

Examples of org.hibernate.annotations.Formula

        );
        if ( property.isAnnotationPresent( Column.class ) || property.isAnnotationPresent(
            Formula.class
        ) ) {
          Column ann = property.getAnnotation( Column.class );
          Formula formulaAnn = property.getAnnotation( Formula.class );
          elementColumns = Ejb3Column.buildColumnFromAnnotation(
              new Column[] { ann },
              formulaAnn,
              nullability,
              propertyHolder,
View Full Code Here

Examples of org.hibernate.annotations.Formula

        );
      }
    }
    if ( property.isAnnotationPresent( Column.class ) || property.isAnnotationPresent( Formula.class ) ) {
      Column ann = property.getAnnotation( Column.class );
      Formula formulaAnn = property.getAnnotation( Formula.class );
      columns = Ejb3Column.buildColumnFromAnnotation(
          new Column[] { ann }, formulaAnn, nullability, propertyHolder, inferredData,
          entityBinder.getSecondaryTables(), mappings
      );
    }
    else if ( property.isAnnotationPresent( Columns.class ) ) {
      Columns anns = property.getAnnotation( Columns.class );
      columns = Ejb3Column.buildColumnFromAnnotation(
          anns.columns(), null, nullability, propertyHolder, inferredData, entityBinder.getSecondaryTables(),
          mappings
      );
    }

    //set default values if needed
    if ( joinColumns == null &&
        ( property.isAnnotationPresent( ManyToOne.class )
            || property.isAnnotationPresent( OneToOne.class ) )
        ) {
      if ( property.isAnnotationPresent( JoinTable.class ) ) {
        JoinTable joinTableAnn = property.getAnnotation( JoinTable.class );
        joinColumns = Ejb3JoinColumn.buildJoinColumns(
            joinTableAnn.inverseJoinColumns(), null, entityBinder.getSecondaryTables(),
            propertyHolder, inferredData.getPropertyName(), mappings
        );
        if ( StringHelper.isEmpty( joinTableAnn.name() ) ) {
          throw new AnnotationException(
              "JoinTable.name() on a @ToOne association has to be explicit: "
                  + StringHelper.qualify( propertyHolder.getPath(), inferredData.getPropertyName() )
          );
        }
      }
      else {
        OneToOne oneToOneAnn = property.getAnnotation( OneToOne.class );
        String mappedBy = oneToOneAnn != null ?
            oneToOneAnn.mappedBy() :
            null;
        joinColumns = Ejb3JoinColumn.buildJoinColumns(
            (JoinColumn[]) null,
            mappedBy, entityBinder.getSecondaryTables(),
            propertyHolder, inferredData.getPropertyName(), mappings
        );
      }
    }
    else if ( joinColumns == null &&
        ( property.isAnnotationPresent( OneToMany.class )
            || property.isAnnotationPresent( CollectionOfElements.class ) ) ) {
      OneToMany oneToMany = property.getAnnotation( OneToMany.class );
      String mappedBy = oneToMany != null ?
          oneToMany.mappedBy() :
          "";
      joinColumns = Ejb3JoinColumn.buildJoinColumns(
          (JoinColumn[]) null,
          mappedBy, entityBinder.getSecondaryTables(),
          propertyHolder, inferredData.getPropertyName(), mappings
      );
    }
    else if ( joinColumns == null && property.isAnnotationPresent( org.hibernate.annotations.Any.class ) ) {
      throw new AnnotationException( "@Any requires an explicit @JoinColumn(s): "
          + StringHelper.qualify( propertyHolder.getPath(), property.getName() ) );
    }
    if ( columns == null && !property.isAnnotationPresent( ManyToMany.class ) ) {
      //useful for collection of embedded elements
      columns = Ejb3Column.buildColumnFromAnnotation(
          null, null, nullability, propertyHolder, inferredData, entityBinder.getSecondaryTables(), mappings
      );
    }

    if ( nullability == Nullability.FORCED_NOT_NULL ) {
      //force columns to not null
      for (Ejb3Column col : columns) {
        col.forceNotNull();
      }
    }

    final XClass returnedClass = inferredData.getClassOrElement();
    if ( !entityBinder.isIgnoreIdAnnotations() &&
        ( property.isAnnotationPresent( Id.class )
            || property.isAnnotationPresent( EmbeddedId.class ) ) ) {
      if ( isIdentifierMapper ) {
        throw new AnnotationException(
            "@IdClass class should not have @Id nor @EmbeddedId properties"
        );
      }
      log.debug( "{} is an id", inferredData.getPropertyName() );
      //clone classGenerator and override with local values
      HashMap<String, IdGenerator> localGenerators = (HashMap<String, IdGenerator>) classGenerators.clone();
      localGenerators.putAll( buildLocalGenerators( property, mappings ) );

      //manage composite related metadata
      //guess if its a component and find id data access (property, field etc)
      final boolean isComponent = returnedClass.isAnnotationPresent( Embeddable.class )
          || property.isAnnotationPresent( EmbeddedId.class );
      boolean propertyAnnotated = entityBinder.isPropertyAnnotated( returnedClass );
      String propertyAccessor = entityBinder.getPropertyAccessor( returnedClass );
      //if ( isComponent && embeddableAnn != null && embeddableAnn.access() == AccessType.FIELD ) propertyAccess = false;

      GeneratedValue generatedValue = property.getAnnotation( GeneratedValue.class );
      String generatorType = generatedValue != null ?
          generatorType( generatedValue.strategy() ) :
          "assigned";
      String generator = generatedValue != null ?
          generatedValue.generator() :
          BinderHelper.ANNOTATION_STRING_DEFAULT;
      if ( isComponent ) generatorType = "assigned"; //a component must not have any generator
           
      bindId(
          generatorType,
          generator,
          inferredData,
          columns,
          propertyHolder,
          localGenerators,
          isComponent,
          propertyAnnotated,
          propertyAccessor, entityBinder,
          false,
          isIdentifierMapper, mappings
      );
           
      log.debug(
          "Bind {} on {}", ( isComponent ? "@EmbeddedId" : "@Id" ), inferredData.getPropertyName()
      );
    }
    else if ( property.isAnnotationPresent( Version.class ) ) {
      if ( isIdentifierMapper ) {
        throw new AnnotationException(
            "@IdClass class should not have @Version property"
        );
      }
      if ( !( propertyHolder.getPersistentClass() instanceof RootClass ) ) {
        throw new AnnotationException(
            "Unable to define/override @Version on a subclass: "
                + propertyHolder.getEntityName()
        );
      }
      if ( ! propertyHolder.isEntity() ) {
        throw new AnnotationException(
            "Unable to define @Version on an embedded class: "
                + propertyHolder.getEntityName()
        );
      }
      log.debug( "{} is a version property", inferredData.getPropertyName() );
      RootClass rootClass = (RootClass) propertyHolder.getPersistentClass();
      PropertyBinder propBinder = new PropertyBinder();
      propBinder.setName( inferredData.getPropertyName() );
      propBinder.setReturnedClassName( inferredData.getTypeName() );
      propBinder.setLazy( false );
      propBinder.setPropertyAccessorName( inferredData.getDefaultAccess() );
      propBinder.setColumns( columns );
      propBinder.setHolder( propertyHolder ); //PropertyHolderBuilder.buildPropertyHolder(rootClass)
      propBinder.setProperty( property );
      propBinder.setReturnedClass( inferredData.getPropertyClass() );

      propBinder.setMappings( mappings );
      Property prop = propBinder.bind();
      rootClass.setVersion( prop );
      SimpleValue simpleValue = (SimpleValue) prop.getValue();
      if ( !simpleValue.isTypeSpecified() ) simpleValue.setTypeName( "integer" );
      simpleValue.setNullValue( "undefined" );
      rootClass.setOptimisticLockMode( Versioning.OPTIMISTIC_LOCK_VERSION );
      log.debug(
          "Version name: {}, unsavedValue: {}", rootClass.getVersion().getName(),
          ( (SimpleValue) rootClass.getVersion().getValue() ).getNullValue()
      );
    }
    else if ( property.isAnnotationPresent( ManyToOne.class ) ) {
      ManyToOne ann = property.getAnnotation( ManyToOne.class );

      //check validity
      if ( property.isAnnotationPresent( Column.class )
          || property.isAnnotationPresent( Columns.class ) ) {
        throw new AnnotationException( "@Column(s) not allowed on a @ManyToOne property: "
            + StringHelper.qualify( propertyHolder.getPath(), inferredData.getPropertyName() ) );
      }

      Cascade hibernateCascade = property.getAnnotation( Cascade.class );
      NotFound notFound = property.getAnnotation( NotFound.class );
      boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE );
      OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class );
      boolean onDeleteCascade = onDeleteAnn != null && OnDeleteAction.CASCADE.equals( onDeleteAnn.action() );
      JoinTable assocTable = property.getAnnotation( JoinTable.class );
      if ( assocTable != null ) {
        Join join = propertyHolder.addJoin( assocTable, false );
        for (Ejb3JoinColumn joinColumn : joinColumns) {
          joinColumn.setSecondaryTableName( join.getTable().getName() );
        }
      }
      bindManyToOne(
          getCascadeStrategy( ann.cascade(), hibernateCascade ),
          joinColumns,
          ann.optional(),
          ignoreNotFound, onDeleteCascade,
          mappings.getReflectionManager().toXClass( ann.targetEntity() ),
          propertyHolder,
          inferredData, false, isIdentifierMapper, inSecondPass, mappings
      );
    }
    else if ( property.isAnnotationPresent( OneToOne.class ) ) {
      OneToOne ann = property.getAnnotation( OneToOne.class );

      //check validity
      if ( property.isAnnotationPresent( Column.class )
          || property.isAnnotationPresent( Columns.class ) ) {
        throw new AnnotationException( "@Column(s) not allowed on a @OneToOne property: "
            + StringHelper.qualify( propertyHolder.getPath(), inferredData.getPropertyName() ) );
      }

      //FIXME support a proper PKJCs
      boolean trueOneToOne = property.isAnnotationPresent( PrimaryKeyJoinColumn.class )
          || property.isAnnotationPresent( PrimaryKeyJoinColumns.class );
      Cascade hibernateCascade = property.getAnnotation( Cascade.class );
      NotFound notFound = property.getAnnotation( NotFound.class );
      boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE );
      OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class );
      boolean onDeleteCascade = onDeleteAnn != null && OnDeleteAction.CASCADE.equals( onDeleteAnn.action() );
      JoinTable assocTable = property.getAnnotation( JoinTable.class );
      if ( assocTable != null ) {
        Join join = propertyHolder.addJoin( assocTable, false );
        for (Ejb3JoinColumn joinColumn : joinColumns) {
          joinColumn.setSecondaryTableName( join.getTable().getName() );
        }
      }
      bindOneToOne(
          getCascadeStrategy( ann.cascade(), hibernateCascade ),
          joinColumns,
          ann.optional(),
          getFetchMode( ann.fetch() ),
          ignoreNotFound, onDeleteCascade,
          mappings.getReflectionManager().toXClass( ann.targetEntity() ),
          propertyHolder,
          inferredData, ann.mappedBy(), trueOneToOne, isIdentifierMapper, inSecondPass, mappings
      );
    }
    else if ( property.isAnnotationPresent( org.hibernate.annotations.Any.class ) ) {

      //check validity
      if ( property.isAnnotationPresent( Column.class )
          || property.isAnnotationPresent( Columns.class ) ) {
        throw new AnnotationException( "@Column(s) not allowed on a @Any property: "
            + StringHelper.qualify( propertyHolder.getPath(), inferredData.getPropertyName() ) );
      }

      Cascade hibernateCascade = property.getAnnotation( Cascade.class );
      NotFound notFound = property.getAnnotation( NotFound.class );
      boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE );
      OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class );
      boolean onDeleteCascade = onDeleteAnn != null && OnDeleteAction.CASCADE.equals( onDeleteAnn.action() );
      JoinTable assocTable = property.getAnnotation( JoinTable.class );
      if ( assocTable != null ) {
        Join join = propertyHolder.addJoin( assocTable, false );
        for (Ejb3JoinColumn joinColumn : joinColumns) {
          joinColumn.setSecondaryTableName( join.getTable().getName() );
        }
      }
      bindAny( getCascadeStrategy( null, hibernateCascade ), //@Any has not cascade attribute
          joinColumns, onDeleteCascade, nullability,
          propertyHolder, inferredData, entityBinder,
          isIdentifierMapper, mappings );
    }
    else if ( property.isAnnotationPresent( OneToMany.class )
        || property.isAnnotationPresent( ManyToMany.class )
        || property.isAnnotationPresent( CollectionOfElements.class )
        || property.isAnnotationPresent( ManyToAny.class ) ) {
      OneToMany oneToManyAnn = property.getAnnotation( OneToMany.class );
      ManyToMany manyToManyAnn = property.getAnnotation( ManyToMany.class );
      CollectionOfElements collectionOfElementsAnn = property.getAnnotation( CollectionOfElements.class );
      org.hibernate.annotations.IndexColumn indexAnn = property.getAnnotation(
          org.hibernate.annotations.IndexColumn.class
      );
      JoinTable assocTable = property.getAnnotation( JoinTable.class );

      IndexColumn indexColumn = IndexColumn.buildColumnFromAnnotation(
          indexAnn, propertyHolder, inferredData, mappings
      );
      CollectionBinder collectionBinder = CollectionBinder.getCollectionBinder(
          propertyHolder.getEntityName(),
          property,
          !indexColumn.isImplicit()
      );
      collectionBinder.setIndexColumn( indexColumn );
      MapKey mapKeyAnn = property.getAnnotation( MapKey.class );
      collectionBinder.setMapKey( mapKeyAnn );
      collectionBinder.setPropertyName( inferredData.getPropertyName() );
      BatchSize batchAnn = property.getAnnotation( BatchSize.class );
      collectionBinder.setBatchSize( batchAnn );
      javax.persistence.OrderBy ejb3OrderByAnn = property.getAnnotation( javax.persistence.OrderBy.class );
      OrderBy orderByAnn = property.getAnnotation( OrderBy.class );
      collectionBinder.setEjb3OrderBy( ejb3OrderByAnn );
      collectionBinder.setSqlOrderBy( orderByAnn );
      Sort sortAnn = property.getAnnotation( Sort.class );
      collectionBinder.setSort( sortAnn );
      Cache cachAnn = property.getAnnotation( Cache.class );
      collectionBinder.setCache( cachAnn );
      collectionBinder.setPropertyHolder( propertyHolder );
      Cascade hibernateCascade = property.getAnnotation( Cascade.class );
      NotFound notFound = property.getAnnotation( NotFound.class );
      boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE );
      collectionBinder.setIgnoreNotFound( ignoreNotFound );
      collectionBinder.setCollectionType( inferredData.getProperty().getElementClass() );
      collectionBinder.setMappings( mappings );
      collectionBinder.setPropertyAccessorName( inferredData.getDefaultAccess() );

      Ejb3Column[] elementColumns = null;
      PropertyData virtualProperty = new WrappedInferredData( inferredData, "element" );
      if ( property.isAnnotationPresent( Column.class ) || property.isAnnotationPresent(
          Formula.class
      ) ) {
        Column ann = property.getAnnotation( Column.class );
        Formula formulaAnn = property.getAnnotation( Formula.class );
        elementColumns = Ejb3Column.buildColumnFromAnnotation(
            new Column[] { ann },
            formulaAnn,
            nullability,
            propertyHolder,
View Full Code Here

Examples of org.hibernate.mapping.Formula

          //column unique-key
          bindUniqueKey( columnElement.attribute( "unique-key" ), table, column, mappings );
          bindUniqueKey( node.attribute( "unique-key" ), table, column, mappings );
        }
        else if ( columnElement.getName().equals( "formula" ) ) {
          Formula formula = new Formula();
          formula.setFormula( columnElement.getText() );
          simpleValue.addFormula( formula );
        }
      }
    }
    else {
View Full Code Here

Examples of org.hibernate.mapping.Formula

  private static void bindColumnsOrFormula(Element node, SimpleValue simpleValue, String path,
      boolean isNullable, Mappings mappings) {
    Attribute formulaNode = node.attribute( "formula" );
    if ( formulaNode != null ) {
      Formula f = new Formula();
      f.setFormula( formulaNode.getText() );
      simpleValue.addFormula( f );
    }
    else {
      bindColumns( node, simpleValue, isNullable, true, path, mappings );
    }
View Full Code Here

Examples of org.hibernate.mapping.Formula

        throw new MappingException("discriminator mapping required for single table polymorphic persistence");
      }
      forceDiscriminator = persistentClass.isForceDiscriminator();
      Selectable selectable = (Selectable) discrimValue.getColumnIterator().next();
      if ( discrimValue.hasFormula() ) {
        Formula formula = (Formula) selectable;
        discriminatorFormula = formula.getFormula();
        discriminatorFormulaTemplate = formula.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
        discriminatorColumnName = null;
        discriminatorAlias = "clazz_";
      }
      else {
        Column column = (Column) selectable;
View Full Code Here

Examples of org.hibernate.mapping.Formula

    iter = collection.getElement().getColumnIterator();
    while ( iter.hasNext() ) {
      Selectable selectable = (Selectable) iter.next();
      elementColumnAliases[j] = selectable.getAlias(dialect);
      if ( selectable.isFormula() ) {
        Formula form = (Formula) selectable;
        elementFormulaTemplates[j] = form.getTemplate(dialect, factory.getSqlFunctionRegistry());
        elementFormulas[j] = form.getFormula();
      }
      else {
        Column col = (Column) selectable;
        elementColumnNames[j] = col.getQuotedName(dialect);
        elementColumnIsSettable[j] = true;
        elementColumnIsInPrimaryKey[j] = !col.isNullable();
        if ( !col.isNullable() ) {
          hasNotNullableColumns = true;
        }
        isPureFormula = false;
      }
      j++;
    }
    elementIsPureFormula = isPureFormula;
   
    //workaround, for backward compatibility of sets with no
    //not-null columns, assume all columns are used in the
    //row locator SQL
    if ( !hasNotNullableColumns ) {
      Arrays.fill( elementColumnIsInPrimaryKey, true );
    }


    // INDEX AND ROW SELECT

    hasIndex = collection.isIndexed();
    if (hasIndex) {
      // NativeSQL: collect index column and auto-aliases
      IndexedCollection indexedCollection = (IndexedCollection) collection;
      indexType = indexedCollection.getIndex().getType();
      int indexSpan = indexedCollection.getIndex().getColumnSpan();
      iter = indexedCollection.getIndex().getColumnIterator();
      indexColumnNames = new String[indexSpan];
      indexFormulaTemplates = new String[indexSpan];
      indexFormulas = new String[indexSpan];
      indexColumnIsSettable = new boolean[indexSpan];
      indexColumnAliases = new String[indexSpan];
      int i = 0;
      boolean hasFormula = false;
      while ( iter.hasNext() ) {
        Selectable s = (Selectable) iter.next();
        indexColumnAliases[i] = s.getAlias(dialect);
        if ( s.isFormula() ) {
          Formula indexForm = (Formula) s;
          indexFormulaTemplates[i] = indexForm.getTemplate(dialect, factory.getSqlFunctionRegistry());
          indexFormulas[i] = indexForm.getFormula();
          hasFormula = true;
        }
        else {
          Column indexCol = (Column) s;
          indexColumnNames[i] = indexCol.getQuotedName(dialect);
View Full Code Here

Examples of org.hibernate.mapping.Formula

          //column unique-key
          bindUniqueKey( columnElement.attribute( "unique-key" ), table, column, mappings );
          bindUniqueKey( node.attribute( "unique-key" ), table, column, mappings );
        }
        else if ( columnElement.getName().equals( "formula" ) ) {
          Formula formula = new Formula();
          formula.setFormula( columnElement.getText() );
          simpleValue.addFormula( formula );
        }
      }

      // todo : another GoodThing would be to go back after all parsing and see if all the columns
View Full Code Here

Examples of org.hibernate.mapping.Formula

  private static void bindColumnsOrFormula(Element node, SimpleValue simpleValue, String path,
      boolean isNullable, Mappings mappings) {
    Attribute formulaNode = node.attribute( "formula" );
    if ( formulaNode != null ) {
      Formula f = new Formula();
      f.setFormula( formulaNode.getText() );
      simpleValue.addFormula( f );
    }
    else {
      bindColumns( node, simpleValue, isNullable, true, path, mappings );
    }
View Full Code Here

Examples of org.hibernate.mapping.Formula

    iter = collection.getElement().getColumnIterator();
    while ( iter.hasNext() ) {
      Selectable selectable = (Selectable) iter.next();
      elementColumnAliases[j] = selectable.getAlias(dialect);
      if ( selectable.isFormula() ) {
        Formula form = (Formula) selectable;
        elementFormulaTemplates[j] = form.getTemplate(dialect, factory.getSqlFunctionRegistry());
        elementFormulas[j] = form.getFormula();
      }
      else {
        Column col = (Column) selectable;
        elementColumnNames[j] = col.getQuotedName(dialect);
        elementColumnIsSettable[j] = true;
        elementColumnIsInPrimaryKey[j] = !col.isNullable();
        if ( !col.isNullable() ) {
          hasNotNullableColumns = true;
        }
        isPureFormula = false;
      }
      j++;
    }
    elementIsPureFormula = isPureFormula;
   
    //workaround, for backward compatibility of sets with no
    //not-null columns, assume all columns are used in the
    //row locator SQL
    if ( !hasNotNullableColumns ) {
      Arrays.fill( elementColumnIsInPrimaryKey, true );
    }


    // INDEX AND ROW SELECT

    hasIndex = collection.isIndexed();
    if (hasIndex) {
      // NativeSQL: collect index column and auto-aliases
      IndexedCollection indexedCollection = (IndexedCollection) collection;
      indexType = indexedCollection.getIndex().getType();
      int indexSpan = indexedCollection.getIndex().getColumnSpan();
      iter = indexedCollection.getIndex().getColumnIterator();
      indexColumnNames = new String[indexSpan];
      indexFormulaTemplates = new String[indexSpan];
      indexFormulas = new String[indexSpan];
      indexColumnIsSettable = new boolean[indexSpan];
      indexColumnAliases = new String[indexSpan];
      int i = 0;
      boolean hasFormula = false;
      while ( iter.hasNext() ) {
        Selectable s = (Selectable) iter.next();
        indexColumnAliases[i] = s.getAlias(dialect);
        if ( s.isFormula() ) {
          Formula indexForm = (Formula) s;
          indexFormulaTemplates[i] = indexForm.getTemplate(dialect, factory.getSqlFunctionRegistry());
          indexFormulas[i] = indexForm.getFormula();
          hasFormula = true;
        }
        else {
          Column indexCol = (Column) s;
          indexColumnNames[i] = indexCol.getQuotedName(dialect);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.