Package org.hibernate.mapping

Examples of org.hibernate.mapping.Selectable


  }

  private static EntityDiscriminator resolveDiscriminator(final PersistentClass persistentClass, final SessionFactoryImplementor factory) {
    if ( persistentClass.isPolymorphic() ) {
      Value discrimValue = persistentClass.getDiscriminator();
      Selectable selectable = (Selectable) discrimValue.getColumnIterator().next();
      if ( discrimValue.hasFormula() ) {
        throw new UnsupportedOperationException( "OGM doesn't support discriminator formulas" );
      }
      else {
        return new ColumnBasedDiscriminator( persistentClass, factory, (Column) selectable );
View Full Code Here


      Value discrimValue = persistentClass.getDiscriminator();
      if (discrimValue==null) {
        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;
        discriminatorColumnName = column.getQuotedName( factory.getDialect() );
        discriminatorAlias = column.getAlias( factory.getDialect(), persistentClass.getRootTable() );
        discriminatorFormula = null;
        discriminatorFormulaTemplate = null;
      }
      discriminatorType = persistentClass.getDiscriminator().getType();
      if ( persistentClass.isDiscriminatorValueNull() ) {
        discriminatorValue = NULL_DISCRIMINATOR;
        discriminatorSQLValue = InFragment.NULL;
        discriminatorInsertable = false;
      }
      else if ( persistentClass.isDiscriminatorValueNotNull() ) {
        discriminatorValue = NOT_NULL_DISCRIMINATOR;
        discriminatorSQLValue = InFragment.NOT_NULL;
        discriminatorInsertable = false;
      }
      else {
        discriminatorInsertable = persistentClass.isDiscriminatorInsertable() && !discrimValue.hasFormula();
        try {
          DiscriminatorType dtype = (DiscriminatorType) discriminatorType;
          discriminatorValue = dtype.stringToObject( persistentClass.getDiscriminatorValue() );
          discriminatorSQLValue = dtype.objectToSQLString( discriminatorValue, factory.getDialect() );
        }
        catch (ClassCastException cce) {
          throw new MappingException("Illegal discriminator type: " + discriminatorType.getName() );
        }
        catch (Exception e) {
          throw new MappingException("Could not format discriminator value to SQL string", e);
        }
      }
    }
    else {
      forceDiscriminator = false;
      discriminatorInsertable = false;
      discriminatorColumnName = null;
      discriminatorAlias = null;
      discriminatorType = null;
      discriminatorValue = null;
      discriminatorSQLValue = null;
      discriminatorFormula = null;
      discriminatorFormulaTemplate = null;
    }

    // PROPERTIES

    propertyTableNumbers = new int[ getPropertySpan() ];
    Iterator iter = persistentClass.getPropertyClosureIterator();
    int i=0;
    while( iter.hasNext() ) {
      Property prop = (Property) iter.next();
      propertyTableNumbers[i++] = persistentClass.getJoinNumber(prop);

    }

    //TODO: code duplication with JoinedSubclassEntityPersister
   
    ArrayList columnJoinNumbers = new ArrayList();
    ArrayList formulaJoinedNumbers = new ArrayList();
    ArrayList propertyJoinNumbers = new ArrayList();
   
    iter = persistentClass.getSubclassPropertyClosureIterator();
    while ( iter.hasNext() ) {
      Property prop = (Property) iter.next();
      Integer join = new Integer( persistentClass.getJoinNumber(prop) );
      propertyJoinNumbers.add(join);

      //propertyTableNumbersByName.put( prop.getName(), join );
      propertyTableNumbersByNameAndSubclass.put(
          prop.getPersistentClass().getEntityName() + '.' + prop.getName(),
          join
      );

      Iterator citer = prop.getColumnIterator();
      while ( citer.hasNext() ) {
        Selectable thing = (Selectable) citer.next();
        if ( thing.isFormula() ) {
          formulaJoinedNumbers.add(join);
        }
        else {
          columnJoinNumbers.add(join);
        }
View Full Code Here

    boolean isPureFormula = true;
    boolean hasNotNullableColumns = false;
    int j = 0;
    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;
        }
View Full Code Here

      Integer tabnum = new Integer( getTableId(tabname, subclassTableNameClosure) );
      propTableNumbers.add(tabnum);

      Iterator citer = prop.getColumnIterator();
      while ( citer.hasNext() ) {
        Selectable thing = (Selectable) citer.next();
        if ( thing.isFormula() ) {
          formulaTableNumbers.add(tabnum);
        }
        else {
          columnTableNumbers.add(tabnum);
        }
View Full Code Here

      String[] colAliases = new String[span];
      String[] templates = new String[span];
      Iterator colIter = prop.getColumnIterator();
      int k = 0;
      while ( colIter.hasNext() ) {
        Selectable thing = ( Selectable ) colIter.next();
        colAliases[k] = thing.getAlias( factory.getDialect() , prop.getValue().getTable() );
        if ( thing.isFormula() ) {
          foundFormula = true;
          templates[k] = thing.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
        }
        else {
          colNames[k] = thing.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
        }
        k++;
      }
      propertyColumnNames[i] = colNames;
      propertyColumnFormulaTemplates[i] = templates;
      propertyColumnAliases[i] = colAliases;

      if ( lazyAvailable && prop.isLazy() ) {
        lazyProperties.add( prop.getName() );
        lazyNames.add( prop.getName() );
        lazyNumbers.add( new Integer( i ) );
        lazyTypes.add( prop.getValue().getType() );
        lazyColAliases.add( colAliases );
      }

      propertyColumnUpdateable[i] = prop.getValue().getColumnUpdateability();
      propertyColumnInsertable[i] = prop.getValue().getColumnInsertability();

      propertySelectable[i] = prop.isSelectable();

      propertyUniqueness[i] = prop.getValue().isAlternateUniqueKey();

      i++;

    }
    hasFormulaProperties = foundFormula;
    lazyPropertyColumnAliases = ArrayHelper.to2DStringArray( lazyColAliases );
    lazyPropertyNames = ArrayHelper.toStringArray( lazyNames );
    lazyPropertyNumbers = ArrayHelper.toIntArray( lazyNumbers );
    lazyPropertyTypes = ArrayHelper.toTypeArray( lazyTypes );

    // SUBCLASS PROPERTY CLOSURE

    ArrayList columns = new ArrayList();
    ArrayList columnsLazy = new ArrayList();
    ArrayList aliases = new ArrayList();
    ArrayList formulas = new ArrayList();
    ArrayList formulaAliases = new ArrayList();
    ArrayList formulaTemplates = new ArrayList();
    ArrayList formulasLazy = new ArrayList();
    ArrayList types = new ArrayList();
    ArrayList names = new ArrayList();
    ArrayList classes = new ArrayList();
    ArrayList templates = new ArrayList();
    ArrayList propColumns = new ArrayList();
    ArrayList joinedFetchesList = new ArrayList();
    ArrayList cascades = new ArrayList();
    ArrayList definedBySubclass = new ArrayList();
    ArrayList propColumnNumbers = new ArrayList();
    ArrayList propFormulaNumbers = new ArrayList();
    ArrayList columnSelectables = new ArrayList();
    ArrayList propNullables = new ArrayList();

    iter = persistentClass.getSubclassPropertyClosureIterator();
    while ( iter.hasNext() ) {
      Property prop = ( Property ) iter.next();
      names.add( prop.getName() );
      classes.add( prop.getPersistentClass().getEntityName() );
      boolean isDefinedBySubclass = !thisClassProperties.contains( prop );
      definedBySubclass.add( Boolean.valueOf( isDefinedBySubclass ) );
      propNullables.add( Boolean.valueOf( prop.isOptional() || isDefinedBySubclass ) ); //TODO: is this completely correct?
      types.add( prop.getType() );

      Iterator colIter = prop.getColumnIterator();
      String[] cols = new String[prop.getColumnSpan()];
      String[] forms = new String[prop.getColumnSpan()];
      int[] colnos = new int[prop.getColumnSpan()];
      int[] formnos = new int[prop.getColumnSpan()];
      int l = 0;
      Boolean lazy = Boolean.valueOf( prop.isLazy() && lazyAvailable );
      while ( colIter.hasNext() ) {
        Selectable thing = ( Selectable ) colIter.next();
        if ( thing.isFormula() ) {
          String template = thing.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
          formnos[l] = formulaTemplates.size();
          colnos[l] = -1;
          formulaTemplates.add( template );
          forms[l] = template;
          formulas.add( thing.getText( factory.getDialect() ) );
          formulaAliases.add( thing.getAlias( factory.getDialect() ) );
          formulasLazy.add( lazy );
        }
        else {
          String colName = thing.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
          colnos[l] = columns.size(); //before add :-)
          formnos[l] = -1;
          columns.add( colName );
          cols[l] = colName;
          aliases.add( thing.getAlias( factory.getDialect(), prop.getValue().getTable() ) );
          columnsLazy.add( lazy );
          columnSelectables.add( Boolean.valueOf( prop.isSelectable() ) );
        }
        l++;
      }
View Full Code Here

        String[] aliases = new String[prop.getColumnSpan()];
        String[] cols = new String[prop.getColumnSpan()];
        Iterator colIter = prop.getColumnIterator();
        int l = 0;
        while ( colIter.hasNext() ) {
          Selectable thing = ( Selectable ) colIter.next();
          aliases[l] = thing.getAlias( getFactory().getDialect(), prop.getValue().getTable() );
          cols[l] = thing.getText( getFactory().getDialect() ); // TODO: skip formulas?
          l++;
        }

        subclassPropertyAliases.put( propname, aliases );
        subclassPropertyColumnNames.put( propname, cols );
View Full Code Here

      }
    }

    StringBuffer annotations = new StringBuffer( "    " );
    if ( span == 1 ) {
        Selectable selectable = (Selectable) columnIterator.next();
        buildJoinColumnAnnotation( selectable, null, annotations, insertable, updatable );
    }
    else {
      Iterator columns = columnIterator;
      annotations.append("@").append( importType("javax.persistence.JoinColumns") ).append("( { " );
View Full Code Here

  private void buildArrayOfJoinColumnAnnotation(
      Iterator columns, Iterator referencedColumnsIterator, StringBuffer annotations, boolean insertable,
      boolean updatable
  ) {
    while ( columns.hasNext() ) {
      Selectable selectable = (Selectable) columns.next();
            Selectable referencedColumn = null;
            if(referencedColumnsIterator!=null) {
              referencedColumn = (Selectable) referencedColumnsIterator.next();
            }

      if ( selectable.isFormula() ) {
View Full Code Here

    boolean foundFormula = false;

    if(value!=null && value.getColumnSpan()>0) {
      Iterator columnIterator = value.getColumnIterator();
      while ( columnIterator.hasNext() ) {
        Selectable element = (Selectable) columnIterator.next();
        if(!(element instanceof Formula)) {
          return false;
        } else {
          foundFormula = true;
        }
View Full Code Here

      annotations.setLength( annotations.length() - 2 );
      annotations.append( " } )" );
    }
    else {
      if ( property.getColumnSpan() == 1 ) {
        Selectable selectable = (Selectable) property.getColumnIterator().next();
        buildColumnAnnotation( selectable, annotations, insertable, updatable );       
      }
      else {
        Iterator columns = property.getColumnIterator();
        annotations.append("@").append( importType("org.hibernate.annotations.Columns") ).append("( { " );
        while ( columns.hasNext() ) {
          Selectable selectable = (Selectable) columns.next();
 
          if ( selectable.isFormula() ) {
            //TODO formula in multicolumns not supported by annotations
            //annotations.append("/* TODO formula in multicolumns not supported by annotations */");
          }
          else {
            annotations.append( "\n        " );
View Full Code Here

TOP

Related Classes of org.hibernate.mapping.Selectable

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.