Package org.hibernate.mapping

Examples of org.hibernate.mapping.Column


        fkColumns != null && pkForeignTableColumns != null
        && fkColumns.size() == pkForeignTableColumns.size();

      Iterator columns = foreignKey.getColumnIterator();
      while (equals && columns.hasNext()) {
        Column fkColumn = (Column) columns.next();
        equals = equals && pkForeignTableColumns.contains(fkColumn);
      }

      return equals;
    } else {
View Full Code Here


     
      // tests that all columns are implied in the fks
      Set columns = new HashSet();
      Iterator columnIterator = table.getColumnIterator();
      while ( columnIterator.hasNext() ) {
        Column column = (Column) columnIterator.next();
        columns.add(column);
      }
     
           
      foreignKeyIterator = table.getForeignKeyIterator();
View Full Code Here

  }

  protected void visitColumns(Configuration cfg, Table table, IssueCollector collector) {
    Iterator columnIter = table.getColumnIterator();
    while ( columnIter.hasNext() ) {
      Column col = ( Column ) columnIter.next();
      this.visit( cfg, table, col, collector );
    }   
  }
View Full Code Here

      IssueCollector pc) {
    if ( currentDbTable == null ) {
      return;
    }

    Column dbColumn = currentDbTable
        .getColumn( new Column( col.getName() ) );

    if ( dbColumn == null ) {
      pc.reportIssue( new Issue( "SCHEMA_COLUMN_MISSING",
          Issue.HIGH_PRIORITY, table(table) + " is missing column: " + col.getName() ) );
    }
    else {
      //TODO: this needs to be able to know if a type is truly compatible or not. Right now it requires an exact match.
      //String sqlType = col.getSqlType( dialect, mapping );
      int dbTypeCode = dbColumn.getSqlTypeCode().intValue();
      int modelTypeCode = col
                .getSqlTypeCode( mapping );
      // TODO: sqltype name string
      if ( !(dbTypeCode == modelTypeCode ) ) {
        pc.reportIssue( new Issue( "SCHEMA_COLUMN_TYPE_MISMATCH",
View Full Code Here

    if ( selectable.isFormula() ) {
      annotations.append("@").append( importType("org.hibernate.annotations.Formula") )
          .append("(value=\"" ).append( selectable.getText() ).append( "\")" );
    }
    else {
      Column column = (Column) selectable;
      annotations.append( "@" + importType("javax.persistence.Column") + "(name=\"" ).append( column.getName() ).append( "\"" );
     
      appendCommonColumnInfo( annotations, column, insertable, updatable );
     
      if (column.getPrecision() != Column.DEFAULT_PRECISION) { // the default is actually 0 in spec
        annotations.append( ", precision=" ).append( column.getPrecision() );
      }
      if (column.getScale() != Column.DEFAULT_SCALE) { // default is actually 0 in spec
        annotations.append( ", scale=" ).append( column.getScale() );
      }
      else if (column.getLength() != 255){
        annotations.append( ", length=" ).append( column.getLength() );
      }
     
         
         
     
View Full Code Here

        while ( columnRefs.hasNext() ) {
          Element columnRef = (Element) columnRefs.next();
          String localColumnName = columnRef.attributeValue("local-column");
          String foreignColumnName = columnRef.attributeValue("foreign-column");
         
          Column localColumn = new Column(localColumnName);
          Column foreignColumn = new Column(foreignColumnName);
         
          localColumns.add(localColumn);
          foreignColumns.add(foreignColumn);
        }
               
View Full Code Here

  private static List bindColumns(List columns, Table table, OverrideRepository repository) {
    Iterator iterator = columns.iterator();
    List columnNames = new ArrayList();
    while( iterator.hasNext() ) {
      Element element = (Element) iterator.next();
      Column column = new Column();
      column.setName( element.attributeValue("name") );
      String attributeValue = element.attributeValue("jdbc-type");
      if(StringHelper.isNotEmpty(attributeValue)) {
        column.setSqlTypeCode(new Integer(JDBCToHibernateTypeHelper.getJDBCType(attributeValue)));
      }
           
      TableIdentifier tableIdentifier = TableIdentifier.create(table);
      if(table.getColumn(column)!=null) {
        throw new MappingException("Column " + column.getName() + " already exists in table " + tableIdentifier );
      }
     
      MultiMap map = MetaAttributeBinder.loadAndMergeMetaMap( element, new MultiHashMap());
      if(map!=null && !map.isEmpty()) {
        repository.addMetaAttributeInfo( tableIdentifier, column.getName(), map);
      }
     
      table.addColumn(column);
      columnNames.add(column.getName());
      repository.setTypeNameForColumn(tableIdentifier, column.getName(), element.attributeValue("type"));
      repository.setPropertyNameForColumn(tableIdentifier, column.getName(), element.attributeValue("property"));
     
      boolean excluded = booleanValue( element.attributeValue("exclude") );
      if(excluded) {
        repository.setExcludedColumn(tableIdentifier, column.getName());
      }
     
      String foreignTableName = element.attributeValue("foreign-table");
      if(foreignTableName!=null) {
        List localColumns = new ArrayList();
        localColumns.add(column);
        List foreignColumns = new ArrayList();
       
        Table foreignTable = new Table();
        foreignTable.setName(foreignTableName);
        foreignTable.setCatalog(getValue(element.attributeValue( "foreign-catalog"),table.getCatalog()) );
        foreignTable.setSchema(getValue(element.attributeValue( "foreign-schema"), table.getSchema()) );
       
        String foreignColumnName = element.attributeValue("foreign-column");
        if(foreignColumnName!=null) {
          Column foreignColumn = new Column();
          foreignColumn.setName(foreignColumnName);
          foreignColumns.add(foreignColumn);
        }
        else {
          throw new MappingException("foreign-column is required when foreign-table is specified on " + column);
        }
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 );
          final String columnName = columnElement.attributeValue( "name" );
          String logicalColumnName = mappings.getNamingStrategy().logicalColumnName(
              columnName, propertyPath
          );
          column.setName( mappings.getNamingStrategy().columnName(
            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();
      }
      final String columnName = columnAttribute.getValue();
      String logicalColumnName = mappings.getNamingStrategy().logicalColumnName(
          columnName, propertyPath
      );
      column.setName( mappings.getNamingStrategy().columnName( 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 );
      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

      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() ) );
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

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.