|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.compass.core.CompassTemplate
public class CompassTemplate
Helper class that simplifies the Compass access code using the template design pattern.
The central method is "execute", supporting Compass code implementing the CompassCallback interface. It provides Compass Session handling such that neither the CompassCallback implementation nor the calling code needs to explicitly care about retrieving/closing Compass Sessions, handling Session lifecycle exceptions, or managing transactions. The template code is similar to
CompassSession session = compass.openSession(); CompassTransaction tx = null; try { tx = session.beginTransaction(); Object result = compassCallback.doInCompass(session); tx.commit(); return result; } catch (RuntimeException e) { if (tx != null) { tx.rollback(); } throw e; } finally { session.close(); }
The template must have a Compass reference set, either using the tempalte constructor or using the set method.
CompassTemplate also provides the same operations available when working with CompassSession, just that they are executed using the "execute" template method, which means that they enjoy it's session lifecycle and transaction support.
Constructor Summary | |
---|---|
CompassTemplate()
Creates a new CompassTemplate instance (remember to set Compass using the setCompass method). |
|
CompassTemplate(Compass compass)
Creates a new CompassTemplate instance, already initialized with a Compass instance. |
Method Summary | ||
---|---|---|
void |
create(Object obj)
Creates a NEW object in Compass. |
|
void |
create(String alias,
Object obj)
Creates a NEW object in Compass that shares mapping alais with multiple objects. |
|
void |
delete(Class clazz,
Object... ids)
Deletes an object from Compass that match the mapping specified for the defined class based on its ids. |
|
void |
delete(Class clazz,
Object obj)
Deletes an object from Compass that match the mapping specified for the defined class. |
|
void |
delete(CompassQuery query)
Deletes all entries in the index that match the given query. |
|
void |
delete(Object obj)
Deletes an object from Compass. |
|
void |
delete(Resource resource)
Deletes a resource with the specified alias. |
|
void |
delete(String alias,
Object... ids)
Deletes an object from Compass with multiple alias's based on its ids. |
|
void |
delete(String alias,
Object obj)
Deletes an object from Compass with multiple alias's. |
|
void |
evict(Object obj)
Evicts the given object from the first level cache (transaction scoped cache). |
|
void |
evict(Resource resource)
Evicts the given resource from the first level cache (transaction scoped cache). |
|
void |
evict(String alias,
Object id)
Evicts the given object from the first level cache (transaction scoped cache). |
|
void |
evictAll()
Evicts all the objects and the resources from the first level cache. |
|
|
execute(CompassCallback<T> action)
Executes the compass callback within a session and a transaction context. |
|
|
execute(CompassTransaction.TransactionIsolation transactionIsolation,
CompassCallback<T> action)
Executes the compass callback within a session and a transaction context. |
|
CompassHitsOperations |
executeFind(CompassCallback<CompassHitsOperations> action)
A helper execute method for find operations. |
|
|
executeLocal(CompassCallback<T> action)
Executes the compass callback within a session and a local transaction context. |
|
CompassHits |
find(String query)
Finds a list of objects that match the specified query. |
|
CompassDetachedHits |
findWithDetach(String query)
|
|
CompassDetachedHits |
findWithDetach(String query,
int from,
int size)
|
|
|
get(Class<T> clazz,
Object... ids)
Returns an object that match the mapping specified for the defined class, and matches the specified ids. |
|
|
get(Class<T> clazz,
Object id)
Returns an object that match the mapping specified for the defined class, and matches the specified id. |
|
Object |
get(String alias,
Object... ids)
Returns an object that match the mapping specified for the defined alias, and matches the specified ids. |
|
Object |
get(String alias,
Object id)
Returns an object that match the mapping specified for the defined alias, and matches the specified id. |
|
Compass |
getCompass()
Returns the compass instance used by the template. |
|
Resource |
getResource(Class clazz,
Object... ids)
Returns a Resource that match the mapping specified for the defined class type, and specified ids. |
|
Resource |
getResource(Class clazz,
Object id)
Returns a Resource that match the mapping specified for the defined class type, and specified id. |
|
Resource |
getResource(String alias,
Object... ids)
Returns a Resource that match the mapping specified for the defined alias (possibley different object types), and matches the specified ids. |
|
Resource |
getResource(String alias,
Object id)
Returns a Resource that match the mapping specified for the defined alias (possibley different object types), and matches the specified id. |
|
CompassSettings |
getSettings()
|
|
|
load(Class<T> clazz,
Object... ids)
Loads and returns an object that match the mapping specified for the defined class, and matches the specified ids. |
|
|
load(Class<T> clazz,
Object id)
Loads and returns an object that match the mapping specified for the defined class, and matches the specified id. |
|
Object |
load(String alias,
Object... ids)
Loads and returns an object that match the mapping specified for the defined class, and matches the specified ids. |
|
Object |
load(String alias,
Object id)
Loads and returns an object that match the mapping specified for the defined class, and matches the specified id. |
|
Resource |
loadResource(Class clazz,
Object... ids)
Loads and returns a Resource that match the mapping specified for the defined class, and matches the specified ids. |
|
Resource |
loadResource(Class clazz,
Object id)
Loads and returns a Resource that match the mapping specified for the defined class, and matches the specified id. |
|
Resource |
loadResource(String alias,
Object... ids)
Loads and returns a Resource that match the mapping specified for the defined alias, and matches the specified ids. |
|
Resource |
loadResource(String alias,
Object id)
Loads and returns a Resource that match the mapping specified for the defined alias, and matches the specified id. |
|
void |
save(Object obj)
Saves an object in Compass. |
|
void |
save(String alias,
Object obj)
Saves an object in Compass that shares mapping alais with multiple objects. |
|
void |
setCompass(Compass compass)
Sets the compass instance that will be used by the template. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CompassTemplate()
public CompassTemplate(Compass compass)
Method Detail |
---|
public void setCompass(Compass compass)
public Compass getCompass()
public <T> T execute(CompassCallback<T> action) throws CompassException
action
- The action to execute witin a compass transaction
CompassException
public <T> T execute(CompassTransaction.TransactionIsolation transactionIsolation, CompassCallback<T> action) throws CompassException
transactionIsolation
- The transaction isolationaction
- The action to execute witin a compass transaction
CompassException
public <T> T executeLocal(CompassCallback<T> action) throws CompassException
action
- The action to execute witin a compass transaction
CompassException
public CompassHitsOperations executeFind(CompassCallback<CompassHitsOperations> action) throws CompassException
action
- the callback to execute.
CompassException
public CompassSettings getSettings()
public void create(Object obj) throws CompassException
CompassOperations
create
in interface CompassOperations
obj
- The object to save.
CompassException
public void create(String alias, Object obj) throws CompassException
CompassOperations
create
in interface CompassOperations
alias
- The alias that match the object mappingsobj
- The object to save
CompassException
public void delete(Object obj) throws CompassException
CompassOperations
delete
in interface CompassOperations
obj
- The object to delete
CompassException
public void delete(Resource resource) throws CompassException
CompassOperations
delete
in interface CompassOperations
resource
- The resource to be deleted.
CompassException
public void delete(Class clazz, Object obj) throws CompassException
CompassOperations
delete
in interface CompassOperations
clazz
- The class that represtents the required mappingobj
- The object to delete
CompassException
public void delete(String alias, Object obj) throws CompassException
CompassOperations
delete
in interface CompassOperations
alias
- The alias that the objects maps underobj
- The object to delete
CompassException
public void delete(CompassQuery query) throws CompassException
CompassOperations
delete
in interface CompassOperations
query
- The query to delete by
CompassException
public CompassHits find(String query) throws CompassException
CompassOperations
Several examples are:
Note that the list may contains several object types (classes) with no relation between them (except for the semantic relation).
find
in interface CompassOperations
query
- The query string to search by
CompassException
public CompassDetachedHits findWithDetach(String query) throws CompassException
CompassException
public CompassDetachedHits findWithDetach(String query, int from, int size) throws CompassException
CompassException
public <T> T get(Class<T> clazz, Object id) throws CompassException
CompassOperations
null
if the object is not found.
get
in interface CompassOperations
clazz
- The class that represents the required mappingid
- The id that identifies the resource
null
if not found
CompassException
public Object get(String alias, Object id) throws CompassException
CompassOperations
null
if the object is not found.
get
in interface CompassOperations
alias
- The alias that represents the required mappingid
- The id that identifies the resource
null
if not found
CompassException
public Resource getResource(Class clazz, Object id) throws CompassException
CompassOperations
null
if the object is not found.
getResource
in interface CompassOperations
clazz
- The class that represents the required mappingid
- The id that identifies the resource
null
if not found
CompassException
public Resource getResource(String alias, Object id) throws CompassException
CompassOperations
null
if the
object is not found.
getResource
in interface CompassOperations
alias
- The alias that represents the required mappingid
- The id that identifies the resource
CompassException
public <T> T load(Class<T> clazz, Object... ids) throws CompassException
CompassOperations
load
in interface CompassOperations
clazz
- The class that represents the required mappingids
- The ids that identifies the resource
CompassException
public <T> T load(Class<T> clazz, Object id) throws CompassException
CompassOperations
load
in interface CompassOperations
clazz
- The class that represents the required mappingid
- The id that identifies the resource
CompassException
public Object load(String alias, Object... ids) throws CompassException
CompassOperations
load
in interface CompassOperations
alias
- The alias that represents the required mappingids
- The ids that identifies the resource
CompassException
public Object load(String alias, Object id) throws CompassException
CompassOperations
load
in interface CompassOperations
alias
- The alias that represents the required mappingid
- The id that identifies the resource
CompassException
public Resource loadResource(Class clazz, Object id) throws CompassException
CompassOperations
loadResource
in interface CompassOperations
clazz
- The class that represents the required mappingid
- The id that identifies the resource
CompassException
public Resource loadResource(String alias, Object id) throws CompassException
CompassOperations
loadResource
in interface CompassOperations
alias
- The alias that represents the required mappingid
- The id that identifies the resource
CompassException
public void save(Object obj) throws CompassException
CompassOperations
save
in interface CompassOperations
obj
- The object to save.
CompassException
public void save(String alias, Object obj) throws CompassException
CompassOperations
save
in interface CompassOperations
alias
- The alias that match the object mappingsobj
- The object to save
CompassException
public void evict(Object obj)
CompassOperations
evict
in interface CompassOperations
obj
- The objects to evict.public void evict(String alias, Object id)
CompassOperations
evict
in interface CompassOperations
alias
- The alias of the object/entry to evict.id
- The id of the object/entry to evict.public void evict(Resource resource)
CompassOperations
evict
in interface CompassOperations
resource
- The resource to evict.public void evictAll()
CompassOperations
evictAll
in interface CompassOperations
public Resource getResource(Class clazz, Object... ids) throws CompassException
CompassOperations
getResource
in interface CompassOperations
clazz
- The class that represents the required mappingids
- The ids that identifies the resource
null
if not found
CompassException
public Resource getResource(String alias, Object... ids) throws CompassException
CompassOperations
null
if the object is not found.
getResource
in interface CompassOperations
alias
- The alias that represents the required mappingids
- The ids that identifies the resource
CompassException
public Resource loadResource(Class clazz, Object... ids) throws CompassException
CompassOperations
loadResource
in interface CompassOperations
clazz
- The class that represents the required mappingids
- The ids that identifies the resource
CompassException
public Resource loadResource(String alias, Object... ids) throws CompassException
CompassOperations
loadResource
in interface CompassOperations
alias
- The alias that represents the required mappingids
- The ids that identifies the resource
CompassException
public void delete(String alias, Object... ids) throws CompassException
CompassOperations
delete
in interface CompassOperations
alias
- The alias that the objects maps underids
- The ids of the object to delete
CompassException
public void delete(Class clazz, Object... ids) throws CompassException
CompassOperations
delete
in interface CompassOperations
clazz
- The class that represtents the required mappingids
- The object ids to delete
CompassException
public <T> T get(Class<T> clazz, Object... ids) throws CompassException
CompassOperations
null
if the object
is not found.
get
in interface CompassOperations
clazz
- The class that represents the required mappingids
- The ids that identifies the resource
null
if not found
CompassException
public Object get(String alias, Object... ids) throws CompassException
CompassOperations
null
if the object is
not found.
get
in interface CompassOperations
alias
- The alias that represents the required mappingids
- The ids that identifies the resource
null
if not found
CompassException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |