Пример #1
0
 @Override
 @Transactional
 public <T> T find(String uuid) {
   KeyValueBinaryVO bvo = dbf.getEntityManager().find(KeyValueBinaryVO.class, uuid);
   try {
     return SerializableHelper.readObject(bvo.getContents());
   } catch (Exception e) {
     throw new CloudRuntimeException(e);
   }
 }
Пример #2
0
  @Override
  @Transactional
  public void persist(KeyValueEntity entity) {
    KeyValueBinaryVO bvo = new KeyValueBinaryVO();
    bvo.setUuid(entity.getUuid());
    try {
      bvo.setContents(SerializableHelper.writeObject(entity));
    } catch (IOException e) {
      throw new CloudRuntimeException(e);
    }
    dbf.getEntityManager().persist(bvo);

    List<KeyValueStruct> structs = new KeyValueSerializer().build(entity);
    for (KeyValueStruct struct : structs) {
      KeyValueVO vo = new KeyValueVO();
      vo.setClassName(entity.getClass().getName());
      vo.setUuid(entity.getUuid());
      vo.setEntityKey(struct.getKey());
      vo.setEntityValue(struct.getValue());
      vo.setValueType(struct.getType().getName());
      dbf.getEntityManager().persist(vo);
    }
  }