Package org.apache.tuscany.das.rdb.config

Examples of org.apache.tuscany.das.rdb.config.Relationship


        List parents = new ArrayList();
        List children = new ArrayList();
        if (config != null) {
            Iterator i = getConfig().getRelationship().iterator();
            while (i.hasNext()) {
                Relationship r = (Relationship) i.next();
                parents.add(r.getPrimaryKeyTable());
                children.add(r.getForeignKeyTable());
                parentToChild.put(r.getPrimaryKeyTable(), r.getForeignKeyTable());
            }
            while (parents.size() > 0) {
                String parent = (String) parents.get(0);
                if (!children.contains(parent)) {
                    if (!inserts.contains(parent)) {
View Full Code Here


    }

    public Relationship getRelationshipByReference(Property ref) {
        Iterator i = config.getRelationship().iterator();
        while (i.hasNext()) {
            Relationship r = (Relationship) i.next();
            if (ref.getName().equals(r.getName()) || ref.getOpposite().getName().equals(r.getName())) {
                return r;
            }
        }
        throw new RuntimeException("Could not find relationship " + ref.getName() + " in the configuration");
    }
View Full Code Here

    }

    public Relationship getRelationshipByName(String name) {
        Iterator i = config.getRelationship().iterator();
        while (i.hasNext()) {
            Relationship r = (Relationship) i.next();
            if (name.equals(r.getName())) {
                return r;
            }
        }
        throw new RuntimeException("Could not find relationship " + name + " in the configuration");
    }
View Full Code Here

     *
     * @throws Exception
     */
    public void testRelationshipAlreadyDefined() throws Exception {
        ConfigHelper helper = new ConfigHelper();
        Relationship r = helper.addRelationship("CUSTOMER.ID", "ANORDER.CUSTOMER_ID");
        r.setName("definedRelationship");

        DAS das = DAS.FACTORY.createDAS(helper.getConfig(), getConnection());
        Command select = das.createCommand("select * from CUSTOMER left join ANORDER "
                + "ON CUSTOMER.ID = ANORDER.CUSTOMER_ID");

View Full Code Here

    private void initialize() {
        if (mappingWrapper.getConfig() != null) {
            List relationships = mappingWrapper.getConfig().getRelationship();
            Iterator i = relationships.iterator();
            while (i.hasNext()) {
                Relationship r = (Relationship) i.next();
                if (this.logger.isDebugEnabled()) {
                    this.logger.debug("Initializing relationship: " + r.getName());
                }
                if (r.getForeignKeyTable().equals(getTypeName())) {
                    List pairs = r.getKeyPair();
                    Iterator iter = pairs.iterator();
                    while (iter.hasNext()) {
                        KeyPair pair = (KeyPair) iter.next();
                        keyMappings.put(pair.getForeignKeyColumn(), r);
                    }
View Full Code Here

        if (isPartOfPrimaryKey(parameter)) {
            return dataObject.get(parameter);
        }

        Relationship r = (Relationship) keyMappings.get(parameter);
        if (r == null) {
            return dataObject.get(parameter);
        }

        Property parentRef = getParentReference(r.getPrimaryKeyTable());
        DataObject parent = dataObject.getDataObject(parentRef);
        if (parent == null) {
            return null;
        }
        String parentKey = getParentKey(r, parameter);
View Full Code Here

            return;
        }

        Iterator i = metadata.getRelationships().iterator();
        while (i.hasNext()) {
            Relationship r = (Relationship) i.next();

            DataObject parentTable = get(wrapper.getTableTypeName(r.getPrimaryKeyTable()));
            DataObject childTable = get(wrapper.getTableTypeName(r.getForeignKeyTable()));

            if (this.logger.isDebugEnabled()) {
                this.logger.debug("Parent table: " + parentTable);
                this.logger.debug("Child table: " + childTable);
            }
            if ((parentTable == null) || (childTable == null)) {
                continue;
            }

            Property p = parentTable.getType().getProperty(r.getName());
            setOrAdd(parentTable, childTable, p);

        }
    }
View Full Code Here

        while (i.hasNext()) {
            DataObject table = (DataObject) i.next();

            Iterator relationships = wrapper.getRelationshipsByChildTable(table.getType().getName()).iterator();
            while (relationships.hasNext()) {
                Relationship r = (Relationship) relationships.next();

                DataObject parentTable = findParentTable(table, r, wrapper);

                if (parentTable == null) {
                    continue;
                }

                Property p = parentTable.getType().getProperty(r.getName());
                setOrAdd(parentTable, table, p);
            }

        }
    }
View Full Code Here

        }

        MappingWrapper wrapper = getConfigWrapper();
        Iterator i = getRelationships().iterator();
        while (i.hasNext()) {
            Relationship r = (Relationship) i.next();

            String parentName = wrapper.getTableTypeName(r.getPrimaryKeyTable());
            String childName = wrapper.getTableTypeName(r.getForeignKeyTable());

            if (parentName == null) {
                throw new RuntimeException("The parent table (" + r.getPrimaryKeyTable()
                        + ") in relationship " + r.getName()
                        + " was not found in the mapping information.");
            } else if (childName == null) {
                throw new RuntimeException("The child table (" + r.getForeignKeyTable()
                        + ") in relationship " + r.getName()
                        + " was not found in the mapping information.");
            }

            Property parentProperty = root.getProperty(parentName);
            Property childProperty = root.getProperty(childName);

            if (parentProperty == null) {
                throw new RuntimeException("The parent table (" + parentName + ") in relationship "
                        + r.getName() + " was not found.");
            } else if (childProperty == null) {
                throw new RuntimeException("The child table (" + childName + ") in relationship "
                        + r.getName() + " was not found.");
            }

            Type parent = parentProperty.getType();
            Type child = childProperty.getType();

            Property parentProp = SDOUtil.createProperty(parent, r.getName(), child);
            Property childProp = SDOUtil.createProperty(child, r.getName() + "_opposite", parent);
            SDOUtil.setOpposite(parentProp, childProp);
            SDOUtil.setOpposite(childProp, parentProp);
            SDOUtil.setMany(parentProp, r.isMany());
        }

        this.rootType = root;
    }
View Full Code Here

                        throw new RuntimeException("Foreign key properties should not be set when the corrsponding relationship has changed");
                    }
                }
            } else {
                if (obj.isSet(p)) {
                    Relationship relationship = config.getRelationshipByReference(p);
                    if ((p.getOpposite() != null && p.getOpposite().isMany())
                            || (hasState(tw, relationship, obj))) {
                        RelationshipWrapper r = new RelationshipWrapper(relationship);
                        Iterator keys = r.getForeignKeys().iterator();
                        while (keys.hasNext()) {
View Full Code Here

TOP

Related Classes of org.apache.tuscany.das.rdb.config.Relationship

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.