use of org.apereo.portal.utils.cache.CacheKey in project uPortal by Jasig.
the class EntityManagerCacheImpl method get.
@Override
public <T> T get(String persistenceUnitName, Serializable key) {
final Map<String, Deque<String>> currentEntityManagers = CURRENT_ENTITY_MANAGER_SESSIONS.get();
if (currentEntityManagers == null) {
logger.error("There is no currentEntityManagers Map in the ThreadLocal, no EntityManager scoped caching will be done. persistenceUnitName=" + persistenceUnitName + ", key=" + key, new Throwable());
return null;
}
final Deque<String> entityManagerIds = currentEntityManagers.get(persistenceUnitName);
if (entityManagerIds == null || entityManagerIds.isEmpty()) {
logger.error("Cannot access cache for persistent unit " + persistenceUnitName + ", it has no active EntityManager, no EntityManager scoped caching will be done. key=" + key, new Throwable());
return null;
}
final String entityManagerId = entityManagerIds.getFirst();
final SimpleCacheEntryTag entityManagerIdTag = new SimpleCacheEntryTag(CACHE_TAG, entityManagerId);
final CacheKey cacheKey = CacheKey.buildTagged(CACHE_KEY_SOURCE, entityManagerIdTag, entityManagerId, key);
final Element element = this.contentCache.get(cacheKey);
if (element == null) {
return null;
}
return (T) element.getObjectValue();
}
use of org.apereo.portal.utils.cache.CacheKey in project uPortal by Jasig.
the class EntityManagerCacheImpl method put.
@Override
public void put(String persistenceUnitName, Serializable key, Object value) {
final Map<String, Deque<String>> currentEntityManagers = CURRENT_ENTITY_MANAGER_SESSIONS.get();
if (currentEntityManagers == null) {
logger.error("There is no currentEntityManagers Map in the ThreadLocal, no EntityManager scoped caching will be done. persistenceUnitName=" + persistenceUnitName + ", key=" + key, new Throwable());
return;
}
final Deque<String> entityManagerIds = currentEntityManagers.get(persistenceUnitName);
if (entityManagerIds == null || entityManagerIds.isEmpty()) {
logger.error("Cannot access cache for persistent unit " + persistenceUnitName + ", it has no active EntityManager, no EntityManager scoped caching will be done. key=" + key, new Throwable());
return;
}
final String entityManagerId = entityManagerIds.getFirst();
final SimpleCacheEntryTag entityManagerIdTag = new SimpleCacheEntryTag(CACHE_TAG, entityManagerId);
final CacheKey cacheKey = CacheKey.buildTagged(CACHE_KEY_SOURCE, entityManagerIdTag, entityManagerId, key);
this.contentCache.put(new Element(cacheKey, value));
}
use of org.apereo.portal.utils.cache.CacheKey in project uPortal by Jasig.
the class JsonWrapperFilteringCharacterPipelineComponentTest method testGetCacheKeyNull.
@Test(expected = IllegalStateException.class)
public void testGetCacheKeyNull() {
CacheKey cacheKey = jsonWrapperFilteringCharacterPipelineComponent.getCacheKey(req, res);
Assert.assertNull(cacheKey);
}
use of org.apereo.portal.utils.cache.CacheKey in project uPortal by Jasig.
the class JpaAggregatedGroupLookupDao method getGroupMapping.
@OpenEntityManager(unitName = BaseAggrEventsJpaDao.PERSISTENCE_UNIT_NAME)
@Override
public AggregatedGroupMapping getGroupMapping(final String groupService, final String groupName) {
final CacheKey key = CacheKey.build(this.getClass().getName(), groupService, groupName);
AggregatedGroupMapping groupMapping = this.entityManagerCache.get(BaseAggrEventsJpaDao.PERSISTENCE_UNIT_NAME, key);
if (groupMapping != null) {
return groupMapping;
}
final NaturalIdQuery<AggregatedGroupMappingImpl> query = this.createNaturalIdQuery(AggregatedGroupMappingImpl.class);
query.using(AggregatedGroupMappingImpl_.groupService, groupService);
query.using(AggregatedGroupMappingImpl_.groupName, groupName);
groupMapping = query.load();
if (groupMapping != null) {
this.entityManagerCache.put(BaseAggrEventsJpaDao.PERSISTENCE_UNIT_NAME, key, groupMapping);
return groupMapping;
}
return this.getTransactionOperations().execute(new TransactionCallback<AggregatedGroupMapping>() {
@Override
public AggregatedGroupMapping doInTransaction(TransactionStatus status) {
final AggregatedGroupMappingImpl aggregatedGroupMapping = new AggregatedGroupMappingImpl(groupService, groupName);
getEntityManager().persist(aggregatedGroupMapping);
logger.debug("Created {}", aggregatedGroupMapping);
entityManagerCache.put(BaseAggrEventsJpaDao.PERSISTENCE_UNIT_NAME, key, aggregatedGroupMapping);
return aggregatedGroupMapping;
}
});
}
use of org.apereo.portal.utils.cache.CacheKey in project uPortal by Jasig.
the class JpaEventSessionDao method getEventSession.
@AggrEventsTransactional
@Override
public EventSession getEventSession(PortalEvent event) {
final String eventSessionId = event.getEventSessionId();
final CacheKey key = CacheKey.build(EVENT_SESSION_CACHE_SOURCE, eventSessionId);
EventSessionImpl eventSession = this.entityManagerCache.get(BaseAggrEventsJpaDao.PERSISTENCE_UNIT_NAME, key);
if (eventSession != null) {
return eventSession;
}
final NaturalIdQuery<EventSessionImpl> naturalIdQuery = this.createNaturalIdQuery(EventSessionImpl.class);
naturalIdQuery.using(EventSessionImpl_.eventSessionId, eventSessionId);
eventSession = naturalIdQuery.load();
if (eventSession == null) {
// No event session, somehow we missed the login event. Look at the groups the user is
// currently a member of
final Set<AggregatedGroupMapping> groupMappings = this.getGroupsForEvent(event);
final DateTime eventDate = event.getTimestampAsDate();
eventSession = new EventSessionImpl(eventSessionId, eventDate, groupMappings);
this.getEntityManager().persist(eventSession);
this.entityManagerCache.put(BaseAggrEventsJpaDao.PERSISTENCE_UNIT_NAME, key, eventSession);
}
return eventSession;
}
Aggregations