Package org.hibernate.mapping

Examples of org.hibernate.mapping.Column


              "columnOwner neither PersistentClass nor Join: " + columnOwner.getClass()
      );
    }
    //build the list of column names
    for (Ejb3JoinColumn column1 : columns) {
      Column column = new Column(
          mappings.getPhysicalColumnName( column1.getReferencedColumn(), referencedTable )
      );
      orderedColumns.add( column );
      columnsToProperty.put( column, new HashSet<Property>() );
    }
View Full Code Here


            final Selectable selectable = columns.next();
            if ( ! Column.class.isInstance( selectable ) ) {
              log.debug( "Encountered formula definition; skipping" );
              continue;
            }
            final Column column = (Column) selectable;
            final Ejb3JoinColumn joinColumn;
            String logicalColumnName = null;
            if ( isExplicitReference ) {
              final String columnName = column.getName();
              logicalColumnName = mappings.getLogicalColumnName( columnName, referencedPersistentClass.getTable() );
              //JPA 2 requires referencedColumnNames to be case insensitive
              joinColumn = columnByReferencedName.get( logicalColumnName.toLowerCase() );
            }
            else {
              joinColumn = columnByReferencedName.get( "" + index );
              index++;
            }
            if ( joinColumn == null && ! joinColumns[0].isNameDeferred() ) {
              throw new AnnotationException(
                  isExplicitReference ?
                      "Unable to find column reference in the @MapsId mapping: " + logicalColumnName :
                      "Implicit column reference in the @MapsId mapping fails, try to use explicit referenceColumnNames: " + referencedEntityName
              );
            }
            final String columnName = joinColumn == null || joinColumn.isNameDeferred() ? "tata_" + column.getName() : joinColumn
                .getName();
            value.addColumn( new Column( columnName ) );
            column.setValue( value );
          }
        }
        component.addProperty( property );
      }
    }
View Full Code Here

        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() );
View Full Code Here

    Set<Column> unboundNoLogical = new HashSet<Column>();
    for ( int index = 0; index < size; index++ ) {
      final String logicalColumnName = normalizer.normalizeIdentifierQuoting( columnNames[index] );
      try {
        final String columnName = createMappings().getPhysicalColumnName( logicalColumnName, table );
        columns[index] = new Column( columnName );
        unbound.add( columns[index] );
        //column equals and hashcode is based on column name
      }
      catch ( MappingException e ) {
        unboundNoLogical.add( new Column( logicalColumnName ) );
      }
    }
    for ( Column column : columns ) {
      if ( table.containsColumn( column ) ) {
        uc = table.getOrCreateUniqueKey( keyName );
View Full Code Here

    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];
    elementColumnWriters = new String[elementSpan];
    elementColumnReaders = new String[elementSpan];
    elementColumnReaderTemplates = 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);
        elementColumnWriters[j] = col.getWriteExpr();
        elementColumnReaders[j] = col.getReadExpr(dialect);
        elementColumnReaderTemplates[j] = col.getTemplate(dialect, factory.getSqlFunctionRegistry());
        elementColumnIsSettable[j] = true;
        elementColumnIsInPrimaryKey[j] = !col.isNullable();
        if ( !col.isNullable() ) {
          hasNotNullableColumns = true;
        }
        isPureFormula = false;
      }
      j++;
    }
    elementIsPureFormula = isPureFormula;
   
    //workaround, for backward compatibility of sets with no
    //not-null columns, assume all columns are used in the
    //row locator SQL
    if ( !hasNotNullableColumns ) {
      Arrays.fill( elementColumnIsInPrimaryKey, true );
    }


    // INDEX AND ROW SELECT

    hasIndex = collection.isIndexed();
    if (hasIndex) {
      // NativeSQL: collect index column and auto-aliases
      IndexedCollection indexedCollection = (IndexedCollection) collection;
      indexType = indexedCollection.getIndex().getType();
      int indexSpan = indexedCollection.getIndex().getColumnSpan();
      iter = indexedCollection.getIndex().getColumnIterator();
      indexColumnNames = new String[indexSpan];
      indexFormulaTemplates = new String[indexSpan];
      indexFormulas = new String[indexSpan];
      indexColumnIsSettable = new boolean[indexSpan];
      indexColumnAliases = new String[indexSpan];
      int i = 0;
      boolean hasFormula = false;
      while ( iter.hasNext() ) {
        Selectable s = (Selectable) iter.next();
        indexColumnAliases[i] = s.getAlias(dialect);
        if ( s.isFormula() ) {
          Formula indexForm = (Formula) s;
          indexFormulaTemplates[i] = indexForm.getTemplate(dialect, factory.getSqlFunctionRegistry());
          indexFormulas[i] = indexForm.getFormula();
          hasFormula = true;
        }
        else {
          Column indexCol = (Column) s;
          indexColumnNames[i] = indexCol.getQuotedName(dialect);
          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(
          cfg.getIdentifierGeneratorFactory(),
          factory.getDialect(),
          factory.getSettings().getDefaultCatalogName(),
View Full Code Here

    Set<Column> unboundNoLogical = new HashSet<Column>();
    for ( int index = 0; index < size; index++ ) {
      String column = columnNames[index];
      try {
        final String columnName = createMappings().getPhysicalColumnName( column, table );
        columns[index] = new Column( columnName );
        unbound.add( columns[index] );
        //column equals and hashcode is based on column name
      }
      catch ( MappingException e ) {
        unboundNoLogical.add( new Column( column ) );
      }
    }
   
    if ( StringHelper.isEmpty( keyName ) ) {
      keyName = Constraint.generateName( "UK_", table, columns );
View Full Code Here

          manyToOne.setReferencedEntityName( value.getReferencedEntityName() );
          manyToOne.setUnwrapProxy( value.isUnwrapProxy() );
          prop.setValue( manyToOne );
          Iterator otherSideJoinKeyColumns = otherSideJoin.getKey().getColumnIterator();
          while ( otherSideJoinKeyColumns.hasNext() ) {
            Column column = (Column) otherSideJoinKeyColumns.next();
            Column copy = new Column();
            copy.setLength( column.getLength() );
            copy.setScale( column.getScale() );
            copy.setValue( manyToOne );
            copy.setName( column.getQuotedName() );
            copy.setNullable( column.isNullable() );
            copy.setPrecision( column.getPrecision() );
            copy.setUnique( column.isUnique() );
            copy.setSqlType( column.getSqlType() );
            copy.setCheckConstraint( column.getCheckConstraint() );
            copy.setComment( column.getComment() );
            copy.setDefaultValue( column.getDefaultValue() );
            manyToOne.addColumn( copy );
          }
          mappedByJoin.addProperty( prop );
        }
        else {
View Full Code Here

    //TODO support for inverse and optional
    join.setOptional( true ); //perhaps not quite per-spec, but a Good Thing anyway
    key.setCascadeDeleteEnabled( false );
    Iterator mappedByColumns = otherSideProperty.getValue().getColumnIterator();
    while ( mappedByColumns.hasNext() ) {
      Column column = (Column) mappedByColumns.next();
      Column copy = new Column();
      copy.setLength( column.getLength() );
      copy.setScale( column.getScale() );
      copy.setValue( key );
      copy.setName( column.getQuotedName() );
      copy.setNullable( column.isNullable() );
      copy.setPrecision( column.getPrecision() );
      copy.setUnique( column.isUnique() );
      copy.setSqlType( column.getSqlType() );
      copy.setCheckConstraint( column.getCheckConstraint() );
      copy.setComment( column.getComment() );
      copy.setDefaultValue( column.getDefaultValue() );
      key.addColumn( copy );
    }
    persistentClass.addJoin( join );
    return join;
  }
View Full Code Here

    if ( StringHelper.isNotEmpty( formulaString ) ) {
      this.formula = new Formula();
      this.formula.setFormula( formulaString );
    }
    else {
      this.mappingColumn = new Column();
      redefineColumnName( columnName, propertyName, applyNamingStrategy );
      this.mappingColumn.setLength( length );
      if ( precision > 0 ) {  //revelent precision
        this.mappingColumn.setPrecision( precision );
        this.mappingColumn.setScale( scale );
View Full Code Here

    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];
    elementColumnWriters = new String[elementSpan];
    elementColumnReaders = new String[elementSpan];
    elementColumnReaderTemplates = 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, table );
      if ( selectable.isFormula() ) {
        Formula form = (Formula) selectable;
        elementFormulaTemplates[j] = form.getTemplate( dialect, factory.getSqlFunctionRegistry() );
        elementFormulas[j] = form.getFormula();
      }
      else {
        Column col = (Column) selectable;
        elementColumnNames[j] = col.getQuotedName( dialect );
        elementColumnWriters[j] = col.getWriteExpr();
        elementColumnReaders[j] = col.getReadExpr( dialect );
        elementColumnReaderTemplates[j] = col.getTemplate( dialect, factory.getSqlFunctionRegistry() );
        elementColumnIsSettable[j] = true;
        elementColumnIsInPrimaryKey[j] = !col.isNullable();
        if ( !col.isNullable() ) {
          hasNotNullableColumns = true;
        }
        isPureFormula = false;
      }
      j++;
    }
    elementIsPureFormula = isPureFormula;

    // workaround, for backward compatibility of sets with no
    // not-null columns, assume all columns are used in the
    // row locator SQL
    if ( !hasNotNullableColumns ) {
      Arrays.fill( elementColumnIsInPrimaryKey, true );
    }

    // INDEX AND ROW SELECT

    hasIndex = collection.isIndexed();
    if ( hasIndex ) {
      // NativeSQL: collect index column and auto-aliases
      IndexedCollection indexedCollection = (IndexedCollection) collection;
      indexType = indexedCollection.getIndex().getType();
      int indexSpan = indexedCollection.getIndex().getColumnSpan();
      iter = indexedCollection.getIndex().getColumnIterator();
      indexColumnNames = new String[indexSpan];
      indexFormulaTemplates = new String[indexSpan];
      indexFormulas = new String[indexSpan];
      indexColumnIsSettable = new boolean[indexSpan];
      indexColumnAliases = new String[indexSpan];
      int i = 0;
      boolean hasFormula = false;
      while ( iter.hasNext() ) {
        Selectable s = (Selectable) iter.next();
        indexColumnAliases[i] = s.getAlias( dialect );
        if ( s.isFormula() ) {
          Formula indexForm = (Formula) s;
          indexFormulaTemplates[i] = indexForm.getTemplate( dialect, factory.getSqlFunctionRegistry() );
          indexFormulas[i] = indexForm.getFormula();
          hasFormula = true;
        }
        else {
          Column indexCol = (Column) s;
          indexColumnNames[i] = indexCol.getQuotedName( dialect );
          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(
          cfg.getIdentifierGeneratorFactory(),
          factory.getDialect(),
          factory.getSettings().getDefaultCatalogName(),
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.