public static Field toProperty(Expression<?> expr) { try { Path<?> path = (Path<?>) expr; Class<?> rootType = path.getRoot().getType(); String propName = path.getMetadata().getName(); return rootType.getDeclaredField(propName); } catch (NoSuchFieldException e) { return null; } }
/** * @param tablePath the query entity * @param path the path * @return the column object */ private static Column createColumn(RelationalPath<?> tablePath, Path<?> path) { final String columnName = path.getMetadata().getExpression().toString(); final ColumnType columnType = getColumnType(path.getType()); final Field field = ClassUtils.getFieldWithValue(tablePath, path); // settings int columnSize = -1; boolean columnNullable = false; boolean hasDefaultValue = false; String defaultValue = null; if (field != null) { final ColumnSize size = field.getAnnotation(ColumnSize.class); if (size != null) { columnSize = size.value(); } final ColumnAutoIncrement autoInc = field.getAnnotation(ColumnAutoIncrement.class); if (autoInc != null) { return new Column(columnName, columnSize, true); } final ColumnNullable nullable = field.getAnnotation(ColumnNullable.class); if (nullable == null) { columnNullable = false; } else { columnNullable = true; } final ColumnDefault def = field.getAnnotation(ColumnDefault.class); if (def == null && nullable != null) { hasDefaultValue = true; defaultValue = null; } else if (def != null) { hasDefaultValue = true; defaultValue = def.value(); } } if (columnType == ColumnType.ENUM) { @SuppressWarnings("unchecked") Class<? extends Enum<?>> enumClass = (Class<? extends Enum<?>>) path.getType(); Enum<?>[] enums = enumClass.getEnumConstants(); final List<String> enumValues = CollectionFactory.newList(); for (final Enum<?> e : enums) { enumValues.add(e.name()); } return new Column(columnName, columnNullable, enumValues, hasDefaultValue, defaultValue); } return new Column( columnName, columnType, columnNullable, columnSize, hasDefaultValue, defaultValue); }
protected String getKeyForPath(Path<?> expr, PathMetadata<?> metadata) { if (expr.getType().equals(ObjectId.class)) { return "_id"; } else { return metadata.getElement().toString(); } }
/** * Creates the foreign key list * * @param tablePath the table object * @param columns the columns * @return the foreign key list */ private static List<ForeignKey> createFKs( RelationalPath<?> tablePath, Map<String, Column> columns) { final List<ForeignKey> fks = CollectionFactory.newList(); for (final com.mysema.query.sql.ForeignKey<?> fk : tablePath.getForeignKeys()) { StringBuilder name = new StringBuilder(); final List<Column> cols = CollectionFactory.newList(); for (final Path<?> path : fk.getLocalColumns()) { String colName = path.getMetadata().getExpression().toString(); cols.add(columns.get(colName)); name.append(colName).append("-"); } name.setLength(name.length() - 1); fks.add(new ForeignKey(name.toString(), cols)); } return fks; }
@Override public String visit(Path<?> expr, Void context) { PathMetadata<?> metadata = expr.getMetadata(); if (metadata.getParent() != null) { if (metadata.getPathType() == PathType.COLLECTION_ANY) { return visit(metadata.getParent(), context); } else if (metadata.getParent().getMetadata().getPathType() != PathType.VARIABLE) { String rv = getKeyForPath(expr, metadata); return visit(metadata.getParent(), context) + "." + rv; } } return getKeyForPath(expr, metadata); }
@Override public Void visit(Path<?> expr, Stack<String> context) { Path<?> parent = expr.getMetadata().getParent(); if (parent != null) { if (expr.getMetadata().getPathType() == PathType.LISTVALUE_CONSTANT) { context.push(collectionSeparator); parent.accept(this, context); } else { if (!"$Values".equals(expr.getMetadata().getName())) { context.push(propertySeparator); } context.push(StringUtils.capitalize(expr.getMetadata().getName())); parent.accept(this, context); } } return null; }
public QCompanyPK(Path<? extends CompanyPK> entity) { super(entity.getType(), entity.getMetadata()); }
public QDefaultLocale(Path<? extends QDefaultLocale> path) { super(path.getType(), path.getMetadata(), "org.everit.osgi.localization", "loc_default_locale"); addMetadata(); }
@SuppressWarnings("all") public QJpaSoftDeletableAuditable(Path<? extends JpaSoftDeletableAuditable> path) { super((Class) path.getType(), path.getMetadata()); }
public SCalendar(Path<? extends SCalendar> entity) { super(entity.getType(), entity.getMetadata(), "APP", "CALENDAR_"); }
protected StartExpression.StartNodesLookup lookup( Path<?> entity, String indexName, Expression.Identifier key, Expression.Value value) { return StartExpression.lookup(entity.toString(), indexName, key, value); }
protected StartExpression.StartNodes node(Path<?> entity, String parameter) { return StartExpression.node(entity.toString(), parameter); }
public QApplication(Path<? extends Application> entity) { super(entity.getType(), entity.getMetadata()); }
@Override public AnnotatedElement getAnnotatedElement() { return pathMixin.getAnnotatedElement(); }
@Override public int hashCode() { return pathMixin.hashCode(); }
protected OrderByExpression property(Path<?> path, OrderByExpression.Order order) { return OrderByExpression.property(path.toString(), order); }
// Additional QueryDSL methods protected StartExpression.StartNodes node(Path<?> entity, long... id) { return StartExpression.node(entity.toString(), id); }
public QChat(Path<? extends Chat> path) { super(path.getType(), path.getMetadata()); }
protected StartExpression.StartNodesLookup lookup( Path<?> entity, String indexName, Path<?> key, String value) { return StartExpression.lookup( entity.toString(), indexName, key.getMetadata().getExpression().toString(), value); }
public SOrderDELIVEREDITEMINDICES2(Path<? extends SOrderDELIVEREDITEMINDICES2> path) { super(path.getType(), path.getMetadata(), "null", "Order_DELIVEREDITEMINDICES"); }
protected StartExpression.StartNodesQuery query( Path<?> entity, String indexName, Predicate query) { return query(entity.toString(), indexName, query); }
public SNamed(Path<? extends SNamed> entity) { super(entity.getType(), entity.getMetadata(), "APP", "NAMED_"); }
@SuppressWarnings("all") public QPgNamespaceNspnameIndex(Path<? extends QPgNamespaceNspnameIndex> path) { super((Class) path.getType(), path.getMetadata(), "pg_catalog", "pg_namespace_nspname_index"); }
public SOrder(Path<? extends SOrder> entity) { super(entity.getType(), entity.getMetadata(), "APP", "ORDER_"); }
private Path<?> findPathOnParent( Path<?> parent, Class<?> targetType, JoinDescription joinDescription) { while (!targetType.equals(Object.class)) { // TODO more efficient cache key String cacheKey = parent.getClass().getName() + parent.toString() + targetType.getSimpleName() + joinDescription.getOriginalAlias().toString(); Path cached = aliasCache.get(cacheKey); if (cached != null && !cached.equals(nullPath)) { // TODO test // TODO optimize inheritance cases return cached; } List<Path<?>> candidatePaths = new ArrayList<>(); for (Field field : parent.getClass().getFields()) { Object candidate = getField(field, parent); testAliasCandidate(targetType, candidatePaths, candidate); } if (candidatePaths.isEmpty()) { for (Class child : ReflectionUtils.getSubclasses(parent.getType(), entityManager)) { Class<?> real; Constructor<?> constructor; try { real = Class.forName( parent.getClass().getPackage().getName() + ".Q" + child.getSimpleName()); constructor = real.getConstructor(String.class); } catch (Exception e) { throw new RuntimeException(); } Object childInstance; try { childInstance = constructor.newInstance(parent.getMetadata().getElement()); } catch (Exception e) { throw new RuntimeException(); } for (Field field : real.getFields()) { Object candidate = getField(field, childInstance); testAliasCandidate(targetType, candidatePaths, candidate); } } } if (candidatePaths.isEmpty()) { // TODO may be exception? J.unrollChildrenJoins(Collections.singletonList(joinDescription)) .forEach(j -> j.fetch(false)); aliasCache.put(cacheKey, nullPath); targetType = targetType.getSuperclass(); } else if (candidatePaths.size() == 1) { aliasCache.put(cacheKey, candidatePaths.get(0)); return candidatePaths.get(0); } else { // Multiple associations on parent, try find by specified alias String targetFieldName = joinDescription.getOriginalAlias().toString(); for (Path<?> candidatePath : candidatePaths) { if (targetFieldName.equals(candidatePath.getMetadata().getElement())) { aliasCache.put(cacheKey, candidatePath); return candidatePath; } } // TODO add candidates to exception throw new JoinerException( "Join with ambiguous alias : " + joinDescription + ". Multiple mappings found: " + candidatePaths); } } return null; }
/** * Path based constructor * * @param path the path for this entity */ public QPhorumUserNewflags(Path<? extends PhorumUserNewflags> path) { super(path.getType(), path.getMetadata(), "null", "phorum_user_newflags"); }
public QTaskHour(Path<? extends TaskHour> path) { this( path.getType(), path.getMetadata(), path.getMetadata().isRoot() ? INITS : PathInits.DEFAULT); }
@SuppressWarnings("all") public QDbUser(Path<? extends DbUser> path) { super((Class) path.getType(), path.getMetadata(), "null", "db_user"); }
public SStore_customer(Path<? extends SStore_customer> path) { super(path.getType(), path.getMetadata(), "null", "store__customer_"); }
protected OrderByExpression property(Path<?> path) { return OrderByExpression.property(path.toString()); }