The Web Graph Database

wiki:Docs/CreatingDeletingRelationships

Creating and Deleting Relationships

Creating a Relationship

Assume the following two MeshObjects are to be related:

MeshObject obj1 = ...;
MeshObject obj2 = ...;

Both MeshObjects need to be in the same MeshBase.

A Transaction is necessary to create, delete or update any MeshObject.

To relate the two MeshObjects:

MeshBase    mb = ob1.getMeshBase();
Transaction tx = null;
try {
    tx = mb.createTransactionAsap();

    ob1.relate( obj2 ); // relating

} finally {
    if( tx != null ) {
        tx.commitTransaction();
    }
}

To simultaneously bless the Relationship, pass in the RoleType:

MeshBase    mb = ob1.getMeshBase();
Transaction tx = null;
try {
    tx = mb.createTransactionAsap();

    ob1.relateAndBless( obj2, TestSubjectArea.R.getSource() ); // relating and blessing

} finally {
    if( tx != null ) {
        tx.commitTransaction();
    }
}

Deleting a Relationship

Assume the following two MeshObjects are currently related and need to be unrelated:

MeshObject obj1 = ...;
MeshObject obj2 = ...;

Both MeshObjects need to be in the same MeshBase.

A Transaction is necessary to create, delete or update any MeshObject.

To unrelate the two MeshObjects:

MeshBase    mb = ob1.getMeshBase();
Transaction tx = null;
try {
    tx = mb.createTransactionAsap();

    ob1.unrelate( obj2 ); // unrelating

} finally {
    if( tx != null ) {
        tx.commitTransaction();
    }
}

Unrelating the two MeshObjects will also remove any type information (RoleType) of the deleted Relationship.

See also:

Last modified 5 years ago Last modified on 07/24/09 15:45:11