Examples of ForeignKey


Examples of org.datanucleus.store.rdbms.key.ForeignKey

            // FK from join table to owner table
            DatastoreClass referencedTable = storeMgr.getDatastoreClass(ownerType, clr);
            if (referencedTable != null)
            {
                // Single owner table, so add a single FK to the owner as appropriate
                ForeignKey fk = getForeignKeyToOwner(referencedTable, autoMode);
                if (fk != null)
                {
                    foreignKeys.add(fk);
                }
            }
            else
            {
                // No single owner so we don't bother with the FK since referential integrity by FK cannot work
                // if we don't have a single owner at the other end of the FK(s).
            }

            // FK from join table to element table(s)
            if (elementMapping instanceof SerialisedPCMapping)
            {
                // Do nothing since no element table
            }
            else if (elementMapping instanceof EmbeddedElementPCMapping)
            {
                // Add any FKs for the fields of the (embedded) element
                EmbeddedElementPCMapping embMapping = (EmbeddedElementPCMapping)elementMapping;
                for (int i=0;i<embMapping.getNumberOfJavaTypeMappings();i++)
                {
                    JavaTypeMapping embFieldMapping = embMapping.getJavaTypeMapping(i);
                    AbstractMemberMetaData embFmd = embFieldMapping.getMemberMetaData();
                    if (ClassUtils.isReferenceType(embFmd.getType()) &&
                        embFieldMapping instanceof ReferenceMapping)
                    {
                        // Field is a reference type, so add a FK to the table of the PC for each PC implementation
                        Collection fks = TableUtils.getForeignKeysForReferenceField(embFieldMapping, embFmd, autoMode, storeMgr, clr);
                        foreignKeys.addAll(fks);
                    }
                    else if (storeMgr.getNucleusContext().getMetaDataManager().getMetaDataForClass(embFmd.getType(), clr) != null &&
                            embFieldMapping.getNumberOfDatastoreMappings() > 0 &&
                            embFieldMapping instanceof PersistableMapping)
                    {
                        // Field is for a PC class with the FK at this side, so add a FK to the table of this PC
                        ForeignKey fk = TableUtils.getForeignKeyForPCField(embFieldMapping, embFmd, autoMode, storeMgr, clr);
                        if (fk != null)
                        {
                            foreignKeys.add(fk);
                        }
                    }
                }
            }
            else if (elementMapping instanceof ReferenceMapping)
            {
                JavaTypeMapping[] implJavaTypeMappings = ((ReferenceMapping)elementMapping).getJavaTypeMapping();
                for (int i=0;i<implJavaTypeMappings.length;i++)
                {
                    JavaTypeMapping implMapping = implJavaTypeMappings[i];
                    if (storeMgr.getNucleusContext().getMetaDataManager().getMetaDataForClass(implMapping.getType(), clr) != null &&
                        implMapping.getNumberOfDatastoreMappings() > 0)
                    {
                        referencedTable = storeMgr.getDatastoreClass(implMapping.getType(), clr);
                        if (referencedTable != null)
                        {
                            ForeignKey fk = getForeignKeyToElement(referencedTable, autoMode, implMapping);
                            if (fk != null)
                            {
                                foreignKeys.add(fk);
                            }
                        }
                    }
                }
            }
            else
            {
                referencedTable = storeMgr.getDatastoreClass(getElementType(), clr);
                if (referencedTable != null)
                {
                    ForeignKey fk = getForeignKeyToElement(referencedTable, autoMode, elementMapping);
                    if (fk != null)
                    {
                        foreignKeys.add(fk);
                    }
                }
View Full Code Here

Examples of org.datanucleus.store.rdbms.key.ForeignKey

        // Add FK back to the primary table unless requested not to
        ForeignKeyMetaData fkmd = joinMetaData != null ? joinMetaData.getForeignKeyMetaData() : null;
        if (autoMode || (fkmd != null && fkmd.getDeleteAction() != ForeignKeyAction.NONE))
        {
            ForeignKey fk = new ForeignKey(getIdMapping(), dba, primaryTable, fkmd != null && fkmd.isDeferred() ? true : false);
            if (fkmd != null && fkmd.getName() != null)
            {
                fk.setName(fkmd.getName());
            }
            foreignKeys.add(0, fk);
        }

        return foreignKeys;
View Full Code Here

Examples of org.hibernate.annotations.ForeignKey

                + " in mappedBy of "
                + StringHelper.qualify( ownerEntity, ownerProperty )
        );
      }
    }
    ForeignKey fk = inferredData.getProperty().getAnnotation( ForeignKey.class );
    String fkName = fk != null ? fk.name() : "";
    if ( !BinderHelper.isEmptyAnnotationValue( fkName ) ) value.setForeignKeyName( fkName );
  }
View Full Code Here

Examples of org.hibernate.mapping.ForeignKey

  }

  private boolean isAppliedToForeignColumns(Table table, Constraint constraint) {
    List<?> constraintColumns = constraint.getColumns();
    for ( Iterator<?> iterator = table.getForeignKeyIterator(); iterator.hasNext(); ) {
      ForeignKey foreignKey = (ForeignKey) iterator.next();
      List<?> foreignKeyColumns = foreignKey.getColumns();
      for ( Object object : foreignKeyColumns ) {
        if ( constraintColumns.contains( object ) ) {
          // This constraint requires a foreign column
          return true;
        }
View Full Code Here

Examples of org.hibernate.mapping.ForeignKey

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

Examples of org.hibernate.mapping.ForeignKey

        }

        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

Examples of org.hibernate.mapping.ForeignKey

          );

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

Examples of org.hibernate.mapping.ForeignKey

  protected void secondPassCompileForeignKeys(Table table, Set done) throws MappingException {
    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"
            );
        }
                LOG.debugf("Resolving reference to class: %s", referencedEntityName);
        PersistentClass referencedClass = 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

Examples of org.hibernate.metamodel.relational.ForeignKey

    buildForeignKey();
  }

  private void buildForeignKey() {
    // TODO: move this stuff to relational model
    ForeignKey foreignKey = getValue().getTable()
        .createForeignKey( referencedAttributeBinding.getValue().getTable(), foreignKeyName );
    Iterator<SimpleValue> referencingValueIterator = getValues().iterator();
    Iterator<SimpleValue> targetValueIterator = referencedAttributeBinding.getValues().iterator();
    while ( referencingValueIterator.hasNext() ) {
      if ( !targetValueIterator.hasNext() ) {
        // TODO: improve this message
        throw new MappingException(
            "number of values in many-to-one reference is greater than number of values in target"
        );
      }
      SimpleValue referencingValue = referencingValueIterator.next();
      SimpleValue targetValue = targetValueIterator.next();
      if ( Column.class.isInstance( referencingValue ) ) {
        if ( !Column.class.isInstance( targetValue ) ) {
          // TODO improve this message
          throw new MappingException( "referencing value is a column, but target is not a column" );
        }
        foreignKey.addColumnMapping( Column.class.cast( referencingValue ), Column.class.cast( targetValue ) );
      }
      else if ( Column.class.isInstance( targetValue ) ) {
        // TODO: improve this message
        throw new MappingException( "referencing value is not a column, but target is a column." );
      }
View Full Code Here

Examples of org.jboss.dna.common.jdbc.model.api.ForeignKey

    }

    public void testAddForeignKey() {
        String NAME = "My FK";
        // create FK
        ForeignKey fk = factory.createForeignKey();
        // set name
        fk.setName(NAME);
        // add
        bean.addForeignKey(fk);
        // check
        assertFalse("FK set should not be empty", bean.getForeignKeys().isEmpty());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.