Package org.apache.openjpa.jdbc.schema

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


    @Override
    public SQLBuffer toNativeJoin(Join join) {
        if (join.getType() != Join.TYPE_OUTER)
            return toTraditionalJoin(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]);
            buf.append("(+)");
        }

        // check constant joins
        if (fk.getConstantColumns().length > 0)
            throw new StoreException(_loc.get("oracle-constant",
                join.getTable1(), join.getTable2())).setFatal(true);

        if (fk.getConstantPrimaryKeyColumns().length > 0)
            throw new StoreException(_loc.get("oracle-constant",
                join.getTable1(), join.getTable2())).setFatal(true);
        return buf;
    }
View Full Code Here


            rs = stmnt.executeQuery();
            List<ForeignKey> fkList = new ArrayList<ForeignKey>();           
            Map<FKMapKey, ForeignKey> fkMap = new HashMap<FKMapKey, ForeignKey>();

            while (rs != null && rs.next()) {
                ForeignKey nfk = newForeignKey(rs);
                if (!partialKeys) {
                    ForeignKey fk = combineForeignKey(fkMap, nfk);
                    // Only add the fk to the import list if it is new
                    if (fk != nfk) {
                        continue;
                    }
                }
View Full Code Here

            getMapping(MappingTest5.class, null, true);

        Table supTable = mapping.getPCSuperclassMapping().getTable();
        assertTrue(mapping.getTable() != supTable);
        FieldMapping field = mapping.getFieldMapping("vertRel");
        ForeignKey fk = field.getForeignKey();
        assertEquals(mapping.getTable(), fk.getTable());
        assertEquals(supTable, fk.getPrimaryKeyTable());
        Column[] cols = field.getColumns();
        assertEquals(2, cols.length);
        assertEquals("V1", cols[0].getName());
        assertEquals("V2", cols[1].getName());
    }
View Full Code Here

            field.getMappingInfo().setColumns(null);
        }

        field.mapJoin(adapt, false);
        if (field.getTypeMapping().isMapped()) {
            ForeignKey fk = vinfo.getTypeJoin(field, field.getName(), true,
                adapt);
            field.setForeignKey(fk);
            field.setColumnIO(vinfo.getColumnIO());
            if (vinfo.getJoinDirection() == vinfo.JOIN_INVERSE)
                field.setJoinDirection(field.JOIN_INVERSE);
View Full Code Here

    }

    public void initialize() {
        field.setUsesIntermediate(true);

        ForeignKey fk = field.getForeignKey();
        if (fk == null)
            _fkOid = Boolean.TRUE;
        else if (field.getJoinDirection() != FieldMapping.JOIN_INVERSE)
            _fkOid = field.getTypeMapping().isForeignKeyObjectId(fk);
    }
View Full Code Here

            // if our foreign key has a delete action, we need to set the
            // related object so constraints can be evaluated
            OpenJPAStateManager rel = RelationStrategies.getStateManager
                (sm.fetchObjectField(field.getIndex()), store.getContext());
            if (rel != null) {
                ForeignKey fk = field.getForeignKey((ClassMapping)
                    rel.getMetaData());
                if (fk.getDeleteAction() == ForeignKey.ACTION_RESTRICT ||
                    fk.getDeleteAction() == ForeignKey.ACTION_CASCADE) {
                    Row row = field.getRow(sm, store, rm, Row.ACTION_DELETE);
                    row.setForeignKey(fk, null, rel);
                }
            }
        }
View Full Code Here

    private void nullInverse(OpenJPAStateManager sm, RowManager rm)
        throws SQLException {
        if (field.getUseClassCriteria())
            return;

        ForeignKey fk = field.getForeignKey();
        ColumnIO io = field.getColumnIO();
        if (!io.isAnyUpdatable(fk, true))
            return;

        // null inverse if not already enforced by fk
        if (field.getIndependentTypeMappings().length != 1)
            throw RelationStrategies.uninversable(field);
        Row row = rm.getAllRows(fk.getTable(), Row.ACTION_UPDATE);
        row.setForeignKey(fk, io, null);
        row.whereForeignKey(fk, sm);
        rm.flushAllRows(row);
    }
View Full Code Here

        JDBCStore store, RowManager rm)
        throws SQLException {
        if (rel == null)
            return;

        ForeignKey fk = field.getForeignKey();
        ColumnIO io = field.getColumnIO();

        int action;
        if (rel.isNew() && !rel.isFlushed()) {
            if (sm.isDeleted() || !io.isAnyInsertable(fk, false))
View Full Code Here

            joins = join(joins, false);
            joins = setEmbeddedVariable(joins);
        }

        // and join into relation
        ForeignKey fk = field.getForeignKey(cls);
        if (!forceInner && field.getNullValue() != FieldMapping.NULL_EXCEPTION)
            return joins.outerJoinRelation(field.getName(), fk, field.
                getTypeMapping(), field.getSelectSubclasses(), inverse, false);
        return joins.joinRelation(field.getName(), fk, field.getTypeMapping(),
            field.getSelectSubclasses(), inverse, false);
View Full Code Here

        if (empty)
            sql.append("0 = ");
        else
            sql.append("0 < ");

        ForeignKey fk = field.getForeignKey();
        ContainerFieldStrategy.appendJoinCount(sql, sel, joins, dict, field,
            fk);
    }
View Full Code Here

TOP

Related Classes of org.apache.openjpa.jdbc.schema.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.