Class AsyncQueryBuilderImpl

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      AsyncQueryBuilder and​(java.lang.String predicate, QueryArg... args)
      Add another condition that must be true of the query results.
      <T> java.util.concurrent.CompletableFuture<T> evaluate​(QueryBuilderImpl.EvaluateArg<T> arg)
      Evaluate the query based on the structure of the provided QueryBuilderImpl.EvaluateArg.
      java.util.concurrent.CompletableFuture<java.lang.String> evaluateLocalFilter​(java.lang.String columnName, TypedVar queryVar)
      Fetches a SQL fragment, which you can embed into the WHERE clause of a SQL query against your database to filter out unauthorized rows (ie.
      java.util.concurrent.CompletableFuture<java.lang.String> evaluateLocalSelect()
      Fetches a complete SQL query that can be run against your database, selecting a single row with a boolean column called result.
      java.util.concurrent.CompletableFuture<java.lang.String> evaluateLocalSelect​(java.util.Map<java.lang.String,​TypedVar> columnNamesToQueryVars)
      Fetches a complete SQL query that can be run against your database, selecting a row for each authorized combination of the query variables in columnNamesToQueryVars (ie.
      AsyncQueryBuilder in​(TypedVar variable, java.util.List<java.lang.String> values)
      Constrain a query variable to be one of a set of values.
      static AsyncQueryBuilderImpl init​(java.util.concurrent.Executor executor, Api api, java.lang.String predicate, QueryArg... args)  
      AsyncQueryBuilder withContextFacts​(java.util.List<Fact> facts)
      Add context facts to the query.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • evaluateLocalSelect

        public java.util.concurrent.CompletableFuture<java.lang.String> evaluateLocalSelect​(java.util.Map<java.lang.String,​TypedVar> columnNamesToQueryVars)
        Description copied from interface: AsyncQueryBuilder
        Fetches a complete SQL query that can be run against your database, selecting a row for each authorized combination of the query variables in columnNamesToQueryVars (ie. combinations of variables that satisfy the Oso query).

        See the Oso documentation for examples and limitations.

        Specified by:
        evaluateLocalSelect in interface AsyncQueryBuilder
        Parameters:
        columnNamesToQueryVars - A mapping of the desired column names to the query variables whose values will be selected into those columns in the returned SQL query.
        Returns:
        Future of SQL query containing the desired columns.
      • evaluateLocalSelect

        public java.util.concurrent.CompletableFuture<java.lang.String> evaluateLocalSelect()
        Description copied from interface: AsyncQueryBuilder
        Fetches a complete SQL query that can be run against your database, selecting a single row with a boolean column called result.

        See the Oso documentation for examples and limitations.

        Specified by:
        evaluateLocalSelect in interface AsyncQueryBuilder
        Returns:
        Future of SQL query containing the result column.
      • evaluateLocalFilter

        public java.util.concurrent.CompletableFuture<java.lang.String> evaluateLocalFilter​(java.lang.String columnName,
                                                                                            TypedVar queryVar)
        Description copied from interface: AsyncQueryBuilder
        Fetches a SQL fragment, which you can embed into the WHERE clause of a SQL query against your database to filter out unauthorized rows (ie. rows that don't satisfy the Oso query).

        See the Oso documentation for examples and limitations.

        Specified by:
        evaluateLocalFilter in interface AsyncQueryBuilder
        Parameters:
        columnName - The name of the SQL column to filter.
        queryVar - The variable corresponding to the column to filter.
        Returns:
        Future of SQL fragment, suitable for embedding in a WHERE clause.
      • and

        public AsyncQueryBuilder and​(java.lang.String predicate,
                                     QueryArg... args)
        Description copied from interface: QueryComposer
        Add another condition that must be true of the query results. For example:
        
         // Query for all the repos on which the user can perform read action,
         // and require the repos to belong to a specific folder
         TypedVar repo = new TypedVar("Repo");
         List<String> authorizedReposInFolder = oso
           .buildQuery("allow", new Value("User", "user123"), new Value("read"), repo)
           .and("has_relation", repo, new Value("folder"), new Value("Folder", "folder456"))
           .evaluate(repo);
         
        Specified by:
        and in interface QueryComposer<AsyncQueryBuilder>
        Parameters:
        predicate - The predicate of the condition
        args - The arguments to the condition
        Returns:
        A new QueryBuilder with the added condition
      • in

        public AsyncQueryBuilder in​(TypedVar variable,
                                    java.util.List<java.lang.String> values)
        Description copied from interface: QueryComposer
        Constrain a query variable to be one of a set of values. For example:
        
         TypedVar repo = new TypedVar("Repo");
         TypedVar action = new TypedVar("String");
         // Get all the actions a user can perform on specific repos
         List<String> authorizedActions = oso
           .buildQuery("allow", new Value("User", "user123"), action, repo)
           .in(repo, Arrays.asList("acme", "anvil"))
           .evaluate(action);
         
        Specified by:
        in in interface QueryComposer<AsyncQueryBuilder>
        Parameters:
        variable - The variable to constrain
        values - The set of allowed values for the constrained variable
        Returns:
        A new QueryBuilder with the added constraint