cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Frank Herrmann <frank.herrm...@modernizingmedicine.com>
Subject Re: QueryCache @CacheGroups Annotation
Date Wed, 03 Feb 2016 20:10:17 GMT
So, is the CacheGroups annotation used by the query cache at all? If I have
to set the cache group via code, then what purpose does the annotation
serve?

Thanks for the clarification.

-Frank

On Wed, Feb 3, 2016 at 3:08 PM, Andrus Adamchik <andrus@objectstyle.org>
wrote:

> Ah, I think this is relevant:
>
> >>>>> If I specify the cache group in the code, i.e.
> >>>>> query.setCacheGroups(), everything works fine, and the cache group
is
> >>>>> utilized.
>
> This is needed. This is how Cayenne knows which cache group a query is
> associated with.
>
> Andrus
>
>
>
>
> > On Feb 3, 2016, at 11:04 PM, Frank Herrmann <
> frank.herrmann@modernizingmedicine.com> wrote:
> >
> > Sure. It takes a few hops to get there but here it is.
> >
> > The actual search is done in our CayenneGenericDao class. The type
> > parameter in this method is the StatusFirm class.
> >
> > public <T> List<T> find(Class<T> type, SearchContext searchContext)
> >> {
> >> DataContext dataContext = getObjectContext();
> >> if (FlushMode.ALWAYS.equals(DataContextUtils.getFlushMode(dataContext))
> ||
> >> FlushMode.AUTO.equals(DataContextUtils.getFlushMode(dataContext)))
> >> flush();
> >> Query query = getQuery(type, searchContext);
> >> if (!validateContext(searchContext, query))
> >> return new ArrayList<T>(0);
> >>
> >> if(type != null)
> >> flushIfNecessary(type, dataContext);
> >> List<T> results = null;
> >> if(query instanceof SelectQuery)
> >> results = (List<T>) doFind((SelectQuery)query, searchContext);
> >>
> >> else if(query instanceof SQLTemplate)
> >> results = (List<T>) doFind((SQLTemplate)query, searchContext, type ==
> >> null);
> >> else
> >> throw new IllegalArgumentException("Query type not supported " +
> >> query.getClass());
> >>
> >> if(type != null && Persistent.class.isAssignableFrom(type))
> >> CayenneObjectUtils.addFreshLoaded(dataContext, (List<? extends
> >> Persistent>)results);
> >> return results;
> >> }
> >
> >
> > Here is the getQuery method. At the point where query.setCacheStrategy()
> is
> > call, the strategy is "CACHE", and it is being cached, just to the
> default
> > cache group.
> >
> > private Query getQuery(Class<?> type, SearchContext searchContext)
> >> {
> >> if (searchContext == null)
> >> return new SelectQuery(type);
> >>
> >> Object path = searchContext.getPath();
> >> Map<String, ?> params = searchContext.getParameters();
> >> if (params == null)
> >> params = Collections.emptyMap();
> >> if (path != null)
> >> {
> >> Query query = resolveQuery(path);
> >> if(query instanceof ParameterizedQuery)
> >> {
> >> query = ((ParameterizedQuery)query).createQuery(params);
> >> }
> >> return query;
> >> }
> >> SelectQuery query = new SelectQuery(type);
> >> Object oCriteria = searchContext.getCriteria();
> >> if (oCriteria instanceof List<?>)
> >> {
> >> List<?> criteria = (List<?>) searchContext.getCriteria();
> >> query.andQualifier(buildQualifiers(criteria, params));
> >> }
> >> else if (oCriteria instanceof Expression)
> >> {
> >> query.andQualifier((Expression) oCriteria);
> >> }
> >> else if (oCriteria instanceof Criterion)
> >> {
> >> query.andQualifier(cayenneCriteriaAdaptor.adapt((Criterion) oCriteria,
> >> params));
> >> }
> >> else if (oCriteria != null)
> >> throw new IllegalArgumentException("Criteria type not supported " +
> >> oCriteria.getClass().getName());
> >> if (searchContext.getCacheStrategy() != null) {
> >>
> >>
> query.setCacheStrategy(cacheStrategies.get(searchContext.getCacheStrategy()));
> >> }
> >> return query;
> >> }
> >
> >
> >
> > Thanks Andrus.
> >
> > On Wed, Feb 3, 2016 at 2:14 PM, Andrus Adamchik <andrus@objectstyle.org>
> > wrote:
> >
> >> Do you have an example of SelectQuery fetching StatusFirms?
> >>
> >> Andrus
> >>
> >>> On Feb 3, 2016, at 10:12 PM, Frank Herrmann <
> >> frank.herrmann@modernizingmedicine.com> wrote:
> >>>
> >>> Hi Andrus,
> >>>
> >>> Thanks for the quick reply. However, adding the filter didn't seem to
> >> work.
> >>> Below is my addition of the filter to our runtime.
> >>>
> >>> public synchronized static void initialize(String cayenneConfig)
> >>>> {
> >>>> if(cayenneRuntime != null) {
> >>>> return;
> >>>> }
> >>>>
> >>>> if(logger.isInfoEnabled()) {
> >>>> logger.info("Loading cayenne domain config from " + cayenneConfig);
> >>>> }
> >>>>
> >>>> Module module = new M2CayenneModule();
> >>>> cayenneRuntime = new ServerRuntime(cayenneConfig, module);
> >>>>
> >>>> CacheInvalidationFilter cacheInvalidationFilter = new
> >>>> CacheInvalidationFilter();
> >>>> cayenneRuntime.getDataDomain().addFilter(cacheInvalidationFilter);
> >>>
> >>>
> >>> Here is the annotation on an object:
> >>>
> >>> @CacheGroups("minimal_cache")
> >>>> public class StatusFirm extends _StatusFirm implements
> >>>> com.m2.domain.StatusFirm {
> >>>> }
> >>>
> >>>
> >>> However, when this object is returned during a find, it uses the
> default
> >>> cache group. Like I said, however, if I specify the cache group in the
> >>> code, it works. So I know ehcache is being used and is configured
> >>> correctly.
> >>>
> >>> Thanks again for the help.
> >>>
> >>> -Frank
> >>>
> >>>
> >>>
> >>> On Wed, Feb 3, 2016 at 1:12 PM, Andrus Adamchik <
> andrus@objectstyle.org>
> >>> wrote:
> >>>
> >>>> Hi Frank,
> >>>>
> >>>> For the annotation to get processed, you will need to add
> >>>> CacheInvalidationFilter to your ServerRuntime. Here is an example:
> >>>>
> >>>>
> >>>>
> >>
> https://github.com/andrus/wowodc13/blob/94ac0f4920a5f494c4e73de717c05e5a54302921/editor/src/main/java/demo/editor/services/cayenne/EditorCayenneService.java
> >>>>
> >>>> Hope this helps,
> >>>> Andrus
> >>>>
> >>>>> On Feb 3, 2016, at 7:55 PM, Frank Herrmann <
> >>>> frank.herrmann@modernizingmedicine.com> wrote:
> >>>>>
> >>>>> Hello All,
> >>>>>
> >>>>> I was wondering if there is anything special I might be missing
to
> >>>> utilize
> >>>>> the @CacheGroups annotation for query caching. I have successfully
> >> gotten
> >>>>> Cayenne to use Ehcache for query caching. I have cache groups
> specified
> >>>> in
> >>>>> the ehcache.xml file. However, if I use the @CacheGroups annotation
> on
> >> an
> >>>>> object, it appears to be ignored. The caching still goes to the
> default
> >>>>> cache. If I specify the cache group in the code, i.e.
> >>>>> query.setCacheGroups(), everything works fine, and the cache group
is
> >>>>> utilized.
> >>>>>
> >>>>> I am using Cayenne 3.1.
> >>>>>
> >>>>> Thanks to anyone who can point me in the right direction.
> >>>>>
> >>>>> -Frank
> >>>>>
> >>>>> --
> >>>>> FRANK HERRMANN
> >>>>> SOFTWARE ENGINEER
> >>>>>
> >>>>> T: 561-880-2998 x1563
> >>>>>
> >>>>> E: frank.herrmann@modmed.com
> >>>>>
> >>>>>
> >>>>>
> >>>>> [image: [ Modernizing Medicine ]] <http://www.modmed.com/>
> >>>>> [image: [ Facebook ]] <http://www.facebook.com/modernizingmedicine>
> >>>> [image:
> >>>>> [ LinkedIn ]] <http://www.linkedin.com/company/modernizing-medicine/
> >
> >>>> [image:
> >>>>> [ YouTube ]] <http://www.youtube.com/user/modernizingmedicine>
> >> [image: [
> >>>>> Twitter ]] <https://twitter.com/modmed_EMA> [image: [ Blog
]]
> >>>>> <http://www.modmed.com/BlogBeyondEMR> [image: [ Instagram
]]
> >>>>> <http://instagram.com/modernizing_medicine>
> >>>>
> >>>>
> >>>
> >>>
> >>> --
> >>> FRANK HERRMANN
> >>> SOFTWARE ENGINEER
> >>>
> >>> T: 561-880-2998 x1563
> >>>
> >>> E: frank.herrmann@modmed.com
> >>>
> >>>
> >>>
> >>> [image: [ Modernizing Medicine ]] <http://www.modmed.com/>
> >>> [image: [ Facebook ]] <http://www.facebook.com/modernizingmedicine>
> >> [image:
> >>> [ LinkedIn ]] <http://www.linkedin.com/company/modernizing-medicine/>
> >> [image:
> >>> [ YouTube ]] <http://www.youtube.com/user/modernizingmedicine>
> [image: [
> >>> Twitter ]] <https://twitter.com/modmed_EMA> [image: [ Blog ]]
> >>> <http://www.modmed.com/BlogBeyondEMR> [image: [ Instagram ]]
> >>> <http://instagram.com/modernizing_medicine>
> >>
> >>
> >
> >
> > --
> > FRANK HERRMANN
> > SOFTWARE ENGINEER
> >
> > T: 561-880-2998 x1563
> >
> > E: frank.herrmann@modmed.com
> >
> >
> >
> > [image: [ Modernizing Medicine ]] <http://www.modmed.com/>
> > [image: [ Facebook ]] <http://www.facebook.com/modernizingmedicine>
> [image:
> > [ LinkedIn ]] <http://www.linkedin.com/company/modernizing-medicine/>
> [image:
> > [ YouTube ]] <http://www.youtube.com/user/modernizingmedicine> [image: [
> > Twitter ]] <https://twitter.com/modmed_EMA> [image: [ Blog ]]
> > <http://www.modmed.com/BlogBeyondEMR> [image: [ Instagram ]]
> > <http://instagram.com/modernizing_medicine>
>
>


-- 
FRANK HERRMANN
SOFTWARE ENGINEER

T: 561-880-2998 x1563

E: frank.herrmann@modmed.com



[image: [ Modernizing Medicine ]] <http://www.modmed.com/>
[image: [ Facebook ]] <http://www.facebook.com/modernizingmedicine> [image:
[ LinkedIn ]] <http://www.linkedin.com/company/modernizing-medicine/> [image:
[ YouTube ]] <http://www.youtube.com/user/modernizingmedicine> [image: [
Twitter ]] <https://twitter.com/modmed_EMA> [image: [ Blog ]]
<http://www.modmed.com/BlogBeyondEMR> [image: [ Instagram ]]
<http://instagram.com/modernizing_medicine>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message