yeah, those are basically wrappers to underlying broker methods.

The addEntity method is a wrapper for the following method that accesses the persistence broker:
----------------------------
public boolean addEntity(SimpleDagNode nodeA) throws Exception {
PersistenceBroker pbroker = PersistenceBrokerFactory.defaultPersistenceBroker();
pbroker.beginTransaction();
pbroker.store(nodeA, modificationType);
pbroker.commitTransaction();
return true;
----------------------------




and broker.linkEntity is implemented as follows:
----------------------------
public void linkEntity(SimpleDagNode parent, SimpleDagNode child) throws Exception {
if(!parent.getChildren().contains(child)){
parent.addChild(child);
}
PersistenceBroker pbroker = PersistenceBrokerFactory.defaultPersistenceBroker();
pbroker.beginTransaction();
pbroker.serviceBrokerHelper().link(o, false);
pbroker.commitTransaction();
}
----------------------------


At 03:05 PM 6/23/2004 +0200, you wrote:

seems you use an user specific PersistenceBroker implementation, can you post methods

broker.addEntity(nodeA);
broker.linkEntity(nodeA, nodeB);

too.

regards,
Armin

Bradford Pielech wrote:
Oops, just realized there was a logic bug in the junit test that makes the code incorrect because I had to quickly rewrite the test to remove unneeded subclasses and such. Here is the correct version:
public void testAddNewChild() throws Exception {
SimpleDAGNode nodeA = new nodeANode();
SimpleDAGNode nodeB = new nodeBNode();
//store nodeA first
broker.addEntity(nodeA);
//then store the nodeB
broker.addEntity(nodeB);
//make A the parent of B because they are not linked in the code automatically
broker.linkEntity(nodeA, nodeB);
SimpleDAGNode retrievednodeB = broker.getEntity(nodeB.getID());
assertNotNull("Verifying the nodeB was retrieved", retrievednodeB);
SimpleDAGNode retrievednodeA = (SimpleDAGNode) retrievednodeB.getParentAt(0);
assertEquals("verify the nodeA was stored", nodeA.getID(),
retrievednodeA.getEboId());
assertEquals("verify the retrieved nodeA has 1 child (the nodeB)", 1,
retrievednodeA.getChildCount());
assertEquals("verify the retrieved nodeB has 1 parent (the nodeA)", 1,
retrievednodeB.getParentCount());
assertEquals(
"verify, using hashcode, that the nodeB's parent is the nodeA",
retrievednodeA.hashCode(),
retrievednodeB.getParentAt(0).hashCode());
for (Iterator i = retrievednodeA.getChildren().iterator(); i.hasNext(); ) {
Object o = i.next();
//this next test fails because the child is null
assertNotNull("Verifying nodeA's children are not null", o);
assertEquals(
"verify, using hashcode, that the nodeAs child is the nodeB",
retrievednodeB.hashCode(), o.hashCode());
}
}



At 08:18 AM 6/23/2004 -0400, you wrote:

Armin:

Sure, no problem. Apologies for the formatting, but the basic idea should be clear. I also attached my OJB.properties and repository_user.xml.

thanks!
Brad


SimpleDagNode class: --------------------------------------- public class SimpleDAGNode{

  private List children;
  private String ID;
  private List parents;

  public SimpleDAGNode() {
    ID = "";
    parents = new Vector();
    children = new Vector();
  }
  public String getID() {
    return ID;
  }
  public void addChildNode(DAGNode child) {
    // Cannot add same child twice
    if (!children.contains(child)) {
      children.add(child);
      if (!child.getParents().contains(this)) {
        child.getParents().add(this);
      }

    }

  }
  public void removeChild(DAGNode child) {
    children.remove(child);
    child.getParents().remove(this);
  }

  public List getParents() {
    return parents;
  }

  public List getChildren() {
    return children;
  }

 public boolean equals(Object ref) {
     if (ref == null) {
       return false;
     }
     if (ref instanceof SimpleDagNode) {
       return (getID().equals( ( (SimpleDagNode) ref).getID()));
     }
     else {
       return false;
     }
   }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to