Пример #1
0
 @Override
 @SuppressWarnings("unchecked")
 public Map<String, Object> extractEntityTuple(Session session, EntityKey key) {
   MongoDBDatastoreProvider provider = MongoDBTestHelper.getProvider(session.getSessionFactory());
   DBObject finder = new BasicDBObject(MongoDBDialect.ID_FIELDNAME, key.getColumnValues()[0]);
   DBObject result = provider.getDatabase().getCollection(key.getTable()).findOne(finder);
   replaceIdentifierColumnName(result, key);
   return result.toMap();
 }
  @Test
  public void shouldSerializeAndDeserializeEntityKey() throws Exception {
    String[] columnNames = {"foo", "bar", "baz"};
    EntityKeyMetadata keyMetadata = new DefaultEntityKeyMetadata("Foobar", columnNames);
    Object[] values = {123, "Hello", 456L};

    // given
    EntityKey key = new EntityKey(keyMetadata, values);

    // when
    byte[] bytes = externalizerHelper.marshall(key);
    EntityKey unmarshalledKey = externalizerHelper.unmarshall(bytes);

    // then
    assertThat(unmarshalledKey.getTable()).isEqualTo(key.getTable());
    assertThat(unmarshalledKey.getColumnNames()).isEqualTo(key.getColumnNames());
    assertThat(unmarshalledKey.getColumnValues()).isEqualTo(key.getColumnValues());

    assertTrue(key.equals(unmarshalledKey));
    assertTrue(unmarshalledKey.equals(key));
    assertThat(unmarshalledKey.hashCode()).isEqualTo(key.hashCode());
  }