@SuppressWarnings("rawtypes") public Object convert(Class destClass, Object srcObj) { // Boolean to Int not supported in apache common's int converter and this is why this class is req'd if (Boolean.class.isAssignableFrom(srcObj.getClass())) { boolean value = (Boolean)srcObj; return value ? (long)1 : (long)0; } else if (MappingUtils.isEnumType(srcObj.getClass())) { return ((Integer)((Enum)srcObj).ordinal()).longValue(); } else { return commonsConverter.convert(destClass, srcObj); } } }
public Object convert(Class destClass, Object srcObj) { // Boolean to Int not supported in apache common's int converter and // this is why this class is req'd if (Boolean.class.isAssignableFrom(srcObj.getClass())) { boolean value = (Boolean) srcObj; return (value ? (long) 1 : (long) 0); } else { return commonsConverter.convert(destClass, srcObj); } }
@SuppressWarnings("rawtypes") public Object convert(Class destClass, Object srcObj) { // Boolean to Int not supported in apache common's int converter and this is why this class is req'd if (Boolean.class.isAssignableFrom(srcObj.getClass())) { boolean value = (Boolean) srcObj; return (value ? (long) 1 : (long) 0); } else if (MappingUtils.isEnumType(srcObj.getClass())) { return ((Integer) ((Enum) srcObj).ordinal()).longValue(); } else { return commonsConverter.convert(destClass, srcObj); } }
@SuppressWarnings("rawtypes") public Object convert(Class destClass, Object srcObj) { // Boolean to Int not supported in apache common's int converter and this is why this class is req'd if (Boolean.class.isAssignableFrom(srcObj.getClass())) { boolean value = (Boolean)srcObj; return value ? (long)1 : (long)0; } else if (MappingUtils.isEnumType(srcObj.getClass())) { return ((Integer)((Enum)srcObj).ordinal()).longValue(); } else { return commonsConverter.convert(destClass, srcObj); } } }
@Override public Long handle(Entity entity, Configuration entityConfiguration) { String sequence = entityConfiguration.getString(SEQUENCE_NAME); if (StringUtils.isBlank(sequence)) { SeedException.createNew(IdentityErrorCodes.NO_SEQUENCE_NAME_FOUND_FOR_ENTITY) .put("entityClass", entity.getClass()).thenThrows(); } Object id = entityManager.createNativeQuery("SELECT " + sequence + ".NEXTVAL FROM DUAL").getSingleResult(); Long convertedId; try { LongConverter converter = new LongConverter(); convertedId = (Long) converter.convert(Long.class, id); } catch (ConversionException e) { throw SeedException.wrap(e, IdentityErrorCodes.ID_CAST_EXCEPTION).put("object", id) .put("objectType", id.getClass()).put("entity", entity.getClass().getSimpleName()); } return convertedId; }