Пример #1
0
 @SuppressWarnings("unchecked")
 private static <T extends Writable> T restore(T writable) {
   try {
     return read((T) writable.getClass().newInstance(), write(writable));
   } catch (Exception e) {
     throw new AssertionError(e);
   }
 }
 /**
  * Puts at the specified URI the specified new state of the resource.
  *
  * @param <T> the type of the resource's state.
  * @param uri the URI at which the resource is.
  * @param newResourceState the new state of the resource.
  * @return
  */
 public <T> T putAt(String uri, T newResourceState) {
   Class<T> c = (Class<T>) newResourceState.getClass();
   return resource()
       .path(uri)
       .header(HTTP_SESSIONKEY, getSessionKey())
       .accept(MediaType.APPLICATION_JSON)
       .type(MediaType.APPLICATION_JSON)
       .put(c, newResourceState);
 }
 public <T> T serialize(T o) {
   String jsonString = jsonStreamMapper.write(o);
   System.out.println(jsonString);
   return (T) jsonStreamMapper.readString(jsonString, o.getClass());
 }
 private <T> String tableName(T entity) {
   final Table table = entity.getClass().getAnnotation(Table.class);
   return table == null ? entity.getClass().getSimpleName() : table.value();
 }
 @SuppressWarnings("unchecked")
 protected <T extends Entity> T findEntity(T entity) {
   Select selection = select().all().from(tableName(entity));
   selection.where(eq("id", entity.getId()));
   return (T) template.selectOne(selection, entity.getClass());
 }