Package com.linkedin.restli.common

Examples of com.linkedin.restli.common.CompoundKey


  }

  @Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestAssociationsSubBuilderDataProvider")
  public void testGetWithAssociationKey(RootBuilderWrapper<CompoundKey, Message> builders) throws Exception
  {
    CompoundKey key = new CompoundKey();
    key.append("src", key1());
    key.append("dest", key2());

    Request<Message> request = builders.get().id(key).build();
    Message response = REST_CLIENT.sendRequest(request).get().getEntity();
    Assert.assertNotNull(response);
    Assert.assertEquals(response.getId(), key.getPart("src") + " " + key.getPart("dest"), "Message should be key1 + ' ' + key2 for associationKey(key1,key2)");
  }
View Full Code Here


  public static int purge(AlbumEntryDatabase db, Long albumId, Long photoId)
  {
    // purge 1 entry
    if (albumId != null && photoId != null)
    {
      CompoundKey key = new CompoundKey().append("photoId", photoId).append("albumId", albumId);
      final boolean isRemoved = (db.getData().remove(key) != null);
      return isRemoved ? 1 : 0;
    }

    // purge all
    if (albumId == null && photoId == null)
    {
      final int numPurged = db.getData().size();
      db.getData().clear();
      return numPurged;
    }

    // purge all matching one of key id, photo id
    Iterator<CompoundKey> it = db.getData().keySet().iterator();
    String partName;
    long compareId;
    if (albumId != null)
    {
      partName = "albumId";
      compareId = albumId;
    }
    else if (photoId != null)
    {
      partName = "photoId";
      compareId = photoId;
    }
    else
      throw new AssertionError();

    int numPurged = 0;
    while (it.hasNext())
    {
      CompoundKey key = it.next();
      if (key.getPart(partName).equals(compareId))
      {
        it.remove();
        numPurged++;
      }
    }
View Full Code Here

                                 @Optional @QueryParam("photoId") Long photoId)
  {
    List<AlbumEntry> result = new ArrayList<AlbumEntry>();
    for (Map.Entry<CompoundKey, AlbumEntry> entry : _db.getData().entrySet())
    {
      CompoundKey key = entry.getKey();
      // if the id is null, don't do any filtering by that id
      // (treat all values as a match)
      if (albumId != null && !key.getPart("albumId").equals(albumId))
        continue;
      if (photoId != null && !key.getPart("photoId").equals(photoId))
        continue;
      result.add(entry.getValue());
    }
    return result;
  }
View Full Code Here

    for (int i = 0; i < numInitEntries; ++i)
    {
      final long photoId = randPhotoId + i;
      final long albumId = 7;

      final CompoundKey key = new CompoundKey();
      key.append("photoId", photoId);
      key.append("albumId", albumId);
      final AlbumEntry entry = new AlbumEntry();
      entry.setPhotoId(photoId);
      entry.setAlbumId(albumId);
      entry.setAddTime(r.nextInt(Integer.MAX_VALUE));
      _data.put(key, entry);
View Full Code Here

            },
            {
                associationResourceParams,
                new Key("myComplexKeyAssociationId", CompoundKey.class, null),
                "myComplexKeyAssociationId",
                new CompoundKey().append("string1", "apples").append("string2", "oranges")
            }
        };
  }
View Full Code Here

    Assert.assertEquals(response.getErrors(), errorResponses);
  }

  private CompoundKey buildCompoundKey(String part1, int part2)
  {
    return new CompoundKey().append("part1", part1).append("part2", part2);
  }
View Full Code Here

  }

  @Test
  public void testCompoundKey()
  {
    CompoundKey c1 = buildCompoundKey("c1", 1);
    CompoundKey c2 = buildCompoundKey("c2", 2);
    CompoundKey c3 = buildCompoundKey("c3", 3);

    Map<CompoundKey, Greeting> recordTemplates = new HashMap<CompoundKey, Greeting>();
    recordTemplates.put(c1, buildGreeting(1L));
    recordTemplates.put(c2, buildGreeting(2L));
View Full Code Here

  public Map<Integer, GroupMembership> batchGetByGroup(int groupID, Set<Integer> memberIDs)
  {
    Map<Integer, GroupMembership> result = new HashMap<Integer, GroupMembership>();
    for (Map.Entry<CompoundKey, GroupMembership> entry : _data.entrySet())
    {
      CompoundKey key = entry.getKey();
      if(key.getPartAsInt(GROUP_ID) == groupID &&
         memberIDs.contains(key.getPartAsInt(MEMBER_ID)))
      {
        result.put(key.getPartAsInt(MEMBER_ID), entry.getValue());
      }
    }
    return result;
  }
View Full Code Here

  public Map<Integer, GroupMembership> batchGetByMember(int memberID, Set<Integer> groupIDs)
  {
    Map<Integer, GroupMembership> result = new HashMap<Integer, GroupMembership>();
    for (Map.Entry<CompoundKey, GroupMembership> entry : _data.entrySet())
    {
      CompoundKey key = entry.getKey();
      if(key.getPartAsInt(MEMBER_ID) == memberID &&
              groupIDs.contains(key.getPartAsInt(GROUP_ID)))
      {
        result.put(key.getPartAsInt(GROUP_ID), entry.getValue());
      }
    }
    return result;
  }
View Full Code Here

    return result;
  }

  private static CompoundKey buildKey(int groupID, int memberID)
  {
    return new CompoundKey().append(GROUP_ID, groupID).append(MEMBER_ID, memberID);
  }
View Full Code Here

TOP

Related Classes of com.linkedin.restli.common.CompoundKey

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.