| java.lang.Object org.compass.core.CompassTemplate
CompassTemplate | public class CompassTemplate implements CompassOperations(Code) | | 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.
author: kimchy |
Constructor Summary | |
public | CompassTemplate() Creates a new CompassTemplate instance (remember to set Compass using the
setCompass method). | public | CompassTemplate(Compass compass) Creates a new CompassTemplate instance, already initialized with a
Compass instance. |
Method Summary | |
public void | create(Object obj) | public void | create(String alias, Object obj) | public void | delete(Object obj) | public void | delete(Resource resource) | public void | delete(Class clazz, Object obj) | public void | delete(String alias, Object obj) | public void | delete(CompassQuery query) | public void | delete(String alias, Object... ids) | public void | delete(Class clazz, Object... ids) | public void | evict(Object obj) | public void | evict(String alias, Object id) | public void | evict(Resource resource) | public void | evictAll() | public T | execute(CompassCallback<T> action) Executes the compass callback within a session and a transaction context. | public T | execute(TransactionIsolation transactionIsolation, CompassCallback<T> action) Executes the compass callback within a session and a transaction context. | public CompassHitsOperations | executeFind(CompassCallback<CompassHitsOperations> action) A helper execute method for find operations.
Parameters: action - the callback to execute. | public T | executeLocal(CompassCallback<T> action) Executes the compass callback within a session and a local transaction context. | public CompassHits | find(String query) | public CompassDetachedHits | findWithDetach(String query) | public CompassDetachedHits | findWithDetach(String query, int from, int size) | public T | get(Class<T> clazz, Object id) | public Object | get(String alias, Object id) | public T | get(Class<T> clazz, Object... ids) | public Object | get(String alias, Object... ids) | public Compass | getCompass() Returns the compass instance used by the template. | public Resource | getResource(Class clazz, Object id) | public Resource | getResource(String alias, Object id) | public Resource | getResource(Class clazz, Object... ids) | public Resource | getResource(String alias, Object... ids) | public CompassSettings | getSettings() | public T | load(Class<T> clazz, Object... ids) | public T | load(Class<T> clazz, Object id) | public Object | load(String alias, Object... ids) | public Object | load(String alias, Object id) | public Resource | loadResource(Class clazz, Object id) | public Resource | loadResource(String alias, Object id) | public Resource | loadResource(Class clazz, Object... ids) | public Resource | loadResource(String alias, Object... ids) | public void | save(Object obj) | public void | save(String alias, Object obj) | public void | saveResource(Resource resource) | public void | setCompass(Compass compass) Sets the compass instance that will be used by the template. |
CompassTemplate | public CompassTemplate()(Code) | | Creates a new CompassTemplate instance (remember to set Compass using the
setCompass method).
|
CompassTemplate | public CompassTemplate(Compass compass)(Code) | | Creates a new CompassTemplate instance, already initialized with a
Compass instance.
|
evictAll | public void evictAll()(Code) | | |
execute | public T execute(CompassCallback<T> action) throws CompassException(Code) | | Executes the compass callback within a session and a transaction context.
Parameters: action - The action to execute witin a compass transaction An object as the result of the compass action throws: CompassException - |
execute | public T execute(TransactionIsolation transactionIsolation, CompassCallback<T> action) throws CompassException(Code) | | Executes the compass callback within a session and a transaction context.
Applies the given transaction isolation level.
Parameters: transactionIsolation - The transaction isolation Parameters: action - The action to execute witin a compass transaction An object as the result of the compass action throws: CompassException - |
executeLocal | public T executeLocal(CompassCallback<T> action) throws CompassException(Code) | | Executes the compass callback within a session and a local transaction context.
Applies the given transaction isolation level.
Parameters: action - The action to execute witin a compass transaction An object as the result of the compass action throws: CompassException - |
getCompass | public Compass getCompass()(Code) | | Returns the compass instance used by the template.
the compass instance |
setCompass | public void setCompass(Compass compass)(Code) | | Sets the compass instance that will be used by the template.
|
|
|