Examples of Formula


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;
        discriminatorColumnReaders = null;
        discriminatorColumnReaderTemplate = null;
        discriminatorAlias = "clazz_";
      }
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

        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;
        discriminatorColumnReaders = null;
        discriminatorColumnReaderTemplate = null;
        discriminatorAlias = "clazz_";
      }
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);
        elementColumnWriters[j] = col.getWriteExpr();
        elementColumnReaders[j] = col.getReadExpr(dialect);
        elementColumnReaderTemplates[j] = col.getTemplate(dialect, factory.getSqlFunctionRegistry());
        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

  }

  public void bind() {
    if ( StringHelper.isNotEmpty( formulaString ) ) {
      log.debug( "binding formula {}", formulaString );
      formula = new Formula();
      formula.setFormula( formulaString );
    }
    else {
      initMappingColumn(
          logicalColumnName, propertyName, length, precision, scale, nullable, sqlType, unique, true
View Full Code Here

Examples of org.hibernate.mapping.Formula

      boolean nullable,
      String sqlType,
      boolean unique,
      boolean applyNamingStrategy) {
    if ( StringHelper.isNotEmpty( formulaString ) ) {
      this.formula = new Formula();
      this.formula.setFormula( formulaString );
    }
    else {
      this.mappingColumn = new Column();
      redefineColumnName( columnName, propertyName, applyNamingStrategy );
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, table );
      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 );
        elementColumnWriters[j] = col.getWriteExpr();
        elementColumnReaders[j] = col.getReadExpr( dialect );
        elementColumnReaderTemplates[j] = col.getTemplate( dialect, factory.getSqlFunctionRegistry() );
        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

        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

      }
      Iterator columns = sourceValue.getColumnIterator();
      Random random = new Random();
      while ( columns.hasNext() ) {
        Object current = columns.next();
        Formula formula = new Formula();
        String formulaString;
        if ( current instanceof Column ) {
          formulaString = ( (Column) current ).getQuotedName();
        }
        else if ( current instanceof Formula ) {
          formulaString = ( (Formula) current ).getFormula();
        }
        else {
          throw new AssertionFailure( "Unknown element in column iterator: " + current.getClass() );
        }
        if ( fromAndWhere != null ) {
          formulaString = Template.renderWhereStringTemplate( formulaString, "$alias$", new HSQLDialect() );
          formulaString = "(select " + formulaString + fromAndWhere + ")";
          formulaString = StringHelper.replace(
              formulaString,
              "$alias$",
              "a" + random.nextInt( 16 )
          );
        }
        formula.setFormula( formulaString );
        targetValue.addFormula( formula );

      }
      return targetValue;
    }
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.