List of usage examples for org.hibernate.criterion Restrictions not
public static Criterion not(Criterion expression)
From source file:org.iternine.jeppetto.dao.hibernate.HibernateQueryModelDAO.java
License:Apache License
@Override public Condition buildCondition(String conditionField, ConditionType conditionType, Iterator argsIterator) { Condition condition = new Condition(); condition.setField(conditionField);//from w ww .j ava 2 s . co m switch (conditionType) { case Between: condition.setConstraint(Restrictions.between(conditionField, argsIterator.next(), argsIterator.next())); break; case Equal: condition.setConstraint(Restrictions.eq(conditionField, argsIterator.next())); break; case GreaterThan: condition.setConstraint(Restrictions.gt(conditionField, argsIterator.next())); break; case GreaterThanEqual: condition.setConstraint(Restrictions.ge(conditionField, argsIterator.next())); break; case IsNotNull: condition.setConstraint(Restrictions.isNotNull(conditionField)); break; case IsNull: condition.setConstraint(Restrictions.isNull(conditionField)); break; case LessThan: condition.setConstraint(Restrictions.lt(conditionField, argsIterator.next())); break; case LessThanEqual: condition.setConstraint(Restrictions.le(conditionField, argsIterator.next())); break; case NotEqual: condition.setConstraint(Restrictions.ne(conditionField, argsIterator.next())); break; case NotWithin: condition.setConstraint( Restrictions.not(Restrictions.in(conditionField, (Collection) argsIterator.next()))); break; case Within: condition.setConstraint(Restrictions.in(conditionField, (Collection) argsIterator.next())); break; } return condition; }
From source file:org.j2free.servlet.EntityAdminServlet.java
License:Apache License
/** * * @param request/* www .j a v a 2s . co m*/ * @param response * @throws ServletException * @throws IOException */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Controller controller = Controller.get(); // Get the controller associated with the current thread; String uri = request.getRequestURI(); uri = uri.replaceFirst(".*?/(list|find|inspect|create|save|update|delete)", "$1"); // chop off the part before what we care about String path[] = uri.split("/"); log.debug(uri); log.debug("path.length = " + path.length); if (path.length < 1) { log.debug("too little path info " + uri); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } RequestDispatcher rd = null; if (path[0].equals("list")) { log.debug("in list"); if (path.length < 2) { log.debug("too few parts for list"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } try { Class klass = entityLookup.get(path[1]); if (klass == null) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().println("Could not find class for entity type: " + path[1]); return; } Marshaller marshaller = ReflectionMarshaller.getForClass(klass); int start = ServletUtils.getIntParameter(request, "start", 0); int limit = ServletUtils.getIntParameter(request, "limit", 100); List entities; if (path.length == 3) { String[] stringIds = path[2].split(","); Object[] ignoredIds = new Object[stringIds.length]; Class idType = marshaller.getIdType(); // NOTE: this will only work with integer entityIds if (idType == Integer.class) { for (int i = 0; i < stringIds.length; i++) ignoredIds[i] = Integer.parseInt(stringIds[i]); } else if (idType == String.class) { for (int i = 0; i < stringIds.length; i++) ignoredIds[i] = stringIds[i]; } else if (idType == Long.class) { for (int i = 0; i < stringIds.length; i++) ignoredIds[i] = Long.parseLong(stringIds[i]); } entities = controller.listByCriterions(klass, start, limit, Order.asc(marshaller.getIdName()), Restrictions.not(Restrictions.in(marshaller.getIdName(), ignoredIds))); } else entities = controller.listByCriterions(klass, start, limit, Order.asc(marshaller.getIdName())); TreeMap<String, Object> entityMap = new TreeMap<String, Object>(); for (Object obj : entities) { entityMap.put(marshaller.extractId(obj).toString(), obj); } request.setAttribute("start", start); request.setAttribute("limit", limit); request.setAttribute("total", controller.count(klass)); request.setAttribute("simpleName", klass.getSimpleName()); request.setAttribute("package", klass.getPackage().getName() + "."); request.setAttribute("entities", entityMap); if (ServletUtils.getBooleanParameter(request, "selector", false)) rd = request.getRequestDispatcher(Dispatch.ENTITY_SELECTOR); else rd = request.getRequestDispatcher(Dispatch.ENTITY_LIST); } catch (Exception e) { log.error("Error listing entities", e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } } else if (path[0].equals("find") || path[0].equals("inspect")) { log.debug("in find"); if (path.length < 3) { log.debug("too few parts for find"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } try { Class klass = entityLookup.get(path[1]); if (klass == null) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().println("Could not find class for entity type: " + path[1]); return; } Marshaller marshaller = ReflectionMarshaller.getForClass(klass); Object entity = controller.findPrimaryKey(klass, marshaller.asIdType(path[2])); request.setAttribute("entity", entity); request.setAttribute("entityId", marshaller.extractId(entity)); request.setAttribute("fields", marshaller.marshallOut(entity, true)); if (path[0].equals("find")) rd = request.getRequestDispatcher(Dispatch.ENTITY_EDIT); else rd = request.getRequestDispatcher(Dispatch.ENTITY_INSPECT); } catch (Exception e) { log.error("error finding entity", e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } } else if (path[0].equals("create")) { log.debug("in create"); if (path.length < 2) { log.debug("too few parts for create"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } try { Class klass = entityLookup.get(path[1]); if (klass == null) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().println("Could not find class for entity type: " + path[1]); return; } Marshaller marshaller = ReflectionMarshaller.getForClass(klass); Constructor zeroArgsConst = klass.getConstructor(); if (!zeroArgsConst.isAccessible()) zeroArgsConst.setAccessible(true); Object entity = zeroArgsConst.newInstance(); request.setAttribute("simpleName", klass.getSimpleName()); request.setAttribute("package", klass.getPackage().getName() + "."); request.setAttribute("fields", marshaller.marshallOut(entity, true)); rd = request.getRequestDispatcher(Dispatch.ENTITY_CREATE); } catch (Exception e) { log.error("error creating entity", e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } } else if (path[0].equals("save")) { log.debug("in save"); if (path.length < 2) { log.debug("too few parts for save"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } Marshaller marshaller = null; try { Class klass = entityLookup.get(path[1]); if (klass == null) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().println("Could not find class for entity type: " + path[1]); return; } marshaller = ReflectionMarshaller.getForClass(klass); Object entity = klass.newInstance(); entity = marshaller.marshallIn(entity, request.getParameterMap(), controller); controller.persist(entity, true); if (controller.hasErrors()) { response.getWriter().println(controller.getErrorsAsString("<br />", true)); return; } else { response.setStatus(HttpServletResponse.SC_CREATED); // need this to display dates in the DB stored format entity = controller.findPrimaryKey(klass, marshaller.extractId(entity)); request.setAttribute("entity", entity); request.setAttribute("entityId", marshaller.extractId(entity)); request.setAttribute("fields", marshaller.marshallOut(entity, true)); rd = request.getRequestDispatcher(Dispatch.ENTITY_EDIT); } } catch (MarshallingException e) { log.error("error saving entity", e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.getWriter().println(e.getMessage()); return; } catch (Exception e) { log.error("error saving entity", e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } } else if (path[0].equals("update")) { log.debug("in update"); if (path.length < 3) { log.debug("too few parts for update"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } try { Class klass = entityLookup.get(path[1]); if (klass == null) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().println("Could not find class for entity type: " + path[1]); return; } Marshaller marshaller = ReflectionMarshaller.getForClass(klass); Object entity = controller.findPrimaryKey(klass, marshaller.asIdType(path[2])); entity = marshaller.marshallIn(entity, request.getParameterMap(), controller); controller.merge(entity); if (controller.hasErrors()) { response.getWriter().println(controller.getErrorsAsString("<br />", true)); return; } else { response.setStatus(HttpServletResponse.SC_CREATED); // need this to display dates in the DB stored format entity = controller.findPrimaryKey(klass, marshaller.extractId(entity)); request.setAttribute("entity", entity); request.setAttribute("entityId", marshaller.extractId(entity)); request.setAttribute("fields", marshaller.marshallOut(entity, true)); rd = request.getRequestDispatcher(Dispatch.ENTITY_EDIT); } } catch (MarshallingException e) { log.error("error saving entity", e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.getWriter().println(e.getMessage()); return; } catch (Exception e) { log.error("error updating entity", e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } } else if (path[0].equals("delete")) { log.debug("in delete"); if (path.length < 3) { log.debug("too few parts for delete"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } try { Class klass = entityLookup.get(path[1]); if (klass == null) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().println("Could not find class for entity type: " + path[1]); return; } Marshaller marshaller = ReflectionMarshaller.getForClass(klass); Object entity = controller.findPrimaryKey(klass, marshaller.asIdType(path[2])); controller.remove(entity); entity = null; controller.flush(); if (controller.hasErrors()) { response.getWriter().println(controller.getErrorsAsString("<br />", true)); return; } else { response.setStatus(HttpServletResponse.SC_CREATED); return; } } catch (Exception e) { log.error("error updating entity", e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } } else { log.debug("Don't know what to do!"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } CharArrayWrapper responseWrapper = new CharArrayWrapper((HttpServletResponse) response); rd.forward(request, responseWrapper); String responseString = responseWrapper.toString().replaceAll("\n", " ").replaceAll("\\s{2,}", " ") .replaceAll("> ", ">").replaceAll(" <", "<").replaceAll(" />", "/>"); response.setContentLength(responseString.length()); response.setContentType("text/javascript"); PrintWriter out = response.getWriter(); out.write(responseString); out.flush(); out.close(); }
From source file:org.jasig.ssp.dao.JournalEntryDao.java
License:Apache License
@SuppressWarnings("unchecked") public PagingWrapper<JournalStepStudentReportTO> getJournalStepStudentReportTOsFromCriteria( JournalStepSearchFormTO personSearchForm, SortingAndPaging sAndP) { final Criteria criteria = createCriteria(sAndP); setPersonCriteria(criteria, personSearchForm); if (personSearchForm.getCreateDateFrom() != null) { criteria.add(Restrictions.ge("createdDate", personSearchForm.getCreateDateFrom())); }//from w w w .j a v a 2 s . co m if (personSearchForm.getCreateDateTo() != null) { criteria.add(Restrictions.le("createdDate", personSearchForm.getCreateDateTo())); } if (personSearchForm.getGetStepDetails()) { JoinType joinType = JoinType.INNER_JOIN; criteria.createAlias("journalEntryDetails", "journalEntryDetails", joinType); criteria.createAlias("journalEntryDetails.journalStepJournalStepDetail", "journalStepJournalStepDetail", joinType); criteria.createAlias("journalStepJournalStepDetail.journalStepDetail", "journalStepDetail", joinType); if (personSearchForm.getJournalStepDetailIds() != null && !personSearchForm.getJournalStepDetailIds().isEmpty()) { criteria.add(Restrictions.in("journalStepDetail.id", personSearchForm.getJournalStepDetailIds())); criteria.add(Restrictions.eq("journalEntryDetails.objectStatus", sAndP.getStatus())); criteria.add(Restrictions.eq("journalStepJournalStepDetail.objectStatus", sAndP.getStatus())); } } else { criteria.createAlias("journalEntryDetails", "journalEntryDetails", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("journalEntryDetails.journalStepJournalStepDetail", "journalStepJournalStepDetail", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("journalStepJournalStepDetail.journalStepDetail", "journalStepDetail", JoinType.LEFT_OUTER_JOIN); if (personSearchForm.getJournalStepDetailIds() != null && !personSearchForm.getJournalStepDetailIds().isEmpty()) { Criterion isNotIds = Restrictions .not(Restrictions.in("journalStepDetail.id", personSearchForm.getJournalStepDetailIds())); Criterion isNull = Restrictions.isNull("journalStepDetail.id"); criteria.add(Restrictions.or(isNotIds, isNull)); } else { criteria.add(Restrictions.isNull("journalStepDetail.id")); } } ProjectionList projections = Projections.projectionList(); projections.add(Projections.distinct( Projections.groupProperty("journalEntryDetails.id").as("journalentry_journalEntryDetailId"))); addBasicStudentProperties(projections, criteria); projections .add(Projections.groupProperty("journalStepDetail.name").as("journalentry_journalStepDetailName")); criteria.setProjection(projections); criteria.setResultTransformer( new NamespacedAliasToBeanResultTransformer(JournalStepStudentReportTO.class, "journalentry_")); if (criteria.list().size() > 1) { List<JournalStepStudentReportTO> reports = criteria.list(); Map<UUID, JournalStepStudentReportTO> cleanReports = new HashMap<UUID, JournalStepStudentReportTO>(); for (JournalStepStudentReportTO report : reports) { if (!cleanReports.containsKey(report.getJournalEntryDetailId())) { cleanReports.put(report.getJournalEntryDetailId(), report); } } List<JournalStepStudentReportTO> sortReports = Lists.newArrayList(cleanReports.values()); Collections.sort(sortReports, new Comparator<JournalStepStudentReportTO>() { public int compare(JournalStepStudentReportTO o1, JournalStepStudentReportTO o2) { JournalStepStudentReportTO p1 = (JournalStepStudentReportTO) o1; JournalStepStudentReportTO p2 = (JournalStepStudentReportTO) o2; int value = p1.getLastName().compareToIgnoreCase(p2.getLastName()); if (value != 0) return value; value = p1.getFirstName().compareToIgnoreCase(p2.getFirstName()); if (value != 0) return value; if (p1.getMiddleName() == null && p2.getMiddleName() == null) return 0; if (p1.getMiddleName() == null) return -1; if (p2.getMiddleName() == null) return 1; return p1.getMiddleName().compareToIgnoreCase(p2.getMiddleName()); } }); return new PagingWrapper<JournalStepStudentReportTO>(sortReports.size(), sortReports); } return new PagingWrapper<JournalStepStudentReportTO>(criteria.list().size(), (List<JournalStepStudentReportTO>) criteria.list()); }
From source file:org.jpos.ee.pm.core.DBEntityFilter.java
License:Open Source License
protected Criterion getCompareCriterion(String fid, List<Object> values) { Object value_0 = values.get(0); switch (getFilterOperation(fid)) { case LIKE:/*from w ww . j a va2s .c o m*/ if (value_0 instanceof String) { return Restrictions.ilike(fid, "%" + value_0 + "%"); } else { return Restrictions.eq(fid, value_0); } case GE: return Restrictions.ge(fid, value_0); case GT: return Restrictions.gt(fid, value_0); case LE: return Restrictions.le(fid, value_0); case LT: return Restrictions.lt(fid, value_0); case NE: return Restrictions.not(Restrictions.eq(fid, value_0)); default: return Restrictions.eq(fid, value_0); } }
From source file:org.jspresso.framework.model.persistence.hibernate.criterion.DefaultCriteriaFactory.java
License:Open Source License
@SuppressWarnings("ConstantConditions") private boolean completeCriteria(EnhancedDetachedCriteria rootCriteria, DetachedCriteria currentCriteria, String path, IQueryComponent aQueryComponent, Map<String, Object> context) { boolean abort = false; IComponentDescriptor<?> componentDescriptor = aQueryComponent.getQueryDescriptor(); if (aQueryComponent instanceof ComparableQueryStructure) { completeCriteria(currentCriteria, createComparableQueryStructureRestriction(path, (ComparableQueryStructure) aQueryComponent, componentDescriptor, aQueryComponent, context)); } else {// w ww . j a va 2 s. com String translationsPath = AbstractComponentDescriptor.getComponentTranslationsDescriptorTemplate() .getName(); String translationsAlias = currentCriteria.getAlias() + "_" + componentDescriptor.getComponentContract().getSimpleName() + "_" + translationsPath; if (componentDescriptor.isTranslatable()) { rootCriteria.getSubCriteriaFor(currentCriteria, translationsPath, translationsAlias, JoinType.LEFT_OUTER_JOIN); } for (Map.Entry<String, Object> property : aQueryComponent.entrySet()) { String propertyName = property.getKey(); Object propertyValue = property.getValue(); IPropertyDescriptor propertyDescriptor = componentDescriptor.getPropertyDescriptor(propertyName); if (propertyDescriptor != null) { boolean isEntityRef = false; if (componentDescriptor.isEntity() && aQueryComponent.containsKey(IEntity.ID)) { isEntityRef = true; } if ((!PropertyViewDescriptorHelper.isComputed(componentDescriptor, propertyName) || (propertyDescriptor instanceof IStringPropertyDescriptor && ((IStringPropertyDescriptor) propertyDescriptor).isTranslatable())) && (!isEntityRef || IEntity.ID.equals(propertyName))) { String prefixedProperty = PropertyHelper.toJavaBeanPropertyName(propertyName); if (path != null) { prefixedProperty = path + "." + prefixedProperty; } if (propertyValue instanceof IEntity) { if (!((IEntity) propertyValue).isPersistent()) { abort = true; } else { completeCriteria(currentCriteria, Restrictions.eq(prefixedProperty, propertyValue)); } } else if (propertyValue instanceof Boolean && (isTriStateBooleanSupported() || (Boolean) propertyValue)) { completeCriteria(currentCriteria, Restrictions.eq(prefixedProperty, propertyValue)); } else if (IEntity.ID.equalsIgnoreCase(propertyName)) { completeCriteria(currentCriteria, createIdRestriction(propertyDescriptor, prefixedProperty, propertyValue, componentDescriptor, aQueryComponent, context)); } else if (propertyValue instanceof String) { completeCriteriaWithTranslations(currentCriteria, translationsPath, translationsAlias, property, propertyDescriptor, prefixedProperty, getBackendController(context).getLocale(), componentDescriptor, aQueryComponent, context); } else if (propertyValue instanceof Number || propertyValue instanceof Date) { completeCriteria(currentCriteria, Restrictions.eq(prefixedProperty, propertyValue)); } else if (propertyValue instanceof EnumQueryStructure) { completeCriteria(currentCriteria, createEnumQueryStructureRestriction(prefixedProperty, ((EnumQueryStructure) propertyValue))); } else if (propertyValue instanceof IQueryComponent) { IQueryComponent joinedComponent = ((IQueryComponent) propertyValue); if (!isQueryComponentEmpty(joinedComponent, propertyDescriptor)) { if (joinedComponent.isInlineComponent()/* || path != null */) { // the joined component is an inline component so we must use // dot nested properties. Same applies if we are in a nested // path i.e. already on an inline component. abort = abort || completeCriteria(rootCriteria, currentCriteria, prefixedProperty, (IQueryComponent) propertyValue, context); } else { // the joined component is an entity so we must use // nested criteria; unless the autoComplete property // is a special char. boolean digDeeper = true; String autoCompleteProperty = joinedComponent.getQueryDescriptor() .getAutoCompleteProperty(); if (autoCompleteProperty != null) { String val = (String) joinedComponent.get(autoCompleteProperty); if (val != null) { boolean negate = false; if (val.startsWith(IQueryComponent.NOT_VAL)) { val = val.substring(1); negate = true; } if (IQueryComponent.NULL_VAL.equals(val)) { Criterion crit = Restrictions.isNull(prefixedProperty); if (negate) { crit = Restrictions.not(crit); } completeCriteria(currentCriteria, crit); digDeeper = false; } } } if (digDeeper) { DetachedCriteria joinCriteria; if (isUseAliasesForJoins()) { joinCriteria = rootCriteria.getSubCriteriaFor(currentCriteria, prefixedProperty, prefixedProperty, JoinType.INNER_JOIN); } else { joinCriteria = rootCriteria.getSubCriteriaFor(currentCriteria, prefixedProperty, JoinType.INNER_JOIN); } abort = abort || completeCriteria(rootCriteria, joinCriteria, null, joinedComponent, context); } } } } else if (propertyValue != null) { // Unknown property type. Assume equals. completeCriteria(currentCriteria, Restrictions.eq(prefixedProperty, propertyValue)); } } } } } return abort; }
From source file:org.jspresso.framework.model.persistence.hibernate.criterion.DefaultCriteriaFactory.java
License:Open Source License
/** * Creates a string based restriction.// ww w . j a v a2s .c om * * @param propertyDescriptor * the property descriptor. * @param prefixedProperty * the full path of the property. * @param propertyValue * the string property value. * @param componentDescriptor * the component descriptor * @param queryComponent * the query component * @param context * the context * @return the created criterion or null if no criterion necessary. */ protected Criterion createStringRestriction(IPropertyDescriptor propertyDescriptor, String prefixedProperty, String propertyValue, IComponentDescriptor<?> componentDescriptor, IQueryComponent queryComponent, Map<String, Object> context) { Junction stringRestriction = null; if (propertyValue.length() > 0) { String[] propValues = propertyValue.split(IQueryComponent.DISJUNCT); stringRestriction = Restrictions.disjunction(); for (String propValue : propValues) { String val = propValue; if (val.length() > 0) { Criterion crit; boolean negate = false; if (val.startsWith(IQueryComponent.NOT_VAL)) { val = val.substring(1); negate = true; } if (IQueryComponent.NULL_VAL.equals(val)) { crit = Restrictions.isNull(prefixedProperty); } else { if (IEntity.ID.equals(propertyDescriptor.getName()) || propertyDescriptor instanceof IEnumerationPropertyDescriptor) { crit = Restrictions.eq(prefixedProperty, val); } else { crit = createLikeRestriction(propertyDescriptor, prefixedProperty, val, componentDescriptor, queryComponent, context); } } if (negate) { crit = Restrictions.not(crit); } stringRestriction.add(crit); } } } return stringRestriction; }
From source file:org.kaaproject.kaa.server.admin.services.dao.UserFacade.java
License:Apache License
/** * Check if username already occupied. Return user with the same username or null if username not * occupied./*from ww w .j a va 2 s.com*/ * * @param userName is sername * @param userId is user's id * @return user with the same username or null if email not occupied */ public User checkUserNameOccupied(String userName, Long userId) { Criteria criteria = getCriteria(); Criterion usernameCriterion = Restrictions.eq(USERNAME_PROPERTY, userName); if (userId != null) { criteria.add( Restrictions.and(usernameCriterion, Restrictions.not(Restrictions.eq(ID_PROPERTY, userId)))); } else { criteria.add(usernameCriterion); } return (User) criteria.uniqueResult(); }
From source file:org.kaaproject.kaa.server.admin.services.dao.UserFacade.java
License:Apache License
/** * Check if email already occupied. Return user with the same email or null if email not occupied. * * @param mail is user's mail// www . j a v a 2 s . c om * @param userId is user's id * @return user with the same email or null if email not occupied */ public User checkEmailOccupied(String mail, Long userId) { Criteria criteria = getCriteria(); Criterion mailCriterion = Restrictions.eq(MAIL_PROPERTY, mail); if (userId != null) { criteria.add(Restrictions.and(mailCriterion, Restrictions.not(Restrictions.eq(ID_PROPERTY, userId)))); } else { criteria.add(mailCriterion); } return (User) criteria.uniqueResult(); }
From source file:org.kaaproject.kaa.server.common.dao.impl.sql.HibernateConfigurationSchemaDao.java
License:Apache License
@Override public List<ConfigurationSchema> findVacantSchemas(String appId, List<String> usedSchemaIds) { LOG.debug("Searching vacant schemas by application id [{}] ", appId); List<ConfigurationSchema> schemas = Collections.emptyList(); if (isNotBlank(appId)) { List<Long> lids = toLongIds(usedSchemaIds); if (lids.isEmpty()) { schemas = findListByCriterionWithAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS, Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId))); } else {/*from w w w . java 2 s . c o m*/ schemas = findListByCriterionWithAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS, Restrictions.and(Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId)), Restrictions.not(Restrictions.in(ID_PROPERTY, lids)))); } } if (LOG.isTraceEnabled()) { LOG.trace("[{}] Search result: {}.", appId, Arrays.toString(schemas.toArray())); } else { LOG.debug("[{}] Search result: {}.", appId, schemas.size()); } return schemas; }
From source file:org.kaaproject.kaa.server.common.dao.impl.sql.HibernateProfileSchemaDao.java
License:Apache License
@Override public List<EndpointProfileSchema> findVacantSchemas(String appId, List<String> usedSchemaIds) { LOG.debug("Searching vacant schemas by application id [{}] and used schema ids [{}] ", appId, usedSchemaIds);/* ww w . j av a 2 s . c o m*/ List<EndpointProfileSchema> schemas = Collections.emptyList(); if (isNotBlank(appId)) { Criteria criteria = getCriteria().createAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS) .add(Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId))); if (usedSchemaIds != null && !usedSchemaIds.isEmpty()) { criteria.add(Restrictions.not(Restrictions.in(ID_PROPERTY, toLongIds(usedSchemaIds)))); } schemas = findListByCriteria(criteria); } if (LOG.isTraceEnabled()) { LOG.trace("[{}] Search result: {}.", appId, Arrays.toString(schemas.toArray())); } else { LOG.debug("[{}] Search result: {}.", appId, schemas.size()); } return schemas; }