EntityDictionary { 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(); } EntityDictionary(Map<String, Class<? extends Check>> checks);  EntityDictionary(Map<String, Class<? extends Check>> checks, Injector injector);  EntityDictionary(Map<String, Class<? extends Check>> checks,
                            Injector injector,
                            Function<Class, Serde> serdeLookup); static String getSimpleName(Class<?> cls); static Method findMethod(Class<?> entityClass, String name, Class<?>... paramClass); boolean isMappedInterface(Class<?> interfaceClass); boolean isIdGenerated(Class<?> entityClass); Class<?> getEntityClass(String entityName); String getJsonAliasFor(Class<?> entityClass); String getEntityFor(Class<?> entityClass); boolean entityHasChecksForPermission(Class<?> resourceClass, Class<? extends Annotation> annotationClass); ParseTree getPermissionsForClass(Class<?> resourceClass, Class<? extends Annotation> annotationClass); ParseTree getPermissionsForField(Class<?> resourceClass,
            String field,
            Class<? extends Annotation> annotationClass); Class<? extends Check> getCheck(String checkIdentifier); List<String> getSubclassingEntityNames(String entityName); List<String> getSubclassingEntityNames(Class entityClass); List<Class<?>> getSubclassingEntities(String entityName); List<Class<?>> getSubclassingEntities(Class entityClass); List<String> getSuperClassEntityNames(String entityName); List<String> getSuperClassEntityNames(Class entityClass); List<Class<?>> getSuperClassEntities(String entityName); List<Class<?>> getSuperClassEntities(Class entityClass); String getCheckIdentifier(Class<? extends Check> checkClass); String getIdFieldName(Class<?> entityClass); AccessType getAccessType(Class<?> entityClass); Set<Class<?>> getBindings(); Map<String, Class<? extends Check>> getCheckMappings(); List<String> getAttributes(Class<?> entityClass); Injector getInjector(); List<String> getAttributes(Object entity); List<String> getRelationships(Class<?> entityClass); List<String> getRelationships(Object entity); List<String> getElideBoundRelationships(Class<?> entityClass); List<String> getElideBoundRelationships(Object entity); boolean isMethodRequestScopeable(Object entity, Method method); boolean isMethodRequestScopeable(Class<?> entityClass, Method method); List<String> getAllFields(Class<?> entityClass); List<String> getAllFields(Object entity); RelationshipType getRelationshipType(Class<?> cls, String relation); String getRelationInverse(Class<?> cls, String relation); RelationshipType getRelationshipType(Object entity, String relation); Class<?> getType(Class<?> entityClass, String identifier); Class<?> getType(Object entity, String identifier); Class<?> getParameterizedType(Class<?> entityClass, String identifier); Class<?> getParameterizedType(Class<?> entityClass, String identifier, int paramIndex); Class<?> getParameterizedType(Object entity, String identifier); Class<?> getParameterizedType(Object entity, String identifier, int paramIndex); String getNameFromAlias(Class<?> entityClass, String alias); String getNameFromAlias(Object entity, String alias); void initializeEntity(T entity); void bindInitializer(Initializer<T> initializer, Class<T> cls); boolean isShareable(Class<?> entityClass); void bindEntity(Class<?> cls); A getAnnotation(PersistentResource record, Class<A> annotationClass); A getAnnotation(Class<?> recordClass, Class<A> annotationClass); A getMethodAnnotation(Class<?> recordClass, String method, Class<A> annotationClass); Collection<LifeCycleHook> getTriggers(Class<?> cls,
                                                                        Class<A> annotationClass,
                                                                        String fieldName); Collection<LifeCycleHook> getTriggers(Class<?> cls,
                                                                        Class<A> annotationClass); A getAttributeOrRelationAnnotation(Class<?> entityClass,
                                                                     Class<A> annotationClass,
                                                                     String identifier); A[] getAttributeOrRelationAnnotations(Class<?> entityClass,
                                                                        Class<A> annotationClass,
                                                                        String identifier); static Annotation getFirstAnnotation(Class<?> entityClass,
                                                List<Class<? extends Annotation>> annotationClassList); boolean isRoot(Class<?> entityClass); String getId(Object value); Class<?> getIdType(Class<?> entityClass); Collection<Annotation> getIdAnnotations(Object value); Class<?> lookupEntityClass(Class<?> objClass); Class<?> lookupIncludeClass(Class<?> objClass); Class<?> lookupAnnotationDeclarationClass(Class<?> objClass, Class<? extends Annotation> annotationClass); Class<?> lookupBoundClass(Class<?> objClass); AccessibleObject getAccessibleObject(Object target, String fieldName); boolean isComputed(Class<?> entityClass, String fieldName); AccessibleObject getAccessibleObject(Class<?> targetClass, String fieldName); Set<String> getFieldsOfType(Class<?> targetClass, Class<?> targetType); boolean isRelation(Class<?> entityClass, String relationName); boolean isAttribute(Class<?> entityClass, String attributeName); void scanForSecurityChecks(); void bindTrigger(Class<?> entityClass,
                            Class<? extends Annotation> annotationClass,
                            String fieldOrMethodName,
                            LifeCycleHook callback); void bindTrigger(Class<?> entityClass,
                            Class<? extends Annotation> annotationClass,
                            LifeCycleHook callback,
                            boolean allowMultipleInvocations); void bindTrigger(Class<?> entityClass,
                            Class<? extends Annotation> annotationClass,
                            LifeCycleHook callback); boolean cascadeDeletes(Class<?> targetClass, String fieldName); List<T> walkEntityGraph(Set<Class<?>> entities,  Function<Class<?>, T> transform); boolean hasBinding(Class<?> cls); Object getValue(Object target, String fieldName, RequestScope scope); void setValue(Object target, String fieldName, Object value); Object coerce(Object target, Object value, String fieldName, Class<?> fieldClass); final static String REGULAR_ID_NAME; }
@Test public void testGetIdAnnotations() throws Exception { Collection<Class> expectedAnnotationClasses = Arrays.asList(new Class[] { Id.class, GeneratedValue.class }); Collection<Class> actualAnnotationsClasses = getIdAnnotations(new Parent()).stream() .map(Annotation::annotationType) .collect(Collectors.toList()); assertEquals(actualAnnotationsClasses, expectedAnnotationClasses, "getIdAnnotations returns annotations on the ID field of the given class"); }
@Test public void testGetIdAnnotationsNoId() throws Exception { Collection<Annotation> expectedAnnotation = Collections.emptyList(); Collection<Annotation> actualAnnotations = getIdAnnotations(new NoId()); assertEquals(actualAnnotations, expectedAnnotation, "getIdAnnotations returns an empty collection if there is no ID field for given class"); }
@Test public void testGetIdAnnotationsSubClass() throws Exception { Collection<Class> expectedAnnotationClasses = Arrays.asList(new Class[] { Id.class, GeneratedValue.class }); Collection<Class> actualAnnotationsClasses = getIdAnnotations(new Friend()).stream() .map(Annotation::annotationType) .collect(Collectors.toList()); assertEquals(actualAnnotationsClasses, expectedAnnotationClasses, "getIdAnnotations returns annotations on the ID field when defined in a super class"); }