/** * Gets id. * * @param value the value * @return the id */ public String getId(Object value) { if (value == null) { return null; } try { AccessibleObject idField = null; for (Class<?> cls = value.getClass(); idField == null && cls != null; cls = cls.getSuperclass()) { idField = getEntityBinding(cls).getIdField(); } if (idField instanceof Field) { return String.valueOf(((Field) idField).get(value)); } if (idField instanceof Method) { return String.valueOf(((Method) idField).invoke(value, (Object[]) null)); } return null; } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) { return null; } }
/** * Returns annotations applied to the ID field. * * @param value the value * @return Collection of Annotations */ public Collection<Annotation> getIdAnnotations(Object value) { if (value == null) { return null; } AccessibleObject idField = getEntityBinding(value.getClass()).getIdField(); if (idField != null) { return Arrays.asList(idField.getDeclaredAnnotations()); } return Collections.emptyList(); }
/** * Returns annotations applied to the ID field. * * @param value the value * @return Collection of Annotations */ public Collection<Annotation> getIdAnnotations(Object value) { if (value == null) { return null; } AccessibleObject idField = getEntityBinding(value.getClass()).getIdField(); if (idField != null) { return Arrays.asList(idField.getDeclaredAnnotations()); } return Collections.emptyList(); }
/** * Gets id. * * @param value the value * @return the id */ public String getId(Object value) { if (value == null) { return null; } try { AccessibleObject idField = null; for (Class<?> cls = value.getClass(); idField == null && cls != null; cls = cls.getSuperclass()) { idField = getEntityBinding(cls).getIdField(); } if (idField instanceof Field) { return String.valueOf(((Field) idField).get(value)); } if (idField instanceof Method) { return String.valueOf(((Method) idField).invoke(value, (Object[]) null)); } return null; } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) { return null; } }