The Web Graph Database

wiki:Docs/BlessingUnblessingRelationship

Blessing and Unblessing a Relationship between two MeshObjects

Blessing a Relationship

Assume an existing Relationship between the following two MeshObjects needs to be blessed with RelationshipType org.infogrid.model.Test.AR1A:

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

A Transaction is necessary to create, delete or update any MeshObject. Note that if the RelationshipType requires the source and/or destination MeshObject to be blessed with a certain EntityType, blessing of the Relationship will fail unless the the MeshObjects are indeed blessed with the correct EntityType.

To bless the Relationship:

MeshBase    mb = obj1.getMeshObject();
Transaction tx = null;
try {
    tx = mb.createTransactionAsap();

    obj1.blessRelationship( TestSubjectArea.AR1A.getSource(), obj2 ); // blessing

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

Note that this RelationshipType is directed. The line:

    obj1.blessRelationship( TestSubjectArea.AR1A.getSource(), obj2 ); // blessing

accomplishes the same effect as the line:

    obj2.blessRelationship( TestSubjectArea.AR1A.getDestination(), obj1 ); // blessing

Unblessing a Relationship

Assume the following two MeshObjects are currently related, the Relationship is blessed with RelationshipType org.infogrid.model.Test.AR1A and needs to be unblessed:

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

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

To unbless the Relationship:

MeshBase    mb = obj.getMeshObject();
Transaction tx = null;
try {
    tx = mb.createTransactionAsap();

    obj1.unblessRelationship( TestSubjectArea.AR1A.getSource(), obj2 ); // unblessing

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

Note that this RelationshipType is directed. The line:

    obj1.unblessRelationship( TestSubjectArea.AR1A.getSource(), obj2 ); // unblessing

accomplishes the same effect as the line:

    obj2.unblessRelationship( TestSubjectArea.AR1A.getDestination(), obj1 ); // unblessing

See also:

Last modified 5 years ago Last modified on 07/24/09 16:23:31