use of com.querydsl.sql.RelationalPath in project querydsl by querydsl.
the class AnnotationMapper method createMap.
@Override
public Map<Path<?>, Object> createMap(RelationalPath<?> path, Object object) {
try {
Map<String, Path<?>> columnToPath = new HashMap<String, Path<?>>();
for (Path<?> column : path.getColumns()) {
columnToPath.put(ColumnMetadata.getName(column), column);
}
Map<Path<?>, Object> values = new HashMap<Path<?>, Object>();
for (Field field : ReflectionUtils.getFields(object.getClass())) {
Column ann = field.getAnnotation(Column.class);
if (ann != null) {
field.setAccessible(true);
Object propertyValue = field.get(object);
if (propertyValue != null) {
if (columnToPath.containsKey(ann.value())) {
values.put(columnToPath.get(ann.value()), propertyValue);
}
} else if (withNullBindings) {
values.put(columnToPath.get(ann.value()), Null.DEFAULT);
}
}
}
return values;
} catch (IllegalAccessException e) {
throw new QueryException(e);
}
}
use of com.querydsl.sql.RelationalPath in project querydsl by querydsl.
the class DefaultMapper method createMap.
@Override
public Map<Path<?>, Object> createMap(RelationalPath<?> entity, Object bean) {
try {
Map<Path<?>, Object> values = new LinkedHashMap<>();
Class<?> beanClass = bean.getClass();
Map<String, Path<?>> columns = getColumns(entity);
// populate in column order
for (Map.Entry<String, Path<?>> entry : columns.entrySet()) {
Path<?> path = entry.getValue();
Field beanField = ReflectionUtils.getFieldOrNull(beanClass, entry.getKey());
if (beanField != null && !Modifier.isStatic(beanField.getModifiers())) {
beanField.setAccessible(true);
Object propertyValue = beanField.get(bean);
if (propertyValue != null) {
values.put(path, propertyValue);
} else if (withNullBindings && !isPrimaryKeyColumn(entity, path)) {
values.put(path, Null.DEFAULT);
}
}
}
return values;
} catch (IllegalAccessException e) {
throw new QueryException(e);
}
}
Aggregations