use of org.apereo.portal.jpa.OpenEntityManager in project uPortal by Jasig.
the class JpaPortletEntityDao method getPortletEntities.
@Override
@DialectAwareTransactional(value = PostgreSQL81Dialect.class, exclude = false)
@PortalTransactionalReadOnly
@OpenEntityManager(unitName = PERSISTENCE_UNIT_NAME)
public Set<IPortletEntity> getPortletEntities(IPortletDefinitionId portletDefinitionId) {
Validate.notNull(portletDefinitionId, "portletEntity can not be null");
final IPortletDefinition portletDefinition = this.portletDefinitionDao.getPortletDefinition(portletDefinitionId);
final TypedQuery<PortletEntityImpl> query = this.createCachedQuery(this.findEntitiesForDefinitionQuery);
query.setParameter(this.portletDefinitionParameter, (PortletDefinitionImpl) portletDefinition);
final List<PortletEntityImpl> portletEntities = query.getResultList();
return new HashSet<IPortletEntity>(portletEntities);
}
use of org.apereo.portal.jpa.OpenEntityManager in project uPortal by Jasig.
the class JpaAggregatedGroupLookupDao method getGroupMapping.
@OpenEntityManager(unitName = BaseAggrEventsJpaDao.PERSISTENCE_UNIT_NAME)
@Override
public AggregatedGroupMapping getGroupMapping(final String portalGroupKey) {
final IEntityGroup group = compositeGroupService.findGroup(portalGroupKey);
if (group == null) {
if (warnedGroupKeys.add(portalGroupKey)) {
logger.warn("No group found for key {}, no aggregate group mapping will be done and the group key will be ignored.", portalGroupKey);
}
final CompositeEntityIdentifier compositeEntityIdentifier = new CompositeEntityIdentifier(portalGroupKey, IEntityGroup.class);
final String serviceName = compositeEntityIdentifier.getServiceName().toString();
final String groupKey = compositeEntityIdentifier.getLocalKey();
return this.getGroupMapping(serviceName, groupKey);
}
final String groupService = group.getServiceName().toString();
final String groupName = group.getName();
return this.getGroupMapping(groupService, groupName);
}
use of org.apereo.portal.jpa.OpenEntityManager in project uPortal by Jasig.
the class JpaAggregatedTabLookupDao method getTabMapping.
@OpenEntityManager(unitName = BaseAggrEventsJpaDao.PERSISTENCE_UNIT_NAME)
@Override
public AggregatedTabMapping getTabMapping(final String fragmentName, final String tabName) {
final CacheKey key = CacheKey.build(this.getClass().getName(), tabName);
AggregatedTabMapping tabMapping = this.entityManagerCache.get(BaseAggrEventsJpaDao.PERSISTENCE_UNIT_NAME, key);
if (tabMapping != null) {
return tabMapping;
}
final NaturalIdQuery<AggregatedTabMappingImpl> query = this.createNaturalIdQuery(AggregatedTabMappingImpl.class);
query.using(AggregatedTabMappingImpl_.fragmentName, fragmentName);
query.using(AggregatedTabMappingImpl_.tabName, tabName);
tabMapping = query.load();
if (tabMapping != null) {
this.entityManagerCache.put(BaseAggrEventsJpaDao.PERSISTENCE_UNIT_NAME, key, tabMapping);
return tabMapping;
}
return this.getTransactionOperations().execute(new TransactionCallback<AggregatedTabMapping>() {
@Override
public AggregatedTabMapping doInTransaction(TransactionStatus status) {
final AggregatedTabMappingImpl aggregatedGroupMapping = new AggregatedTabMappingImpl(fragmentName, tabName);
getEntityManager().persist(aggregatedGroupMapping);
logger.debug("Created {}", aggregatedGroupMapping);
entityManagerCache.put(BaseAggrEventsJpaDao.PERSISTENCE_UNIT_NAME, key, aggregatedGroupMapping);
return aggregatedGroupMapping;
}
});
}
use of org.apereo.portal.jpa.OpenEntityManager in project uPortal by Jasig.
the class JpaAggregatedPortletLookupDao method getMappedPortletForFname.
@OpenEntityManager(unitName = BaseAggrEventsJpaDao.PERSISTENCE_UNIT_NAME)
@Override
public AggregatedPortletMapping getMappedPortletForFname(final String fname) {
final CacheKey key = CacheKey.build(this.getClass().getName(), fname);
AggregatedPortletMapping portletMapping = this.entityManagerCache.get(BaseAggrEventsJpaDao.PERSISTENCE_UNIT_NAME, key);
if (portletMapping != null) {
return portletMapping;
}
final NaturalIdQuery<AggregatedPortletMappingImpl> query = this.createNaturalIdQuery(AggregatedPortletMappingImpl.class);
query.using(AggregatedPortletMappingImpl_.fname, fname);
portletMapping = query.load();
if (portletMapping != null) {
this.entityManagerCache.put(BaseAggrEventsJpaDao.PERSISTENCE_UNIT_NAME, key, portletMapping);
return portletMapping;
}
return this.getTransactionOperations().execute(new TransactionCallback<AggregatedPortletMapping>() {
@Override
public AggregatedPortletMapping doInTransaction(TransactionStatus status) {
final IPortletDefinition portletDefinition = portletDefinitionDao.getPortletDefinitionByFname(fname);
final String name;
if (portletDefinition != null) {
name = portletDefinition.getName();
} else {
name = fname;
}
final AggregatedPortletMappingImpl aggregatedGroupMapping = new AggregatedPortletMappingImpl(name, fname);
getEntityManager().persist(aggregatedGroupMapping);
logger.debug("Created {}", aggregatedGroupMapping);
entityManagerCache.put(BaseAggrEventsJpaDao.PERSISTENCE_UNIT_NAME, key, aggregatedGroupMapping);
return aggregatedGroupMapping;
}
});
}
use of org.apereo.portal.jpa.OpenEntityManager in project uPortal by Jasig.
the class JpaPortletEntityDao method getPortletEntity.
@Override
@DialectAwareTransactional(value = PostgreSQL81Dialect.class, exclude = false)
@PortalTransactionalReadOnly
@OpenEntityManager(unitName = PERSISTENCE_UNIT_NAME)
public IPortletEntity getPortletEntity(String layoutNodeId, int userId) {
Validate.notNull(layoutNodeId, "portletEntity can not be null");
/* Since portal entities mostly are retrieved in batches (for each "channel" element in user's layout), it is
* faster to retrieve all portlet entities, so that persistence framework can place them in 2nd level cache, and
* iterate over them manually instead of retrieving single portlet entity one by one. */
Set<IPortletEntity> entities = getPortletEntitiesForUser(userId);
for (IPortletEntity entity : entities) {
if (StringUtils.equals(entity.getLayoutNodeId(), layoutNodeId)) {
return entity;
}
}
return null;
}
Aggregations