|
![]() |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsf.qof.QueryObjectFactory
public final class QueryObjectFactory
Used to create query object implementations from definition interfaces or classes. It only provides static methods and can not be instantiated.
Definition interfaces or classes define abstract methods that are decorated with annotations to specify the SQL query and mappings to primitive types or Java beans.
public class Person { int id; String name; public int getId() { return id; } public void setId(int id) { this.id = id; } ... } public interface PersonQueries extends BaseQuery { @Query(sql = "select id {%%.id}, name {%%.name} from person where id = {%1}") Person getPerson(int id); ... } Connection connection = ... // get the database connection from somewhere PersonQueries personQueries = QueryObjectFactory.createQueryObject(PersonQueries.class); personQueries.setConnection(connection); Person person = personQueries.getPerson(123);
Generated query object classes implement BaseQuery
to set the
connection etc.
Generated query object classes are cached for each ClassLoader. The generation process is thread safe i.e. if two threads are trying to create the same query object implementation one will wait till the generation of the class completes and then just instantiate an object while the other thread is generating the class.
The generation process can be customized by using a Customizer
BaseQuery
,
Query
,
Insert
,
Update
,
Delete
,
Call
Method Summary | ||
---|---|---|
static
|
createQueryObject(Class<T> queryDefinitionClass)
Creates a query object class defined by a query definition and returns a new instance. |
|
static
|
createQueryObject(Class<T> queryDefinitionClass,
Object... parameters)
Creates a query object class defined by a query definition and returns a new instance. |
|
static
|
createQueryObjectFromSuperClass(Class<T> queryDefinitionClass,
Class<S> superClass)
Creates a query object class defined by a query definition and a super class and returns a new instance. |
|
static
|
createQueryObjectFromSuperClass(Class<T> queryDefinitionClass,
Class<S> superClass,
Object... parameters)
Creates a query object class defined by a query definition and a super class and returns a new instance. |
|
static void |
registerMapper(String type,
MappingAdapter adapter)
Register a custom mapping adapter in the mapping registry. |
|
static void |
setCustomizer(Customizer cust)
Sets the Customizer for the code generation. |
|
static void |
setDefaultCustomizer()
Resets the Customizer for the code generation to the default customizer. |
|
static void |
setSQLDialect(SQLDialect dialect)
Sets the SQL dialect. |
|
static void |
unregisterMapper(String type)
Unregister a custom mapping adapter from the mapping registry. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <T> T createQueryObject(Class<T> queryDefinitionClass)
If the query definition is a class then the generated query object class will be a subclass of this class. The query definition class can be abstract or concrete but is not allowed to be final. All constructors of the query definition class will be implemented by the query object class but only the default constructor will be used to instantiate the query object.
If the query definition is an interface then the superclass will be Object
.
queryDefinitionClass
- query definition class or interface
queryDefinitionClass
createQueryObject(Class, Object...)
,
createQueryObjectFromSuperClass(Class, Class)
,
createQueryObjectFromSuperClass(Class, Class, Object...)
public static <T> T createQueryObject(Class<T> queryDefinitionClass, Object... parameters)
The generated query object class is a subclass of query definition class. The
query definition class can be abstract or concrete but is not allowed to be final.
All constructors of the query definition class will be implemented by the query object
class and parameters
will be used to find a matching constructor to instantiate
the query object with these parameters. The matching process works on the type of
the parameters and will match the first constructor that matches all parameter type.
A single null
parameter should be passed to a constructor as:
new Class[] {null}
.
queryDefinitionClass
- query definition classparameters
- parameters to be used in the constructor
queryDefinitionClass
createQueryObject(Class)
,
createQueryObjectFromSuperClass(Class, Class)
,
createQueryObjectFromSuperClass(Class, Class, Object...)
public static <T,S> T createQueryObjectFromSuperClass(Class<T> queryDefinitionClass, Class<S> superClass)
The generated query object class will be a subclass of superClass
which can be abstract or concrete but is not allowed to be final.
All constructors of superClass
will be implemented by the query object
class but only the default constructor will be used to instantiate the query object.
queryDefinitionClass
must be an interface.
queryDefinitionClass
- query definition interfacesuperClass
- the class the query object class will inherit from
queryDefinitionClass
createQueryObject(Class)
,
createQueryObject(Class, Object...)
,
createQueryObjectFromSuperClass(Class, Class, Object...)
public static <T,S> T createQueryObjectFromSuperClass(Class<T> queryDefinitionClass, Class<S> superClass, Object... parameters)
The generated query object class will be a subclass of superClass
which can be abstract or concrete but is not allowed to be final.
All constructors of superClass
will be implemented by the query object class
and parameters
will be used to find a matching constructor to instantiate
the query object with these parameters. The matching process works on the type of
the parameters and will match the first constructor that matches all parameter type.
A single null
parameter should be passed to a constructor as:
new Class[] {null}
.
queryDefinitionClass
must be an interface.
queryDefinitionClass
- query definition interfacesuperClass
- the class the query object class will inherit fromparameters
- parameters to be used in the constructor
queryDefinitionClass
createQueryObject(Class)
,
createQueryObject(Class, Object...)
,
createQueryObjectFromSuperClass(Class, Class)
public static void setCustomizer(Customizer cust)
Customizer
for the code generation.
cust
- a customizerCustomizer
public static void setDefaultCustomizer()
Customizer
for the code generation to the default customizer.
Customizer
,
DefaultCustomizer
public static void registerMapper(String type, MappingAdapter adapter)
This method can be used to register custom mapping adapters.
type
- mapping type nameadapter
- mapping adapterGeneratorMappingAdapter
,
DynamicMappingAdapter
,
MappingAdapter
public static void unregisterMapper(String type)
type
- mapping type namepublic static void setSQLDialect(SQLDialect dialect)
dialect
- SQL dialectSQLDialect
|
![]() |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |