@Test public void to_value_not_found() { Session session = mockSession(); Logger logger = mockLogger(); expect(session.get(SampleEntity.class, new Long(12345))).andReturn(null); logger.error("Unable to convert client value '12345' into an entity instance."); replay(); SampleEntity entity = new SampleEntity(); HibernateEntityValueEncoder<SampleEntity> encoder = new HibernateEntityValueEncoder<SampleEntity>( SampleEntity.class, "id", session, access, typeCoercer, logger); assertNull(encoder.toValue("12345")); verify(); }
@Override @SuppressWarnings("unchecked") public E toValue(String clientValue) { if (InternalUtils.isBlank(clientValue)) return null; Object id = null; try { id = typeCoercer.coerce(clientValue, propertyAdapter.getType()); } catch (Exception ex) { throw new RuntimeException(String.format( "Exception converting '%s' to instance of %s (id type for entity %s): %s", clientValue, propertyAdapter.getType().getName(), entityClass.getName(), ExceptionUtils.toMessage(ex)), ex); } Serializable ser = (Serializable) id; E result = (E) session.get(entityClass, ser); if (result == null) { logger.error(String.format("Unable to convert client value '%s' into an entity instance.", clientValue)); } return result; }
HibernateEntityValueEncoder implements ValueEncoder<E> { @Override @SuppressWarnings("unchecked") public E toValue(String clientValue) { if (InternalUtils.isBlank(clientValue)) return null; Object id = null; try { id = typeCoercer.coerce(clientValue, propertyAdapter.getType()); } catch (Exception ex) { throw new RuntimeException(String.format( "Exception converting '%s' to instance of %s (id type for entity %s): %s", clientValue, propertyAdapter.getType().getName(), entityClass.getName(), ExceptionUtils.toMessage(ex)), ex); } Serializable ser = (Serializable) id; E result = (E) session.get(entityClass, ser); if (result == null) { logger.error(String.format("Unable to convert client value '%s' into an entity instance.", clientValue)); } return result; } }
HibernateEntityValueEncoder implements ValueEncoder<E> { @Override @SuppressWarnings("unchecked") public E toValue(String clientValue) { if (InternalUtils.isBlank(clientValue)) return null; Object id = null; try { id = typeCoercer.coerce(clientValue, propertyAdapter.getType()); } catch (Exception ex) { throw new RuntimeException(String.format( "Exception converting '%s' to instance of %s (id type for entity %s): %s", clientValue, propertyAdapter.getType().getName(), entityClass.getName(), ExceptionUtils.toMessage(ex)), ex); } Serializable ser = (Serializable) id; E result = (E) session.get(entityClass, ser); if (result == null) { logger.error(String.format("Unable to convert client value '%s' into an entity instance.", clientValue)); } return result; } HibernateEntityValueEncoder(Class<E> entityClass, String identifierPropertyName, Session session,
                                       PropertyAccess propertyAccess, TypeCoercer typeCoercer, Logger logger); }
HibernateEntityValueEncoder implements ValueEncoder<E> { @Override @SuppressWarnings("unchecked") public E toValue(String clientValue) { if (InternalUtils.isBlank(clientValue)) return null; Object id = null; try { id = typeCoercer.coerce(clientValue, propertyAdapter.getType()); } catch (Exception ex) { throw new RuntimeException(String.format( "Exception converting '%s' to instance of %s (id type for entity %s): %s", clientValue, propertyAdapter.getType().getName(), entityClass.getName(), ExceptionUtils.toMessage(ex)), ex); } Serializable ser = (Serializable) id; E result = (E) session.get(entityClass, ser); if (result == null) { logger.error(String.format("Unable to convert client value '%s' into an entity instance.", clientValue)); } return result; } HibernateEntityValueEncoder(Class<E> entityClass, String identifierPropertyName, Session session,
                                       PropertyAccess propertyAccess, TypeCoercer typeCoercer, Logger logger); @Override String toClient(E value); @Override @SuppressWarnings("unchecked") E toValue(String clientValue); }
HibernateEntityValueEncoder implements ValueEncoder<E> { @Override @SuppressWarnings("unchecked") public E toValue(String clientValue) { if (InternalUtils.isBlank(clientValue)) return null; Object id = null; try { id = typeCoercer.coerce(clientValue, propertyAdapter.getType()); } catch (Exception ex) { throw new RuntimeException(String.format( "Exception converting '%s' to instance of %s (id type for entity %s): %s", clientValue, propertyAdapter.getType().getName(), entityClass.getName(), ExceptionUtils.toMessage(ex)), ex); } Serializable ser = (Serializable) id; E result = (E) session.get(entityClass, ser); if (result == null) { logger.error(String.format("Unable to convert client value '%s' into an entity instance.", clientValue)); } return result; } HibernateEntityValueEncoder(Class<E> entityClass, String identifierPropertyName, Session session,
                                       PropertyAccess propertyAccess, TypeCoercer typeCoercer, Logger logger); @Override String toClient(E value); @Override @SuppressWarnings("unchecked") E toValue(String clientValue);  }