Package org.hibernate.mapping

Examples of org.hibernate.mapping.Column


   * @param primaryKey
   */
  private void bindColumnsToProperties(Table table, RootClass rc, Set processedColumns, Mapping mapping) {

    for (Iterator iterator = table.getColumnIterator(); iterator.hasNext();) {
      Column column = (Column) iterator.next();
      if ( !processedColumns.contains(column) ) {
        checkColumn(column);

        String propertyName = revengStrategy.columnToPropertyName(TableIdentifier.create(table), column.getName() );

        Property property = bindBasicProperty(
            makeUnique(rc,propertyName),
            table,
            column,
View Full Code Here


    TableIdentifier identifier = TableIdentifier.create(table);

    String optimisticLockColumnName = revengStrategy.getOptimisticLockColumnName(identifier);

    if(optimisticLockColumnName!=null) {
      Column column = table.getColumn(new Column(optimisticLockColumnName));
      if(column==null) {
        log.warn("Column " + column + " wanted for <version>/<timestamp> not found in " + identifier);
      } else {
        bindVersionProperty(table, identifier, column, rc, processed, mapping);
      }
    } else {
      log.debug("Scanning " + identifier + " for <version>/<timestamp> columns.");
      Iterator columnIterator = table.getColumnIterator();
      while(columnIterator.hasNext()) {
        Column column = (Column) columnIterator.next();
        boolean useIt = revengStrategy.useColumnForOptimisticLock(identifier, column.getName());
        if(useIt && !processed.contains(column)) {
          bindVersionProperty( table, identifier, column, rc, processed, mapping );
          return;
        }
      }
View Full Code Here

     * @param processedColumns
     * @return
     */
    private boolean contains(Iterator columnIterator, Set processedColumns) {
        while (columnIterator.hasNext() ) {
            Column element = (Column) columnIterator.next();
            if(processedColumns.contains(element) ) {
                return true;
            }
        }
        return false;
View Full Code Here

        }
        for (Iterator iter = list.iterator(); iter.hasNext();) {
            Object element = iter.next();
      Property property;
            if (element instanceof Column) {
                Column column = (Column) element;
                if ( processedColumns.contains(column) ) {
                    throw new JDBCBinderException("Binding column twice for primary key should not happen: " + column);
                }
        else {
                    checkColumn(column);

                    String propertyName = revengStrategy.columnToPropertyName( TableIdentifier.create(table), column.getName() );
          property = bindBasicProperty( makeUnique(pkc, propertyName), table, column, processedColumns, mapping);

                    processedColumns.add(column);
                }
            }
View Full Code Here

      }

//      Collections.reverse(tempList);

      List result = new ArrayList();
      Column myPkColumns[] = (Column[]) pkColumns.toArray(new Column[pkColumns.size()]);

      for (int i = 0; i < myPkColumns.length; i++) {

        boolean foundKey = false;
        foreignKeyIterator = tempList.iterator();
View Full Code Here

        return null; // not enough columns in the key
      }

      List columns = new ArrayList();
      for (int j = 0; j < key.getColumnSpan(); j++) {
      Column column = myPkColumns[j+offset];
      if(!column.equals(key.getColumn(j))) {
        return null;
      } else {
        columns.add(column);
      }
    }
View Full Code Here

  }

    private Property bindMeta(Property property, TableIdentifier identifier) {
      Iterator columnIterator = property.getValue().getColumnIterator();
    while(columnIterator.hasNext()) {
      Column col = (Column) columnIterator.next();

      Map map = revengStrategy.columnToMetaAttributes( identifier, col.getName() );
      if(map!=null) { // TODO: merge from each column ?
        property.setMetaAttributes( map );
      }
    }
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

      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

      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

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.