示例#1
0
  public void rn() throws IOException {
    List<RoadLink> links = loadToDatabase("/Users/duduba/gj.mif", "/Users/duduba/gj.mid", false);

    GraphDatabaseService graphDb = neo.getDb();
    Index<Node> nodeIndex = neo.getNodeIndex();

    for (RoadLink link : links) {
      Transaction tx = graphDb.beginTx();
      try {

        Node fromNode = nodeIndex.get("id", link.fromNode).getSingle();
        if (fromNode == null) {
          fromNode = graphDb.createNode();
          fromNode.setProperty("id", link.fromNode);
          nodeIndex.add(fromNode, "id", link.fromNode);
        }
        Node toNode = nodeIndex.get("id", link.toNode).getSingle();
        if (toNode == null) {
          toNode = graphDb.createNode();
          toNode.setProperty("id", link.toNode);
          nodeIndex.add(toNode, "id", link.toNode);
        }

        Relationship r = fromNode.createRelationshipTo(toNode, Neo.RelTypes.TO);
        r.setProperty("no", link.no);
        r.setProperty("name", link.name);

        tx.success();
      } finally {
        tx.finish();
      }
    }
    logger.debug("haha, it's ok!");
  }
示例#2
0
 /**
  * Packs a Pdu into the ByteBuffer.
  *
  * @throws java.nio.BufferOverflowException if buff is too small
  * @throws java.nio.ReadOnlyBufferException if buff is read only
  * @see java.nio.ByteBuffer
  * @param buff The ByteBuffer at the position to begin writing
  * @since ??
  */
 public void marshal(java.nio.ByteBuffer buff) {
   super.marshal(buff);
   orginatingEntityID.marshal(buff);
   receivingEntityID.marshal(buff);
   relationship.marshal(buff);
   partLocation.marshal(buff);
   namedLocationID.marshal(buff);
   partEntityType.marshal(buff);
 } // end of marshal method
示例#3
0
  public int getMarshalledSize() {
    int marshalSize = 0;

    marshalSize = super.getMarshalledSize();
    marshalSize = marshalSize + orginatingEntityID.getMarshalledSize(); // orginatingEntityID
    marshalSize = marshalSize + receivingEntityID.getMarshalledSize(); // receivingEntityID
    marshalSize = marshalSize + relationship.getMarshalledSize(); // relationship
    marshalSize = marshalSize + partLocation.getMarshalledSize(); // partLocation
    marshalSize = marshalSize + namedLocationID.getMarshalledSize(); // namedLocationID
    marshalSize = marshalSize + partEntityType.getMarshalledSize(); // partEntityType

    return marshalSize;
  }
示例#4
0
 /**
  * Checks the status of a friendship
  *
  * @param id the user to check friendship status with
  * @return a string representing the status
  */
 public String checkFriendship(Long id) {
   User current = Application.user();
   if (Application.user().id == id) {
     return "";
   }
   Relationship r1 =
       Relationship.find(
               "SELECT r FROM Relationship r where r.from = ?1 AND r.to = ?2", current, this)
           .first();
   Relationship r2 =
       Relationship.find(
               "SELECT r FROM Relationship r where r.to = ?1 AND r.from = ?2", current, this)
           .first();
   if (r1 != null) {
     if (r1.accepted) {
       return "Friends";
     }
     if (r1.requested) {
       return "Friendship Requested";
     }
   }
   return "Request Friendship";
 }
示例#5
0
 public void marshal(DataOutputStream dos) {
   super.marshal(dos);
   try {
     orginatingEntityID.marshal(dos);
     receivingEntityID.marshal(dos);
     relationship.marshal(dos);
     partLocation.marshal(dos);
     namedLocationID.marshal(dos);
     partEntityType.marshal(dos);
   } // end try
   catch (Exception e) {
     System.out.println(e);
   }
 } // end of marshal method
示例#6
0
    private Object toJsonCompatible(Object value) {
      if (value instanceof Node) {
        final Node node = (Node) value;
        final Map<String, Object> result = SubGraph.toMap((PropertyContainer) node);
        result.put("_id", node.getId());

        final List<String> labelNames = SubGraph.getLabelNames(node);
        if (!labelNames.isEmpty()) result.put("_labels", labelNames);
        return result;
      }
      if (value instanceof Relationship) {
        final Relationship relationship = (Relationship) value;
        final Map<String, Object> result = SubGraph.toMap((PropertyContainer) relationship);
        result.put("_id", relationship.getId());
        result.put("_start", relationship.getStartNode().getId());
        result.put("_end", relationship.getEndNode().getId());
        result.put("_type", relationship.getType().name());
        return result;
      }
      if (value instanceof Map) {
        @SuppressWarnings("unchecked")
        Map<String, Object> map = (Map<String, Object>) value;
        final Map<String, Object> result = new LinkedHashMap<>(map.size());
        for (Map.Entry<String, Object> entry : map.entrySet()) {
          result.put(entry.getKey(), toJsonCompatible(entry.getValue()));
        }
        return result;
      }
      if (value instanceof Iterable) {
        final List<Object> result = new ArrayList<>();
        for (Object inner : (Iterable) value) {
          result.add(toJsonCompatible(inner));
        }
        return result;
      }
      return value;
    }
示例#7
0
  @Override
  public boolean equalsImpl(Object obj) {
    boolean ivarsEqual = true;

    if (!(obj instanceof IsPartOfPdu)) return false;

    final IsPartOfPdu rhs = (IsPartOfPdu) obj;

    if (!(orginatingEntityID.equals(rhs.orginatingEntityID))) ivarsEqual = false;
    if (!(receivingEntityID.equals(rhs.receivingEntityID))) ivarsEqual = false;
    if (!(relationship.equals(rhs.relationship))) ivarsEqual = false;
    if (!(partLocation.equals(rhs.partLocation))) ivarsEqual = false;
    if (!(namedLocationID.equals(rhs.namedLocationID))) ivarsEqual = false;
    if (!(partEntityType.equals(rhs.partEntityType))) ivarsEqual = false;

    return ivarsEqual && super.equalsImpl(rhs);
  }
示例#8
0
 /**
  * Get a list of any users who have requested to be friends
  *
  * @return a list of relationships related to incoming friend requests
  */
 public List<Relationship> requestedFriends() {
   return Relationship.find(
           "SELECT r FROM Relationship r where r.to = ? and r.requested = true and r.accepted = false",
           this)
       .fetch();
 }
示例#9
0
 /**
  * Get any confirmed friends
  *
  * @return a list of relationships for confirmed friends
  */
 public List<Relationship> confirmedFriends() {
   return Relationship.find(
           "SELECT r FROM Relationship r where r.from = ? and r.accepted = true", this)
       .fetch();
 }
 @Override
 public void remove(Relationship relationship) {
    removeFromIndexes(relationship);
    relationship.delete();
 }