List of usage examples for org.hibernate.criterion CriteriaSpecification LEFT_JOIN
int LEFT_JOIN
To view the source code for org.hibernate.criterion CriteriaSpecification LEFT_JOIN.
Click Source Link
From source file:org.infoscoop.dao.OAuthTokenDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public OAuthToken getAccessToken(String uid, String gadgetUrl, String serviceName) { if (uid == null || gadgetUrl == null || serviceName == null) { throw new RuntimeException("uid, gadgetUrl and serviceName must be set."); }//from w w w .j a v a 2s .co m Iterator results = super.getHibernateTemplate() .findByCriteria(DetachedCriteria.forClass(OAuthConsumerProp.class, "ocp") .createAlias("OAuthGadgetUrl", "ogu", CriteriaSpecification.LEFT_JOIN) .createAlias("OAuthToken", "ot", CriteriaSpecification.LEFT_JOIN) .add(Restrictions.conjunction().add(Restrictions.eq("ot.Id.Uid", uid)) .add(Restrictions.eq("ocp.ServiceName", serviceName)) .add(Restrictions.eq("ogu.GadgetUrlKey", Crypt.getHash(gadgetUrl))))) .iterator(); if (results.hasNext()) { OAuthConsumerProp o = (OAuthConsumerProp) results.next(); Set<OAuthToken> s = o.getOAuthToken(); Iterator i = s.iterator(); if (i.hasNext()) return (OAuthToken) i.next(); } return null; }
From source file:org.infoscoop.dao.OAuthTokenDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<OAuthToken> getAccessTokens(String uid, String serviceName) { if (uid == null || serviceName == null) { throw new RuntimeException("uid and serviceName must be set."); }//w ww . ja v a 2 s . co m Iterator<OAuthConsumerProp> results = super.getHibernateTemplate() .findByCriteria(DetachedCriteria.forClass(OAuthConsumerProp.class, "ocp") .createAlias("OAuthGadgetUrl", "ogu", CriteriaSpecification.LEFT_JOIN) .createAlias("OAuthToken", "ot", CriteriaSpecification.LEFT_JOIN) .add(Restrictions.conjunction().add(Restrictions.eq("ot.Id.Uid", uid)) .add(Restrictions.eq("ocp.ServiceName", serviceName)))) .iterator(); if (results.hasNext()) { OAuthConsumerProp o = (OAuthConsumerProp) results.next(); List l = new ArrayList(); l.addAll(o.getOAuthToken()); return l; } return null; }
From source file:org.infoscoop.dao.StaticTabDAO.java
License:Open Source License
/** * Get all static tabs without commandBar and portalHeader. * @return//from w w w .ja va 2 s . com */ public List getStaticTabList() { DetachedCriteria c = DetachedCriteria.forClass(StaticTab.class); c.add(Expression.eq(StaticTab.PROP_DELETEFLAG, StaticTab.DELETEFLAG_FALSE)); c.add(Expression.ne(StaticTab.PROP_ID, StaticTab.COMMANDBAR_TAB_ID)); c.add(Expression.ne(StaticTab.PROP_ID, StaticTab.PORTALHEADER_TAB_ID)); c.createAlias(TabAdmin.REF, "ta", CriteriaSpecification.LEFT_JOIN); c.addOrder(Order.asc(StaticTab.PROP_TABNUMBER)); return super.getHibernateTemplate().findByCriteria(c); }
From source file:org.infoscoop.dao.StaticTabDAO.java
License:Open Source License
/** * Get all static tabs with commandBar and portalHeader. * @return//from w w w . j a v a2s. c o m */ public List getAllStaicLayoutList() { DetachedCriteria c = DetachedCriteria.forClass(StaticTab.class); c.add(Expression.eq(StaticTab.PROP_DELETEFLAG, StaticTab.DELETEFLAG_FALSE)); c.createAlias(TabAdmin.REF, "ta", CriteriaSpecification.LEFT_JOIN); c.addOrder(Order.asc(StaticTab.PROP_TABNUMBER)); return super.getHibernateTemplate().findByCriteria(c); }
From source file:org.openmrs.api.db.hibernate.PatientSearchCriteria.java
License:Mozilla Public License
private void addAliasForIdentifiers(Criteria criteria) { criteria.createAlias("identifiers", "ids", CriteriaSpecification.LEFT_JOIN); }
From source file:org.openmrs.api.db.hibernate.PersonSearchCriteria.java
License:Mozilla Public License
void addAliasForAttribute(Criteria criteria) { criteria.createAlias("attributes", "attribute", CriteriaSpecification.LEFT_JOIN); criteria.createAlias("attribute.attributeType", "attributeType", CriteriaSpecification.LEFT_JOIN); }
From source file:org.openmrs.module.muzima.api.db.hibernate.HibernateDataDao.java
License:Open Source License
/** * Get data with matching search term for particular page. * * @param search the search term./* ww w .java2 s . c om*/ * @param pageNumber the page number. * @param pageSize the size of the page. * @return list of data for the page. */ @Override @SuppressWarnings("unchecked") public List<T> getPagedData(final String search, final Integer pageNumber, final Integer pageSize) { Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(mappedClass); criteria.createAlias("location", "location", CriteriaSpecification.LEFT_JOIN); criteria.createAlias("provider", "provider", CriteriaSpecification.LEFT_JOIN); if (StringUtils.isNotEmpty(search)) { Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.ilike("payload", search, MatchMode.ANYWHERE)); disjunction.add(Restrictions.ilike("discriminator", search, MatchMode.ANYWHERE)); disjunction.add(Restrictions.ilike("location.name", search, MatchMode.ANYWHERE)); disjunction.add(Restrictions.ilike("patientUuid", search, MatchMode.ANYWHERE)); disjunction.add(Restrictions.ilike("formName", search, MatchMode.ANYWHERE)); disjunction.add(Restrictions.ilike("provider.identifier", search, MatchMode.ANYWHERE)); disjunction.add(Restrictions.ilike("provider.name", search, MatchMode.ANYWHERE)); if (StringUtils.isNumeric(search)) { disjunction.add(Restrictions.eq("location.locationId", Integer.parseInt(search))); } criteria.add(disjunction); } if (pageNumber != null) { criteria.setFirstResult((pageNumber - 1) * pageSize); } if (pageSize != null) { criteria.setMaxResults(pageSize); } criteria.addOrder(Order.desc("dateCreated")); return criteria.list(); }
From source file:org.openmrs.module.muzima.api.db.hibernate.HibernateDataDao.java
License:Open Source License
/** * Get the total number of data with matching search term. * * * @param search the search term.// w w w . j ava 2s .c o m * @return total number of data in the database. */ @Override public Number countData(final String search) { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(mappedClass); criteria.createAlias("location", "location", CriteriaSpecification.LEFT_JOIN); criteria.createAlias("provider", "provider", CriteriaSpecification.LEFT_JOIN); if (StringUtils.isNotEmpty(search)) { Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.ilike("payload", search, MatchMode.ANYWHERE)); disjunction.add(Restrictions.ilike("discriminator", search, MatchMode.ANYWHERE)); disjunction.add(Restrictions.ilike("location.name", search, MatchMode.ANYWHERE)); disjunction.add(Restrictions.ilike("patientUuid", search, MatchMode.ANYWHERE)); disjunction.add(Restrictions.ilike("formName", search, MatchMode.ANYWHERE)); disjunction.add(Restrictions.ilike("provider.identifier", search, MatchMode.ANYWHERE)); disjunction.add(Restrictions.ilike("provider.name", search, MatchMode.ANYWHERE)); if (StringUtils.isNumeric(search)) { disjunction.add(Restrictions.eq("location.locationId", Integer.parseInt(search))); } criteria.add(disjunction); } criteria.setProjection(Projections.rowCount()); return (Number) criteria.uniqueResult(); }
From source file:org.openmrs.module.nbs.datasource.HibernateLogicProviderDAO.java
License:Open Source License
private List<User> logicToHibernate(LogicExpression expression, List<Integer> userIds) { Criteria criteria = this.sessionFactory.getCurrentSession().createCriteria(User.class) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria = criteria.createAlias("names", "na"); criteria = criteria.createAlias("attributes", "attr", CriteriaSpecification.LEFT_JOIN); criteria = criteria.createAlias("attr.attributeType", "type") .add(Restrictions.eq("type.name", "Provider ID")); Date indexDate = Calendar.getInstance().getTime(); Operator transformOperator = null;/* w ww . j a va2 s. com*/ LogicTransform transform = expression.getTransform(); Integer numResults = null; if (transform != null) { transformOperator = transform.getTransformOperator(); numResults = transform.getNumResults(); } if (numResults == null) { numResults = 1; } // set the transform and evaluate the right criteria // if there is any if (transformOperator == Operator.DISTINCT) { criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); } Criterion c = this.getCriterion(expression, indexDate); if (c != null) { criteria.add(c); } List<User> results = new ArrayList<User>(); criteria.add(Restrictions.in("userId", userIds)); results.addAll(criteria.list()); // return a single result per patient for these operators // I don't see an easy way to do this in hibernate so I am // doing some postprocessing if (transformOperator == Operator.FIRST || transformOperator == Operator.LAST) { HashMap<Integer, ArrayList<User>> nResultMap = new HashMap<Integer, ArrayList<User>>(); for (User currResult : results) { Integer currUserId = currResult.getUserId(); ArrayList<User> prevResults = nResultMap.get(currUserId); if (prevResults == null) { prevResults = new ArrayList<User>(); nResultMap.put(currUserId, prevResults); } if (prevResults.size() < numResults) { prevResults.add(currResult); } } if (nResultMap.values().size() > 0) { results.clear(); for (ArrayList<User> currPatientUser : nResultMap.values()) { results.addAll(currPatientUser); } } } return results; }
From source file:to.etc.domui.hibernate.model.CriteriaCreatingVisitor.java
License:Open Source License
/** * * @param rootAlias The current alias which starts off this last segment, or "" if we start from root object. * @param fullpath The root object absolute path, i.e. the input up to the current level including the relation property * @param relativepath The relative path from the rootAlias. * @param pmm// www . ja v a 2 s. co m * @return */ private String getPathAlias(String rootAlias, String fullpath, String relativepath, PropertyMetaModel<?> pmm) { String alias = m_aliasMap.get(fullpath); // Path is already known? if (null != alias) return alias; //-- This is new... Create the alias and refer it off the previous root alias, String nextAlias = nextAlias(); String aliasedPath = relativepath; if (rootAlias.length() > 0) aliasedPath = rootAlias + "." + relativepath; m_aliasMap.put(fullpath, nextAlias); //-- We need to create this join. int joinType = pmm.isRequired() ? CriteriaSpecification.INNER_JOIN : CriteriaSpecification.LEFT_JOIN; if (m_currentCriteria instanceof Criteria) { ((Criteria) m_currentCriteria).createAlias(aliasedPath, nextAlias, joinType); // Crapfest } else if (m_currentCriteria instanceof DetachedCriteria) { ((DetachedCriteria) m_currentCriteria).createAlias(aliasedPath, nextAlias, joinType); } else throw new IllegalStateException("Unexpected current thing: " + m_currentCriteria); return nextAlias; }