Package org.hibernate.mapping

Examples of org.hibernate.mapping.Column


    keyColumnNames = new String[keySpan];
    keyColumnAliases = new String[keySpan];
    int k = 0;
    while ( iter.hasNext() ) {
      // NativeSQL: collect key column and auto-aliases
      Column col = ( (Column) iter.next() );
      keyColumnNames[k] = col.getQuotedName(dialect);
      keyColumnAliases[k] = col.getAlias(dialect,collection.getOwner().getRootTable());
      k++;
    }
   
    //unquotedKeyColumnNames = StringHelper.unQuote(keyColumnAliases);

    //ELEMENT

    String elemNode = collection.getElementNodeName();
    if ( elementType.isEntityType() ) {
      String entityName = ( (EntityType) elementType ).getAssociatedEntityName();
      elementPersister = factory.getEntityPersister(entityName);
      if ( elemNode==null ) {
        elemNode = cfg.getClassMapping(entityName).getNodeName();
      }
      // NativeSQL: collect element column and auto-aliases
     
    }
    else {
      elementPersister = null;
    }   
    elementNodeName = elemNode;

    int elementSpan = collection.getElement().getColumnSpan();
    elementColumnAliases = new String[elementSpan];
    elementColumnNames = new String[elementSpan];
    elementFormulaTemplates = new String[elementSpan];
    elementFormulas = new String[elementSpan];
    elementColumnIsSettable = new boolean[elementSpan];
    elementColumnIsInPrimaryKey = new boolean[elementSpan];
    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;
        }
        else {
          Column indexCol = (Column) s;
          indexColumnNames[i] = indexCol.getQuotedName(dialect);
          indexColumnIsSettable[i] = true;
        }
        i++;
      }
      indexContainsFormula = hasFormula;
      baseIndex = indexedCollection.isList() ?
          ( (List) indexedCollection ).getBaseIndex() : 0;

      indexNodeName = indexedCollection.getIndexNodeName();

    }
    else {
      indexContainsFormula = false;
      indexColumnIsSettable = null;
      indexFormulaTemplates = null;
      indexFormulas = null;
      indexType = null;
      indexColumnNames = null;
      indexColumnAliases = null;
      baseIndex = 0;
      indexNodeName = null;
    }
   
    hasIdentifier = collection.isIdentified();
    if (hasIdentifier) {
      if ( collection.isOneToMany() ) {
        throw new MappingException( "one-to-many collections with identifiers are not supported" );
      }
      IdentifierCollection idColl = (IdentifierCollection) collection;
      identifierType = idColl.getIdentifier().getType();
      iter = idColl.getIdentifier().getColumnIterator();
      Column col = ( Column ) iter.next();
      identifierColumnName = col.getQuotedName(dialect);
      identifierColumnAlias = col.getAlias(dialect);
      //unquotedIdentifierColumnName = identifierColumnAlias;
      identifierGenerator = idColl.getIdentifier().createIdentifierGenerator(
          factory.getDialect(),
          factory.getSettings().getDefaultCatalogName(),
          factory.getSettings().getDefaultSchemaName(),
View Full Code Here


      Iterator iter = join.getKey().getColumnIterator();
      keyColumnNames[j] = new String[ join.getKey().getColumnSpan() ];
      int i = 0;
      while ( iter.hasNext() ) {
        Column col = (Column) iter.next();
        keyColumnNames[j][i++] = col.getQuotedName( factory.getDialect() );
      }

      j++;
    }

    constraintOrderedTableNames = new String[qualifiedTableNames.length];
    constraintOrderedKeyColumnNames = new String[qualifiedTableNames.length][];
    for ( int i = qualifiedTableNames.length - 1, position = 0; i >= 0; i--, position++ ) {
      constraintOrderedTableNames[position] = qualifiedTableNames[i];
      constraintOrderedKeyColumnNames[position] = keyColumnNames[i];
    }

    spaces = ArrayHelper.join(
        qualifiedTableNames,
        ArrayHelper.toStringArray( persistentClass.getSynchronizedTables() )
    );
   
    final boolean lazyAvailable = isInstrumented(EntityMode.POJO);

    boolean hasDeferred = false;
    ArrayList subclassTables = new ArrayList();
    ArrayList joinKeyColumns = new ArrayList();
    ArrayList isConcretes = new ArrayList();
    ArrayList isDeferreds = new ArrayList();
    ArrayList isInverses = new ArrayList();
    ArrayList isNullables = new ArrayList();
    ArrayList isLazies = new ArrayList();
    subclassTables.add( qualifiedTableNames[0] );
    joinKeyColumns.add( getIdentifierColumnNames() );
    isConcretes.add(Boolean.TRUE);
    isDeferreds.add(Boolean.FALSE);
    isInverses.add(Boolean.FALSE);
    isNullables.add(Boolean.FALSE);
    isLazies.add(Boolean.FALSE);
    joinIter = persistentClass.getSubclassJoinClosureIterator();
    while ( joinIter.hasNext() ) {
      Join join = (Join) joinIter.next();
      isConcretes.add( new Boolean( persistentClass.isClassOrSuperclassJoin(join) ) );
      isDeferreds.add( new Boolean( join.isSequentialSelect() ) );
      isInverses.add( new Boolean( join.isInverse() ) );
      isNullables.add( new Boolean( join.isOptional() ) );
      isLazies.add( new Boolean( lazyAvailable && join.isLazy() ) );
      if ( join.isSequentialSelect() && !persistentClass.isClassOrSuperclassJoin(join) ) hasDeferred = true;
      subclassTables.add( join.getTable().getQualifiedName(
          factory.getDialect(),
          factory.getSettings().getDefaultCatalogName(),
          factory.getSettings().getDefaultSchemaName()
      ) );
      Iterator iter = join.getKey().getColumnIterator();
      String[] keyCols = new String[ join.getKey().getColumnSpan() ];
      int i = 0;
      while ( iter.hasNext() ) {
        Column col = (Column) iter.next();
        keyCols[i++] = col.getQuotedName( factory.getDialect() );
      }
      joinKeyColumns.add(keyCols);
    }
   
    subclassTableSequentialSelect = ArrayHelper.toBooleanArray(isDeferreds);
    subclassTableNameClosure = ArrayHelper.toStringArray(subclassTables);
    subclassTableIsLazyClosure = ArrayHelper.toBooleanArray(isLazies);
    subclassTableKeyColumnClosure = ArrayHelper.to2DStringArray(joinKeyColumns);
    isClassOrSuperclassTable = ArrayHelper.toBooleanArray(isConcretes);
    isInverseSubclassTable = ArrayHelper.toBooleanArray(isInverses);
    isNullableSubclassTable = ArrayHelper.toBooleanArray(isNullables);
    hasSequentialSelects = hasDeferred;

    // DISCRIMINATOR

    final Object discriminatorValue;
    if ( persistentClass.isPolymorphic() ) {
      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() ) {
View Full Code Here

    loaderName = persistentClass.getLoaderName();

    Iterator iter = persistentClass.getIdentifier().getColumnIterator();
    int i = 0;
    while ( iter.hasNext() ) {
      Column col = ( Column ) iter.next();
      rootTableKeyColumnNames[i] = col.getQuotedName( factory.getDialect() );
      rootTableKeyColumnReaders[i] = col.getReadExpr( factory.getDialect() );
      rootTableKeyColumnReaderTemplates[i] = col.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
      identifierAliases[i] = col.getAlias( factory.getDialect(), persistentClass.getRootTable() );
      i++;
    }

    // VERSION

    if ( persistentClass.isVersioned() ) {
      versionColumnName = ( ( Column ) persistentClass.getVersion().getColumnIterator().next() ).getQuotedName( factory.getDialect() );
    }
    else {
      versionColumnName = null;
    }

    //WHERE STRING

    sqlWhereString = StringHelper.isNotEmpty( persistentClass.getWhere() ) ? "( " + persistentClass.getWhere() + ") " : null;
    sqlWhereStringTemplate = sqlWhereString == null ?
        null :
        Template.renderWhereStringTemplate( sqlWhereString, factory.getDialect(), factory.getSqlFunctionRegistry() );

    // PROPERTIES

    final boolean lazyAvailable = isInstrumented(EntityMode.POJO);

    int hydrateSpan = entityMetamodel.getPropertySpan();
    propertyColumnSpans = new int[hydrateSpan];
    propertySubclassNames = new String[hydrateSpan];
    propertyColumnAliases = new String[hydrateSpan][];
    propertyColumnNames = new String[hydrateSpan][];
    propertyColumnFormulaTemplates = new String[hydrateSpan][];
    propertyColumnReaderTemplates = new String[hydrateSpan][];
    propertyColumnWriters = new String[hydrateSpan][];
    propertyUniqueness = new boolean[hydrateSpan];
    propertySelectable = new boolean[hydrateSpan];
    propertyColumnUpdateable = new boolean[hydrateSpan][];
    propertyColumnInsertable = new boolean[hydrateSpan][];
    HashSet thisClassProperties = new HashSet();

    lazyProperties = new HashSet();
    ArrayList lazyNames = new ArrayList();
    ArrayList lazyNumbers = new ArrayList();
    ArrayList lazyTypes = new ArrayList();
    ArrayList lazyColAliases = new ArrayList();

    iter = persistentClass.getPropertyClosureIterator();
    i = 0;
    boolean foundFormula = false;
    while ( iter.hasNext() ) {
      Property prop = ( Property ) iter.next();
      thisClassProperties.add( prop );

      int span = prop.getColumnSpan();
      propertyColumnSpans[i] = span;
      propertySubclassNames[i] = prop.getPersistentClass().getEntityName();
      String[] colNames = new String[span];
      String[] colAliases = new String[span];
      String[] colReaderTemplates = new String[span];
      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() );
          readerTemplates[l] = readerTemplate;
          columnReaderTemplates.add( readerTemplate );
        }
        l++;
      }
View Full Code Here

      JoinColumn joinAnn,
      Value identifier,
      Map<String, Join> joins,
      PropertyHolder propertyHolder,
      Mappings mappings) {
    Column col = (Column) identifier.getColumnIterator().next();
    String defaultName = mappings.getLogicalColumnName( col.getQuotedName(), identifier.getTable() );
    if ( pkJoinAnn != null || joinAnn != null ) {
      String colName;
      String columnDefinition;
      String referencedColumnName;
      if ( pkJoinAnn != null ) {
View Full Code Here

      SimpleValue value) {
    if ( !isNameDeferred() ) {
      throw new AssertionFailure( "Building implicit column but the column is not implicit" );
    }
    while ( columnIterator.hasNext() ) {
      Column synthCol = (Column) columnIterator.next();
      this.linkValueUsingDefaultColumnNaming( synthCol, referencedEntity, value );
    }
    //reset for the future
    setMappingColumn( null );
  }
View Full Code Here

              "Unable to find column with logical name: "
                  + logicalReferencedColumnName + " in " + matchingTable.getName()
          );
        }
        noReferencedColumn = false;
        Column refCol = new Column( referencedColumnName );
        boolean contains = idColumns.contains( refCol );
        if ( !contains ) {
          isFkReferencedColumnName = true;
          break; //we know the state
        }
View Full Code Here

      if ( !table.isAbstractUnionTable() ) {
        //TODO: move to .sql package!!
        buf.append("select ");
        Iterator citer = columns.iterator();
        while ( citer.hasNext() ) {
          Column col = (Column) citer.next();
          if ( !table.containsColumn(col) ) {
            int sqlType = col.getSqlTypeCode(mapping);
            buf.append( dialect.getSelectClauseNullString(sqlType) )
              .append(" as ");
          }
          buf.append( col.getName() );
          buf.append(", ");
        }
        buf.append( clazz.getSubclassId() )
          .append(" as clazz_");
        buf.append(" from ")
View Full Code Here

      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( new Boolean( 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 tabIndex = 0;
    Iterator joinIter = persistentClass.getJoinClosureIterator();
    while ( joinIter.hasNext() ) {
      Join join = (Join) joinIter.next();
     
      isNullableTable[tabIndex++] = join.isOptional();
     
      Table tab = join.getTable();
      
      String tabname = tab.getQualifiedName(
          factory.getDialect(),
          factory.getSettings().getDefaultCatalogName(),
          factory.getSettings().getDefaultSchemaName()
      );
      tables.add(tabname);
     
      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( new Boolean( key.isCascadeDeleteEnabled() && factory.getDialect().supportsCascadeDelete() ) );
View Full Code Here

      if ( !table.isAbstractUnionTable() ) {
        //TODO: move to .sql package!!
        buf.append("select ");
        Iterator citer = columns.iterator();
        while ( citer.hasNext() ) {
          Column col = (Column) citer.next();
          if ( !table.containsColumn(col) ) {
            int sqlType = col.getSqlTypeCode(mapping);
            buf.append( dialect.getSelectClauseNullString(sqlType) )
              .append(" as ");
          }
          buf.append( col.getQuotedName(dialect) );
          buf.append(", ");
        }
        buf.append( clazz.getSubclassId() )
          .append(" as clazz_");
        buf.append(" from ")
View Full Code Here

      Iterator itr = node.elementIterator();
      int count = 0;
      while ( itr.hasNext() ) {
        Element columnElement = (Element) itr.next();
        if ( columnElement.getName().equals( "column" ) ) {
          Column column = new Column();
          column.setValue( simpleValue );
          column.setTypeIndex( count++ );
          bindColumn( columnElement, column, isNullable );
          String columnName = columnElement.attributeValue( "name" );
          String logicalColumnName = mappings.getNamingStrategy().logicalColumnName(
              columnName, propertyPath
          );
          columnName = mappings.getNamingStrategy().columnName( columnName );
          columnName = quoteIdentifier( columnName, mappings );
          column.setName( columnName );
          if ( table != null ) {
            table.addColumn( column ); // table=null -> an association
                                       // - fill it in later
            //TODO fill in the mappings for table == null
            mappings.addColumnBinding( logicalColumnName, column, table );
          }


          simpleValue.addColumn( column );
          // column index
          bindIndex( columnElement.attribute( "index" ), table, column, mappings );
          bindIndex( node.attribute( "index" ), table, column, mappings );
          //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
      // (and no formulas) are contained in a defined unique key that only contains these columns.
      // That too would mark this as a logical one-to-one
      final Attribute uniqueAttribute = node.attribute( "unique" );
      if ( uniqueAttribute != null
          && "true".equals( uniqueAttribute.getValue() )
          && ManyToOne.class.isInstance( simpleValue ) ) {
        ( (ManyToOne) simpleValue ).markAsLogicalOneToOne();
      }
    }
    else {
      if ( node.elementIterator( "column" ).hasNext() ) {
        throw new MappingException(
          "column attribute may not be used together with <column> subelement" );
      }
      if ( node.elementIterator( "formula" ).hasNext() ) {
        throw new MappingException(
          "column attribute may not be used together with <formula> subelement" );
      }

      Column column = new Column();
      column.setValue( simpleValue );
      bindColumn( node, column, isNullable );
      if ( column.isUnique() && ManyToOne.class.isInstance( simpleValue ) ) {
        ( (ManyToOne) simpleValue ).markAsLogicalOneToOne();
      }
      String columnName = columnAttribute.getValue();
      String logicalColumnName = mappings.getNamingStrategy().logicalColumnName(
          columnName, propertyPath
      );
      columnName = mappings.getNamingStrategy().columnName( columnName );
      columnName = quoteIdentifier( columnName, mappings );
      column.setName( columnName );
      if ( table != null ) {
        table.addColumn( column ); // table=null -> an association - fill
                                   // it in later
        //TODO fill in the mappings for table == null
        mappings.addColumnBinding( logicalColumnName, column, table );
      }
      simpleValue.addColumn( column );
      bindIndex( node.attribute( "index" ), table, column, mappings );
      bindUniqueKey( node.attribute( "unique-key" ), table, column, mappings );
    }

    if ( autoColumn && simpleValue.getColumnSpan() == 0 ) {
      Column column = new Column();
      column.setValue( simpleValue );
      bindColumn( node, column, isNullable );
      String columnName = mappings.getNamingStrategy().propertyToColumnName( propertyPath );
      columnName = quoteIdentifier( columnName, mappings );
      column.setName( columnName );
      String logicalName = mappings.getNamingStrategy().logicalColumnName( null, propertyPath );
      mappings.addColumnBinding( logicalName, column, table );
      /* TODO: joinKeyColumnName & foreignKeyColumnName should be called either here or at a
       * slightly higer level in the stack (to get all the information we need)
       * Right now HbmMetadataSourceProcessorImpl does not support the
View Full Code Here

TOP

Related Classes of org.hibernate.mapping.Column

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.