Package org.neo4j.graphdb

Examples of org.neo4j.graphdb.PropertyContainer


    }

    public void setPermissionForUser(String user, Permission permission) {
        Transaction transaction = graph.beginTx();
        try {
            PropertyContainer properties = getGraphProperties();
            String key = getUserKey(user);
            if (permission == Permission.NONE) {
                properties.removeProperty(key);
            } else {
                properties.setProperty(key, permission.name());
            }
            transaction.success();
        } catch (Exception e) {
            transaction.failure();
        } finally {
View Full Code Here


  private Neo4JErsatz asUltimate(PropertyContainer n) {
    return Neo4JErsatz.create(entity, n);
  }
 
  public Neo4JErsatz next() {
    PropertyContainer candidate = cursor.next();
     
    return asUltimate(candidate);
  }
View Full Code Here

  }

  public static String extractProperties(final Schema entity, final Set<String> propertyNames, final Set<Validator> validators, final Set<String> enums, final Map<String, Set<String>> views, final Map<Actions.Type, List<ActionEntry>> actions, final ErrorBuffer errorBuffer) throws FrameworkException {

    final PropertyContainer propertyContainer = entity.getPropertyContainer();
     final StringBuilder src                   = new StringBuilder();

    // output property source code and collect views
    for (String propertyName : SchemaHelper.getProperties(propertyContainer)) {

      if (!propertyName.startsWith("__") && propertyContainer.hasProperty(propertyName)) {

        String rawType = propertyContainer.getProperty(propertyName).toString();

        String dbName = null;
        // detect optional db name
        if (rawType.contains("|")) {

          dbName = rawType.substring(0, rawType.indexOf("|"));
          rawType = rawType.substring(rawType.indexOf("|")+1);

        }

        boolean notNull = false;

        // detect and remove not-null constraint
        if (rawType.startsWith("+")) {
          rawType = rawType.substring(1);
          notNull = true;
        }

        String defaultValue = null;

        // detect and remove default value
        if (rawType.contains(":") && !rawType.startsWith(Type.Cypher.name())) {

          final int lastIndex = rawType.lastIndexOf(":");
          defaultValue = rawType.substring(lastIndex+1);
          rawType = rawType.substring(0, lastIndex);

        }

        PropertyParser parser = SchemaHelper.getParserForRawValue(errorBuffer, entity.getClassName(), propertyName, dbName, rawType, notNull, defaultValue);
        if (parser != null) {

          // add property name to set for later use
          propertyNames.add(parser.getPropertyName());

          // append created source from parser
          src.append(parser.getPropertySource(entity, errorBuffer));

          // register global elements created by parser
          validators.addAll(parser.getGlobalValidators());
          enums.addAll(parser.getEnumDefinitions());

          // register property in default view
          //addPropertyToView(PropertyView.Public, propertyName.substring(1), views);
          addPropertyToView(PropertyView.Ui, propertyName.substring(1), views);
        }
      }
    }

    for (final String rawViewName : getViews(propertyContainer)) {

      if (!rawViewName.startsWith("___") && propertyContainer.hasProperty(rawViewName)) {

        final String value = propertyContainer.getProperty(rawViewName).toString();
        final String[] parts = value.split("[,\\s]+");
        final String viewName = rawViewName.substring(2);

        // clear view before filling it again
        Set<String> view = views.get(viewName);
        if (view == null) {

          view = new LinkedHashSet<>();
          views.put(viewName, view);

        } else {

          view.clear();
        }

        // add parts to view, overrides defaults (because of clear() above)
        for (int i = 0; i < parts.length; i++) {
          view.add(parts[i].trim());
        }
      }
    }

    for (final String rawActionName : getActions(propertyContainer)) {

      if (propertyContainer.hasProperty(rawActionName)) {

        // split value on ";"
        final String value     = propertyContainer.getProperty(rawActionName).toString();
        final String[] parts1  = value.split("[;]+");
        final int parts1Length = parts1.length;

        for (int i=0; i<parts1Length; i++) {
View Full Code Here

  @Override
  public T getProperty(SecurityContext securityContext, GraphObject obj, boolean applyConverter, final Predicate<GraphObject> predicate) {

    Object value = null;
   
    final PropertyContainer propertyContainer = obj.getPropertyContainer();
    if (propertyContainer != null) {
     
      // this may throw a java.lang.IllegalStateException: Relationship[<id>] has been deleted in this tx
      if (propertyContainer.hasProperty(dbName())) {

        value = propertyContainer.getProperty(dbName());
      }
    }

    if (applyConverter) {
View Full Code Here

    } else {

      convertedValue = value;
    }

    final PropertyContainer propertyContainer = obj.getPropertyContainer();
    if (propertyContainer != null) {

      if (!TransactionCommand.inTransaction()) {

        logger.log(Level.SEVERE, "setProperty outside of transaction");
        throw new FrameworkException(500, "setProperty outside of transaction.");
      }

      // notify only non-system properties
      if (!unvalidated) {

        // collect modified properties
        if (obj instanceof AbstractNode) {

          TransactionCommand.nodeModified(
            (AbstractNode)obj,
            AbstractPrimitiveProperty.this,
            propertyContainer.hasProperty(dbName()) ? propertyContainer.getProperty(dbName()) : null,
            value
          );

        } else if (obj instanceof AbstractRelationship) {

          TransactionCommand.relationshipModified(
            (AbstractRelationship)obj,
            AbstractPrimitiveProperty.this,
            propertyContainer.hasProperty(dbName()) ? propertyContainer.getProperty(dbName()) : null,
            value
          );
        }
      }

      // catch all sorts of errors and wrap them in a FrameworkException
      try {
       
        // save space
        if (convertedValue == null) {

          propertyContainer.removeProperty(dbName());

        } else {

          // Setting last modified date explicetely is not allowed
          if (!AbstractPrimitiveProperty.this.equals(AbstractNode.lastModifiedDate)) {

            propertyContainer.setProperty(dbName(), convertedValue);

            // set last modified date if not already happened
            propertyContainer.setProperty(AbstractNode.lastModifiedDate.dbName(), System.currentTimeMillis());

          } else {

            logger.log(Level.FINE, "Tried to set lastModifiedDate explicitly (action was denied)");
View Full Code Here

    final RelationshipFactory relFactory = new RelationshipFactory(securityContext);
    final NodeFactory nodeFactory        = new NodeFactory(securityContext);
    final String uuidPropertyName        = GraphObject.id.dbName();
    double t0                            = System.nanoTime();
    Map<String, Node> uuidMap            = new LinkedHashMap<>();
    PropertyContainer currentObject      = null;
    String currentKey                    = null;
    boolean finished                     = false;
    long totalNodeCount                  = 0;
    long totalRelCount                   = 0;

    final BufferedReader reader = new BufferedReader(new InputStreamReader(zis));

    do {

      try (final Tx tx = app.tx(doValidation)) {

        final List<Relationship> rels = new LinkedList<>();
        final List<Node> nodes        = new LinkedList<>();
        long nodeCount                = 0;
        long relCount                 = 0;

        do {

          try {

            // store current position
            reader.mark(4);

            // read one byte
            String objectType = read(reader, 1);

            // skip newlines
            if ("\n".equals(objectType)) {
              continue;
            }

            if ("N".equals(objectType)) {

              currentObject = graphDb.createNode();
              nodeCount++;

              // store for later use
              nodes.add((Node)currentObject);

            } else if ("R".equals(objectType)) {

              String startId     = (String)deserialize(reader);
              String endId       = (String)deserialize(reader);
              String relTypeName = (String)deserialize(reader);

              Node endNode   = uuidMap.get(endId);
              Node startNode = uuidMap.get(startId);

              if (startNode != null && endNode != null) {

                RelationshipType relType = DynamicRelationshipType.withName(relTypeName);
                currentObject = startNode.createRelationshipTo(endNode, relType);

                // store for later use
                rels.add((Relationship)currentObject);
              }

              relCount++;

            } else {

              // reset if not at the beginning of a line
              reader.reset();

              if (currentKey == null) {

                currentKey = (String)deserialize(reader);

              } else {

                if (currentObject != null) {

                  Object obj = deserialize(reader);

                  if (uuidPropertyName.equals(currentKey) && currentObject instanceof Node) {

                    String uuid = (String)obj;
                    uuidMap.put(uuid, (Node)currentObject);
                  }

                  if (currentKey.length() != 0) {

                    // store object in DB
                    currentObject.setProperty(currentKey, obj);

                    // set type label
                    if (currentObject instanceof Node && NodeInterface.type.dbName().equals(currentKey)) {
                      ((Node) currentObject).addLabel(DynamicLabel.label((String) obj));
                    }
View Full Code Here

        return new RelationshipResult(relationship, RelationshipResult.Type.NEW);
    }

    @SuppressWarnings("unchecked")
    public <R extends PropertyContainer> R getPersistentState(Object entity, Class<R> type) {
        final PropertyContainer state = getPersistentState(entity);
        if (type==null || type.isInstance(state)) return (R)state;
        throw new IllegalArgumentException("Target state is not the requested "+type+" but "+state);
    }
View Full Code Here

    }

    public final boolean equals(Object first, Object second) {
        if (second == first) return true;
        if (second == null) return false;
        final PropertyContainer firstState = getPersistentState(first,false);
        if (firstState == null) return false;
        final PropertyContainer secondState = getPersistentState(second,false);
        if (secondState == null) return false;
        return firstState.equals(secondState);
    }
View Full Code Here

    /**
     * @return result of the hashCode of the underlying node (if any, otherwise identityHashCode)
     */
    public final int hashCode(Object entity) {
        if (entity == null) throw new IllegalArgumentException("Entity is null");
        final PropertyContainer state = getPersistentState(entity);
        if (state == null) return System.identityHashCode(entity);
        return state.hashCode();
    }
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    public <M extends ModuleMetadata> M getModuleMetadata(String moduleId) {
        final String key = moduleKey(moduleId);
        PropertyContainer container = getOrCreateMetadataContainer();

        Map<String, Object> internalProperties = getInternalProperties(container);

        try {
            byte[] serializedMetadata = (byte[]) internalProperties.get(key);
View Full Code Here

TOP

Related Classes of org.neo4j.graphdb.PropertyContainer

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.