private <A extends Annotation, P> Optional<A> findAnnotation(FieldDescriptorImpl<BEAN, P> classField, Class<A> annotationType) { return ReflectionUtils.findAnnotation(mainClazz, classField.getField().getAccessor(), classField.getGetter().getAccessor(), classField.getSetter().getAccessor(), annotationType); }
public <P> void addClassField(final FieldDescriptorImpl<BEAN, P> classField) { this.fieldClassMapByJavaName.put(classField.getFieldName(), classField); if (classField.getVersionInfo().isVersionable()) { if (this.versionGenerator) { throw new JpoWrongAnnotationException("A bean can have maximum one field annotated with @" + Version.class.getSimpleName() //$NON-NLS-1$ + ". Error in class:[" + this.getMappedClass() + "] field: [" + classField.getFieldName() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } this.versionGenerator = true; } }
private void initializeClassFields(final ClassDescriptorImpl<BEAN> classMap) { final List<Method> methods = Arrays.asList(this.mainClazz.getMethods()); final List<Field> fields = ReflectionUtils.getAllInheritedFields(this.mainClazz); for (final Field field : fields) { if (!ReflectionUtils.isStatic(field) && !ignoredFieldNames.contains(field.getName())) { final FieldDescriptorImpl<BEAN, ?> classField = this.buildClassField(classMap, field, methods, field.getType()); if (!classField.isIgnored()) { classMap.addClassField(classField); } } } }
private <P> void setColumnInfo(FieldDescriptorImpl<BEAN, P> classField) { classField.setColumnInfo(new InferedColumnName(classField.getFieldName())); findAnnotation(classField, Column.class) .ifPresent(column -> { classField.setColumnInfo(new AnnotationColumnInfo(column.name())); }); }
allColumnJavaNamesList.add(javaFieldName); if (entry.getValue().isIdentifier()) { primaryKeyColumnJavaNamesList.add(javaFieldName); primaryKeyAndVersionColumnJavaNamesList.add(javaFieldName); if (entry.getValue().getGeneratorInfo().isValid()) { if (!hasGenerator) { allGeneratedColumnJavaNamesList.add(javaFieldName); allGeneratedColumnDBNamesList.add(entry.getValue().getColumnInfo().getDBColumnName()); this.logger.debug("Field [" + javaFieldName + "] is an autogenerated field"); //$NON-NLS-1$ //$NON-NLS-2$ hasGenerator = true; if (entry.getValue().getVersionInfo().isVersionable()) { this.logger.debug("Field [" + javaFieldName + "] is an version field"); //$NON-NLS-1$ //$NON-NLS-2$ primaryKeyAndVersionColumnJavaNamesList.add(javaFieldName);
private <P> FieldDescriptorImpl<BEAN, P> buildClassField(final ClassDescriptorImpl<BEAN> classMap, final Field field, final List<Method> methods, final Class<P> fieldClass) { final Class<?> realClass = field.getType(); Class<P> processedClass = (Class<P>) field.getType(); // In future this should be more generic. Not required at the moment if (isOptional(realClass)) { processedClass = getGenericClass(field.getGenericType()); } final FieldDescriptorImpl<BEAN, P> classField = new FieldDescriptorImpl<>(field.getName(), processedClass, buildPropertyFieldWrapper(field), getGetter(field, methods), getSetter(field, methods, classMap.getMappedClass()) ); setIgnored(classField); setColumnInfo(classField); setIdentifier(classField); setGeneratorInfo(classField); setVersionInfo(classField); setJsonInfo(classField); this.logger.debug("DB column [" + classField.getColumnInfo().getDBColumnName() + "]" + " will be associated with object field [" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + classField.getFieldName() + "]"); //$NON-NLS-1$ return classField; }
private String getDbColumn(final String alias, final String field) { String dbColumn = registeredClass.get(alias).getFieldDescriptorByJavaName(field).getColumnInfo().getDBColumnName(); if (dbColumn.isEmpty()) { throw new JpoWrongPropertyNameException("Field with name [" + field + "] is not present or ignored for alias [" + alias + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } return dbColumn; }