Package org.dbwiki.data.schema

Examples of org.dbwiki.data.schema.SchemaNode


    Statement statement = con.createStatement()
    String schemaTable = dbName + RelationSchema;
   
    if (schema != null) {
      for (int i = 0; i < schema.size(); i++) {
        SchemaNode node = schema.get(i);
        String newNode = "INSERT INTO " + schemaTable + "(" +
          RelSchemaColID +", " +
          RelSchemaColType + ", " +
          RelSchemaColLabel + ", " +
          RelSchemaColParent + ", " +
          RelSchemaColUser + ") VALUES(";
        newNode = newNode + node.id() + ", ";
        if (node.isAttribute()) {
          newNode = newNode + RelSchemaColTypeValAttribute + ", ";
        } else {
          newNode = newNode + RelSchemaColTypeValGroup + ", ";       
        }
        newNode = newNode + "'" + node.label() + "', ";
        if (node.parent() != null) {
          newNode = newNode + node.parent().id() + ", ";
        } else {
          newNode = newNode + "-1, ";
        }
        if (user != null) {
          newNode = newNode + user.id() + ")";
View Full Code Here


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

    SchemaNode schemaNode = _schema.get(((SchemaNodeIdentifier)identifier).nodeID());
    Version version = _versionIndex.getNextVersion(new ProvenanceUnknown(user));
   
    try {
      con.setAutoCommit(false);
      try {
View Full Code Here

      throw new WikiSchemaException(WikiSchemaException.SyntaxError, "Invalid element name " + name);
    }
   
    Version version = _versionIndex.getNextVersion(new ProvenanceUnknown(user));
   
    SchemaNode schema = null;
    if (type == SchemaNodeTypeAttribute) {
      if (_schema.size() == 0) {
        throw new WikiSchemaException(WikiSchemaException.InvalidSchemaType, "Schema root cannot be an attribute");
      }
      schema = new AttributeSchemaNode(_schema.size(), name, parent, new TimeSequence(version));
View Full Code Here

    }
  }

  private void deleteGroupSchemaNode(Connection con, GroupSchemaNode schema, Version version) throws org.dbwiki.exception.WikiException {
    for (int i = 0; i < schema.children().size(); i++) {
      SchemaNode child = schema.children().get(i);
      if ((child.hasTimestamp()) && child.getTimestamp().isCurrent()) {
        updateTimestamp(con, child, child.getTimestamp().finishAt(version.number() - 1));
      }
      deletetSchemaNode(con, child, version);
    }
  }
View Full Code Here

      }
    }
  }
 
  private DocumentNode getPasteInsertNode(GroupSchemaNode parentSchemaNode, PasteElementNode sourceNode, DatabaseSchema schema) throws org.dbwiki.exception.WikiException {
    SchemaNode schemaNode = null;
   
    if (parentSchemaNode != null) {
      for (int i = 0; i < parentSchemaNode.children().size(); i++) {
        // TODO: we probably need to be careful about which bits of the
        // schema are current
        if (parentSchemaNode.children().get(i).label().equals(sourceNode.label())) {
          schemaNode = parentSchemaNode.children().get(i);
          break;
        }
      }
      if (schemaNode == null) {
        if (_wiki.getAutoSchemaChanges() == DatabaseWikiProperties.AutoSchemaChangesAllow) {
          if (sourceNode.isAttribute()) {
            schemaNode = new AttributeSchemaNode(schema.size(), sourceNode.label(), parentSchemaNode, null);
          } else {
            schemaNode = new GroupSchemaNode(schema.size(), sourceNode.label(), parentSchemaNode, null);
          }
          schema.add(schemaNode);
        } else if (_wiki.getAutoSchemaChanges() == DatabaseWikiProperties.AutoSchemaChangesNever) {
          throw new WikiDataException(WikiDataException.UnknownSchemaNode, sourceNode.label() + " not allowed under " + parentSchemaNode.label());
        }
      }
    } else if (schema.root() != null) {
      schemaNode = schema.root();
      if (!schemaNode.label().equals(sourceNode.label())) {
        throw new WikiDataException(WikiDataException.InvalidPasteTarget, "Node label does not match root label");
      }
    } else {
      if (_wiki.getAutoSchemaChanges() == DatabaseWikiProperties.AutoSchemaChangesAllow) {
        schemaNode = new GroupSchemaNode(schema.size(), sourceNode.label(), null, null);
        schema.add(schemaNode);
      } else if (_wiki.getAutoSchemaChanges() == DatabaseWikiProperties.AutoSchemaChangesNever) {
        throw new WikiDataException(WikiDataException.UnknownSchemaNode, sourceNode.label() + " not allowed as schema root");
      }
    }
   
    if (schemaNode != null) {
      if (schemaNode.isAttribute()) {
        return new DocumentAttributeNode((AttributeSchemaNode)schemaNode, ((PasteAttributeNode)sourceNode).getValue().getValue());
      } else {
        DocumentGroupNode group = new DocumentGroupNode((GroupSchemaNode)schemaNode);
        for (int iChild = 0; iChild < ((PasteGroupNode)sourceNode).children().size(); iChild++) {
          DocumentNode insertChild = getPasteInsertNode((GroupSchemaNode)schemaNode, (PasteElementNode)((PasteGroupNode)sourceNode).children().get(iChild), schema);
View Full Code Here

    // 'order by' clause.
    while (results.next()) {
      int id = results.getInt(RelSchemaColID);
     
      // if the schema node isn't already loaded, then load it
      SchemaNode schema;
      schema = get(id);    
      if(schema == null) {
        String label = results.getString(RelSchemaColLabel);
        GroupSchemaNode parent = null;
        if (results.getInt(RelSchemaColParent) != -1) {
          parent = (GroupSchemaNode)get(results.getInt(RelSchemaColParent));
        }

        if ((results.getInt(RelSchemaColType) == RelSchemaColTypeValAttribute) && (parent != null)) {
          schema = new AttributeSchemaNode(id, label, parent);
        } else if (results.getInt(RelSchemaColType) == RelSchemaColTypeValGroup) {
          schema = new GroupSchemaNode(id, label, parent);
        } else {
          throw new WikiSchemaException(WikiSchemaException.InvalidSchemaType, "Database value " + results.getInt(RelSchemaColType));
        }
      }

      // load the time interval - if any
      int end = RelTimestampColEndValOpen;
      int start = results.getInt(RelTimesequenceColStart);
      if(!results.wasNull()) {
        // a time interval for this node
        end = results.getInt(RelTimesequenceColStop);
        if(schema.hasTimestamp()) {
          schema.getTimestamp().elongate(start, end);
        } else {
          schema.setTimestamp(new TimeSequence(start, end));
        }
      }
     
      add(schema);
    }
View Full Code Here

  public XPath getTargetPath(SchemaNode parentEntity, VersionIndex versionIndex, Iterator<XAQLToken> pathTokens) throws org.dbwiki.exception.WikiException {

    XAQLToken token = pathTokens.next();
   
    String entityName = token.children().firstElement().value();
    SchemaNode entity = ((GroupSchemaNode)parentEntity).children().get(entityName);
    if (entity == null) {
      throw new WikiQueryException(WikiQueryException.InvalidQueryStatement, "Unknown entity " + entityName + " as child of " + parentEntity.label());
    }
   
    XPathComponent pathElement = null;
View Full Code Here

        elements.next().reset(1);
      }
      try {
        _resultSchema = new GroupSchemaNode(-1, "result", null, new TimeSequence(1));
        for (SubTreeSelectStatement stmt : _statements) {
          SchemaNode schema = stmt.targetPath().lastElement().entity();
          String label = null;
          if (stmt.label() != null) {
            label = stmt.label();
          } else {
            label = schema.label();
          }
          if (labelCounter.containsKey(label)) {
            Counter counter = labelCounter.get(label);
            label = label + Integer.toString(counter.value());
            stmt.setLabel(label);
            counter.inc();
          }
          SchemaNode renamedSchema = null;
          if (schema.isAttribute()) {
            renamedSchema = new AttributeSchemaNode(-1, label, _resultSchema, schema.getTimestamp());
            //renamedSchema = new AttributeSchemaNode(schema.id(), label, _resultSchema, schema.getTimestamp());
          } else {
            renamedSchema = new GroupSchemaNode(-1, label, _resultSchema, schema.getTimestamp());
View Full Code Here

  public void print(HtmlLinePrinter body) throws org.dbwiki.exception.WikiException {
    RequestParameterVersion versionParameter = RequestParameter.versionParameter(_request.parameters().get(RequestParameter.ParameterVersion));

    String line = null;
   
    SchemaNode schema = _request.schema();
    while (schema != null) {
      String target = _request.wri().databaseIdentifier().linkPrefix() + schema.identifier().toURLString();
      if (!versionParameter.versionCurrent()) {
        target = target + "?" + versionParameter.toURLString();
      }
      String link = schema.label();
      // FIXME #schema
      // perhaps this should use the layouter, but currently
      // the treatment of data nodes is hard-coded.
      // It isn't obvious what the code does or how to adapt it
      // to entities.
      //
      //_layouter.get(schema).getShortLabel(schema, versionParameter);
      link = "<a CLASS=\"" + CSS.CSSObjectPath + "\" HREF=\"" + target + "\">" + link + "</a>";
      if (line != null) {
        line = link + " &gt; " + line;
      } else {
        line = link;
      }
      schema = schema.parent();
    }
    if (line != null) {
      body.paragraph(line, CSS.CSSObjectPath);
    }
  }
View Full Code Here

   
    for (int iChild = 0; iChild < group.children().size(); iChild++) {
      content.openTABLE(CSS.CSSContentFrameListing);
      content.openTR();
      content.openTD(CSS.CSSContentFrameListing);
      SchemaNode child = group.children().get(iChild);
      if (child.isAttribute()) {
        printAttributeSchemaNode((AttributeSchemaNode)child, _versionParameter, _layouter.get(child), content);
      } else {
        printGroupSchemaNode((GroupSchemaNode)child, _versionParameter, _layouter.get(child), content);
      }
      content.closeTD();
View Full Code Here

TOP

Related Classes of org.dbwiki.data.schema.SchemaNode

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.