use of com.querydsl.core.Tuple in project querydsl by querydsl.
the class InsertBase method insert_dates.
@Test
// https://bitbucket.org/xerial/sqlite-jdbc/issue/133/prepstmtsetdate-int-date-calendar-seems
@ExcludeIn({ CUBRID, SQLITE })
public void insert_dates() {
QDateTest dateTest = QDateTest.qDateTest;
LocalDate localDate = new LocalDate(1978, 1, 2);
Path<LocalDate> localDateProperty = ExpressionUtils.path(LocalDate.class, "DATE_TEST");
Path<DateTime> dateTimeProperty = ExpressionUtils.path(DateTime.class, "DATE_TEST");
SQLInsertClause insert = insert(dateTest);
insert.set(localDateProperty, localDate);
insert.execute();
Tuple result = query().from(dateTest).select(dateTest.dateTest.year(), dateTest.dateTest.month(), dateTest.dateTest.dayOfMonth(), dateTimeProperty).fetchFirst();
assertEquals(Integer.valueOf(1978), result.get(0, Integer.class));
assertEquals(Integer.valueOf(1), result.get(1, Integer.class));
assertEquals(Integer.valueOf(2), result.get(2, Integer.class));
DateTime dateTime = result.get(dateTimeProperty);
if (target == CUBRID) {
// XXX Cubrid adds random milliseconds for some reason
dateTime = dateTime.withMillisOfSecond(0);
}
assertEquals(localDate.toDateTimeAtStartOfDay(), dateTime);
}
use of com.querydsl.core.Tuple in project querydsl by querydsl.
the class ListSubQueryTest method hashCode1.
@Test
public void hashCode1() {
QSurvey survey = QSurvey.survey;
QSurvey survey2 = new QSurvey("survey2");
SubQueryExpression<Tuple> query1 = select(survey.all()).from(survey);
SubQueryExpression<Tuple> query2 = select(survey2.all()).from(survey2);
Set<SubQueryExpression<Tuple>> queries = new HashSet<>();
queries.add(query1);
queries.add(query2);
assertEquals(2, queries.size());
}
use of com.querydsl.core.Tuple in project midpoint by Evolveum.
the class SqaleRepositoryService method prepareUpdateContext.
/**
* Read object for update and returns update context that contains it with specific get options.
*/
private <S extends ObjectType, Q extends QObject<R>, R extends MObject> RootUpdateContext<S, Q, R> prepareUpdateContext(@NotNull JdbcSession jdbcSession, @NotNull Class<S> schemaType, @NotNull UUID oid, Collection<SelectorOptions<GetOperationOptions>> getOptions, RepoModifyOptions options) throws SchemaException, ObjectNotFoundException {
SqaleTableMapping<S, QObject<R>, R> rootMapping = sqlRepoContext.getMappingBySchemaType(schemaType);
QObject<R> entityPath = rootMapping.defaultAlias();
Path<?>[] selectExpressions = ObjectArrays.concat(rootMapping.selectExpressions(entityPath, getOptions), entityPath.containerIdSeq);
Tuple result = jdbcSession.newQuery().select(selectExpressions).from(entityPath).where(entityPath.oid.eq(oid)).forUpdate().fetchOne();
if (result == null || result.get(entityPath.fullObject) == null) {
throw new ObjectNotFoundException(schemaType, oid.toString());
}
S object = rootMapping.toSchemaObject(result, entityPath, getOptions, jdbcSession, RepoModifyOptions.isForceReindex(options));
R rootRow = rootMapping.newRowObject();
rootRow.oid = oid;
rootRow.containerIdSeq = result.get(entityPath.containerIdSeq);
// This column is generated, some sub-entities need it, but we can't push it to DB.
rootRow.objectType = MObjectType.fromSchemaType(object.getClass());
return new RootUpdateContext<>(sqlRepoContext, jdbcSession, object, rootRow);
}
use of com.querydsl.core.Tuple in project midpoint by Evolveum.
the class SqaleRepositoryService method readByOid.
/**
* Read object using provided {@link JdbcSession} as a part of already running transaction.
*/
private <S extends ObjectType> S readByOid(@NotNull JdbcSession jdbcSession, @NotNull Class<S> schemaType, @NotNull UUID oid, Collection<SelectorOptions<GetOperationOptions>> options) throws SchemaException, ObjectNotFoundException {
SqaleTableMapping<S, QObject<MObject>, MObject> rootMapping = sqlRepoContext.getMappingBySchemaType(schemaType);
QObject<MObject> root = rootMapping.defaultAlias();
Tuple result = jdbcSession.newQuery().from(root).select(rootMapping.selectExpressions(root, options)).where(root.oid.eq(oid)).fetchOne();
if (result == null || result.get(root.fullObject) == null) {
throw new ObjectNotFoundException(schemaType, oid.toString());
}
return rootMapping.toSchemaObject(result, root, options, jdbcSession, false);
}
use of com.querydsl.core.Tuple in project midpoint by Evolveum.
the class QAccessCertificationCampaignMapping method loadCases.
private void loadCases(AccessCertificationCampaignType base, Collection<SelectorOptions<GetOperationOptions>> options, @NotNull JdbcSession jdbcSession, boolean forceFull) throws SchemaException {
QAccessCertificationCaseMapping casesMapping = QAccessCertificationCaseMapping.getAccessCertificationCaseMapping();
PrismContainer<AccessCertificationCaseType> cases = base.asPrismObject().findOrCreateContainer(F_CASE);
QAccessCertificationCase qcase = casesMapping.defaultAlias();
var query = jdbcSession.newQuery().from(qcase).select(casesMapping.selectExpressions(qcase, options)).where(qcase.ownerOid.eq(SqaleUtils.oidToUUid(base.getOid())));
// Load all / changed containers
Collection<Long> idsToFetch = casesToFetch(options);
if (forceFull || idsToFetch == null) {
// Noop, no need to add additional condition
// we are fetching all cases
cases.setIncomplete(false);
} else if (idsToFetch.isEmpty()) {
return;
} else {
// We fetch only containers explicitly mentioned in retrieve options
query = query.where(qcase.cid.in(idsToFetch));
}
List<Tuple> rows = query.fetch();
for (Tuple row : rows) {
AccessCertificationCaseType c = casesMapping.toSchemaObject(row, qcase, options, jdbcSession, forceFull);
cases.add(c.asPrismContainerValue());
}
}
Aggregations