use of com.querydsl.core.QueryException in project querydsl by querydsl.
the class CollQuerySerializer method visit.
@Override
public Void visit(Path<?> path, Void context) {
final PathType pathType = path.getMetadata().getPathType();
if (pathType == PathType.PROPERTY) {
final Path<?> parent = path.getMetadata().getParent();
final String property = path.getMetadata().getName();
final Class<?> parentType = parent.getType();
try {
// getter
Method m = getAccessor(parentType, property);
if (m != null && Modifier.isPublic(m.getModifiers())) {
handle(parent);
append(".").append(m.getName()).append("()");
} else {
// field
Field f = getField(parentType, property);
if (f != null && Modifier.isPublic(f.getModifiers())) {
handle(parent);
append(".").append(property);
} else {
// field access by reflection
append(CollQueryFunctions.class.getName() + ".<");
append((path.getType()).getName()).append(">get(");
handle(parent);
append(", \"" + property + "\")");
}
}
} catch (Exception e) {
throw new QueryException(e);
}
} else if (pathType == PathType.DELEGATE) {
append("(");
append("(").append(path.getType().getName()).append(")");
path.getMetadata().getParent().accept(this, context);
append(")");
} else {
List<Object> args = new ArrayList<Object>(2);
if (path.getMetadata().getParent() != null) {
args.add(path.getMetadata().getParent());
}
args.add(path.getMetadata().getElement());
final Template template = getTemplate(pathType);
for (Template.Element element : template.getElements()) {
Object rv = element.convert(args);
if (rv instanceof Expression) {
((Expression<?>) rv).accept(this, context);
} else if (element.isString()) {
append(rv.toString());
} else {
visitConstant(rv);
}
}
}
return null;
}
use of com.querydsl.core.QueryException 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.core.QueryException 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 = Maps.newLinkedHashMap();
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);
}
}
use of com.querydsl.core.QueryException in project querydsl by querydsl.
the class JavaSE7SQLExceptionWrapper method wrap.
@Override
public RuntimeException wrap(String message, SQLException exception) {
QueryException rv = new QueryException(message, exception);
SQLException linkedException = exception.getNextException();
while (linkedException != null) {
rv.addSuppressed(linkedException);
linkedException = linkedException.getNextException();
}
return rv;
}
use of com.querydsl.core.QueryException in project querydsl by querydsl.
the class AbstractDomainExporter method execute.
/**
* Export the contents
*
* @throws IOException
*/
public void execute() throws IOException {
// collect types
try {
collectTypes();
} catch (Exception e) {
throw new QueryException(e);
}
// go through supertypes
Set<Supertype> additions = Sets.newHashSet();
for (Map.Entry<Class<?>, EntityType> entry : allTypes.entrySet()) {
EntityType entityType = entry.getValue();
if (entityType.getSuperType() != null && !allTypes.containsKey(entityType.getSuperType().getType().getJavaClass())) {
additions.add(entityType.getSuperType());
}
}
for (Supertype type : additions) {
type.setEntityType(createEntityType(type.getType(), this.superTypes));
}
// merge supertype fields into subtypes
Set<EntityType> handled = new HashSet<EntityType>();
for (EntityType type : superTypes.values()) {
addSupertypeFields(type, allTypes, handled);
}
for (EntityType type : entityTypes.values()) {
addSupertypeFields(type, allTypes, handled);
}
for (EntityType type : embeddableTypes.values()) {
addSupertypeFields(type, allTypes, handled);
}
// serialize them
serialize(superTypes, supertypeSerializer);
serialize(embeddableTypes, embeddableSerializer);
serialize(entityTypes, entitySerializer);
}
Aggregations