Examples of ForeignKey


Examples of com.foundationdb.ais.model.ForeignKey

                    } else if(curIndex.isConnectedToFK()) {
                        // this is the constructed referencing index, its IndexName is the foreign key constraint name
                        name = curIndex.getIndexName().getName();
                        type = "FOREIGN KEY";
                       
                        ForeignKey fk = curTable.getReferencingForeignKey(curIndex.getIndexName().getName());
                        isDeferrable = fk.isDeferrable();
                        isInitiallyDeferred = fk.isInitiallyDeferred();
                        return true;
                    }
                }
                indexIt = null;
                curIndex = null;
View Full Code Here

Examples of com.impetus.kundera.metadata.model.Relation.ForeignKey

                {
                    log.error("Persistence unit for class : " + entityClass + " is not loaded");
                    throw new SchemaGenerationException("Persistence unit for class : " + entityClass
                            + " is not loaded");
                }
                ForeignKey relationType = relation.getType();

                // if relation type is one to many or join by primary key
                if (targetEntityMetadata != null && relationType.equals(ForeignKey.ONE_TO_MANY)
                        && relation.getJoinColumnName(kunderaMetadata) != null)
                {
                    // if self association
                    if (targetEntityMetadata.equals(entityMetadata))
                    {
                        tableInfo.addColumnInfo(getJoinColumn(tableInfo, relation.getJoinColumnName(kunderaMetadata),
                                entityMetadata.getIdAttribute().getJavaType()));
                    }
                    else
                    {
                        String pu = targetEntityMetadata.getPersistenceUnit();
                        Type targetEntityType = targetEntityMetadata.getType();
                        Class idClass = targetEntityMetadata.getIdAttribute().getJavaType();
                        String idName = ((AbstractAttribute) targetEntityMetadata.getIdAttribute()).getJPAColumnName();
                        TableInfo targetTableInfo = new TableInfo(targetEntityMetadata.getTableName(),
                                targetEntityType.name(), idClass, idName);

                        // In case of different persistence unit. case for poly
                        // glot
                        // persistence.
                        if (!pu.equals(persistenceUnit))
                        {
                            List<TableInfo> targetTableInfos = getSchemaInfo(pu);

                            addJoinColumnToInfo(relation.getJoinColumnName(kunderaMetadata), targetTableInfo,
                                    targetTableInfos, entityMetadata);

                            // add for newly discovered persistence unit.
                            puToSchemaMetadata.put(pu, targetTableInfos);
                        }
                        else
                        {
                            addJoinColumnToInfo(relation.getJoinColumnName(kunderaMetadata), targetTableInfo,
                                    tableInfos, entityMetadata);
                        }
                    }
                }
                // if relation type is one to one or many to one.
                else if (relation.isUnary() && relation.getJoinColumnName(kunderaMetadata) != null)
                {
                    if (!relation.isJoinedByPrimaryKey())
                    {
                        tableInfo.addColumnInfo(getJoinColumn(tableInfo, relation.getJoinColumnName(kunderaMetadata),
                                targetEntityMetadata.getIdAttribute().getJavaType()));
                    }
                }
                // if relation type is many to many and relation via join table.
                else if ((relationType.equals(ForeignKey.MANY_TO_MANY)) && (entityMetadata.isRelationViaJoinTable()))
                {
                    JoinTableMetadata joinTableMetadata = relation.getJoinTableMetadata();
                    String joinTableName = joinTableMetadata != null ? joinTableMetadata.getJoinTableName() : null;
                    String joinColumnName = joinTableMetadata != null ? (String) joinTableMetadata.getJoinColumns()
                            .toArray()[0] : null;
View Full Code Here

Examples of liquibase.structure.core.ForeignKey

          new UnparsedSql(sb.toString(), getAffectedForeignKey(statement))
      };
    }

    protected ForeignKey getAffectedForeignKey(AddForeignKeyConstraintStatement statement) {
        return new ForeignKey().setName(statement.getConstraintName()).setForeignKeyColumns(Column.listFromNames(statement.getBaseColumnNames())).setForeignKeyTable((Table) new Table().setName(statement.getBaseTableName()).setSchema(statement.getBaseTableCatalogName(), statement.getBaseTableSchemaName()));
    }
View Full Code Here

Examples of net.sf.minuteProject.configuration.bean.model.data.ForeignKey

  public List<ForeignKey> getForeignKeyList() {
      if (foreignKeys == null) {
        foreignKeys = new ArrayList<ForeignKey>();
        for (int i = 0; i < table.getForeignKeyCount(); i++) {
          ForeignKey foreignKey = new ForeignKeyDDLUtils (table.getForeignKey(i));
          foreignKeys.add(foreignKey);
        }
      }
      return foreignKeys;
  }
View Full Code Here

Examples of org.apache.ddlutils.model.ForeignKey

    {
        ArrayList changes = new ArrayList();

        for (int fkIdx = 0; fkIdx < sourceTable.getForeignKeyCount(); fkIdx++)
        {
            ForeignKey sourceFk = sourceTable.getForeignKey(fkIdx);
            ForeignKey targetFk = findCorrespondingForeignKey(targetTable, sourceFk);

            if (targetFk == null)
            {
                if (_log.isInfoEnabled())
                {
                    _log.info("Foreign key " + sourceFk + " needs to be removed from table " + sourceTable.getName());
                }
                changes.add(new RemoveForeignKeyChange(sourceTable, sourceFk));
            }
        }

        for (int fkIdx = 0; fkIdx < targetTable.getForeignKeyCount(); fkIdx++)
        {
            ForeignKey targetFk = targetTable.getForeignKey(fkIdx);
            ForeignKey sourceFk = findCorrespondingForeignKey(sourceTable, targetFk);

            if (sourceFk == null)
            {
                if (_log.isInfoEnabled())
                {
View Full Code Here

Examples of org.apache.openjpa.jdbc.schema.ForeignKey

                constant = true;
        }

        // if this is not a constant join, look for existing foreign key
        // on local columns
        ForeignKey exist = null;
        if (!constant && local.getForeignKeys().length > 0) {
            Column[] cols = new Column[joins.length];
            Column[] pks = new Column[joins.length];
            for (int i = 0; i < joins.length; i++) {
                cols[i] = (Column) joins[i][0];
                pks[i] = (Column) joins[i][1];
            }

            ForeignKey[] fks = local.getForeignKeys();
            for (int i = 0; i < fks.length; i++) {
                if (fks[i].getConstantColumns().length == 0
                    && fks[i].getConstantPrimaryKeyColumns().length == 0
                    && fks[i].columnsMatch(cols, pks)) {
                    exist = fks[i];
                    break;
                }
            }
        }

        MappingRepository repos = (MappingRepository) context.getRepository();
        DBDictionary dict = repos.getDBDictionary();
        if (exist != null) {
            // make existing key logical?
            if (!_canFK) {
                if (exist.getDeleteAction() != exist.ACTION_NONE && !adapt)
                    throw new MetaDataException(_loc.get(prefix
                        + "-fk-exists", context));
                exist.setDeleteAction(exist.ACTION_NONE);
            }

            if (_fk != null && _fk.isDeferred() && !exist.isDeferred()) {
                Log log = repos.getLog();
                if (log.isWarnEnabled())
                    log.warn(_loc.get(prefix + "-defer-fk", context));
            }

            // allow user-given info to override existing key if we're adapting;
            // template info cannot override existing key
            if (adapt && _fk != null) {
                if (_fk.getUpdateAction() != ForeignKey.ACTION_NONE)
                    exist.setUpdateAction(_fk.getUpdateAction());
                if (_fk.getDeleteAction() != ForeignKey.ACTION_NONE)
                    exist.setDeleteAction(_fk.getDeleteAction());
            }
            setIOFromJoins(exist, joins);
            return exist;
        }

        String name = null;
        int delAction = ForeignKey.ACTION_NONE;
        int upAction = ForeignKey.ACTION_NONE;
        boolean deferred = false;
        boolean fill = repos.getMappingDefaults().defaultMissingInfo();
        ForeignKey tmplate = (def == null) ? null
            : def.get(local, foreign, _join == JOIN_INVERSE);
        if (_fk != null && (tmplate == null || (!adapt && !fill))) {
            // if not adapting or no template info use given data
            name = _fk.getName();
            delAction = _fk.getDeleteAction();
            upAction = _fk.getUpdateAction();
            deferred = _fk.isDeferred();
        } else if (_canFK && (adapt || fill)) {
            if (_fk == null && tmplate != null) {
                // no user given info; use template data
                name = tmplate.getName();
                delAction = tmplate.getDeleteAction();
                upAction = tmplate.getUpdateAction();
                deferred = tmplate.isDeferred();
            } else if (_fk != null && tmplate != null) {
                // merge user and template data, always letting user info win
                name = _fk.getName();
                if (name == null && tmplate.getName() != null)
                    name = tmplate.getName();
                delAction = _fk.getDeleteAction();
                if (delAction == ForeignKey.ACTION_NONE)
                    delAction = tmplate.getDeleteAction();
                upAction = _fk.getUpdateAction();
                if (upAction == ForeignKey.ACTION_NONE)
                    upAction = tmplate.getUpdateAction();
                deferred = _fk.isDeferred();
            }
        }

        if (!dict.supportsDeleteAction(delAction)
            || !dict.supportsUpdateAction(upAction)) {
            Log log = repos.getLog();
            if (log.isWarnEnabled())
                log.warn(_loc.get(prefix + "-unsupported-fk-action", context));
            delAction = ForeignKey.ACTION_NONE;
            upAction = ForeignKey.ACTION_NONE;
        }
        if (deferred && !dict.supportsDeferredConstraints) {
            Log log = repos.getLog();
            if (log.isWarnEnabled())
                log.warn(_loc.get(prefix + "-create-defer-fk",
                    context, dict.platform));
            deferred = false;
        }

        // create foreign key with merged info
        ForeignKey fk = local.addForeignKey(name);
        fk.setDeleteAction(delAction);
        fk.setUpdateAction(upAction);
        fk.setDeferred(deferred);

        // add joins to key
        Column col;
        for (int i = 0; i < joins.length; i++) {
            col = (Column) joins[i][0];
            if (joins[i][1]instanceof Column)
                fk.join(col, (Column) joins[i][1]);
            else if ((joins[i][2] == Boolean.TRUE) != (_join == JOIN_INVERSE))
                fk.joinConstant(joins[i][1], col);
            else
                fk.joinConstant(col, joins[i][1]);
        }
        setIOFromJoins(fk, joins);
        return fk;
    }
View Full Code Here

Examples of org.apache.openjpa.jdbc.schema.ForeignKey

    /**
     * Use the given join instance to create SQL joining its tables in
     * the traditional style.
     */
    public SQLBuffer toTraditionalJoin(Join join) {
        ForeignKey fk = join.getForeignKey();
        if (fk == null)
            return null;

        boolean inverse = join.isForeignKeyInversed();
        Column[] from = (inverse) ? fk.getPrimaryKeyColumns()
            : fk.getColumns();
        Column[] to = (inverse) ? fk.getColumns()
            : fk.getPrimaryKeyColumns();

        // do column joins
        SQLBuffer buf = new SQLBuffer(this);
        int count = 0;
        for (int i = 0; i < from.length; i++, count++) {
            if (count > 0)
                buf.append(" AND ");
            buf.append(join.getAlias1()).append(".").append(from[i]);
            buf.append(" = ");
            buf.append(join.getAlias2()).append(".").append(to[i]);
        }

        // do constant joins
        Column[] constCols = fk.getConstantColumns();
        for (int i = 0; i < constCols.length; i++, count++) {
            if (count > 0)
                buf.append(" AND ");
            if (inverse)
                buf.appendValue(fk.getConstant(constCols[i]), constCols[i]);
            else
                buf.append(join.getAlias1()).append(".").
                    append(constCols[i]);
            buf.append(" = ");

            if (inverse)
                buf.append(join.getAlias2()).append(".").
                    append(constCols[i]);
            else
                buf.appendValue(fk.getConstant(constCols[i]), constCols[i]);
        }

        Column[] constColsPK = fk.getConstantPrimaryKeyColumns();
        for (int i = 0; i < constColsPK.length; i++, count++) {
            if (count > 0)
                buf.append(" AND ");
            if (inverse)
                buf.append(join.getAlias1()).append(".").
                    append(constColsPK[i]);
            else
                buf.appendValue(fk.getPrimaryKeyConstant(constColsPK[i]),
                    constColsPK[i]);
            buf.append(" = ");

            if (inverse)
                buf.appendValue(fk.getPrimaryKeyConstant(constColsPK[i]),
                    constColsPK[i]);
            else
                buf.append(join.getAlias2()).append(".").
                    append(constColsPK[i]);
        }
View Full Code Here

Examples of org.apache.openjpa.jdbc.schema.ForeignKey

    /**
     * Create a new foreign key from the information in the schema metadata.
     */
    protected ForeignKey newForeignKey(ResultSet fkMeta)
        throws SQLException {
        ForeignKey fk = new ForeignKey();
        fk.setSchemaName(fkMeta.getString("FKTABLE_SCHEM"));
        fk.setTableName(fkMeta.getString("FKTABLE_NAME"));
        fk.setColumnName(fkMeta.getString("FKCOLUMN_NAME"));
        fk.setName(fkMeta.getString("FK_NAME"));
        fk.setPrimaryKeySchemaName(fkMeta.getString("PKTABLE_SCHEM"));
        fk.setPrimaryKeyTableName(fkMeta.getString("PKTABLE_NAME"));
        fk.setPrimaryKeyColumnName(fkMeta.getString("PKCOLUMN_NAME"));
        fk.setKeySequence(fkMeta.getInt("KEY_SEQ"));
        fk.setDeferred(fkMeta.getInt("DEFERRABILITY")
            == DatabaseMetaData.importedKeyInitiallyDeferred);

        int del = fkMeta.getInt("DELETE_RULE");
        switch (del) {
            case DatabaseMetaData.importedKeySetNull:
                fk.setDeleteAction(ForeignKey.ACTION_NULL);
                break;
            case DatabaseMetaData.importedKeySetDefault:
                fk.setDeleteAction(ForeignKey.ACTION_DEFAULT);
                break;
            case DatabaseMetaData.importedKeyCascade:
                fk.setDeleteAction(ForeignKey.ACTION_CASCADE);
                break;
            default:
                fk.setDeleteAction(ForeignKey.ACTION_RESTRICT);
                break;
        }
        return fk;
    }
View Full Code Here

Examples of org.apache.openjpa.jdbc.schema.ForeignKey

        if (fk.isLogical())
            _fk = null;
        else {
            _canFK = true;
            _fk = new ForeignKey();
            _fk.setName(fk.getName());
            _fk.setDeleteAction(fk.getDeleteAction());
            _fk.setUpdateAction(fk.getUpdateAction());
            _fk.setDeferred(fk.isDeferred());
        }
View Full Code Here

Examples of org.apache.openjpa.jdbc.schema.ForeignKey

        return res.load(elem, store, fetch, joins);
    }

    protected Joins join(Joins joins, ClassMapping elem) {
        ValueMapping vm = field.getElementMapping();
        ForeignKey fk = vm.getForeignKey(elem);
        ClassMapping owner = field.getDefiningMapping();
        while (fk.getPrimaryKeyTable() != owner.getTable()) {
            joins = owner.joinSuperclass(joins, false);
            owner = owner.getJoinablePCSuperclassMapping();
            if (owner == null)
                throw new InternalException();
        }
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.