Package org.hibernate.mapping

Examples of org.hibernate.mapping.Selectable


        Component component = (Component) subProperty.getValue();
        buildRecursiveAttributeOverride( component.getPropertyIterator(), path, subProperty, annotations );
      }
      else {
        Iterator columns = subProperty.getColumnIterator();
        Selectable selectable = (Selectable) columns.next();
        if ( selectable.isFormula() ) {
          //TODO formula in multicolumns not supported by annotations
        }
        else {
          annotations.append( "\n        " ).append("@")
              .append( importType("javax.persistence.AttributeOverride") ).append("(name=\"" );
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

    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

      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;
        discriminatorColumnReaders = null;
        discriminatorColumnReaderTemplate = null;
        discriminatorAlias = "clazz_";
      }
      else {
        Column column = (Column) selectable;
        discriminatorColumnName = column.getQuotedName( factory.getDialect() );
        discriminatorColumnReaders = column.getReadExpr( factory.getDialect() );
        discriminatorColumnReaderTemplate = column.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
        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;
      discriminatorColumnReaders = null;
      discriminatorColumnReaderTemplate = 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

      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[] 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( 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();
     
      if (prop.isLob() && getFactory().getDialect().forceLobAsLastValue() ) {
        lobProperties.add( i );
      }

      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

      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;
        discriminatorColumnReaders = null;
        discriminatorColumnReaderTemplate = null;
        discriminatorAlias = "clazz_";
      }
      else {
        Column column = (Column) selectable;
        discriminatorColumnName = column.getQuotedName( factory.getDialect() );
        discriminatorColumnReaders = column.getReadExpr( factory.getDialect() );
        discriminatorColumnReaderTemplate = column.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
        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;
      discriminatorColumnReaders = null;
      discriminatorColumnReaderTemplate = 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 = 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

            value);
        }
        else {
          //FIXME take care of Formula
          while ( columns.hasNext() ) {
            final Selectable selectable = columns.next();
            if ( ! Column.class.isInstance( selectable ) ) {
              log.debug( "Encountered formula definition; skipping" );
              continue;
            }
            final Column column = (Column) selectable;
View Full Code Here

    if ( persistentClass.isPolymorphic() ) {
      final Value discriminatorMapping = persistentClass.getDiscriminator();
      if ( discriminatorMapping != null ) {
        log.debug( "Encountered explicit discriminator mapping for joined inheritance" );

        final Selectable selectable = discriminatorMapping.getColumnIterator().next();
        if ( Formula.class.isInstance( selectable ) ) {
          throw new MappingException( "Discriminator formulas on joined inheritance hierarchies not supported at this time" );
        }
        else {
          final Column column = (Column) selectable;
          explicitDiscriminatorColumnName = column.getQuotedName( factory.getDialect() );
          discriminatorAlias = column.getAlias( factory.getDialect(), persistentClass.getRootTable() );
        }
        discriminatorType = (DiscriminatorType) persistentClass.getDiscriminator().getType();
        if ( persistentClass.isDiscriminatorValueNull() ) {
          discriminatorValue = NULL_DISCRIMINATOR;
          discriminatorSQLString = InFragment.NULL;
        }
        else if ( persistentClass.isDiscriminatorValueNotNull() ) {
          discriminatorValue = NOT_NULL_DISCRIMINATOR;
          discriminatorSQLString = InFragment.NOT_NULL;
        }
        else {
          try {
            discriminatorValue = discriminatorType.stringToObject( persistentClass.getDiscriminatorValue() );
            discriminatorSQLString = discriminatorType.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 {
        explicitDiscriminatorColumnName = null;
        discriminatorAlias = IMPLICIT_DISCRIMINATOR_ALIAS;
        discriminatorType = StandardBasicTypes.INTEGER;
        try {
          discriminatorValue = persistentClass.getSubclassId();
          discriminatorSQLString = discriminatorValue.toString();
        }
        catch ( Exception e ) {
          throw new MappingException( "Could not format discriminator value to SQL string", e );
        }
      }
    }
    else {
      explicitDiscriminatorColumnName = null;
      discriminatorAlias = IMPLICIT_DISCRIMINATOR_ALIAS;
      discriminatorType = StandardBasicTypes.INTEGER;
      discriminatorValue = null;
      discriminatorSQLString = null;
    }

    if ( optimisticLockStyle() == OptimisticLockStyle.ALL || optimisticLockStyle() == OptimisticLockStyle.DIRTY ) {
      throw new MappingException( "optimistic-lock=all|dirty not supported for joined-subclass mappings [" + getEntityName() + "]" );
    }

    //MULTITABLES

    final int idColumnSpan = getIdentifierColumnSpan();

    ArrayList tables = new ArrayList();
    ArrayList keyColumns = new ArrayList();
    ArrayList keyColumnReaders = new ArrayList();
    ArrayList keyColumnReaderTemplates = new ArrayList();
    ArrayList cascadeDeletes = new ArrayList();
    Iterator titer = persistentClass.getTableClosureIterator();
    Iterator kiter = persistentClass.getKeyClosureIterator();
    while ( titer.hasNext() ) {
      Table tab = (Table) titer.next();
      KeyValue key = (KeyValue) kiter.next();
      String tabname = tab.getQualifiedName(
          factory.getDialect(),
          factory.getSettings().getDefaultCatalogName(),
          factory.getSettings().getDefaultSchemaName()
      );
      tables.add( tabname );
      String[] keyCols = new String[idColumnSpan];
      String[] keyColReaders = new String[idColumnSpan];
      String[] keyColReaderTemplates = new String[idColumnSpan];
      Iterator citer = key.getColumnIterator();
      for ( int k = 0; k < idColumnSpan; k++ ) {
        Column column = (Column) citer.next();
        keyCols[k] = column.getQuotedName( factory.getDialect() );
        keyColReaders[k] = column.getReadExpr( factory.getDialect() );
        keyColReaderTemplates[k] = column.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
      }
      keyColumns.add( keyCols );
      keyColumnReaders.add( keyColReaders );
      keyColumnReaderTemplates.add( keyColReaderTemplates );
      cascadeDeletes.add( key.isCascadeDeleteEnabled() && factory.getDialect().supportsCascadeDelete() );
    }

    //Span of the tables directly mapped by this entity and super-classes, if any
    coreTableSpan = tables.size();

    isNullableTable = new boolean[persistentClass.getJoinClosureSpan()];

    int tableIndex = 0;
    Iterator joinIter = persistentClass.getJoinClosureIterator();
    while ( joinIter.hasNext() ) {
      Join join = (Join) joinIter.next();

      isNullableTable[tableIndex++] = join.isOptional();

      Table table = join.getTable();

      String tableName = table.getQualifiedName(
          factory.getDialect(),
          factory.getSettings().getDefaultCatalogName(),
          factory.getSettings().getDefaultSchemaName()
      );
      tables.add( tableName );

      KeyValue key = join.getKey();
      int joinIdColumnSpan = key.getColumnSpan();

      String[] keyCols = new String[joinIdColumnSpan];
      String[] keyColReaders = new String[joinIdColumnSpan];
      String[] keyColReaderTemplates = new String[joinIdColumnSpan];

      Iterator citer = key.getColumnIterator();

      for ( int k = 0; k < joinIdColumnSpan; k++ ) {
        Column column = (Column) citer.next();
        keyCols[k] = column.getQuotedName( factory.getDialect() );
        keyColReaders[k] = column.getReadExpr( factory.getDialect() );
        keyColReaderTemplates[k] = column.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
      }
      keyColumns.add( keyCols );
      keyColumnReaders.add( keyColReaders );
      keyColumnReaderTemplates.add( keyColReaderTemplates );
      cascadeDeletes.add( key.isCascadeDeleteEnabled() && factory.getDialect().supportsCascadeDelete() );
    }

    naturalOrderTableNames = ArrayHelper.toStringArray( tables );
    naturalOrderTableKeyColumns = ArrayHelper.to2DStringArray( keyColumns );
    naturalOrderTableKeyColumnReaders = ArrayHelper.to2DStringArray( keyColumnReaders );
    naturalOrderTableKeyColumnReaderTemplates = ArrayHelper.to2DStringArray( keyColumnReaderTemplates );
    naturalOrderCascadeDeleteEnabled = ArrayHelper.toBooleanArray( cascadeDeletes );

    ArrayList subtables = new ArrayList();
    ArrayList isConcretes = new ArrayList();
    ArrayList isDeferreds = new ArrayList();
    ArrayList isLazies = new ArrayList();

    keyColumns = new ArrayList();
    titer = persistentClass.getSubclassTableClosureIterator();
    while ( titer.hasNext() ) {
      Table tab = (Table) titer.next();
      isConcretes.add( persistentClass.isClassOrSuperclassTable( tab ) );
      isDeferreds.add( Boolean.FALSE );
      isLazies.add( Boolean.FALSE );
      String tabname = tab.getQualifiedName(
          factory.getDialect(),
          factory.getSettings().getDefaultCatalogName(),
          factory.getSettings().getDefaultSchemaName()
      );
      subtables.add( tabname );
      String[] key = new String[idColumnSpan];
      Iterator citer = tab.getPrimaryKey().getColumnIterator();
      for ( int k = 0; k < idColumnSpan; k++ ) {
        key[k] = ( (Column) citer.next() ).getQuotedName( factory.getDialect() );
      }
      keyColumns.add( key );
    }

    //Add joins
    joinIter = persistentClass.getSubclassJoinClosureIterator();
    while ( joinIter.hasNext() ) {
      Join join = (Join) joinIter.next();

      Table tab = join.getTable();

      isConcretes.add( persistentClass.isClassOrSuperclassTable( tab ) );
      isDeferreds.add( join.isSequentialSelect() );
      isLazies.add( join.isLazy() );

      String tabname = tab.getQualifiedName(
          factory.getDialect(),
          factory.getSettings().getDefaultCatalogName(),
          factory.getSettings().getDefaultSchemaName()
      );
      subtables.add( tabname );
      String[] key = new String[idColumnSpan];
      Iterator citer = tab.getPrimaryKey().getColumnIterator();
      for ( int k = 0; k < idColumnSpan; k++ ) {
        key[k] = ( (Column) citer.next() ).getQuotedName( factory.getDialect() );
      }
      keyColumns.add( key );
    }

    String[] naturalOrderSubclassTableNameClosure = ArrayHelper.toStringArray( subtables );
    String[][] naturalOrderSubclassTableKeyColumnClosure = ArrayHelper.to2DStringArray( keyColumns );
    isClassOrSuperclassTable = ArrayHelper.toBooleanArray( isConcretes );
    subclassTableSequentialSelect = ArrayHelper.toBooleanArray( isDeferreds );
    subclassTableIsLazyClosure = ArrayHelper.toBooleanArray( isLazies );

    constraintOrderedTableNames = new String[naturalOrderSubclassTableNameClosure.length];
    constraintOrderedKeyColumnNames = new String[naturalOrderSubclassTableNameClosure.length][];
    int currentPosition = 0;
    for ( int i = naturalOrderSubclassTableNameClosure.length - 1; i >= 0; i--, currentPosition++ ) {
      constraintOrderedTableNames[currentPosition] = naturalOrderSubclassTableNameClosure[i];
      constraintOrderedKeyColumnNames[currentPosition] = naturalOrderSubclassTableKeyColumnClosure[i];
    }

    /**
     * Suppose an entity Client extends Person, mapped to the tables CLIENT and PERSON respectively.
     * For the Client entity:
     * naturalOrderTableNames -> PERSON, CLIENT; this reflects the sequence in which the tables are
     * added to the meta-data when the annotated entities are processed.
     * However, in some instances, for example when generating joins, the CLIENT table needs to be
     * the first table as it will the driving table.
     * tableNames -> CLIENT, PERSON
     */

    tableSpan = naturalOrderTableNames.length;
    tableNames = reverse( naturalOrderTableNames, coreTableSpan );
    tableKeyColumns = reverse( naturalOrderTableKeyColumns, coreTableSpan );
    tableKeyColumnReaders = reverse( naturalOrderTableKeyColumnReaders, coreTableSpan );
    tableKeyColumnReaderTemplates = reverse( naturalOrderTableKeyColumnReaderTemplates, coreTableSpan );
    subclassTableNameClosure = reverse( naturalOrderSubclassTableNameClosure, coreTableSpan );
    subclassTableKeyColumnClosure = reverse( naturalOrderSubclassTableKeyColumnClosure, coreTableSpan );

    spaces = ArrayHelper.join(
        tableNames,
        ArrayHelper.toStringArray( persistentClass.getSynchronizedTables() )
    );

    // Custom sql
    customSQLInsert = new String[tableSpan];
    customSQLUpdate = new String[tableSpan];
    customSQLDelete = new String[tableSpan];
    insertCallable = new boolean[tableSpan];
    updateCallable = new boolean[tableSpan];
    deleteCallable = new boolean[tableSpan];
    insertResultCheckStyles = new ExecuteUpdateResultCheckStyle[tableSpan];
    updateResultCheckStyles = new ExecuteUpdateResultCheckStyle[tableSpan];
    deleteResultCheckStyles = new ExecuteUpdateResultCheckStyle[tableSpan];

    PersistentClass pc = persistentClass;
    int jk = coreTableSpan - 1;
    while ( pc != null ) {
      customSQLInsert[jk] = pc.getCustomSQLInsert();
      insertCallable[jk] = customSQLInsert[jk] != null && pc.isCustomInsertCallable();
      insertResultCheckStyles[jk] = pc.getCustomSQLInsertCheckStyle() == null
          ? ExecuteUpdateResultCheckStyle.determineDefault(
          customSQLInsert[jk], insertCallable[jk]
      )
          : pc.getCustomSQLInsertCheckStyle();
      customSQLUpdate[jk] = pc.getCustomSQLUpdate();
      updateCallable[jk] = customSQLUpdate[jk] != null && pc.isCustomUpdateCallable();
      updateResultCheckStyles[jk] = pc.getCustomSQLUpdateCheckStyle() == null
          ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLUpdate[jk], updateCallable[jk] )
          : pc.getCustomSQLUpdateCheckStyle();
      customSQLDelete[jk] = pc.getCustomSQLDelete();
      deleteCallable[jk] = customSQLDelete[jk] != null && pc.isCustomDeleteCallable();
      deleteResultCheckStyles[jk] = pc.getCustomSQLDeleteCheckStyle() == null
          ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLDelete[jk], deleteCallable[jk] )
          : pc.getCustomSQLDeleteCheckStyle();
      jk--;
      pc = pc.getSuperclass();
    }

    if ( jk != -1 ) {
      throw new AssertionFailure( "Tablespan does not match height of joined-subclass hiearchy." );
    }

    joinIter = persistentClass.getJoinClosureIterator();
    int j = coreTableSpan;
    while ( joinIter.hasNext() ) {
      Join join = (Join) joinIter.next();

      customSQLInsert[j] = join.getCustomSQLInsert();
      insertCallable[j] = customSQLInsert[j] != null && join.isCustomInsertCallable();
      insertResultCheckStyles[j] = join.getCustomSQLInsertCheckStyle() == null
          ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLInsert[j], insertCallable[j] )
          : join.getCustomSQLInsertCheckStyle();
      customSQLUpdate[j] = join.getCustomSQLUpdate();
      updateCallable[j] = customSQLUpdate[j] != null && join.isCustomUpdateCallable();
      updateResultCheckStyles[j] = join.getCustomSQLUpdateCheckStyle() == null
          ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLUpdate[j], updateCallable[j] )
          : join.getCustomSQLUpdateCheckStyle();
      customSQLDelete[j] = join.getCustomSQLDelete();
      deleteCallable[j] = customSQLDelete[j] != null && join.isCustomDeleteCallable();
      deleteResultCheckStyles[j] = join.getCustomSQLDeleteCheckStyle() == null
          ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLDelete[j], deleteCallable[j] )
          : join.getCustomSQLDeleteCheckStyle();
      j++;
    }

    // PROPERTIES
    int hydrateSpan = getPropertySpan();
    naturalOrderPropertyTableNumbers = new int[hydrateSpan];
    propertyTableNumbers = new int[hydrateSpan];
    Iterator iter = persistentClass.getPropertyClosureIterator();
    int i = 0;
    while ( iter.hasNext() ) {
      Property prop = (Property) iter.next();
      String tabname = prop.getValue().getTable().getQualifiedName(
          factory.getDialect(),
          factory.getSettings().getDefaultCatalogName(),
          factory.getSettings().getDefaultSchemaName()
      );
      propertyTableNumbers[i] = getTableId( tabname, tableNames );
      naturalOrderPropertyTableNumbers[i] = getTableId( tabname, naturalOrderTableNames );
      i++;
    }

    // subclass closure properties

    //TODO: code duplication with SingleTableEntityPersister

    ArrayList columnTableNumbers = new ArrayList();
    ArrayList formulaTableNumbers = new ArrayList();
    ArrayList propTableNumbers = new ArrayList();

    iter = persistentClass.getSubclassPropertyClosureIterator();
    while ( iter.hasNext() ) {
      Property prop = (Property) iter.next();
      Table tab = prop.getValue().getTable();
      String tabname = tab.getQualifiedName(
          factory.getDialect(),
          factory.getSettings().getDefaultCatalogName(),
          factory.getSettings().getDefaultSchemaName()
      );
      Integer tabnum = 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.