List of usage examples for org.hibernate.criterion Restrictions idEq
public static Criterion idEq(Object value)
From source file:com.qcadoo.model.api.search.SearchRestrictions.java
License:Open Source License
/** * Creates criterion which checks if id is equal to given value. * //from w ww. ja va 2s .co m * @param value * value * @return criterion */ public static SearchCriterion idEq(final long value) { return new SearchCriterionImpl(Restrictions.idEq(value)); }
From source file:com.qcadoo.model.api.search.SearchRestrictions.java
License:Open Source License
/** * Creates criterion which checks if id isn't equal to given value. * //from w ww. j a v a 2s.co m * @param value * value * @return criterion */ public static SearchCriterion idNe(final long value) { return new SearchCriterionImpl(Restrictions.not(Restrictions.idEq(value))); }
From source file:com.qcadoo.model.internal.PriorityServiceImpl.java
License:Open Source License
private void setPriorityIfNotPresent(final InternalDataDefinition dataDefinition, final FieldDefinition fieldDefinition, final Object databaseEntity, int currentPriority) { Criteria criteria = getCriteria(dataDefinition, fieldDefinition, databaseEntity) .add(Restrictions.isNull(fieldDefinition.getName())) .add(Restrictions.not(Restrictions.idEq(entityService.getId(databaseEntity)))); List<Object> entitiesToDecrement = criteria.list(); int index = currentPriority + 1; for (Object entity : entitiesToDecrement) { Integer priorityInteger = (Integer) entityService.getField(entity, fieldDefinition); int priority = priorityInteger != null ? priorityInteger.intValue() : index; entityService.setField(entity, fieldDefinition, priority); hibernateService.getCurrentSession().update(entity); index++;//from w ww. jav a2 s. co m } }
From source file:com.redhat.rhn.manager.errata.test.ErrataManagerTest.java
License:Open Source License
/** * Get an ErrataAction from an Action.// w ww . j av a 2s . c o m * @param action the action * @return the errata action */ private ErrataAction errataActionFromAction(Action action) { ErrataAction errataAction = (ErrataAction) HibernateFactory.getSession().createCriteria(ErrataAction.class) .add(Restrictions.idEq(action.getId())).uniqueResult(); return errataAction; }
From source file:com.romeikat.datamessie.core.base.dao.impl.AbstractEntityWithIdDao.java
License:Open Source License
@Override public E getEntity(final SharedSessionContract ssc, final long id) { // Query/* w w w .j a va 2 s . c o m*/ final Criteria criteria = ssc.createCriteria(getEntityClass()); criteria.add(Restrictions.idEq(id)); // Done @SuppressWarnings("unchecked") final E result = (E) criteria.uniqueResult(); return result; }
From source file:com.romeikat.datamessie.core.base.dao.impl.DocumentDao.java
License:Open Source License
public Document getForUrlAndSource(final SharedSessionContract ssc, final String url, final long sourceId) { // Query: Download final EntityWithIdQuery<Download> downloadQuery = new EntityWithIdQuery<>(Download.class); downloadQuery.addRestriction(Restrictions.eq("url", url)); downloadQuery.addRestriction(Restrictions.eq("sourceId", sourceId)); final Long documentId = downloadQuery.uniqueIdForProperty(ssc, "documentId"); if (documentId == null) { return null; }/*w w w . j av a 2s.c o m*/ // Query: Document final EntityWithIdQuery<Document> documentQuery = new EntityWithIdQuery<>(Document.class); documentQuery.addRestriction(Restrictions.idEq(documentId)); final Document document = documentQuery.uniqueObject(ssc); return document; }
From source file:com.romeikat.datamessie.core.base.dao.impl.DocumentDao.java
License:Open Source License
public DocumentDto getAsDto(final SharedSessionContract ssc, final long id) { // Query: Document final EntityWithIdQuery<Document> documentQuery = new EntityWithIdQuery<>(Document.class); documentQuery.addRestriction(Restrictions.idEq(id)); final Document document = documentQuery.uniqueObject(ssc); if (document == null) { return null; }// w ww . ja v a 2 s . co m // Query: RawContent final EntityWithIdQuery<RawContent> rawContentQuery = new EntityWithIdQuery<>(RawContent.class); rawContentQuery.addRestriction(Restrictions.eq("documentId", document.getId())); final RawContent rawContent = rawContentQuery.uniqueObject(ssc); // Query: CleanedContent final EntityWithIdQuery<CleanedContent> cleanedContentQuery = new EntityWithIdQuery<>(CleanedContent.class); cleanedContentQuery.addRestriction(Restrictions.eq("documentId", document.getId())); final CleanedContent cleanedContent = cleanedContentQuery.uniqueObject(ssc); // Query: StemmedContent final EntityWithIdQuery<StemmedContent> stemmedContentQuery = new EntityWithIdQuery<>(StemmedContent.class); stemmedContentQuery.addRestriction(Restrictions.eq("documentId", document.getId())); final StemmedContent stemmedContent = stemmedContentQuery.uniqueObject(ssc); // Query: Source final EntityWithIdQuery<Source> sourceQuery = new EntityWithIdQuery<>(Source.class); sourceQuery.addRestriction(Restrictions.idEq(document.getSourceId())); final Source source = sourceQuery.uniqueObject(ssc); if (source == null) { return null; } // Transform final DocumentDto dto = new DocumentDto(); dto.setId(document.getId()); dto.setTitle(document.getTitle()); dto.setStemmedTitle(document.getStemmedTitle()); dto.setUrl(document.getUrl()); dto.setDescription(document.getDescription()); dto.setStemmedDescription(document.getStemmedDescription()); dto.setPublished(document.getPublished()); dto.setDownloaded(document.getDownloaded()); dto.setStatusCode(document.getStatusCode()); dto.setState(document.getState()); dto.setRawContent(rawContent == null ? null : rawContent.getContent()); dto.setCleanedContent(cleanedContent == null ? null : cleanedContent.getContent()); dto.setStemmedContent(stemmedContent == null ? null : stemmedContent.getContent()); dto.setSourceId(source.getId()); dto.setSourceName(source.getName()); dto.setSourceUrl(source.getUrl()); // Named entities final List<NamedEntityDto> namedEntities = namedEntityService.getAsDtosByDocument(ssc, id); final String namedEntitiesAsString = getNamedEntitesAsString(namedEntities); dto.setNamedEntities(namedEntitiesAsString); // Done return dto; }
From source file:com.romeikat.datamessie.core.base.dao.impl.ProjectDao.java
License:Open Source License
public ProjectDto getAsDto(final SharedSessionContract ssc, final long projectId, final Long userId) { // Restrict to user final Collection<Long> projectIdsForUser = getIdsForUser(ssc, userId); if (projectIdsForUser.isEmpty()) { return null; }//w w w . ja va2 s .co m // Query: Project final EntityWithIdQuery<Project> projectQuery = new EntityWithIdQuery<>(Project.class); projectQuery.addRestriction(Restrictions.idEq(projectId)); projectQuery.addIdRestriction(projectIdsForUser); projectQuery.addOrder(Order.desc("started")); projectQuery.setResultTransformer(new AliasToBeanResultTransformer(ProjectDto.class)); // Done final ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("id"), "id"); projectionList.add(Projections.property("name"), "name"); projectionList.add(Projections.property("crawlingEnabled"), "crawlingEnabled"); projectionList.add(Projections.property("crawlingInterval"), "crawlingInterval"); projectionList.add(Projections.property("preprocessingEnabled"), "preprocessingEnabled"); final ProjectDto dto = (ProjectDto) projectQuery.uniqueForProjection(ssc, projectionList); return dto; }
From source file:com.romeikat.datamessie.core.base.dao.impl.SourceDao.java
License:Open Source License
public SourceDto getAsDto(final SharedSessionContract ssc, final Long userId, final Long id) { if (id == null) { return null; }//ww w . j av a 2 s.co m // Restrict to user final Collection<Long> projectIdsForUser = projectDao.getIdsForUser(ssc, userId); if (projectIdsForUser.isEmpty()) { return null; } // Query: Project2Source final EntityQuery<Project2Source> project2SourceQuery = new EntityQuery<>(Project2Source.class); project2SourceQuery.addRestriction(Restrictions.in("projectId", projectIdsForUser)); final Collection<Long> sourceIds = project2SourceQuery.listIdsForProperty(ssc, "sourceId"); if (sourceIds.isEmpty()) { return null; } // Query: Source final EntityWithIdQuery<Source> sourceQuery = new EntityWithIdQuery<>(Source.class); sourceQuery.addRestriction(Restrictions.idEq(id)); sourceQuery.addRestriction(Restrictions.in("id", sourceIds)); final Source source = sourceQuery.uniqueObject(ssc); return sourceToDto(ssc, source); }
From source file:com.romeikat.datamessie.core.base.dao.impl.SourceDao.java
License:Open Source License
public List<SourceOverviewDto> getAsOverviewDtos(final SharedSessionContract ssc, final Long userId, final Long projectId, final Long sourceId, final Collection<Long> sourceTypeIds) { if (projectId == null) { return Collections.emptyList(); }/*from w w w.ja v a2s . co m*/ // Restrict to user final Collection<Long> projectIdsForUser = projectDao.getIdsForUser(ssc, userId); if (projectIdsForUser.isEmpty()) { return Collections.emptyList(); } // Query: Project2Source Collection<Long> sourceIds = null; final EntityQuery<Project2Source> project2SourceQuery = new EntityQuery<>(Project2Source.class); project2SourceQuery.addRestriction(Restrictions.eq("projectId", projectId)); project2SourceQuery.addRestriction(Restrictions.in("projectId", projectIdsForUser)); sourceIds = project2SourceQuery.listIdsForProperty(ssc, "sourceId"); if (sourceIds.isEmpty()) { return Collections.emptyList(); } // Query: Source2SourceType Collection<Long> sourceIds2 = null; if (CollectionUtils.isNotEmpty(sourceTypeIds)) { final EntityQuery<Source2SourceType> source2SourceTypeQuery = new EntityQuery<>( Source2SourceType.class); source2SourceTypeQuery.addRestriction(Restrictions.in("sourceTypeId", sourceTypeIds)); sourceIds2 = source2SourceTypeQuery.listIdsForProperty(ssc, "sourceId"); if (sourceIds2.isEmpty()) { return Collections.emptyList(); } } // Query: Source final EntityWithIdQuery<Source> sourceQuery = new EntityWithIdQuery<>(Source.class); if (sourceId != null) { sourceQuery.addRestriction(Restrictions.idEq(sourceId)); } if (sourceIds != null) { sourceQuery.addRestriction(Restrictions.in("id", sourceIds)); } if (sourceIds2 != null) { sourceQuery.addRestriction(Restrictions.in("id", sourceIds2)); } sourceQuery.addOrder(Order.asc("name")); // Done final List<Source> sources = sourceQuery.listObjects(ssc); // Transform final List<SourceOverviewDto> dtos = Lists.transform(sources, s -> sourceToOverviewDto(ssc, s)); return Lists.newArrayList(dtos); }