Search in sources :

Example 26 with IBeanKey

use of org.jowidgets.cap.common.api.bean.IBeanKey in project jo-client-platform by jo-source.

the class JpaBeanAccessImpl method getBeans.

@SuppressWarnings("unchecked")
@Override
public List<BEAN_TYPE> getBeans(final Collection<? extends IBeanKey> keys, final IExecutionCallback executionCallback) {
    if (EmptyCheck.isEmpty(keys)) {
        return Collections.emptyList();
    } else {
        final Collection<Object> ids = new HashSet<Object>(keys.size());
        for (final IBeanKey beanKey : keys) {
            ids.add(beanKey.getId());
        }
        final EntityManager entityManager = EntityManagerProvider.get();
        final CriteriaQuery<? extends BEAN_TYPE> query = entityManager.getCriteriaBuilder().createQuery(beanType);
        final Root<? extends BEAN_TYPE> bean = query.from(beanType);
        query.where(bean.get(IBean.ID_PROPERTY).in(ids));
        CapServiceToolkit.checkCanceled(executionCallback);
        final List<? extends BEAN_TYPE> result = entityManager.createQuery(query).getResultList();
        CapServiceToolkit.checkCanceled(executionCallback);
        return (List<BEAN_TYPE>) result;
    }
}
Also used : IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) EntityManager(javax.persistence.EntityManager) List(java.util.List) HashSet(java.util.HashSet)

Example 27 with IBeanKey

use of org.jowidgets.cap.common.api.bean.IBeanKey in project jo-client-platform by jo-source.

the class SyncNeo4JSimpleRelatedReaderServiceImpl method getAllRelatedBeans.

private List<? extends BEAN_TYPE> getAllRelatedBeans(final List<? extends IBeanKey> parentBeans, final IExecutionCallback executionCallback) {
    final Set<BEAN_TYPE> result = new LinkedHashSet<BEAN_TYPE>();
    for (final IBeanKey beanKey : parentBeans) {
        CapServiceToolkit.checkCanceled(executionCallback);
        final Node parentNode = NodeAccess.findNode(parentBeanTypeId, beanKey.getId());
        if (parentNode != null) {
            for (final Tuple<Node, Relationship> tuple : getAllRelatedNodes(parentNode, executionCallback)) {
                CapServiceToolkit.checkCanceled(executionCallback);
                result.add(beanFactory.createRelatedNodeBean(beanType, beanTypeId, tuple.getFirst(), tuple.getSecond()));
            }
        }
    }
    return new LinkedList<BEAN_TYPE>(result);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) LinkedList(java.util.LinkedList)

Aggregations

IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)27 LinkedList (java.util.LinkedList)15 IBeanProxy (org.jowidgets.cap.ui.api.bean.IBeanProxy)5 IBeanDto (org.jowidgets.cap.common.api.bean.IBeanDto)4 DeletedBeanException (org.jowidgets.cap.common.api.exception.DeletedBeanException)4 BeanKey (org.jowidgets.cap.common.tools.bean.BeanKey)4 List (java.util.List)3 ILinkDeletion (org.jowidgets.cap.common.api.link.ILinkDeletion)3 SyncResultCallback (org.jowidgets.cap.common.tools.execution.SyncResultCallback)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 BeanException (org.jowidgets.cap.common.api.exception.BeanException)2 StaleBeanException (org.jowidgets.cap.common.api.exception.StaleBeanException)2 IFilter (org.jowidgets.cap.common.api.filter.IFilter)2 IFilterFactory (org.jowidgets.cap.common.api.filter.IFilterFactory)2 IBeanKeyFactory (org.jowidgets.cap.ui.api.bean.IBeanKeyFactory)2 IExecutionTask (org.jowidgets.cap.ui.api.execution.IExecutionTask)2 Node (org.neo4j.graphdb.Node)2