Package org.hibernate.mapping

Examples of org.hibernate.mapping.Column


          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

      Iterator iter = node.elementIterator();
      int count = 0;
      while ( iter.hasNext() ) {
        Element columnElement = (Element) iter.next();
        if ( columnElement.getName().equals( "column" ) ) {
          Column column = new Column();
          column.setValue( simpleValue );
          column.setTypeIndex( count++ );
          bindColumn( columnElement, column, isNullable );
          String logicalColumnName = mappings.getNamingStrategy().logicalColumnName(
              columnElement.attributeValue( "name" ), propertyPath
          );
          column.setName( mappings.getNamingStrategy().columnName(
            logicalColumnName ) );
          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 );
        }
      }
    }
    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 );
      String logicalColumnName = mappings.getNamingStrategy().logicalColumnName(
          columnAttribute.getValue(), propertyPath
      );
      column.setName( mappings.getNamingStrategy().columnName( logicalColumnName ) );
      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 );
      column.setName( mappings.getNamingStrategy().propertyToColumnName( propertyPath ) );
      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 HbmBinder does not support the
View Full Code Here

    ExtendedMappings mappings = createExtendedMappings();
    for (int index = 0; index < size; index++) {
      String columnName;
      try {
        columnName = mappings.getPhysicalColumnName( columnNames[index], 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( columnNames[index] ) );
      }
    }
    for (Column column : columns) {
      if ( table.containsColumn( column ) ) {
        uc = table.getOrCreateUniqueKey( keyName );
View Full Code Here

  protected void initMappingColumn(
      String columnName, String propertyName, int length, int precision, int scale, boolean nullable,
      String sqlType, boolean unique, boolean applyNamingStrategy
  ) {
    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];
    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

      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

    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() );
      identifierAliases[i] = col.getAlias( factory.getDialect(), persistentClass.getRootTable() );
      i++;
    }

    // VERSION
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;
        discriminatorAlias = "clazz_";
      }
      else {
        Column column = (Column) selectable;
        discriminatorColumnName = column.getQuotedName( factory.getDialect() );
        discriminatorAlias = column.getAlias( factory.getDialect(), persistentClass.getRootTable() );
        discriminatorFormula = null;
        discriminatorFormulaTemplate = null;
      }
      discriminatorType = persistentClass.getDiscriminator().getType();
      if ( persistentClass.isDiscriminatorValueNull() ) {
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);
      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

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.