public static class ImportWorker.QueryHelper
extends java.lang.Object
An instance of this class is constructed for a particular, target DMO.
Any number of typed, named parameters may be added using the addParameter(java.lang.String, java.lang.String, java.lang.String, boolean)
method. Once all named parameters have been added,
getQuery(org.hibernate.Session)
is invoked to build and/or retrieve the resulting
Hibernate query. The underlying HQL query string which is composed is
of the form:
select dmo.id from <dmo_name> dmo where dmo.<parm1> = :parm1 [and dmo.<parm2> = :parm2 ... [and dmo.<parm_n> = :<parm_n>]]
Note that the result of executing the query is the primary key of the
DMO which matches the query's criteria (or null
if no
match is found).
Modifier and Type | Class and Description |
---|---|
(package private) static class |
ImportWorker.QueryHelper.NameType
Simple container which holds a parameter's property name and its
Hibernate type, for purposes of substituting parameter values into
queries at runtime.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
cacheable
Cache query results?
|
private P2JDialect |
dialect
Database dialect in use
|
private java.lang.Class<?> |
dmoClass
Class of the DMO which is to be returned as the query result
|
private java.util.Map<java.lang.String,ImportWorker.QueryHelper.NameType> |
nameTypeMap
Map of query local parameter names to
NameType s |
private org.hibernate.Query |
query
Hibernate query object
|
private org.hibernate.Session |
session
Cached session object
|
private static java.util.Map<java.lang.String,org.hibernate.type.Type> |
TYPES
Mapping of data type names to Hibernate
Type s |
Constructor and Description |
---|
QueryHelper(P2JDialect dialect,
java.lang.Class<?> dmoClass,
boolean cacheable)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addParameter(java.lang.String localName,
java.lang.String foreignName,
java.lang.String type,
boolean ignoreCase)
Add a named parameter to the query and determine its Hibernate
Type . |
(package private) java.lang.Class<?> |
getDMOClass()
Get the class of the DMO implementation instance which is to be
returned from executing this helper's query.
|
java.util.Map<java.lang.String,ImportWorker.QueryHelper.NameType> |
getNameTypeMap()
Get a mapping of all local parameter names parameters for this query
to their foreign property names and Hibernate
Type s. |
org.hibernate.Query |
getQuery(org.hibernate.Session session)
Get the Hibernate query object generated by this query helper,
based upon the DMO name supplied at construction and all the named
parameters supplied via the
addParameter(java.lang.String, java.lang.String, java.lang.String, boolean) method. |
private static final java.util.Map<java.lang.String,org.hibernate.type.Type> TYPES
Type
sprivate java.lang.Class<?> dmoClass
private java.util.Map<java.lang.String,ImportWorker.QueryHelper.NameType> nameTypeMap
NameType
sprivate org.hibernate.Query query
private org.hibernate.Session session
private boolean cacheable
private P2JDialect dialect
public QueryHelper(P2JDialect dialect, java.lang.Class<?> dmoClass, boolean cacheable)
dialect
- Database dialect in use.dmoClass
- Implementation class of the DMO which is to be returned as
the query result.cacheable
- true
to enable query results to be cached;
false
to disable this feature. This is only
useful to enable for many-to-one associations, where a
query is likely to be repeated.public void addParameter(java.lang.String localName, java.lang.String foreignName, java.lang.String type, boolean ignoreCase)
Type
. This will resolve to an equality test in the
the where clause of the HQL query (as in: from MyClass dmo
where dmo.myParam = :myParam
...).localName
- Name of the parameter property in the local class (i.e.,
the near end of the association).foreignName
- Name of the parameter property in the foreign class (i.e.,
the far end of the association). This is often the same
as localName
, but may be different if the
names got out of synch during name conversion from the
Progress schema to the data model representation.type
- Type name for the parameter; typically the unqualified
class name or primitive name of the data type of the
parameter.ignoreCase
- true
to ignore case in the query (applicable to
text properties only); false
for a case
sensitive query.java.lang.IllegalStateException
- if this method is called after the getQuery(org.hibernate.Session)
method is invoked for a particular helper instance. This
is because getQuery
assumes that no more
parameters will be added once a query has been built and
cached.public java.util.Map<java.lang.String,ImportWorker.QueryHelper.NameType> getNameTypeMap()
Type
s.public org.hibernate.Query getQuery(org.hibernate.Session session)
addParameter(java.lang.String, java.lang.String, java.lang.String, boolean)
method. Once this
method is called for a particular helper instance, no more named
parameters may be added, since this method builds and caches the
query the first time it is executed. Thereafter, it simply returns
the cached query, as long as session
matches the
session in use at the time the cached query was created. If
session
is new, the query is rebuilt and recached.session
- Hibernate session object used to create the query.java.lang.Class<?> getDMOClass()