Ejemplo n.º 1
0
 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;
   }
 }
Ejemplo n.º 2
0
  /**
   * @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);
  }
Ejemplo n.º 3
0
 protected String getKeyForPath(Path<?> expr, PathMetadata<?> metadata) {
   if (expr.getType().equals(ObjectId.class)) {
     return "_id";
   } else {
     return metadata.getElement().toString();
   }
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }
Ejemplo n.º 5
0
 @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);
 }
Ejemplo n.º 6
0
    @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;
    }
Ejemplo n.º 7
0
 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());
 }
Ejemplo n.º 10
0
 public SCalendar(Path<? extends SCalendar> entity) {
   super(entity.getType(), entity.getMetadata(), "APP", "CALENDAR_");
 }
Ejemplo n.º 11
0
 protected StartExpression.StartNodesLookup lookup(
     Path<?> entity, String indexName, Expression.Identifier key, Expression.Value value) {
   return StartExpression.lookup(entity.toString(), indexName, key, value);
 }
Ejemplo n.º 12
0
 protected StartExpression.StartNodes node(Path<?> entity, String parameter) {
   return StartExpression.node(entity.toString(), parameter);
 }
Ejemplo n.º 13
0
 public QApplication(Path<? extends Application> entity) {
   super(entity.getType(), entity.getMetadata());
 }
Ejemplo n.º 14
0
 @Override
 public AnnotatedElement getAnnotatedElement() {
   return pathMixin.getAnnotatedElement();
 }
Ejemplo n.º 15
0
 @Override
 public int hashCode() {
   return pathMixin.hashCode();
 }
Ejemplo n.º 16
0
 protected OrderByExpression property(Path<?> path, OrderByExpression.Order order) {
   return OrderByExpression.property(path.toString(), order);
 }
Ejemplo n.º 17
0
 // Additional QueryDSL methods
 protected StartExpression.StartNodes node(Path<?> entity, long... id) {
   return StartExpression.node(entity.toString(), id);
 }
Ejemplo n.º 18
0
 public QChat(Path<? extends Chat> path) {
   super(path.getType(), path.getMetadata());
 }
Ejemplo n.º 19
0
 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");
 }
Ejemplo n.º 21
0
 protected StartExpression.StartNodesQuery query(
     Path<?> entity, String indexName, Predicate query) {
   return query(entity.toString(), indexName, query);
 }
Ejemplo n.º 22
0
 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");
 }
Ejemplo n.º 24
0
 public SOrder(Path<? extends SOrder> entity) {
   super(entity.getType(), entity.getMetadata(), "APP", "ORDER_");
 }
Ejemplo n.º 25
0
  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;
  }
Ejemplo n.º 26
0
 /**
  * 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");
 }
Ejemplo n.º 27
0
 public QTaskHour(Path<? extends TaskHour> path) {
   this(
       path.getType(),
       path.getMetadata(),
       path.getMetadata().isRoot() ? INITS : PathInits.DEFAULT);
 }
Ejemplo n.º 28
0
 @SuppressWarnings("all")
 public QDbUser(Path<? extends DbUser> path) {
   super((Class) path.getType(), path.getMetadata(), "null", "db_user");
 }
Ejemplo n.º 29
0
 public SStore_customer(Path<? extends SStore_customer> path) {
   super(path.getType(), path.getMetadata(), "null", "store__customer_");
 }
Ejemplo n.º 30
0
 protected OrderByExpression property(Path<?> path) {
   return OrderByExpression.property(path.toString());
 }