Class QueryModel<T>

java.lang.Object
org.apache.juneau.commons.beanquery.QueryModel<T>
Type Parameters:
T - The bean type.

public final class QueryModel<T> extends Object
The query view of a bean class: its readable properties (query columns), its writable properties, and how to create an instance.

Built from Juneau's BeanMeta, so it follows the same bean rules as serializers and parsers:

Dynamic ("*") properties are excluded. A class that isn't a bean (for example, one with no properties) yields an empty model rather than an error.
Example:

QueryModel<Person> model = QueryModel.of(Person.class); for (QueryProperty p : model.getReadableProperties().values()) System.out.println(p.getName() + " " + p.getSearchType()); // Same rules as a serializer configured with a dashed-lower-case namer. BeanConfigContext config = BeanConfigContext.create().propertyNamer(PropertyNamerDLC.INSTANCE).build(); QueryModel<Person> dashed = QueryModel.of(Person.class, config);

Since:
10.0.0
  • Method Details

    • of

      public static <T> QueryModel<T> of(Class<T> beanClass)
      Builds a model with BeanConfigContext.DEFAULT.
      Type Parameters:
      T - The bean type.
      Parameters:
      beanClass - The bean class. Must not be null.
      Returns:
      A new model.
    • of

      public static <T> QueryModel<T> of(Class<T> beanClass, BeanConfigContext config)
      Builds a model with the given bean configuration.
      Type Parameters:
      T - The bean type.
      Parameters:
      beanClass - The bean class. Must not be null.
      config - The bean configuration. Must not be null.
      Returns:
      A new model.
    • of

      public static <T> QueryModel<T> of(BeanMeta<T> beanMeta)
      Builds a model from existing bean metadata.
      Type Parameters:
      T - The bean type.
      Parameters:
      beanMeta - The bean metadata. Must not be null.
      Returns:
      A new model.
    • getBeanClass

      public Class<T> getBeanClass()
      Returns the bean class.
      Returns:
      The bean class. Never null.
    • getReadableProperties

      Returns the readable properties (the query columns), keyed by name, in bean property order. Write-only properties are excluded.
      Returns:
      An unmodifiable map. Never null.
    • getReadableProperty

      Returns a readable property. Write-only properties are excluded.
      Parameters:
      name - The property name.
      Returns:
      The property, or null if there is no readable property with that name.
    • getWritableProperties

      Returns the writable properties (setter or non-final field), keyed by name, in bean property order. Read-only properties are excluded.

      Record components are not listed here; they are set through the constructor (see getConstructorArgs()).

      Returns:
      An unmodifiable map. Never null.
    • getConstructorArgs

      Returns the names of the properties passed to the constructor, in parameter order.

      Non-empty for records (canonical constructor) and @BeanCtor classes; empty for no-arg beans.

      Returns:
      An unmodifiable list. Never null.
    • getConstructorArgTypes

      Returns the constructor parameter types, parallel to getConstructorArgs().
      Returns:
      An unmodifiable list. Never null.
    • newInstance

      public T newInstance(Object... args)
      Creates an instance.

      Non-static inner classes are not supported (they need an outer instance); the model reports no usable constructor for them.

      Parameters:
      args - The constructor arguments, parallel to getConstructorArgs() (none for a no-arg bean). A null for a primitive parameter becomes that primitive's default. To pass a single null argument, pass (Object)null.
      Returns:
      A new instance. Never null.
      Throws:
      IllegalArgumentException - If the args array is null, or the argument count doesn't match getConstructorArgs().
      IllegalStateException - If the class has no usable constructor.
      BeanQueryExecutionException - If the constructor throws, or the arguments can't be passed to it (for example, a wrong type). The cause is the constructor's own exception, or the reflection error.