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

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


        ArrayList parents = new ArrayList();
        ArrayList 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)) {
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

    if (metadata.hasMappingModel()) {
      MappingWrapper wrapper = new MappingWrapper(metadata.getMapping());
      Iterator i = metadata.getRelationships().iterator();
      while (i.hasNext()) {
        Relationship r = (Relationship) i.next();

        Type parent = rootType.getProperty(
            wrapper.getTablePropertyName(r.getPrimaryKeyTable())).getType();
        Type child = rootType.getProperty(
            wrapper.getTablePropertyName(r.getForeignKeyTable())).getType();
        if (parent == null) {
          throw new RuntimeException("The parent table ("
              + r.getPrimaryKeyTable() + ") in relationship "
              + r.getName()
              + " was not found in the mapping information.");
        } else if (child == null) {
          throw new RuntimeException("The child table ("
              + r.getForeignKeyTable() + ") in relationship "
              + r.getName()
              + " was not found in the mapping information.");
        }

      //  ReferenceImpl ref = refMaker.createReference(r, parent, child); 
       
        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());
       
               

      }
View Full Code Here

                if (obj.isSet(p)) {
                    fields.add(p);
                }
            } else {
                if (obj.isSet(p)) {
                    Relationship relationship = config.getRelationshipByReference(p);
                    if ((p.getOpposite() != null && p.getOpposite().isMany())
                            || (hasState(config, relationship, obj))) {
                        RelationshipWrapper r = new RelationshipWrapper(relationship);
                        Iterator keys = r.getForeignKeys().iterator();
                        while (keys.hasNext()) {
View Full Code Here

        }

        // Don't create a relationship if one already exists in the config
        Iterator i = config.getRelationship().iterator();
        while (i.hasNext()) {
            Relationship r = (Relationship) i.next();
            if (r.getPrimaryKeyTable().equals(parentTableName) && r.getForeignKeyTable().equals(childTableName)) {
                return;
            }
        }

        Relationship r = FACTORY.createRelationship();
        r.setName(childTableName);
        r.setPrimaryKeyTable(parentTableName);
        r.setForeignKeyTable(childTableName);

        KeyPair pair = FACTORY.createKeyPair();
        pair.setPrimaryKeyColumn("ID");
        pair.setForeignKeyColumn(fkColumnName);

        r.getKeyPair().add(pair);
        r.setMany(true);

        config.getRelationship().add(r);
    }
View Full Code Here

        }
        if (mw.getConfig() == null) {
            return false;
        }

        Relationship rel = mw.getRelationshipByReference(ref);

        if (!rel.isMany()) {
            if (rel.isKeyRestricted()) {
                throw new RuntimeException("Can not modify a one to one relationship that is key restricted");
            }
            // This is a one-one relationship
            Table t = mapping.getTableByTypeName(changedObject.getType().getName());
            TableWrapper tw = new TableWrapper(t);
            RelationshipWrapper rw = new RelationshipWrapper(rel);
            if ((rel.getForeignKeyTable().equals(t.getTableName()))
                    && (Collections.disjoint(tw.getPrimaryKeyProperties(), rw.getForeignKeys()))) {
                return true;
            }

        }
View Full Code Here

    public Relationship addRelationship(String parentName, String childName) {

        QualifiedColumn parent = new QualifiedColumn(parentName);
        QualifiedColumn child = new QualifiedColumn(childName);

        Relationship r = FACTORY.createRelationship();
        r.setName(child.getTableName());
        r.setPrimaryKeyTable(parent.getTableName());
        r.setForeignKeyTable(child.getTableName());

        if (this.logger.isDebugEnabled()) {
            this.logger.debug("Created relationship from " + r.getPrimaryKeyTable()
                    + " to " + r.getForeignKeyTable() + " named " + r.getName());
        }

        KeyPair pair = FACTORY.createKeyPair();
        pair.setPrimaryKeyColumn(parent.getColumnName());
        pair.setForeignKeyColumn(child.getColumnName());

        r.getKeyPair().add(pair);
        r.setMany(true);

        config.getRelationship().add(r);

        return r;
View Full Code Here

    public boolean hasRecursiveRelationships() {
        if (config != null) {
            Iterator i = getConfig().getRelationship().iterator();
            while (i.hasNext()) {
                Relationship r = (Relationship) i.next();
                if (r.getPrimaryKeyTable().equals(r.getForeignKeyTable())) {
                    return true;
                }
            }
        }
        return false;
View Full Code Here

    public Collection getRelationshipsByChildTable(String name) {
        List results = new ArrayList();
        if (config != null) {
            Iterator i = getConfig().getRelationship().iterator();
            while (i.hasNext()) {
                Relationship r = (Relationship) i.next();
                if (name.equals(r.getForeignKeyTable())) {
                    results.add(r);
                }
            }
        }
        return results;
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.