Example #1
0
 /**
  * @clonedesc com.servoy.j2db.querybuilder.IQueryBuilderJoins#add(String, int, String)
  * @sampleas add(String, int)
  * @param dataSource data source
  * @param joinType join type, one of {@link IQueryBuilderJoin#LEFT_OUTER_JOIN}, {@link
  *     IQueryBuilderJoin#INNER_JOIN}, {@link IQueryBuilderJoin#RIGHT_OUTER_JOIN}, {@link
  *     IQueryBuilderJoin#FULL_JOIN}
  * @param alias the alias for joining table
  */
 @JSFunction
 public QBJoin add(String dataSource, int joinType, String alias) throws RepositoryException {
   String name;
   QBJoin join;
   if (alias == null) {
     name = UUID.randomUUID().toString();
     join = null;
   } else {
     name = alias;
     join = joins.get(name);
   }
   if (join == null) {
     Table foreignTable = root.getTable(dataSource);
     join =
         addJoin(
             new QueryJoin(
                 name,
                 parent.getQueryTable(),
                 new QueryTable(
                     foreignTable.getSQLName(),
                     foreignTable.getDataSource(),
                     foreignTable.getCatalog(),
                     foreignTable.getSchema(),
                     alias),
                 new AndCondition(),
                 joinType),
             dataSource,
             name);
   }
   return join;
 }
Example #2
0
  private QBJoin getOrAddRelation(IRelation relation, String relationName, String alias) {
    if (relation == null || !parent.getDataSource().equals(relation.getPrimaryDataSource())) {
      if (relation == null) {
        Debug.log("relation '" + relationName + "' not found");
      } else {
        Debug.log(
            "relation '"
                + relationName
                + "' does not match parent data source: "
                + parent.getDataSource()
                + '/'
                + relation.getPrimaryDataSource());
      }
      return null;
    }

    String name = alias == null ? relationName : alias;
    QBJoin join = joins.get(name);
    if (join == null) {
      try {
        Table foreignTable = root.getTable(relation.getForeignDataSource());
        if (foreignTable == null) {
          Debug.log("foreign table for relation '" + relationName + "' not found");
          return null;
        }
        join =
            addJoin(
                SQLGenerator.createJoin(
                    root.getDataProviderHandler(),
                    relation,
                    parent.getQueryTable(),
                    new QueryTable(
                        foreignTable.getSQLName(),
                        foreignTable.getDataSource(),
                        foreignTable.getCatalog(),
                        foreignTable.getSchema(),
                        alias),
                    root.getGlobalScopeProvider()),
                relation.getForeignDataSource(),
                name);
      } catch (RepositoryException e) {
        Debug.error("could not load relation '" + relationName + "'", e);
      }
    }
    return join;
  }