Package org.hibernate.mapping

Examples of org.hibernate.mapping.Selectable


      StringBuilder orderByBuffer = new StringBuilder();
      if ( hqlOrderBy.length() == 0 ) {
        //order by id
        Iterator it = associatedClass.getIdentifier().getColumnIterator();
        while ( it.hasNext() ) {
          Selectable col = (Selectable) it.next();
          orderByBuffer.append( col.getText() ).append( " asc" ).append( ", " );
        }
      }
      else {
        StringTokenizer st = new StringTokenizer( hqlOrderBy, " ,", false );
        String currentOrdering = null;
        //FIXME make this code decent
        while ( st.hasMoreTokens() ) {
          String token = st.nextToken();
          if ( isNonPropertyToken( token ) ) {
            if ( currentOrdering != null ) {
              throw new AnnotationException(
                  "Error while parsing HQL orderBy clause: " + hqlOrderBy
                      + " (" + role + ")"
              );
            }
            currentOrdering = token;
          }
          else {
            //Add ordering of the previous
            if ( currentOrdering == null ) {
              //default ordering
              ordering.add( "asc" );
            }
            else {
              ordering.add( currentOrdering );
              currentOrdering = null;
            }
            properties.add( token );
          }
        }
        ordering.remove( 0 ); //first one is the algorithm starter
        // add last one ordering
        if ( currentOrdering == null ) {
          //default ordering
          ordering.add( "asc" );
        }
        else {
          ordering.add( currentOrdering );
          currentOrdering = null;
        }
        int index = 0;

        for (String property : properties) {
          Property p = BinderHelper.findPropertyByName( associatedClass, property );
          if ( p == null ) {
            throw new AnnotationException(
                "property from @OrderBy clause not found: "
                    + associatedClass.getEntityName() + "." + property
            );
          }
          PersistentClass pc = p.getPersistentClass();
          String table;
          if ( pc == null ) {
            //we are touching a @IdClass property, the pc is not set
            //this means pc == associatedClass
            //TODO check whether @ManyToOne @JoinTable in @IdClass used for @OrderBy works: doh!
            table = "";
          }

          else if (pc == associatedClass
              || (associatedClass instanceof SingleTableSubclass && pc
                  .getMappedClass().isAssignableFrom(
                      associatedClass.getMappedClass()))) {
            table = "";
          } else {
            table = pc.getTable().getQuotedName() + ".";
          }

          Iterator propertyColumns = p.getColumnIterator();
          while ( propertyColumns.hasNext() ) {
            Selectable column = (Selectable) propertyColumns.next();
            orderByBuffer.append( table )
                .append( column.getText() )
                .append( " " )
                .append( ordering.get( index ) )
                .append( ", " );
          }
          index++;
View Full Code Here


            );
          }

          Iterator propertyColumns = p.getColumnIterator();
          while ( propertyColumns.hasNext() ) {
            Selectable column = (Selectable) propertyColumns.next();
            orderByBuffer.append( column.getText() )
                .append( " " )
                .append( ordering.get( index ) )
                .append( ", " );
          }
          index++;
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);
        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;
        }
View Full Code Here

      String[] colWriters = new String[span];
      String[] formulaTemplates = 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;
          formulaTemplates[k] = thing.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
        }
        else {
          Column col = (Column)thing;
          colNames[k] = col.getQuotedName( factory.getDialect() );
          colReaderTemplates[k] = col.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
          colWriters[k] = col.getWriteExpr();
        }
        k++;
      }
      propertyColumnNames[i] = colNames;
      propertyColumnFormulaTemplates[i] = formulaTemplates;
      propertyColumnReaderTemplates[i] = colReaderTemplates;
      propertyColumnWriters[i] = colWriters;
      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 columnReaderTemplates = 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 propColumnReaders = new ArrayList();
    ArrayList propColumnReaderTemplates = 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[] readers = new String[prop.getColumnSpan()];
      String[] readerTemplates = 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 {
          Column col = (Column)thing;
          String colName = col.getQuotedName( factory.getDialect() );
          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() ) );
         
          readers[l] = col.getReadExpr( factory.getDialect() );
          String readerTemplate = col.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
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

      StringBuilder orderByBuffer = new StringBuilder();
      if ( hqlOrderBy.length() == 0 ) {
        //order by id
        Iterator it = associatedClass.getIdentifier().getColumnIterator();
        while ( it.hasNext() ) {
          Selectable col = (Selectable) it.next();
          orderByBuffer.append( col.getText() ).append( " asc" ).append( ", " );
        }
      }
      else {
        StringTokenizer st = new StringTokenizer( hqlOrderBy, " ,", false );
        String currentOrdering = null;
        //FIXME make this code decent
        while ( st.hasMoreTokens() ) {
          String token = st.nextToken();
          if ( isNonPropertyToken( token ) ) {
            if ( currentOrdering != null ) {
              throw new AnnotationException(
                  "Error while parsing HQL orderBy clause: " + hqlOrderBy
                      + " (" + role + ")"
              );
            }
            currentOrdering = token;
          }
          else {
            //Add ordering of the previous
            if ( currentOrdering == null ) {
              //default ordering
              ordering.add( "asc" );
            }
            else {
              ordering.add( currentOrdering );
              currentOrdering = null;
            }
            properties.add( token );
          }
        }
        ordering.remove( 0 ); //first one is the algorithm starter
        // add last one ordering
        if ( currentOrdering == null ) {
          //default ordering
          ordering.add( "asc" );
        }
        else {
          ordering.add( currentOrdering );
          currentOrdering = null;
        }
        int index = 0;

        for (String property : properties) {
          Property p = BinderHelper.findPropertyByName( associatedClass, property );
          if ( p == null ) {
            throw new AnnotationException(
                "property from @OrderBy clause not found: "
                    + associatedClass.getEntityName() + "." + property
            );
          }
          PersistentClass pc = p.getPersistentClass();
          String table;
          if ( pc == null ) {
            //we are touching a @IdClass property, the pc is not set
            //this means pc == associatedClass
            //TODO check whether @ManyToOne @JoinTable in @IdClass used for @OrderBy works: doh!
            table = "";
          }
         
          else if (pc == associatedClass
              || (associatedClass instanceof SingleTableSubclass && pc
                  .getMappedClass().isAssignableFrom(
                      associatedClass.getMappedClass()))) {
            table = "";
          } else {
            table = pc.getTable().getQuotedName() + ".";
          }
         
          Iterator propertyColumns = p.getColumnIterator();
          while ( propertyColumns.hasNext() ) {
            Selectable column = (Selectable) propertyColumns.next();
            orderByBuffer.append( table )
                .append( column.getText() )
                .append( " " )
                .append( ordering.get( index ) )
                .append( ", " );
          }
          index++;
View Full Code Here

            );
          }

          Iterator propertyColumns = p.getColumnIterator();
          while ( propertyColumns.hasNext() ) {
            Selectable column = (Selectable) propertyColumns.next();
            orderByBuffer.append( column.getText() )
                .append( " " )
                .append( ordering.get( index ) )
                .append( ", " );
          }
          index++;
View Full Code Here

      String[] colWriters = new String[span];
      String[] formulaTemplates = 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;
          formulaTemplates[k] = thing.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
        }
        else {
          Column col = (Column)thing;
          colNames[k] = col.getQuotedName( factory.getDialect() );
          colReaderTemplates[k] = col.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
          colWriters[k] = col.getWriteExpr();
        }
        k++;
      }
      propertyColumnNames[i] = colNames;
      propertyColumnFormulaTemplates[i] = formulaTemplates;
      propertyColumnReaderTemplates[i] = colReaderTemplates;
      propertyColumnWriters[i] = colWriters;
      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 columnReaderTemplates = 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 propColumnReaders = new ArrayList();
    ArrayList propColumnReaderTemplates = 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[] readers = new String[prop.getColumnSpan()];
      String[] readerTemplates = 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 {
          Column col = (Column)thing;
          String colName = col.getQuotedName( factory.getDialect() );
          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() ) );
         
          readers[l] = col.getReadExpr( factory.getDialect() );
          String readerTemplate = col.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
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

      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

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.