Java Examples for com.querydsl.core.Tuple
The following java examples will help you to understand the usage of com.querydsl.core.Tuple. These source code samples are taken from different open source projects.
Example 1
| Project: querydsl-master File: SQLSerializerTest.java View source code |
@Test
public void complex_subQuery() {
// create sub queries
List<SubQueryExpression<Tuple>> sq = new ArrayList<SubQueryExpression<Tuple>>();
String[] strs = new String[] { "a", "b", "c" };
for (String str : strs) {
Expression<Boolean> alias = Expressions.cases().when(survey.name.eq(str)).then(true).otherwise(false);
sq.add(select(survey.name, alias).from(survey).distinct());
}
// master query
PathBuilder<Tuple> subAlias = new PathBuilder<Tuple>(Tuple.class, "sub");
SubQueryExpression<?> master = selectOne().from(union(sq).as(subAlias)).groupBy(subAlias.get("prop1"));
SQLSerializer serializer = new SQLSerializer(Configuration.DEFAULT);
serializer.serialize(master.getMetadata(), false);
System.err.println(serializer);
}Example 2
| Project: commafeed-master File: FeedEntryStatusDAO.java View source code |
public List<FeedEntryStatus> findBySubscriptions(User user, List<FeedSubscription> subs, boolean unreadOnly, List<FeedEntryKeyword> keywords, Date newerThan, int offset, int limit, ReadingOrder order, boolean includeContent, boolean onlyIds, String tag) {
int capacity = offset + limit;
Comparator<FeedEntryStatus> comparator;
if (order == ReadingOrder.desc) {
comparator = STATUS_COMPARATOR_DESC;
} else if (order == ReadingOrder.abc) {
comparator = STATUS_COMPARATOR_ABC;
} else if (order == ReadingOrder.zyx) {
comparator = STATUS_COMPARATOR_ZYX;
} else {
comparator = STATUS_COMPARATOR_ASC;
}
FixedSizeSortedSet<FeedEntryStatus> set = new FixedSizeSortedSet<FeedEntryStatus>(capacity, comparator);
for (FeedSubscription sub : subs) {
FeedEntryStatus last = (order != null && set.isFull()) ? set.last() : null;
HibernateQuery<FeedEntry> query = buildQuery(user, sub, unreadOnly, keywords, newerThan, -1, capacity, order, last, tag);
List<Tuple> tuples = query.select(entry.id, entry.updated, status.id, entry.content.title).fetch();
for (Tuple tuple : tuples) {
Long id = tuple.get(entry.id);
Date updated = tuple.get(entry.updated);
Long statusId = tuple.get(status.id);
FeedEntryContent content = new FeedEntryContent();
content.setTitle(tuple.get(entry.content.title));
FeedEntry entry = new FeedEntry();
entry.setId(id);
entry.setUpdated(updated);
entry.setContent(content);
FeedEntryStatus status = new FeedEntryStatus();
status.setId(statusId);
status.setEntryUpdated(updated);
status.setEntry(entry);
status.setSubscription(sub);
set.add(status);
}
}
List<FeedEntryStatus> placeholders = set.asList();
int size = placeholders.size();
if (size < offset) {
return new ArrayList<>();
}
placeholders = placeholders.subList(Math.max(offset, 0), size);
List<FeedEntryStatus> statuses = null;
if (onlyIds) {
statuses = placeholders;
} else {
statuses = new ArrayList<>();
for (FeedEntryStatus placeholder : placeholders) {
Long statusId = placeholder.getId();
FeedEntry entry = feedEntryDAO.findById(placeholder.getEntry().getId());
FeedEntryStatus status = handleStatus(user, statusId == null ? null : findById(statusId), placeholder.getSubscription(), entry);
status = fetchTags(user, status);
statuses.add(status);
}
statuses = lazyLoadContent(includeContent, statuses);
}
return statuses;
}Example 3
| Project: owsi-core-parent-master File: StatisticDaoImpl.java View source code |
@Override
public Table<UserGender, Date, Integer> getUserCreationCountByGenderByWeekStatistics(Range<Date> dateRange) {
final DateDiscreteDomain domain = DateDiscreteDomain.weeks();
dateRange = domain.alignOut(dateRange);
return new JPAQuery<>(getEntityManager()).from(QUser.user).groupBy(QUser.user.gender, QUser.user.creationDate).where(Expressions2.inRange(QUser.user.creationDate, dateRange)).orderBy(QUser.user.gender.asc(), QUser.user.creationDate.asc()).transform(GroupBy2.transformer(GroupBy2.table(QUser.user.gender, new MappingProjection<Date>(Date.class, QUser.user.creationDate) {
private static final long serialVersionUID = 1L;
@Override
protected Date map(Tuple row) {
return domain.alignPrevious(row.get(0, Date.class));
}
}, /**
* We sum twice: once in the SQL query (for each date) and once in Java (for each week).
* We could have summed only in Java, but it would be less optimized if
* many user are created each day.
* The even better solution would have been to group by week in the SQL query,
* but unfortunately it's not easy to do with JPQL.
*/
GroupBy.sum(QUser.user.count().intValue()))));
}Example 4
| Project: timetracker-master File: ProjectSummaryReportQueryBuilder.java View source code |
@Override
public List<ProjectSummaryDTO> call(final Connection connection, final Configuration configuration) throws SQLException {
NumberPath<Long> fromProjectIdPath = Expressions.numberPath(Long.class, new PathMetadata(null, "fromProjectId", PathType.VARIABLE));
NumberPath<Long> timeOriginalSumPath = Expressions.numberPath(Long.class, new PathMetadata(null, ProjectSummaryDTO.AliasNames.ISSUE_TIME_ORIGINAL_ESTIMATE_SUM, PathType.VARIABLE));
NumberPath<Long> timeEstimateSumPath = Expressions.numberPath(Long.class, new PathMetadata(null, ProjectSummaryDTO.AliasNames.ISSUE_TIME_ESTIMATE_SUM, PathType.VARIABLE));
NumberPath<Long> workloggedSumPath = Expressions.numberPath(Long.class, new PathMetadata(null, ProjectSummaryDTO.AliasNames.WORKLOGGED_TIME_SUM, PathType.VARIABLE));
NumberPath<Long> timeOriginalIssueSumPath = Expressions.numberPath(Long.class, new PathMetadata(null, "timeOriginalIssueSumPath", PathType.VARIABLE));
NumberPath<Long> timeEstimateIssueSumPath = Expressions.numberPath(Long.class, new PathMetadata(null, "timeEstimateIssueSumPath", PathType.VARIABLE));
NumberPath<Long> workloggedIssueSumPath = Expressions.numberPath(Long.class, new PathMetadata(null, "workloggedIssueSumPath", PathType.VARIABLE));
SQLQuery<Tuple> fromQuery = SQLExpressions.select(qProject.id.as(fromProjectIdPath), qIssue.timeoriginalestimate.min().as(timeOriginalIssueSumPath), qIssue.timeestimate.min().as(timeEstimateIssueSumPath), qWorklog.timeworked.sum().as(workloggedIssueSumPath));
appendBaseFromAndJoin(fromQuery);
appendBaseWhere(fromQuery);
fromQuery.groupBy(qProject.id, qIssue.id);
QProject qProject = new QProject("m_project");
SQLQuery<ProjectSummaryDTO> query = new SQLQuery<ProjectSummaryDTO>(connection, configuration).select(Projections.bean(ProjectSummaryDTO.class, qProject.pkey.as(ProjectSummaryDTO.AliasNames.PROJECT_KEY), qProject.pname.as(ProjectSummaryDTO.AliasNames.PROJECT_NAME), timeOriginalIssueSumPath.sum().as(timeOriginalSumPath), timeEstimateIssueSumPath.sum().as(timeEstimateSumPath), workloggedIssueSumPath.sum().as(workloggedSumPath))).from(fromQuery.as("sums")).join(qProject).on(qProject.id.eq(fromProjectIdPath)).groupBy(fromProjectIdPath, qProject.pkey, qProject.pname).orderBy(qProject.pkey.asc());
appendQueryRange(query);
List<ProjectSummaryDTO> fetch = query.fetch();
if ((fetch.size() == 1) && (fetch.get(0).getProjectKey() == null)) {
return Collections.emptyList();
}
return fetch;
}Example 5
| Project: parkandrideAPI-master File: FacilityDao.java View source code |
@Override
protected Port map(Tuple row) {
Boolean entry = row.get(qPort.entry);
if (entry == null) {
return null;
}
Point location = row.get(qPort.location);
boolean exit = row.get(qPort.exit);
boolean pedestrian = row.get(qPort.pedestrian);
boolean bicycle = row.get(qPort.bicycle);
Port port = new Port(location, entry, exit, pedestrian, bicycle);
port.address = addressMapping.map(row);
port.info = portInfoMapping.map(row);
return port;
}Example 6
| Project: javersion-master File: AbstractVersionStoreJdbc.java View source code |
protected FetchResults<Id, M> fetch(List<Group> versionsAndParents, boolean optimized, BooleanExpression predicate) {
if (versionsAndParents.isEmpty()) {
return noResults;
}
Map<Revision, List<Tuple>> properties = fetchProperties(optimized, predicate);
ListMultimap<Id, ObjectVersion<M>> results = ArrayListMultimap.create();
Revision latestRevision = null;
for (Group versionAndParents : versionsAndParents) {
Id id = versionAndParents.getOne(options.version.docId);
latestRevision = versionAndParents.getOne(options.version.revision);
Map<PropertyPath, Object> changeset = toChangeSet(properties.get(latestRevision));
results.put(id, buildVersion(latestRevision, versionAndParents, changeset));
}
return new FetchResults<>(results, latestRevision);
}