Package org.dbwiki.data.database

Examples of org.dbwiki.data.database.DatabaseNode


      }
      body.paragraph(_layouter.get(schema).getName(), CSS.CSSHeadline);
      this.printInsertForm(_request, schema, body);
    } else if (_request.parameters().hasParameter(RequestParameter.ParameterEdit)) {
      body.paragraph("Edit", CSS.CSSHeadline);
      DatabaseNode node = _request.node();
      if (node.isElement()) {
        DatabaseElementNode element = (DatabaseElementNode)node;
        this.printUpdateForm(_request, element, body);
      } else {
        DatabaseTextNode textNode = (DatabaseTextNode)node;
        this.printUpdateForm(_request, textNode, body);
View Full Code Here


 
 
  public ResourceIdentifier insertNode(NodeIdentifier identifier, DocumentNode node, Version version) throws org.dbwiki.exception.WikiException {
    RDBMSDatabaseGroupNode parent = (RDBMSDatabaseGroupNode)DatabaseReader.get(_con, _database, identifier);
   
    DatabaseNode entry = parent;
    while (entry.parent() != null) {
      entry = entry.parent();
    }

    // Idea:  Find size of inserted subtree.
    // Let newpre be the post index of the parent.
    // Index to-be-inserted nodes starting from post, ending at newpost
    // Let delta = newpost - post = the size of the inserted subtree *2
    int newPre = parent.getpost();
    int newPost = node.doNumbering(newPre);
    int delta = newPost - newPre;
   
    ResourceIdentifier nodeIdentifier = null;
   
    try {
      int entryID = ((NodeIdentifier)entry.identifier()).nodeID();
      // Shift all node indexes that are >= newpre
      shiftNodes(RelDataColPre, entryID,newPre,delta);
      shiftNodes(RelDataColPost, entryID,newPre,delta);
      // Add the new nodes
      if (node.isAttribute()) {
View Full Code Here

   *
   * @param node
   * @throws org.dbwiki.exception.WikiException
   */
  public void updateNode(DatabaseNode node) throws org.dbwiki.exception.WikiException {
    DatabaseNode entry = node;
    while (entry.parent() != null) {
      entry = entry.parent();
    }

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

          " AND v2.n_entry=v1.entry" +
          " ORDER BY n_id, t_start, a_id ");
 


      DatabaseNode node = null;
      int i=0;
      
      while (rs.next()) {
        i++;
        int id = rs.getInt(ViewDataColNodeID);
    //    System.out.println(id);
        // The following condition allows information about nodes to be built up
        // incrementally when spread across multiple rows.
        //
        // It relies on the results being ordered first by node id.
        //
        // A single node id may appear in consecutive rows if the
        // node has existed in multiple time intervals, or if it has
        // multiple annotations.
        if (node == null || ((NodeIdentifier)node.identifier()).nodeID() != id)  {
          int schema = rs.getInt(ViewDataColNodeSchema);
          int parent = rs.getInt(ViewDataColNodeParent);
          int pre = rs.getInt(ViewDataColNodePre);
          int post = rs.getInt(ViewDataColNodePost);
          if (schema != RelDataColSchemaValUnknown) {
            // FIXME #database: This seems to assume that the nodes are in parent-child order.
            // The following logic seems rather fragile.
            // It isn't at all clear that things will
            // work properly if a child node is encountered
            // in the result set before its parent.
            //
            // There doesn't appear to be any code for
            // connecting up parents to children later on.
            //
            // It may be that the problematic situation
            // never occurs. This seems quite likely, as
            // child nodes are always going to be created
            // after their parents, and ids are assigned
            // in sequence. If this is the case, then
            // the constraint should be explicitly stated
            // in the data model, we should implement code
            // for checking that the constraint hasn't been
            // violated, and the following null-checking code
            // should be removed.
            RDBMSDatabaseGroupNode parentNode = null;
            if (parent != RelDataColParentValUnknown) {
              parentNode = (RDBMSDatabaseGroupNode)nodeIndex.get(new Integer(parent));
            }
            SchemaNode schemaNode = database.schema().get(schema);
            if (schemaNode.isAttribute()) {
              node = new RDBMSDatabaseAttributeNode(id, (AttributeSchemaNode)schemaNode, parentNode, pre, post);
            } else {
              node = new RDBMSDatabaseGroupNode(id, (GroupSchemaNode)schemaNode, parentNode, pre, post);
            }
            if (parentNode != null) {
              parentNode.children().add((DatabaseElementNode)node);
            }
          } else {
            RDBMSDatabaseAttributeNode parentNode = (RDBMSDatabaseAttributeNode)nodeIndex.get(new Integer(parent));
            node =  new RDBMSDatabaseTextNode(id, parentNode, rs.getString(ViewDataColNodeValue));
            parentNode.value().add((DatabaseTextNode)node);
          }
          nodeIndex.put(new Integer(id), node);
        }
        int end = RelTimestampColEndValOpen;
        int start = rs.getInt(ViewDataColTimestampStart);
        
         
        if (!rs.wasNull()) {
          end = rs.getInt(ViewDataColTimestampEnd);
          if (!node.hasTimestamp()) {
            node.setTimestamp(new TimeSequence(start, end));
          } else {
            node.getTimestamp().elongate(start, end);
          }
        }
        int annotationID = rs.getInt(ViewDataColAnnotationID);
        if (!rs.wasNull()) {
          if (!node.annotation().contains(annotationID)) {
            node.annotation().add(new Annotation(annotationID, rs.getString(ViewDataColAnnotationText), rs.getString(ViewDataColAnnotationDate), database.users().get(rs.getInt(ViewDataColAnnotationUser))));
          }
        }
      }
      System.out.println(i);
      rs.close();
View Full Code Here

            "WHERE " + ViewDataColNodeEntry + " = (SELECT " + RelDataColEntry + " FROM " + database.name() + RelationData + " WHERE " + RelDataColID + " = " + identifier.nodeID() + ") " +
            "ORDER BY " + ViewDataColNodeID + ", " + ViewDataColTimestampStart + ", " + ViewDataColAnnotationID);
    //    long getdata = System.nanoTime() - startevalute;
      //  System.out.println("getdata:\t"+getdata);  
       
        DatabaseNode node = null;
        //int i=0;
        while (rs.next()) {
         
        //  i++;
          int id = rs.getInt(ViewDataColNodeID);
      //    System.out.println(id);
          // The following condition allows information about nodes to be built up
          // incrementally when spread across multiple rows.
          //
          // It relies on the results being ordered first by node id.
          //
          // A single node id may appear in consecutive rows if the
          // node has existed in multiple time intervals, or if it has
          // multiple annotations.
          if (node == null || ((NodeIdentifier)node.identifier()).nodeID() != id)  {
            int schema = rs.getInt(ViewDataColNodeSchema);
            int parent = rs.getInt(ViewDataColNodeParent);
            if (schema != RelDataColSchemaValUnknown) {
              // FIXME #database: This seems to assume that the nodes are in parent-child order.
              // The following logic seems rather fragile.
              // It isn't at all clear that things will
              // work properly if a child node is encountered
              // in the result set before its parent.
              //
              // There doesn't appear to be any code for
              // connecting up parents to children later on.
              //
              // It may be that the problematic situation
              // never occurs. This seems quite likely, as
              // child nodes are always going to be created
              // after their parents, and ids are assigned
              // in sequence. If this is the case, then
              // the constraint should be explicitly stated
              // in the data model, we should implement code
              // for checking that the constraint hasn't been
              // violated, and the following null-checking code
              // should be removed.
              RDBMSDatabaseGroupNode parentNode = null;
              if (parent != RelDataColParentValUnknown) {
                parentNode = (RDBMSDatabaseGroupNode)nodeIndex.get(new Integer(parent));
              }
              SchemaNode schemaNode = database.schema().get(schema);
              if (schemaNode.isAttribute()) {
                node = new RDBMSDatabaseAttributeNode(id, (AttributeSchemaNode)schemaNode, parentNode);
              } else {
                node = new RDBMSDatabaseGroupNode(id, (GroupSchemaNode)schemaNode, parentNode);
              }
              if (parentNode != null) {
                parentNode.children().add((DatabaseElementNode)node);
              }
            } else {
              RDBMSDatabaseAttributeNode parentNode = (RDBMSDatabaseAttributeNode)nodeIndex.get(new Integer(parent));
              node =  new RDBMSDatabaseTextNode(id, parentNode, rs.getString(ViewDataColNodeValue));
              parentNode.value().add((DatabaseTextNode)node);
            }
            nodeIndex.put(new Integer(id), node);
          }
          int end = RelTimestampColEndValOpen;
          int start = rs.getInt(ViewDataColTimestampStart);
          if (!rs.wasNull()) {
            end = rs.getInt(ViewDataColTimestampEnd);
            if (!node.hasTimestamp()) {
              //FIXME is this right?
              node.setTimestamp(new TimeSequence(start, end));
            } else {
              node.getTimestamp().elongate(start, end);
            }
          }
          int annotationID = rs.getInt(ViewDataColAnnotationID);
          if (!rs.wasNull()) {
            if (!node.annotation().contains(annotationID)) {
              node.annotation().add(new Annotation(annotationID, rs.getString(ViewDataColAnnotationText), rs.getString(ViewDataColAnnotationDate), database.users().get(rs.getInt(ViewDataColAnnotationUser))));
            }
          }
        }
        //System.out.println(i);
        rs.close();
View Full Code Here

   */
 
  public synchronized void activate(ResourceIdentifier identifier, User user) throws org.dbwiki.exception.WikiException {
    Connection con = _connector.getConnection();

    DatabaseNode node = DatabaseReader.get(con, this, (NodeIdentifier)identifier);

    Version version = _versionIndex.getNextVersion(new ProvenanceActivate(user, identifier));

    try {
      con.setAutoCommit(false);
View Full Code Here

  }

  public synchronized void delete(ResourceIdentifier identifier, User user) throws org.dbwiki.exception.WikiException {
    Connection con = _connector.getConnection();

    DatabaseNode node = DatabaseReader.get(con, this, (NodeIdentifier)identifier);
    Version version = _versionIndex.getNextVersion(new ProvenanceDelete(user, identifier));
   
    try {
      con.setAutoCommit(false);
      try {
View Full Code Here

    }
  }

  public DatabaseNode get(ResourceIdentifier identifier) throws org.dbwiki.exception.WikiException {
    Connection con = _connector.getConnection();
    DatabaseNode node = DatabaseReader.get(con, this, (NodeIdentifier)identifier);
    try {
      con.close();
    } catch (java.sql.SQLException sqlException) {
      throw new WikiFatalException(sqlException);
    }
View Full Code Here

  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());
View Full Code Here

   * set is empty or if the result node(s) are TextNodes.
   *
   */
  public SchemaNode schema() {
    if (_nodes.size() > 0) {
      DatabaseNode node = _nodes.firstElement();
      if (node.isElement()) {
        return ((DatabaseElementNode)node).schema();
      } else {
        return null;
      }
    } else {
View Full Code Here

TOP

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

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.