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


    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

          if(fkTable != previousTable) {
            throw new JDBCBinderException("Foreign key name (" + fkName + ") mapped to different tables! previous: " + previousTable + " current:" + fkTable);
          }
        }
       
        Column column = new Column(fkColumnName);
        Column existingColumn = fkTable.getColumn(column);
        column = existingColumn==null ? column : existingColumn;
       
        depColumns.add(column);
       
        List primColumns = (List) referencedColumns.get(fkName);
        if (primColumns == null) {
          primColumns = new ArrayList();
          referencedColumns.put(fkName,primColumns);         
        }
       
        Column refColumn = new Column(pkColumnName);
        existingColumn = referencedTable.getColumn(refColumn);
        refColumn = existingColumn==null?refColumn:existingColumn;
       
        primColumns.add(refColumn);
       
      }
    }
        finally {
          try {
            if(exportedKeyIterator!=null) {
              getMetaDataDialect().close(exportedKeyIterator);
            }
          } catch(JDBCException se) {
            log.warn("Exception while closing result set for foreign key meta data",se);
          }
        }
        } catch(JDBCException se) {
          //throw sec.convert(se, "Exception while reading foreign keys for " + referencedTable, null);
          log.warn("Exception while reading foreign keys for " + referencedTable + " [" + se.toString() + "]", se);
          // sybase (and possibly others has issues with exportedkeys) see HBX-411
          // we continue after this to allow user provided keys to be added.
        }
       
        List userForeignKeys = revengStrategy.getForeignKeys(TableIdentifier.create(referencedTable));
        if(userForeignKeys!=null) {
          Iterator iterator = userForeignKeys.iterator();
          while ( iterator.hasNext() ) {
            ForeignKey element = (ForeignKey) iterator.next();
           
            if(!equalTable(referencedTable, element.getReferencedTable() ) ) {
              log.debug("Referenced table " + element.getReferencedTable().getName() + " is not " +  referencedTable + ". Ignoring userdefined foreign key " + element );
              continue; // skip non related foreign keys
            }
           
            String userfkName = element.getName();           
            Table userfkTable = element.getTable();
           
            List userColumns = element.getColumns();
            List userrefColumns = element.getReferencedColumns();
           
            Table deptable = (Table) dependentTables.get(userfkName);
            if(deptable!=null) { // foreign key already defined!?
              throw new MappingException("Foreign key " + userfkName + " already defined in the database!");
            }
           
            deptable = dbs.getTable(userfkTable.getSchema(), userfkTable.getCatalog(), userfkTable.getName() );
            if(deptable==null) {
          //  filter out stuff we don't have tables for!
          log.debug("User defined foreign key " + userfkName + " references unknown or filtered table " + TableIdentifier.create(userfkTable) );
          continue;             
            }
           
            dependentTables.put(userfkName, deptable);
           
            List depColumns = new ArrayList(userColumns.size() );
            Iterator colIterator = userColumns.iterator();
            while(colIterator.hasNext() ) {
              Column jdbcColumn = (Column) colIterator.next();
              Column column = new Column(jdbcColumn.getName() );
            Column existingColumn = deptable.getColumn(column);
            column = existingColumn==null ? column : existingColumn;
            depColumns.add(column);
            }
           
            List refColumns = new ArrayList(userrefColumns.size() );
            colIterator = userrefColumns.iterator();
            while(colIterator.hasNext() ) {
              Column jdbcColumn = (Column) colIterator.next();
              Column column = new Column(jdbcColumn.getName() );
            Column existingColumn = referencedTable.getColumn(column);
            column = existingColumn==null ? column : existingColumn;
            refColumns.add(column);
            }
           
            referencedColumns.put(userfkName, refColumns );
View Full Code Here

        if(key!=null) {
          cols = columns.iterator();
          while (cols.hasNext() ) {
            String name = (String) cols.next();
            // should get column from table if it already exists!
            Column col = getColumn(table, name);
            key.addColumn(col);
          }
          log.debug("primary key for " + table + " -> "  + key);
        }
              
View Full Code Here

        }
       
        int size = ((Integer)columnRs.get("COLUMN_SIZE")).intValue();
        int decimalDigits = ((Integer)columnRs.get("DECIMAL_DIGITS")).intValue();
       
        Column column = new Column();
        column.setName(quote(columnName));
        Column existing = table.getColumn(column);
        if(existing!=null) {
          // TODO: should we just pick it up and fill it up with whatever we get from the db instead ?
          throw new JDBCBinderException(column + " already exists in " + qualify);
        }
               
View Full Code Here

              }
         
              if(indexes.containsKey(indexName) ) {
                throw new JDBCBinderException("UniqueKey exists also as Index! ");
              }
              Column column = getColumn(table, columnName);
              key.addColumn(column);
             
              if (unique && key.getColumnSpan()==1) {
                // make list of columns that has the chance of being unique
                List l = (List) uniqueColumns.get(column);
                if (l == null) {
                  l = new ArrayList();
                  uniqueColumns.put(column, l);
                }
                l.add(key);
              }
            }
            else {
              Index index = (Index) indexes.get(indexName);
              if(index==null) {
                index = new Index();
                index.setName(indexName);
                index.setTable(table);
                table.addIndex(index);
                indexes.put(indexName, index);         
              }
             
              if(uniquekeys.containsKey(indexName) ) {
                throw new JDBCBinderException("Index exists also as Unique! ");
              }
              Column column = getColumn(table, columnName);
              index.addColumn(column);
            }
           
          }
          else {
            if(DatabaseMetaData.tableIndexStatistic != ((Short)indexRs.get("TYPE")).shortValue() ) {
              log.warn("Index was not statistical, but no column name was found in " + indexName);
            }
             
          }               
        }
      }
      catch (JDBCException t) {
        log.warn("Exception while trying to get indexinfo on " + Table.qualify(table.getCatalog(), table.getSchema(), table.getName() ) "=" + t.getMessage() );
        // Bug #604761 Oracle getIndexInfo() needs major grants And other dbs sucks too ;)
        // http://sourceforge.net/tracker/index.php?func=detail&aid=604761&group_id=36044&atid=415990       
      }
      finally {
        if (indexIterator != null) {
          try {
            getMetaDataDialect().close(indexIterator);
          } catch(JDBCException se) {
            log.warn("Exception while trying to close resultset for index meta data",se);
          }
        }
      }
     
      // mark columns that are unique TODO: multiple columns are not unique on their own.
      Iterator iterator = uniqueColumns.entrySet().iterator();
      while (iterator.hasNext() ) {
        Map.Entry entry = (Map.Entry) iterator.next();
        Column col = (Column) entry.getKey();
        Iterator keys = ( (List)entry.getValue() ).iterator();
         while (keys.hasNext() ) {
          UniqueKey key = (UniqueKey) keys.next();
       
          if(key.getColumnSpan()==1) {
            col.setUnique(true);
          }
        }
      }
     
      iterator = uniquekeys.entrySet().iterator();
View Full Code Here

      }
      existing.add(item);
    }

    private Column getColumn(Table table, String columnName) {
      Column column = new Column();
      column.setName(quote(columnName));
      Column existing = table.getColumn(column);
      if(existing!=null) {
        column = existing;
      }
      return column;
    }
View Full Code Here

  ) {
    if ( selectable.isFormula() ) {
      //TODO not supported by HA
    }
    else {
      Column column = (Column) selectable;
      annotations.append("@").append( importType("javax.persistence.JoinColumn") )
          .append("(name=\"" ).append( column.getName() ).append( "\"" );
          //TODO handle referenced column name, this is a hard one
              if(referencedColumn!=null) {
               annotations.append(", referencedColumnName=\"" ).append( referencedColumn.getText() ).append( "\"" );
              }
View Full Code Here

            }
            tableList.add(table);

            Iterator columns = table.getColumnIterator();
            while (columns.hasNext() ) {
                Column column = (Column) columns.next();
                String columnFQN = getQualifiedColumnName(table, column);
                List values = (List) valuesByColumn.get(columnFQN);
                if (values == null) {
                    values = new ArrayList();
                    valuesByColumn.put(columnFQN, values);
                }
                values.add(column.getValue() );
            }
        }
       
        Map components = new HashMap();
View Full Code Here

      return true; // we don't know better
    }
   
    if(isManyToManyTable(fkTable)) {
           // if the reference column is the first one then we are inverse.
         Column column = fkTable.getColumn(0);
         Column fkColumn = (Column) referencedColumns.get(0);
         if(fkColumn.equals(column)) {
           return true;  
         } else {
           return false;
         }
    }
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.