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

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


        parentColumnNames.add(1, "ORDERDETAILS.PRODUCTID");

        childColumnNames.add(0, "ORDERDETAILSDESC.ORDERID_INVALID");
        childColumnNames.add(1, "ORDERDETAILSDESC.PRODUCTID");       
       
        Relationship r = helper.addRelationship(parentColumnNames, childColumnNames);

        DAS das = DAS.FACTORY.createDAS(helper.getConfig(), getConnection());
        Command select = das.createCommand("SELECT * FROM ORDERDETAILS LEFT JOIN ORDERDETAILSDESC ON ORDERDETAILS.ORDERID = ORDERDETAILSDESC.ORDERID " +
                    " AND ORDERDETAILS.PRODUCTID = ORDERDETAILSDESC.PRODUCTID");

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());
                    this.logger.debug("r.getForeignKeyTable():"+r.getForeignKeyTable());
                    this.logger.debug("getTypeName():"+getTypeName());
                }
               
                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);
                      if (this.logger.isDebugEnabled()) {
View Full Code Here

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

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

        //JIRA-952
        Table tbl = this.mappingWrapper.getTable(r.getPrimaryKeyTable());
        Property parentRef = null;
        if(tbl == null){
          //this is case when config file is not present and
          //ConfigHelper helper = new ConfigHelper(); is used
          parentRef = getParentReference(r.getPrimaryKeyTable())
        }
        else{
          //other cases, its better to use typeName as r.getPrimaryKeyTable()
          //gives tableName and tableName and typeName can be different
          //and SDO looks for typeName and not tableName.
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

        }
        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()))
                    && (CollectionsUtil.disjoint(tw.getPrimaryKeyProperties(), rw.getForeignKeys()))) {
                return true;
            }

        }
View Full Code Here

        }
    }
   
    public void testInvalidFKColumn() throws SQLException {
        ConfigHelper helper = new ConfigHelper();
        Relationship r = helper.addRelationship("CUSTOMER.ID", "ANORDER.CUSTOMER_ID_INVALID");
        r.setName("orders");
      

        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

                        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

        }

        // 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

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.