List of usage examples for org.hibernate Criteria setFetchMode
public Criteria setFetchMode(String associationPath, FetchMode mode) throws HibernateException;
From source file:net.firejack.platform.core.store.process.CaseObjectStore.java
License:Apache License
/** * @param processLookup - lookup of the process to search by * @param entityId - ID of the entity * @param entityType - type of the entity * @return/*from www .j av a 2s . c o m*/ * @see ICaseObjectStore#findCaseByProcessAndEntity(java.lang.String, java.lang.Long, java.lang.String) */ @Override @Transactional(readOnly = true) public CaseModel findCaseByProcessAndEntity(String processLookup, Long entityId, String entityType) { final List<Criterion> criterions = createCriterions(processLookup, entityId, entityType); List<CaseObjectModel> caseObjectModels = getHibernateTemplate() .execute(new HibernateCallback<List<CaseObjectModel>>() { @Override public List<CaseObjectModel> doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = session.createCriteria(CaseObjectModel.class); criteria = criteria.createAlias("case", "cs"); criteria = criteria.createAlias("cs.process", "proc"); for (Criterion restrictions : criterions) { criteria.add(restrictions); } criteria.setFetchMode("case", FetchMode.JOIN); return criteria.list(); } }); CaseModel processCase = null; if (!caseObjectModels.isEmpty()) { processCase = caseObjectModels.get(0).getCase(); Hibernate.initialize(processCase.getStatus()); } return processCase; }
From source file:net.firejack.platform.core.store.process.CaseObjectStore.java
License:Apache License
/** * @param processLookup - lookup of the process to search by * @param entityIdList/*from w w w. j a v a 2 s.co m*/ * @param entityType - type of the entity * @return * @see ICaseObjectStore#findCaseByProcessAndEntity(java.lang.String, java.lang.Long, java.lang.String) */ @Override @Transactional(readOnly = true) public List<Tuple<Long, CaseModel>> findCaseByProcessAndEntity(final String processLookup, final List<Long> entityIdList, final String entityType) { if (entityIdList == null || entityIdList.isEmpty()) { return new ArrayList<Tuple<Long, CaseModel>>(); } final List<Criterion> criterions = createCriterions(processLookup, entityIdList, entityType); return getHibernateTemplate().execute(new HibernateCallback<List<Tuple<Long, CaseModel>>>() { @Override public List<Tuple<Long, CaseModel>> doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = session.createCriteria(CaseObjectModel.class); criteria = criteria.createAlias("case", "cs"); criteria = criteria.createAlias("cs.process", "proc"); criteria = criteria.createAlias("cs.status", "case_status"); for (Criterion restrictions : criterions) { criteria.add(restrictions); } criteria.setFetchMode("case", FetchMode.JOIN); List<CaseObjectModel> caseObjectModels = (List<CaseObjectModel>) criteria.list(); ArrayList<Tuple<Long, CaseModel>> result = new ArrayList<Tuple<Long, CaseModel>>(); if (caseObjectModels != null) { Map<Long, CaseModel> caseMap = new HashMap<Long, CaseModel>(); for (CaseObjectModel caseObjectModel : caseObjectModels) { Long id = caseObjectModel.getEntityId(); CaseModel processCase = caseObjectModel.getCase(); if (processCase != null) { Hibernate.initialize(processCase.getTaskModels()); caseMap.put(id, processCase); } } for (Map.Entry<Long, CaseModel> entry : caseMap.entrySet()) { result.add(new Tuple<Long, CaseModel>(entry.getKey(), entry.getValue())); } } return result; } }); }
From source file:net.firejack.platform.core.store.process.TaskStore.java
License:Apache License
@Override @Transactional(readOnly = true)//from w w w . j a v a2s. co m public TaskModel readWorkflowTask(final ProcessModel processModel, final EntityModel entityModel, final Long recordId) { final String processLookup = processModel.getLookup(); final String entityLookup = entityModel.getLookup(); CaseObjectModel caseObjectModel = getHibernateTemplate().execute(new HibernateCallback<CaseObjectModel>() { @Override public CaseObjectModel doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = session.createCriteria(CaseObjectModel.class); criteria = criteria.createAlias("task", "ts"); criteria = criteria.createAlias("case", "cs"); criteria = criteria.createAlias("cs.process", "proc"); criteria.add(Restrictions.eq("ts.active", true)); criteria.add(Restrictions.eq("proc.lookup", processLookup)); criteria.add(Restrictions.eq("entityId", recordId)); criteria.add(Restrictions.eq("entityType", entityLookup)); criteria.setFetchMode("task", FetchMode.JOIN); criteria.setFetchMode("ts.activity", FetchMode.JOIN); criteria.setFetchMode("case", FetchMode.JOIN); criteria.setFetchMode("cs.process", FetchMode.JOIN); criteria.setFetchMode("cs.status", FetchMode.JOIN); return (CaseObjectModel) criteria.uniqueResult(); } }); TaskModel taskModel = null; if (caseObjectModel != null) { taskModel = caseObjectModel.getTask(); List<ActivityFieldModel> activityFieldModels = activityFieldStore .findActivityFieldsByActivityId(taskModel.getActivity().getId()); taskModel.getActivity().setFields(activityFieldModels); } return taskModel; }
From source file:net.firejack.platform.core.store.registry.ActionStore.java
License:Apache License
@Override @Transactional(readOnly = true)// w ww . j av a 2 s . co m public ActionModel findById(final Long id) { final ActionModel example = instantiate(); ActionModel action = getHibernateTemplate().execute(new HibernateCallback<ActionModel>() { @Override public ActionModel doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = session.createCriteria(example.getClass()); criteria.add(Restrictions.eq("id", id)); criteria.setFetchMode("actionParameters", FetchMode.JOIN); criteria.setFetchMode("inputVOEntity", FetchMode.JOIN); criteria.setFetchMode("outputVOEntity", FetchMode.JOIN); return (ActionModel) criteria.uniqueResult(); } }); if (action != null) { Hibernate.initialize(action.getPermissions()); } return action; }
From source file:net.firejack.platform.core.store.registry.ActionStore.java
License:Apache License
@Override @Transactional(readOnly = true)//from ww w .j a v a2 s. co m public ActionModel findByUID(String uid) { if (uid == null) { throw new IllegalArgumentException("Empty UID parameter."); } Criteria criteria = getSession().createCriteria(getClazz()); criteria.createAlias("uid", "uid"); criteria.add(Restrictions.eq("uid.uid", uid)); criteria.setFetchMode("actionParameters", FetchMode.JOIN); ActionModel action = (ActionModel) criteria.uniqueResult(); if (action != null) { Hibernate.initialize(action.getPermissions()); for (ActionParameterModel parameter : action.getActionParameters()) { Hibernate.initialize(parameter.getUid()); } } return action; }
From source file:net.firejack.platform.core.store.registry.ConfigStore.java
License:Apache License
@Override @Transactional(readOnly = true)/* ww w . j a v a 2s . c o m*/ public ConfigModel findById(final Long id) { final ConfigModel example = instantiate(); return getHibernateTemplate().execute(new HibernateCallback<ConfigModel>() { @Override public ConfigModel doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = session.createCriteria(example.getClass()); criteria.add(Restrictions.eq("id", id)); criteria.setFetchMode("parent", FetchMode.JOIN); return (ConfigModel) criteria.uniqueResult(); } }); }
From source file:net.firejack.platform.core.store.registry.EntityStore.java
License:Apache License
@Override @Transactional(readOnly = true)/*from w w w . j a v a 2 s. c om*/ public EntityModel findById(final Long id) { EntityModel entityModel = getHibernateTemplate().execute(new HibernateCallback<EntityModel>() { @Override public EntityModel doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = session.createCriteria(EntityModel.class); criteria.add(Restrictions.eq("id", id)); criteria.setFetchMode("fields", FetchMode.JOIN); criteria.setFetchMode("extendedEntity", FetchMode.JOIN); criteria.setFetchMode("referenceObject", FetchMode.JOIN); EntityModel entityModel = (EntityModel) criteria.uniqueResult(); if (entityModel != null) { initializeExtendedEntities(entityModel.getExtendedEntity()); } return entityModel; } }); if (entityModel != null) { Hibernate.initialize(entityModel.getContextRoles()); Hibernate.initialize(entityModel.getIndexes()); } return entityModel; }
From source file:net.firejack.platform.core.store.registry.EntityStore.java
License:Apache License
@Override @Transactional(readOnly = true)// ww w. j a va2s .c o m public EntityModel findByLookup(final String lookup) { return getHibernateTemplate().execute(new HibernateCallback<EntityModel>() { @Override public EntityModel doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = session.createCriteria(EntityModel.class); criteria.add(Restrictions.eq("lookup", lookup)); criteria.setFetchMode("fields", FetchMode.JOIN); criteria.setFetchMode("extendedEntity", FetchMode.JOIN); return (EntityModel) criteria.uniqueResult(); } }); }
From source file:net.firejack.platform.core.store.registry.EntityStore.java
License:Apache License
@Override @Transactional(readOnly = true)//from w ww. ja va 2 s .co m public List<EntityModel> findParentTypesByEntityLookup(String entityLookup) { List<EntityModel> parentTypes = new ArrayList<EntityModel>(); List<EntityModel> hierarchicalEntities = findEntitiesDownInHierarchy(entityLookup); if (hierarchicalEntities != null && !hierarchicalEntities.isEmpty()) { Criteria criteria = getSession().createCriteria(RelationshipModel.class); criteria.add(Restrictions.eq("relationshipType", RelationshipType.PARENT_CHILD)); criteria.add(Restrictions.in("sourceEntity", hierarchicalEntities)); criteria.setFetchMode("targetEntity", FetchMode.JOIN); @SuppressWarnings("unchecked") List<RelationshipModel> hierarchicalRelationships = (List<RelationshipModel>) criteria.list(); if (hierarchicalRelationships != null && !hierarchicalRelationships.isEmpty()) { for (RelationshipModel rel : hierarchicalRelationships) { parentTypes.add(rel.getTargetEntity()); } } } return parentTypes; }
From source file:net.firejack.platform.core.store.registry.EntityStore.java
License:Apache License
@Override @Transactional(readOnly = true)//from w ww. ja v a2 s. c om public Map<String, List<EntityModel>> findAllEntitiesUpHierarchies() { Criteria criteria = getSession().createCriteria(EntityModel.class); criteria.setFetchMode("extendedEntity", FetchMode.JOIN); @SuppressWarnings("unchecked") List<EntityModel> allEntities = (List<EntityModel>) criteria.list(); Map<Long, EntityModel> entitiesById = new HashMap<Long, EntityModel>(); for (EntityModel entity : allEntities) { entitiesById.put(entity.getId(), entity); } Map<String, List<EntityModel>> result = new HashMap<String, List<EntityModel>>(); for (EntityModel entity : allEntities) { List<EntityModel> subTypes = new ArrayList<EntityModel>(); subTypes.add(entity); result.put(entity.getLookup(), subTypes); findAllSubTypes(entity, subTypes, entitiesById); } return result; }