|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trendmicro.grid.acl.ds.jpa.util.JpaUtils
public class JpaUtils
A small set of common helper methods used to simplify working with JPA.
Nested Class Summary | |
---|---|
static interface |
JpaUtils.Callback<E,V>
Defines a callback to use for converting types. |
Field Summary | |
---|---|
static boolean |
EMPTY_METADATA_EQUALS_NULL
Toggles whether EMPTY metadata and 'NULL' are treated equal. |
static JpaUtils.Callback |
SINGLE_ELEMENT_CALLBACK
Straight converter callback that simply passed single or array input to a single output. |
Method Summary | ||
---|---|---|
static
|
appendSingleElementToList(Collection<T> result,
javax.persistence.TypedQuery<? extends T> query)
Appends exactly one element to the given result list (using 'null' if the query produces no results). |
|
static
|
applyPage(Q query,
int pageNumber,
int pageSize)
Applies page number and size to the query. |
|
static com.trendmicro.grid.acl.metadata.Metadata |
deserializeMetadata(Source rawData)
Deserizalizes the given XML serialized metadata. |
|
static com.trendmicro.grid.acl.metadata.Metadata |
deserializeMetadata(String rawData)
Deserizalizes the given XML serialized metadata. |
|
static String[] |
deserializeTags(String tags)
Deserizalizes the given serialized tags. |
|
static String |
extractName(String name,
int delimiterCount)
Extracts a name part of a hierarchic package, family or vendor name. |
|
static UUID |
fromBytes(byte[] publicGUID)
Decodes a UUID from its byte representation. |
|
static Boolean |
isTaggedWith(com.trendmicro.grid.acl.l0.datatypes.Tagged element,
String[] tags)
Returns true if the element is tagged with the given tags. |
|
static boolean |
metadataDiffers(com.trendmicro.grid.acl.l0.datatypes.MetadataOwner a,
com.trendmicro.grid.acl.l0.datatypes.MetadataOwner b)
Returns true if the 2 metadata owning instances differ. |
|
static String |
serializeMetadata(com.trendmicro.grid.acl.metadata.Metadata metadata)
Serializes the given metadata to XML. |
|
static String |
serializeTags(String[] tags)
Serializes the given tag array to text. |
|
static boolean |
tagsDiffer(com.trendmicro.grid.acl.l0.datatypes.Tagged a,
com.trendmicro.grid.acl.l0.datatypes.Tagged b)
Returns true if the 2 tagged instances differ. |
|
static byte[] |
toBytes(UUID guid)
Encodes a UUID to its byte representation. |
|
static
|
toListPage(javax.persistence.Query query,
JpaUtils.Callback<V,E> converterCallback,
T emptyListPage)
Converts the given query to a list page using converterCallback to convert results. |
|
static
|
toListPage(javax.persistence.TypedQuery<E> query,
T emptyListPage)
Converts the given query to a list page. |
|
static
|
toListPage(javax.persistence.TypedQuery<V> query,
JpaUtils.Callback<V,E> converterCallback,
T emptyListPage)
Converts the given query to a list page using converterCallback to convert results. |
|
static com.trendmicro.grid.acl.l0.datatypes.NameListPage |
toNameListPage(javax.persistence.Query query,
int pageNumber,
int pageSize)
Converts the given query to a name list page. |
|
static com.trendmicro.grid.acl.l0.datatypes.NameListPage |
toNameListPage(javax.persistence.TypedQuery<String> query,
int pageNumber,
int pageSize)
Converts the given query to a name list page. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final boolean EMPTY_METADATA_EQUALS_NULL
public static final JpaUtils.Callback SINGLE_ELEMENT_CALLBACK
Method Detail |
---|
public static byte[] toBytes(UUID guid)
guid
- the UUID to convert.
public static UUID fromBytes(byte[] publicGUID)
publicGUID
- the UUID to convert.
public static String serializeTags(String[] tags)
tags
- the tags to encode.
public static String[] deserializeTags(String tags)
tags
- the text encoded tags.
public static String serializeMetadata(com.trendmicro.grid.acl.metadata.Metadata metadata)
metadata
- the metadata to encode.
public static com.trendmicro.grid.acl.metadata.Metadata deserializeMetadata(String rawData)
rawData
- the XML encoded metadata.
public static com.trendmicro.grid.acl.metadata.Metadata deserializeMetadata(Source rawData)
rawData
- the XML encoded metadata.
public static boolean metadataDiffers(com.trendmicro.grid.acl.l0.datatypes.MetadataOwner a, com.trendmicro.grid.acl.l0.datatypes.MetadataOwner b)
a
- the first instance to check.b
- the second instance to check.
public static boolean tagsDiffer(com.trendmicro.grid.acl.l0.datatypes.Tagged a, com.trendmicro.grid.acl.l0.datatypes.Tagged b)
a
- the first instance to check.b
- the second instance to check.
public static Boolean isTaggedWith(com.trendmicro.grid.acl.l0.datatypes.Tagged element, String[] tags)
element
- the element to check.tags
- the tags to verify.
public static String extractName(String name, int delimiterCount)
name
- the name to work on.delimiterCount
- the count of delimiters to include (e.g. 1 => vendorName, 2 => familyName, ...).
public static <T> void appendSingleElementToList(Collection<T> result, javax.persistence.TypedQuery<? extends T> query)
result
- the result list to add the element of the given query or 'null'
if the query produced no results.query
- the query that fetches the element to add to the result.
javax.persistence.NonUniqueResultException
- In case of the query produced more than one result.public static <Q extends javax.persistence.Query> Q applyPage(Q query, int pageNumber, int pageSize)
query
- the query to apply the limits on.pageNumber
- the number of the page to query.pageSize
- the size of a single page.
public static <E,T extends com.trendmicro.grid.acl.l0.datatypes.AbstractListPage<E>> T toListPage(javax.persistence.TypedQuery<E> query, T emptyListPage)
query
- the query to convert.emptyListPage
- the list page template instance to use.
public static <E,V,T extends com.trendmicro.grid.acl.l0.datatypes.AbstractListPage<E>> T toListPage(javax.persistence.TypedQuery<V> query, JpaUtils.Callback<V,E> converterCallback, T emptyListPage)
query
- the query to convert.converterCallback
- a converter used to convert the query results to the type needed
within the list page.emptyListPage
- the list page template instance to use.
public static <E,V,T extends com.trendmicro.grid.acl.l0.datatypes.AbstractListPage<E>> T toListPage(javax.persistence.Query query, JpaUtils.Callback<V,E> converterCallback, T emptyListPage)
query
- the query to convert.converterCallback
- a converter used to convert the query results to the type needed
within the list page.emptyListPage
- the list page template instance to use.
public static com.trendmicro.grid.acl.l0.datatypes.NameListPage toNameListPage(javax.persistence.Query query, int pageNumber, int pageSize)
query
- the query to convert.pageNumber
- the number of the page to extract.pageSize
- the size of the page to return.
public static com.trendmicro.grid.acl.l0.datatypes.NameListPage toNameListPage(javax.persistence.TypedQuery<String> query, int pageNumber, int pageSize)
query
- the query to convert.pageNumber
- the number of the page to extract.pageSize
- the size of the page to return.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |