Package org.dbwiki.data.database

Examples of org.dbwiki.data.database.DatabaseElementNode


  public void eval(DatabaseGroupNode node, XPath targetPath, ConditionEvaluator evaluator) {
   
    if (targetPath.size() > 0) {
      XPathComponent pathComponent = targetPath.firstElement();
      for (int iChild = 0; iChild < node.children().size(); iChild++) {
        DatabaseElementNode childNode = node.children().get(iChild);
        if (pathComponent.matches(childNode)) {
          if (targetPath.size() == 1) {
            evaluator.eval(childNode, this.evalResult());
          } else {
            new XPathEvaluator(this.evalResult()).eval((DatabaseGroupNode)childNode, targetPath.subpath(1), evaluator);
View Full Code Here


      int entryID = ((NodeIdentifier)entry.identifier()).nodeID();
     
      // FIXME: ugly casts - perhaps a visitor
      // would be appropriate here?
      if (node.isElement()) {
        DatabaseElementNode element = (DatabaseElementNode)node;
        if (element.isAttribute()) {
          writeTextNodes((RDBMSDatabaseAttributeNode)element, entryID);
        } else {
          writeTextNodes((RDBMSDatabaseGroupNode)element, entryID);
        }
      } else {
View Full Code Here

    }
  }
 
  private void writeTextNodes(RDBMSDatabaseGroupNode group, int entry) throws java.sql.SQLException, org.dbwiki.exception.WikiException {
    for (int iChild = 0; iChild < group.children().size(); iChild++) {
      DatabaseElementNode child = group.children().get(iChild);
      if (child.isAttribute()) {
        this.writeTextNodes((RDBMSDatabaseAttributeNode)child, entry);
      } else {
        this.writeTextNodes((RDBMSDatabaseGroupNode)child, entry);
      }
    }
View Full Code Here

 
  public void evalTimestamp(DatabaseGroupNode node, XPath targetPath, ConditionEvaluator evaluator) {
   
    XPathComponent pathComponent = targetPath.firstElement();
    for (int iChild = 0; iChild < node.children().size(); iChild++) {
      DatabaseElementNode childNode = node.children().get(iChild);
      if (pathComponent.matches(childNode)) {
        if (targetPath.size() == 1) {
          evaluator.evalTimestamp(childNode, this.evalResult());
        } else {
          new XPathTimestampEvaluator(this.evalResult()).evalTimestamp((DatabaseGroupNode)childNode, targetPath.subpath(1), evaluator);
View Full Code Here

    // below the ID of the given node
    if (node.parent() != null) {
      if (node.parent().isGroup()) {
        DatabaseGroupNode parent = (DatabaseGroupNode)node.parent();
        for (int iChild = 0; iChild < parent.children().size(); iChild++) {
          DatabaseElementNode child = parent.children().get(iChild);
          if (child.schema().equals(node.schema())) {
            if (child.identifier().compareTo(node.identifier()) < 0) {
              nodeIndex++;
            }
          }
        }
      }
View Full Code Here

  public String name() {
    return _wiki.name();
  }

  public synchronized void paste(ResourceIdentifier target, PasteNode pasteNode, String sourceURL, User user) throws org.dbwiki.exception.WikiException {
    DatabaseElementNode targetElement = null;
   
    if (!target.isRootIdentifier()) {
      DatabaseNode targetNode = get(target);
      if (targetNode.isText()) {
        targetElement = targetNode.parent();
      } else {
        targetElement = (DatabaseElementNode)targetNode;
      }
    } else if (!pasteNode.isElement()) {
      throw new WikiDataException(WikiDataException.InvalidPasteTarget, target.toParameterString());
    }
   
    if (pasteNode.isElement()) {
      if (targetElement != null) {
        if (!targetElement.isGroup()) {
          throw new WikiDataException(WikiDataException.InvalidPasteTarget, target.toParameterString());
        }
      }
      Connection con = _connector.getConnection();     
      try {
        SQLDatabaseSchema schema = new SQLDatabaseSchema(con, _versionIndex, _wiki.name());
        DocumentNode insertNode = null;
        if (targetElement != null) {
          // FIXME #copypaste: This code looks unnecessarily complicated
          // Isn't:
          //
          //   (GroupSchemaNode)schema.get(targetElement.schema().id())
          //
          // entirely equivalent to:
          //
          //   (GroupSchemaNode)targetElement.schema()
          //
          // ?
          insertNode = getPasteInsertNode((GroupSchemaNode)schema.get(targetElement.schema().id()), (PasteElementNode)pasteNode, schema);
        } else {
          insertNode = getPasteInsertNode(null, (PasteElementNode)pasteNode, schema);
        }
        if (insertNode != null) {
          Version version = _versionIndex.getNextVersion(new ProvenanceCopy(user, target, sourceURL));
          try {
            con.setAutoCommit(false);
            try {
              if (target.isRootIdentifier()) {
                new DatabaseWriter(con, this).insertRootNode((DocumentGroupNode)insertNode, version);     
              } else {
                new DatabaseWriter(con, this).insertNode((NodeIdentifier)target, insertNode, version);
              }
              for (int i = schema().size(); i < schema.size(); i++) {
                new DatabaseWriter(con, this).insertSchemaNode(schema.get(i), version);
              }
              _versionIndex.add(version);
              _versionIndex.store(con);
            } catch (org.dbwiki.exception.WikiException wikiException) {
              con.rollback();
              con.close();
              throw wikiException;
            }
            con.commit();
            con.close();
          } catch (java.sql.SQLException sqlException) {
            throw new WikiFatalException(sqlException);
          }
          _schema = schema;
        }
      } catch (java.sql.SQLException sqlException) {
        throw new WikiFatalException(sqlException);
      }
    } else {
      // targetElement should be nonnull
      assert(targetElement != null);
      if (!targetElement.isAttribute()) {
        throw new WikiDataException(WikiDataException.InvalidPasteTarget, target.toParameterString());
      }
      Update update = new Update();
      update.add(new NodeUpdate(targetElement.identifier(), ((PasteTextNode)pasteNode).getValue()));
      updateNodeWrapped(targetElement, update, _versionIndex.getNextVersion(new ProvenanceCopy(user, targetElement.identifier(), sourceURL)));
    }
  }
View Full Code Here

   */
 
  private void activateNode(Connection con, DatabaseNode node, Version version) throws org.dbwiki.exception.WikiException {
    if (!node.getTimestamp().isCurrent()) {
      boolean activeParent = true;
      DatabaseElementNode parent = node.parent();
      if (parent != null) {
        activeParent = parent.getTimestamp().isCurrent();
      }
      if (activeParent) {
        int deletedAt = node.getTimestamp().lastValue();
        if (node.isElement()) {
          if (node.hasTimestamp()) {
View Full Code Here

        }
      }
    } else {
      DatabaseGroupNode group = (DatabaseGroupNode)node;
      for (int iChild = 0; iChild < group.children().size(); iChild++) {
        DatabaseElementNode child = group.children().get(iChild);
        if ((child.hasTimestamp()) && (child.getTimestamp().lastValue() == deletedAt)) {
          insertTimestamp(con, child, child.getTimestamp().continueAt(version.number()));
        }
        activateElementNode(con, child, deletedAt, version);
      }
    }
  }
View Full Code Here

        }
      }
    } else {
      DatabaseGroupNode group = (DatabaseGroupNode)node;
      for (int iChild = 0; iChild < group.children().size(); iChild++) {
        DatabaseElementNode child = group.children().get(iChild);
        if ((child.hasTimestamp()) && (child.getTimestamp().isCurrent())) {
          updateTimestamp(con, child, child.getTimestamp().finishAt(version.number() - 1));
        }
        deleteElementNode(con, child, version);
      }
    }
  }
View Full Code Here

  }
 
  private void exportNode(DatabaseNode node, int version, NodeWriter out, boolean last) throws org.dbwiki.exception.WikiException {
    if (node.getTimestamp().contains(version)) {
      if (node.isElement()) {
        DatabaseElementNode element = (DatabaseElementNode)node;
        if (element.isAttribute()) {
          DatabaseAttributeNode attribute = (DatabaseAttributeNode)element;
          DatabaseTextNode value = null;
          for (int iValue = 0; iValue < attribute.value().size(); iValue++) {
            if (attribute.value().get(iValue).getTimestamp().contains(version)) {
              value = attribute.value().get(iValue);
View Full Code Here

TOP

Related Classes of org.dbwiki.data.database.DatabaseElementNode

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.