List of usage examples for org.hibernate.criterion DetachedCriteria forEntityName
@SuppressWarnings("UnusedDeclaration") public static DetachedCriteria forEntityName(String entityName)
From source file:com.heliosapm.aa4h.parser.XMLQueryParser.java
License:Apache License
/** * Element Start SAX ContentHandler Method. * @param uri// ww w.j a va2 s . c o m * @param localName * @param qName * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) * @throws SAXException * TODO: Document supported tags in javadoc. */ @SuppressWarnings({ "unchecked" }) public void startElement(String uri, String localNameX, String qName, Attributes attrs) throws SAXException { if ("Query".equalsIgnoreCase(qName)) { queryName = attrs.getValue("name"); rootElementName = queryName; } else if ("Class".equalsIgnoreCase(qName)) { processCriteria(attrs); } else if ("Union".equalsIgnoreCase(qName)) { inDetached = true; DetachedCriteria dc = DetachedCriteria.forEntityName(className); criteriaStack.push(dc); } else if ("NamedQuery".equalsIgnoreCase(qName)) { isNamedQuery = true; namedQuery = attrs.getValue("name"); rootElementName = namedQuery; try { query = session.getNamedQuery(namedQuery); } catch (HibernateException he) { throw new SAXException("Failed to retrieve named query[" + namedQuery + "]", he); } } else if ("qparam".equalsIgnoreCase(qName)) { processQueryBind(attrs); } else if ("Join".equalsIgnoreCase(qName)) { processCriteria(attrs); } else if ("Projections".equalsIgnoreCase(qName)) { startProjection(attrs); } else if ("Projection".equalsIgnoreCase(qName)) { addProjection(attrs); } else if ("Order".equalsIgnoreCase(qName)) { if (isRowCountOnly() == false) { try { String name = attrs.getValue("name"); String type = attrs.getValue("type"); ((Criteria) criteriaStack.peek()) .addOrder(type.equalsIgnoreCase("asc") ? Order.asc(name) : Order.desc(name)); } catch (Exception e) { throw new SAXException("Unable To Parse GreaterThan:" + attrs.getValue("name"), e); } } } else if ("GreaterThan".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.gt(operator.getName(), operator.getNativeValue())); } catch (Exception e) { throw new SAXException("Unable To Parse GreaterThan:" + attrs.getValue("name"), e); } } else if ("GreaterThanOrEqual".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.ge(operator.getName(), operator.getNativeValue())); } catch (Exception e) { throw new SAXException("Unable To Parse GreaterThanOrEqual:" + attrs.getValue("name"), e); } } else if ("LessThan".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.lt(operator.getName(), operator.getNativeValue())); } catch (Exception e) { throw new SAXException("Unable To Parse LessThan:" + attrs.getValue("name"), e); } } else if ("LessThanOrEqual".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.le(operator.getName(), operator.getNativeValue())); } catch (Exception e) { throw new SAXException("Unable To Parse LessThanOrEqual:" + attrs.getValue("name"), e); } } else if ("Equals".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); if ("true".equalsIgnoreCase(attrs.getValue("not"))) { addCriterion(Restrictions.not(Restrictions.eq(operator.getName(), operator.getNativeValue()))); } else { addCriterion(Restrictions.eq(operator.getName(), operator.getNativeValue())); } } catch (Exception e) { throw new SAXException("Unable To Parse Equals:" + attrs.getValue("name"), e); } } else if ("Alias".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); ((Criteria) criteriaStack.peek()).createAlias(operator.getName(), operator.getValue()); } catch (Exception e) { throw new SAXException("Unable To Create Alias:" + attrs.getValue("name"), e); } } else if ("GreaterThanProperty".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.gtProperty(operator.getName(), operator.getName2())); } catch (Exception e) { throw new SAXException("Unable To Parse GreaterThanProperty:" + attrs.getValue("name"), e); } } else if ("GreaterThanOrEqualProperty".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.geProperty(operator.getName(), operator.getName2())); } catch (Exception e) { throw new SAXException("Unable To Parse GreaterThanOrEqualProperty:" + attrs.getValue("name"), e); } } else if ("LessThanProperty".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.ltProperty(operator.getName(), operator.getName2())); } catch (Exception e) { throw new SAXException("Unable To Parse LessThanProperty:" + attrs.getValue("name"), e); } } else if ("LessThanOrEqualProperty".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.leProperty(operator.getName(), operator.getName2())); } catch (Exception e) { throw new SAXException("Unable To Parse LessThanOrEqualProperty:" + attrs.getValue("name"), e); } } else if ("EqualsProperty".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); if ("true".equalsIgnoreCase(attrs.getValue("not"))) { addCriterion( Restrictions.not(Restrictions.eqProperty(operator.getName(), operator.getName2()))); } else { addCriterion(Restrictions.eqProperty(operator.getName(), operator.getName2())); } } catch (Exception e) { throw new SAXException("Unable To Parse EqualsProperty:" + attrs.getValue("name"), e); } } else if ("Like".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.like(operator.getName(), operator.getNativeValue())); } catch (Exception e) { throw new SAXException("Unable To Parse Like:" + attrs.getValue("name"), e); } } else if ("Between".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.between(operator.getName(), operator.getNativeValue(), operator.getNativeValue2())); } catch (Exception e) { throw new SAXException("Unable To Parse Between:" + attrs.getValue("name"), e); } } else if ("IsEmpty".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.isEmpty(operator.getName())); } catch (Exception e) { throw new SAXException("Unable To Parse IsEmpty:" + attrs.getValue("name"), e); } } else if ("IsNotEmpty".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.isNotEmpty(operator.getName())); } catch (Exception e) { throw new SAXException("Unable To Parse IsNotEmpty:" + attrs.getValue("name"), e); } } else if ("IsNull".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.isNull(operator.getName())); } catch (Exception e) { throw new SAXException("Unable To Parse IsNull:" + attrs.getValue("name"), e); } } else if ("IsNotNull".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); addCriterion(Restrictions.isNotNull(operator.getName())); } catch (Exception e) { throw new SAXException("Unable To Parse IsNotNull:" + attrs.getValue("name"), e); } } else if ("In".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); if (operator.isLiteral()) { addCriterion(new LiteralInExpression(operator.getName(), (String) operator.getNativeValue())); } else { addCriterion(Restrictions.in(operator.getName(), (Collection) operator.getNativeValue())); } } catch (Exception e) { throw new SAXException("Unable To Parse In:" + attrs.getValue("name"), e); } } else if ("SizeEquals".equalsIgnoreCase(qName)) { try { Operator operator = new Operator(attrs); int i = ((Integer) operator.getNativeValue()).intValue(); addCriterion(Restrictions.sizeEq(operator.getName(), i)); } catch (Exception e) { throw new SAXException("Unable To Parse SizeEquals:" + attrs.getValue("name"), e); } } else if ("Not".equalsIgnoreCase(qName)) { notStack.push(new Object()); } else if ("Or".equalsIgnoreCase(qName)) { opStack.push(Restrictions.disjunction()); } else if ("And".equalsIgnoreCase(qName)) { opStack.push(Restrictions.conjunction()); } else { throw new SAXException("Element Name[" + qName + "] Not Recognized."); } }
From source file:com.qcadoo.model.internal.search.SearchCriteriaImpl.java
License:Open Source License
public SearchCriteriaImpl(final DataDefinition dataDefinition) { checkNotNull(dataDefinition);/* w w w.j a va 2 s. co m*/ sourceDataDefinition = dataDefinition; criteria = DetachedCriteria .forEntityName(((InternalDataDefinition) dataDefinition).getFullyQualifiedClassName()); }
From source file:com.rockagen.gnext.qo.QueryObject.java
License:Apache License
/** * Generate hibernate {@link DetachedCriteria} * //from w w w . j a va 2 s. c o m * @param entityName * @see DetachedCriteria * @see Restrictions */ public DetachedCriteria generateDetachedCriteria(String entityName) { return DetachedCriteria.forEntityName(entityName); }
From source file:corner.orm.tapestry.service.pushlet.PushletService.java
License:Apache License
public void service(IRequestCycle cycle) throws IOException { System.out.println("start to push!"); String componentPageName = cycle.getParameter(ServiceConstants.PAGE); String messageEntityName = cycle.getParameter(QUERY_MESSAGE_ENTITY_NAME); String messageListPageName = cycle.getParameter(QUERY_MESSAGE_LIST_PAGE_NAME); IPushletFramePage page = (IPushletFramePage) cycle.getPage(componentPageName); cycle.activate(page);//from ww w. jav a2 s. co m DetachedCriteria dCriteria = page.addCriteria(DetachedCriteria.forEntityName(messageEntityName)); EntityService entityService = page.getEntityService(); ShowMessage showMsg = new ShowMessage(); showMsg.setDCriteria(dCriteria); showMsg.setEntityService(entityService); showMsg.setMessageListPageName(messageListPageName); showMsg.run(); }
From source file:net.sf.xplanner.dao.impl.RoleDaoImpl.java
License:Open Source License
@Override public List<Role> getRoles(final int personId, final int projectId, final boolean includeWildcardProject) { final Criteria criteria = this.createCriteria(); criteria.add(Restrictions.isNotEmpty("right")); DetachedCriteria.forEntityName("Role"); // ChangeSoon return null;/*from ww w . j a v a2 s .co m*/ }
From source file:org.LexGrid.LexBIG.caCore.dao.orm.translators.GridCQLToDetachedCriteria.java
License:Open Source License
public DetachedCriteria translate(CQLQuery query) throws TranslationException { //Do a little housekeeping and make sure everything is in order if (query.getTarget() == null) { throw new TranslationException("Target of the CQLQuery cannot be null, please specify a Target."); }//from www . j a va 2s .c o m Object target = query.getTarget(); String targetClassName = target.getName(); DetachedCriteria crit = DetachedCriteria.forEntityName(targetClassName); crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); //Conjunction all the properties Conjunction con = Restrictions.conjunction(); //Process Attribute Attribute attribute = target.getAttribute(); if (attribute != null) { con.add(processAttribute(attribute, crit.getAlias())); } //Process Association Association association = target.getAssociation(); if (association != null) { con.add(processAssociation(association, crit.getAlias(), crit, targetClassName)); } //Process Group Group group = target.getGroup(); if (group != null) { crit.add(processGroup(group, crit.getAlias(), crit, targetClassName)); } crit.add(con); QueryModifier modifiers = query.getQueryModifier(); crit = handleQueryOptions(crit, modifiers); return crit; }
From source file:org.LexGrid.LexBIG.caCore.dao.orm.translators.QBEPathToDetachedCriteria.java
License:Open Source License
public DetachedCriteria translate(String path, List searchObjectList) throws TranslationException { List<String> pathList = new ArrayList<String>(); StringTokenizer tokens = new StringTokenizer(path, ","); while (tokens.hasMoreTokens()) { pathList.add(tokens.nextToken().trim()); }/*from ww w .j ava 2 s . c o m*/ String rootClass = pathList.remove(0); DetachedCriteria dCrit = DetachedCriteria.forEntityName(rootClass); dCrit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); //Set the Association Path String alias = dCrit.getAlias(); for (String pathElement : pathList) { String roleName = LexEVSTranslatorsUtil.getRoleName(rootClass, pathElement); dCrit.createAlias(alias + "." + roleName, roleName); rootClass = pathElement; alias = roleName; } //Apply the List of Associated Objects (OR'ed) Disjunction disjunction = Restrictions.disjunction(); for (Object searchObject : searchObjectList) { Criterion crit = translator.buildCriterionFromNestedObjects(searchObject, alias, dCrit); disjunction.add(crit); } dCrit.add(disjunction); return dCrit; }
From source file:org.LexGrid.LexBIG.caCore.dao.orm.translators.SDKCQLToDetachedCriteria.java
License:Open Source License
public DetachedCriteria translate(CQLQuery query) throws TranslationException { CQLObject target = query.getTarget(); String targetClassName = target.getName(); DetachedCriteria crit = DetachedCriteria.forEntityName(targetClassName); crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); //Conjunction all the properties Conjunction con = Restrictions.conjunction(); //Process Attribute CQLAttribute attribute = target.getAttribute(); if (attribute != null) { con.add(processAttribute(attribute, crit.getAlias())); }/* w w w. j ava 2 s. com*/ //Process Association CQLAssociation association = target.getAssociation(); if (association != null) { con.add(processAssociation(association, crit.getAlias(), crit, targetClassName)); } //Process Group CQLGroup group = target.getGroup(); if (group != null) { crit.add(processGroup(group, crit.getAlias(), crit, targetClassName)); } crit.add(con); return crit; }
From source file:ro.cs.cm.model.dao.impl.DaoClientImpl.java
License:Open Source License
/** * Searches for clients using the criterion defined in searchClientBean * @author Coni// w w w .java 2 s . c om * @param searchClientBean * @param isDeleteAction * @return */ public List<Client> getClientBeanFromSearch(SearchClientBean searchClientBean, boolean isDeleteAction) { logger.debug("getClientBeanFromSearch - START"); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.clientForListingEntity); DetachedCriteria dcCount = DetachedCriteria.forEntityName(IModelConstant.clientForListingEntity); if (searchClientBean.getOrganizationId() != -1) { dc.add(Restrictions.eq("organizationId", searchClientBean.getOrganizationId())); dcCount.add(Restrictions.eq("organizationId", searchClientBean.getOrganizationId())); } //if the c_name property is set it means it is a client of type firm and the p_firstName and //p_lastName properties of a person won't be set; there is a third case when the client search is first displayed, //with no client type being selected if (searchClientBean.getC_name() != null && !"".equals(searchClientBean.getC_name()) && searchClientBean.getType() == IConstant.NOM_CLIENT_TYPE_FIRM) { dc.add(Restrictions.ilike("c_name", "%".concat(searchClientBean.getC_name().concat("%")))); dcCount.add(Restrictions.ilike("c_name", "%".concat(searchClientBean.getC_name().concat("%")))); } else if (searchClientBean.getC_name() != null && !"".equals(searchClientBean.getC_name()) && searchClientBean.getType() == -1) { //no client type is selected, but the name field isn't empty //we consider the firstname and lastname that might have been entered are split by " "; if no space is entered, we consider it as the firstName String firstName = null; String lastName = null; if (searchClientBean.getC_name().lastIndexOf(" ") != -1) { firstName = searchClientBean.getC_name().substring(0, searchClientBean.getC_name().lastIndexOf(" ")); lastName = searchClientBean.getC_name() .substring(searchClientBean.getC_name().lastIndexOf(" ") + 1); } else { firstName = searchClientBean.getC_name(); } if (firstName != null && !"".equals(firstName) && lastName != null && !"".equals(lastName)) { dc.add(Restrictions.or( Restrictions.ilike("c_name", "%".concat(searchClientBean.getC_name().concat("%"))), Restrictions.and(Restrictions.ilike("p_firstName", "%".concat(firstName).concat("%")), Restrictions.ilike("p_lastName", "%".concat(lastName).concat("%"))))); } else if (firstName != null && !"".equals(firstName)) { dc.add(Restrictions.or( Restrictions.ilike("c_name", "%".concat(searchClientBean.getC_name().concat("%"))), Restrictions.ilike("p_firstName", "%".concat(firstName).concat("%")))); } else if (lastName != null && !"".equals(lastName)) { dc.add(Restrictions.or( Restrictions.ilike("c_name", "%".concat(searchClientBean.getC_name().concat("%"))), Restrictions.ilike("p_lastName", "%".concat(lastName).concat("%")))); } } else { if (searchClientBean.getP_firstName() != null && !"".equals(searchClientBean.getP_firstName())) { dc.add(Restrictions.ilike("p_firstName", "%".concat(searchClientBean.getP_firstName().concat("%")))); dcCount.add(Restrictions.ilike("p_firstName", "%".concat(searchClientBean.getP_firstName().concat("%")))); } if (searchClientBean.getP_lastName() != null && !"".equals(searchClientBean.getP_lastName())) { dc.add(Restrictions.ilike("p_lastName", "%".concat(searchClientBean.getP_lastName().concat("%")))); dcCount.add( Restrictions.ilike("p_lastName", "%".concat(searchClientBean.getP_lastName().concat("%")))); } } if (searchClientBean.getEmail() != null && !"".equals(searchClientBean.getEmail())) { dc.add(Restrictions.ilike("email", "%".concat(searchClientBean.getEmail().concat("%")))); dcCount.add(Restrictions.ilike("email", "%".concat(searchClientBean.getEmail().concat("%")))); } if (searchClientBean.getAddress() != null && !"".equals(searchClientBean.getAddress())) { dc.add(Restrictions.ilike("address", "%".concat(searchClientBean.getAddress().concat("%")))); dcCount.add(Restrictions.ilike("address", "%".concat(searchClientBean.getAddress().concat("%")))); } if (searchClientBean.getType() != -1) { dc.add(Restrictions.eq("type", searchClientBean.getType())); dcCount.add(Restrictions.eq("type", searchClientBean.getType())); } if (searchClientBean.getStatus() != -1) { dc.add(Restrictions.eq("status", searchClientBean.getStatus())); dcCount.add(Restrictions.eq("status", searchClientBean.getStatus())); } // check if I have to order the results if (searchClientBean.getSortParam() != null && !"".equals(searchClientBean.getSortParam()) && !IConstant.NOM_CLIENT_SORT_PARAM_NAME.equals(searchClientBean.getSortParam())) { // if I have to, check if I have to order them ascending or descending if (searchClientBean.getSortDirection() == -1) { // ascending dc.addOrder(Order.asc(searchClientBean.getSortParam())); } else { // descending dc.addOrder(Order.desc(searchClientBean.getSortParam())); } } // if the request didn't come from the pagination area, // it means that I have to set the number of results and pages if (isDeleteAction || searchClientBean.getNbrOfResults() == -1) { boolean isSearch = false; if (searchClientBean.getNbrOfResults() == -1) { isSearch = true; } // set the count(*) restriction dcCount.setProjection(Projections.countDistinct("clientId")); //findByCriteria must be called with firstResult and maxResults parameters; the default findByCriteria(DetachedCriteria criteria) implementation //sets firstResult and maxResults to -1, which kills the countDistinct Projection int nbrOfResults = ((Integer) getHibernateTemplate().findByCriteria(dcCount, 0, 0).get(0)).intValue(); logger.debug("search results: ".concat(String.valueOf(nbrOfResults))); searchClientBean.setNbrOfResults(nbrOfResults); // get the number of pages if (nbrOfResults % searchClientBean.getResultsPerPage() == 0) { searchClientBean.setNbrOfPages(nbrOfResults / searchClientBean.getResultsPerPage()); } else { searchClientBean.setNbrOfPages(nbrOfResults / searchClientBean.getResultsPerPage() + 1); } // after a client is deleted, the same page has to be displayed; //only when all the client from last page are deleted, the previous page will be shown if (isDeleteAction && (searchClientBean.getCurrentPage() > searchClientBean.getNbrOfPages())) { searchClientBean.setCurrentPage(searchClientBean.getNbrOfPages()); } else if (isSearch) { searchClientBean.setCurrentPage(1); } } List<Client> res = (List<Client>) getHibernateTemplate().findByCriteria(dc, (searchClientBean.getCurrentPage() - 1) * searchClientBean.getResultsPerPage(), searchClientBean.getResultsPerPage()); logger.debug("getClientBeanFromSearch - END results size : ".concat(String.valueOf(res.size()))); return res; }
From source file:ro.cs.cm.model.dao.impl.DaoClientImpl.java
License:Open Source License
/** Get Clients by OrganizationId * /*from ww w.ja v a 2 s . c o m*/ * @author Adelina * * @param organizationId * @return */ public List<Client> getClientsByOrganizationId(Integer organizationId) { logger.debug( "getClientsByOrganizationId - START , organizationid = ".concat(String.valueOf(organizationId))); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.clientEntity); dc.add(Restrictions.eq("organizationId", organizationId)); dc.add(Restrictions.ne("status", IConstant.NOM_CLIENT_STATUS_DELETED)); List<Client> clients = (List<Client>) getHibernateTemplate().findByCriteria(dc); logger.debug("getClientsByOrganizationId - END"); return clients; }