Package org.hibernate.mapping

Examples of org.hibernate.mapping.ForeignKey


                    processedColumns.add(column);
                }
            }
      else if (element instanceof ForeignKeyForColumns) {
                ForeignKeyForColumns fkfc = (ForeignKeyForColumns) element;
                ForeignKey foreignKey = fkfc.key;
                String propertyName = revengStrategy.foreignKeyToEntityName(
            foreignKey.getName(),
            TableIdentifier.create(foreignKey.getTable() ),
            foreignKey.getColumns(), TableIdentifier.create(foreignKey.getReferencedTable() ), foreignKey.getReferencedColumns(), true
          );
                property = bindManyToOne( makeUnique(pkc, propertyName), true, table, foreignKey, processedColumns);
                processedColumns.addAll(fkfc.columns);
            }
      else {
View Full Code Here


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

        boolean foundKey = false;
        foreignKeyIterator = tempList.iterator();
        while(foreignKeyIterator.hasNext()) {
          ForeignKey key = (ForeignKey) foreignKeyIterator.next();
          List matchingColumns = columnMatches(myPkColumns, i, key);
          if(matchingColumns!=null) {
            result.add(new ForeignKeyForColumns(key, matchingColumns));
            i+=matchingColumns.size()-1;
            foreignKeyIterator.remove();
View Full Code Here

      while ( iter.hasNext() ) {
        Table table = (Table) iter.next();
        if ( table.isPhysicalTable() ) {
          Iterator subIter = table.getForeignKeyIterator();
          while ( subIter.hasNext() ) {
            ForeignKey fk = (ForeignKey) subIter.next();
            if ( fk.isPhysicalConstraint() ) {
              script.add(
                  fk.sqlDropString(
                      dialect,
                      defaultCatalog,
                      defaultSchema
                    )
                );
View Full Code Here

        }

        if ( dialect.hasAlterTable() ) {
          subIter = table.getForeignKeyIterator();
          while ( subIter.hasNext() ) {
            ForeignKey fk = (ForeignKey) subIter.next();
            if ( fk.isPhysicalConstraint() ) {
              script.add(
                  fk.sqlCreateString(
                      dialect, mapping,
                      defaultCatalog,
                      defaultSchema
                    )
                );
View Full Code Here

          );

        if ( dialect.hasAlterTable() ) {
          Iterator subIter = table.getForeignKeyIterator();
          while ( subIter.hasNext() ) {
            ForeignKey fk = (ForeignKey) subIter.next();
            if ( fk.isPhysicalConstraint() ) {
              boolean create = tableInfo == null || (
                  tableInfo.getForeignKeyMetadata( fk.getName() ) == null && (
                      //Icky workaround for MySQL bug:
                      !( dialect instanceof MySQLDialect ) ||
                          tableInfo.getIndexMetadata( fk.getName() ) == null
                    )
                );
              if ( create ) {
                script.add(
                    fk.sqlCreateString(
                        dialect,
                        mapping,
                        defaultCatalog,
                        defaultSchema
                      )
View Full Code Here

    table.createForeignKeys();

    Iterator iter = table.getForeignKeyIterator();
    while ( iter.hasNext() ) {

      ForeignKey fk = (ForeignKey) iter.next();
      if ( !done.contains( fk ) ) {
        done.add( fk );
        final String referencedEntityName = fk.getReferencedEntityName();
        if ( referencedEntityName == null ) {
          throw new MappingException(
              "An association from the table " +
              fk.getTable().getName() +
              " does not specify the referenced entity"
            );
        }
        if ( log.isDebugEnabled() ) {
          log.debug( "resolving reference to class: " + referencedEntityName );
        }
        PersistentClass referencedClass = (PersistentClass) classes.get( referencedEntityName );
        if ( referencedClass == null ) {
          throw new MappingException(
              "An association from the table " +
              fk.getTable().getName() +
              " refers to an unmapped class: " +
              referencedEntityName
            );
        }
        if ( referencedClass.isJoinedSubclass() ) {
          secondPassCompileForeignKeys( referencedClass.getSuperclass().getTable(), done );
        }
        fk.setReferencedTable( referencedClass.getTable() );
        fk.alignColumns();
      }
    }
  }
View Full Code Here

       
        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!");
            }
View Full Code Here

        List columns = (List) dependentColumns.get(fkName);
        List refColumns = (List) referencedColumns.get(fkName);
       
        String className = revengStrategy.tableToClassName(TableIdentifier.create(referencedTable) );

        ForeignKey key = fkTable.createForeignKey(fkName, columns, className, refColumns);     
        key.setReferencedTable(referencedTable);

        addToMultiMap(oneToManyCandidates, className, key);       
      }
      // map<className, foreignkey>
      return oneToManyCandidates;
View Full Code Here

      List foreignKeys = new ArrayList();
     
      // if we have more than 2 fk, means we have more than 2 table implied
      // in this table --> cannot be a simple many-to-many
      while ( foreignKeyIterator.hasNext() ) {
        ForeignKey fkey = (ForeignKey) foreignKeyIterator.next();
        foreignKeys.add( fkey );
        if(foreignKeys.size()>2) {
          return false; // early exit if we have more than two fk.
        }
      }
      if(foreignKeys.size()!=2) {
        return false;
      }
     
      // 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();
      while ( !columns.isEmpty() && foreignKeyIterator.hasNext() ) {
        ForeignKey element = (ForeignKey) foreignKeyIterator.next();       
        columns.removeAll( element.getColumns() );       
      }
      // what if one of the columns is not the primary key?
     
      return columns.isEmpty();
     
View Full Code Here

  }

  public void addTable(Table table, String wantedClassName) {
    Iterator fkIter = table.getForeignKeyIterator();
    while ( fkIter.hasNext() ) {
      ForeignKey fk = (ForeignKey) fkIter.next();
      TableIdentifier identifier = TableIdentifier.create(fk.getReferencedTable());
      List existing = (List) foreignKeys.get(identifier);
      if(existing==null) {
        existing = new ArrayList();
        foreignKeys.put(identifier, existing);
      }
View Full Code Here

TOP

Related Classes of org.hibernate.mapping.ForeignKey

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.