@Override public ClassDescriptor<BEAN> build() { this.logger.debug("generate " + ClassDescriptor.class.getSimpleName() + " for Class " + this.mainClazz.getName()); //$NON-NLS-1$ //$NON-NLS-2$ final TableInfo tableInfo = TableInfoFactory.getTableInfo(this.mainClazz); this.logger.debug("Table name expected in relation with class " + this.mainClazz.getSimpleName() + ": " + tableInfo.getTableName() + " - schema: " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + tableInfo.getSchemaName()); final ClassDescriptorImpl<BEAN> classMap = new ClassDescriptorImpl<>(this.mainClazz, tableInfo); this.initializeClassFields(classMap); this.initializeColumnNames(classMap); return classMap; }
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); } } } }
for (final Entry<String, FieldDescriptorImpl<BEAN, ?>> entry : classMap.getUnmodifiableFieldClassMap().entrySet()) { classMap.setAllColumnJavaNames(allColumnJavaNamesList.toArray(new String[0])); classMap.setAllNotGeneratedColumnJavaNames(allNotGeneratedColumnJavaNamesList.toArray(new String[0])); classMap.setAllGeneratedColumnJavaNames(allGeneratedColumnJavaNamesList.toArray(new String[0])); classMap.setAllGeneratedColumnDBNames(allGeneratedColumnDBNamesList.toArray(new String[0])); classMap.setNotPrimaryKeyColumnJavaNames(notPrimaryKeyColumnJavaList.toArray(new String[0])); classMap.setPrimaryKeyColumnJavaNames(primaryKeyColumnJavaNamesList.toArray(new String[0])); classMap.setPrimaryKeyAndVersionColumnJavaNames(primaryKeyAndVersionColumnJavaNamesList.toArray(new String[0]));
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 <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; }