Search in sources :

Example 1 with OpenEntityManager

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);
}
Also used : IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) HashSet(java.util.HashSet) DialectAwareTransactional(org.apereo.portal.spring.tx.DialectAwareTransactional) OpenEntityManager(org.apereo.portal.jpa.OpenEntityManager)

Example 2 with OpenEntityManager

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);
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) CompositeEntityIdentifier(org.apereo.portal.groups.CompositeEntityIdentifier) OpenEntityManager(org.apereo.portal.jpa.OpenEntityManager)

Example 3 with OpenEntityManager

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;
        }
    });
}
Also used : TransactionStatus(org.springframework.transaction.TransactionStatus) CacheKey(org.apereo.portal.utils.cache.CacheKey) OpenEntityManager(org.apereo.portal.jpa.OpenEntityManager)

Example 4 with OpenEntityManager

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;
        }
    });
}
Also used : TransactionStatus(org.springframework.transaction.TransactionStatus) CacheKey(org.apereo.portal.utils.cache.CacheKey) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) OpenEntityManager(org.apereo.portal.jpa.OpenEntityManager)

Example 5 with OpenEntityManager

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;
}
Also used : IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) DialectAwareTransactional(org.apereo.portal.spring.tx.DialectAwareTransactional) OpenEntityManager(org.apereo.portal.jpa.OpenEntityManager)

Aggregations

OpenEntityManager (org.apereo.portal.jpa.OpenEntityManager)7 HashSet (java.util.HashSet)2 EntityManager (javax.persistence.EntityManager)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)2 DialectAwareTransactional (org.apereo.portal.spring.tx.DialectAwareTransactional)2 CacheKey (org.apereo.portal.utils.cache.CacheKey)2 TransactionStatus (org.springframework.transaction.TransactionStatus)2 Function (com.google.common.base.Function)1 Predicate (javax.persistence.criteria.Predicate)1 CompositeEntityIdentifier (org.apereo.portal.groups.CompositeEntityIdentifier)1 IEntityGroup (org.apereo.portal.groups.IEntityGroup)1 IMarketplaceRating (org.apereo.portal.portlet.marketplace.IMarketplaceRating)1 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)1