Examples of RelationshipFactory


Examples of org.structr.core.graph.RelationshipFactory

  }

  @Override
  public void processMessage(WebSocketMessage webSocketData) {

    final RelationshipFactory factory = new RelationshipFactory(this.getWebSocket().getSecurityContext());
    final AbstractNode node           = getNode(webSocketData.getId());

    if (node == null) {

      return;
View Full Code Here

Examples of org.structr.core.graph.RelationshipFactory

  }

  public void setSecurityContext(SecurityContext securityContext) {
    this.securityContext = securityContext;
    this.nodeFactory     = new NodeFactory(securityContext);
    this.relFactory      = new RelationshipFactory(securityContext);
  }
View Full Code Here

Examples of org.structr.core.graph.RelationshipFactory

  @Override
  public void execute(final Map<String, Object> map) throws FrameworkException {

    final GraphDatabaseService graphDb   = (GraphDatabaseService)arguments.get("graphDb");
    final RelationshipFactory relFactory = new RelationshipFactory(securityContext);

    if (graphDb != null) {

      // collect relationships in transactional context
      List<AbstractRelationship> rels = new LinkedList<>();
      try (final Tx tx = StructrApp.getInstance().tx()) {
       
        rels.addAll(relFactory.instantiate(GlobalGraphOperations.at(graphDb).getAllRelationships()));
      }

      long count = bulkGraphOperation(securityContext, rels, 1000, "MigrateRelationships", new BulkGraphOperation<AbstractRelationship>() {

        @Override
View Full Code Here

Examples of org.structr.core.graph.RelationshipFactory

*/
public class SearchRelationshipCommand<T extends RelationshipInterface> extends SearchCommand<Relationship, T> {

  @Override
  public Factory<Relationship, T> getFactory(SecurityContext securityContext, boolean includeDeletedAndHidden, boolean publicOnly, int pageSize, int page, String offsetId) {
    return new RelationshipFactory(securityContext);
  }
View Full Code Here

Examples of org.structr.core.graph.RelationshipFactory

  private void migrateDatabase() {

    final GraphDatabaseService graphDb     = getService(NodeService.class).getGraphDb();
    final SecurityContext superUserContext = SecurityContext.getSuperUserInstance();
    final NodeFactory nodeFactory          = new NodeFactory(superUserContext);
    final RelationshipFactory relFactory   = new RelationshipFactory(superUserContext);
    final App app                          = StructrApp.getInstance();
    final StringProperty uuidProperty      = new StringProperty("uuid");
    final int txLimit                      = 2000;

    boolean hasChanges                     = true;
    int actualNodeCount                    = 0;
    int actualRelCount                     = 0;

    logger.log(Level.INFO, "Migration of ID properties from uuid to id requested.");

    while (hasChanges) {

      hasChanges = false;

      try (final Tx tx = app.tx(false, false)) {

        // iterate over all nodes,
        final Iterator<Node> allNodes = GlobalGraphOperations.at(graphDb).getAllNodes().iterator();
        while (allNodes.hasNext()) {

          final Node node = allNodes.next();

          // do migration of our own ID properties (and only our own!)
          if (node.hasProperty("uuid") && node.getProperty("uuid") instanceof String && !node.hasProperty("id")) {

            try {
              final NodeInterface nodeInterface = nodeFactory.instantiate(node);
              final String uuid = nodeInterface.getProperty(uuidProperty);

              if (uuid != null) {

                nodeInterface.setProperty(GraphObject.id, uuid);
                nodeInterface.removeProperty(uuidProperty);
                actualNodeCount++;
                hasChanges = true;
              }

            } catch (Throwable t) {
              t.printStackTrace();
            }
          }

          // break out of loop to allow transaction to commit
          if (hasChanges && (actualNodeCount % txLimit) == 0) {
            break;
          }
        }

        tx.success();

      } catch (Throwable t) {

        t.printStackTrace();
      }

      logger.log(Level.INFO, "Migrated {0} nodes so far.", actualNodeCount);
    }

    logger.log(Level.INFO, "Migrated {0} nodes to new ID property.", actualNodeCount);

    // iterate over all relationships
    hasChanges = true;
    while (hasChanges) {

      hasChanges = false;

      try (final Tx tx = app.tx(false, false)) {

        final Iterator<Relationship> allRels = GlobalGraphOperations.at(graphDb).getAllRelationships().iterator();
        while (allRels.hasNext()) {

          final Relationship rel = allRels.next();

          // do migration of our own ID properties (and only our own!)
          if (rel.hasProperty("uuid") && rel.getProperty("uuid") instanceof String && !rel.hasProperty("id")) {

            try {
              final RelationshipInterface relInterface = relFactory.instantiate(rel);
              final String uuid = relInterface.getProperty(uuidProperty);

              if (uuid != null) {
                relInterface.setProperty(GraphObject.id, uuid);
                relInterface.removeProperty(uuidProperty);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.