Search in sources :

Example 51 with Tuple

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);
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) Tuple(com.querydsl.core.Tuple) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Example 52 with Tuple

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());
}
Also used : SubQueryExpression(com.querydsl.core.types.SubQueryExpression) QSurvey(com.querydsl.sql.domain.QSurvey) Tuple(com.querydsl.core.Tuple) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 53 with Tuple

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);
}
Also used : Path(com.querydsl.core.types.Path) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) RootUpdateContext(com.evolveum.midpoint.repo.sqale.update.RootUpdateContext) QObject(com.evolveum.midpoint.repo.sqale.qmodel.object.QObject) Tuple(com.querydsl.core.Tuple)

Example 54 with Tuple

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);
}
Also used : MObject(com.evolveum.midpoint.repo.sqale.qmodel.object.MObject) QObject(com.evolveum.midpoint.repo.sqale.qmodel.object.QObject) Tuple(com.querydsl.core.Tuple)

Example 55 with Tuple

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());
    }
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) Tuple(com.querydsl.core.Tuple)

Aggregations

Tuple (com.querydsl.core.Tuple)55 Test (org.junit.Test)41 ExcludeIn (com.querydsl.core.testutil.ExcludeIn)10 Pair (com.mysema.commons.lang.Pair)7 QTuple (com.querydsl.core.types.QTuple)6 Expression (com.querydsl.core.types.Expression)4 StringPath (com.querydsl.core.types.dsl.StringPath)4 AbstractBaseTest (com.querydsl.sql.AbstractBaseTest)4 QCat (com.querydsl.jpa.domain.QCat)3 SAnimal (com.querydsl.jpa.domain.sql.SAnimal)3 QEmployee (com.querydsl.sql.domain.QEmployee)3 ArrayList (java.util.ArrayList)3 Ignore (org.junit.Ignore)3 QObject (com.evolveum.midpoint.repo.sqale.qmodel.object.QObject)2 ResultListRowTransformer (com.evolveum.midpoint.repo.sqlbase.mapping.ResultListRowTransformer)2 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 QueryMetadata (com.querydsl.core.QueryMetadata)2 Group (com.querydsl.core.group.Group)2