final DocumentImpl owner = (DocumentImpl)getOwnerDocument(); long childGid; NodeImplRef last = new NodeImplRef(); if (children == 0) { childGid = firstChildID(); last.setNode(this); } else { childGid = lastChildID() + 1; last.setNode(getLastNode((StoredNode) owner.getNode(childGid - 1))); }
    public Node appendChild(Node child) throws DOMException {        final DocumentImpl owner = (DocumentImpl)getOwnerDocument();        long childGid;        NodeImplRef last = new NodeImplRef();        if (children == 0) {            childGid = firstChildID();            last.setNode(this);        } else {            childGid = lastChildID() + 1;            last.setNode(getLastNode((StoredNode) owner.getNode(childGid - 1)));        }        TransactionManager transact = getBroker().getBrokerPool().getTransactionManager();        Txn transaction = transact.beginTransaction();        try {            checkTree(1);            children++;            Node node = appendChild(transaction, null, childGid, last, getPath(), child, true);            getBroker().updateNode(transaction, this);            getBroker().reindexXMLResource(transaction, owner, owner, null);            getBroker().storeXMLResource(transaction, owner);            transact.commit(transaction);            return node;        } catch (EXistException e) {            transact.abort(transaction);            throw new DOMException(DOMException.INVALID_STATE_ERR, e.getMessage());        }    }