Java 类org.jooq.SelectQuery 实例源码

项目:jdblender    文件:RunnerJooq.java   
@Override
public Collection<SpareWrapper> getSpares(String label, Boolean flag, Integer numFromInclusive, Integer numToInclusive) throws Exception {
    SelectQuery<Record> query = jooq.selectQuery();
    query.addFrom(Spares.SPARES);

    if (label != null) {
        query.addConditions(Spares.SPARES.LABEL.eq(label));
    }

    if (flag != null) {
        query.addConditions(Spares.SPARES.FLAG.eq(flag));
    }

    if (numFromInclusive != null) {

        if (numToInclusive == null) {
            query.addConditions(Spares.SPARES.NUM.eq(numFromInclusive));
        } else {
            query.addConditions(Spares.SPARES.NUM.ge(numFromInclusive));
            query.addConditions(Spares.SPARES.NUM.le(numToInclusive));
        }
    }

    return query.fetch(SpareWrapper::of);
}
项目:steve-plugsurfing    文件:TransactionRepositoryImpl.java   
@SuppressWarnings("unchecked")
private
SelectQuery<Record8<Integer, String, Integer, String, DateTime, String, DateTime, String>>
getInternalCSV(TransactionQueryForm form) {

    SelectQuery selectQuery = ctx.selectQuery();
    selectQuery.addFrom(TRANSACTION);
    selectQuery.addJoin(CONNECTOR, TRANSACTION.CONNECTOR_PK.eq(CONNECTOR.CONNECTOR_PK));
    selectQuery.addSelect(
            TRANSACTION.TRANSACTION_PK,
            CONNECTOR.CHARGE_BOX_ID,
            CONNECTOR.CONNECTOR_ID,
            TRANSACTION.ID_TAG,
            TRANSACTION.START_TIMESTAMP,
            TRANSACTION.START_VALUE,
            TRANSACTION.STOP_TIMESTAMP,
            TRANSACTION.STOP_VALUE
    );

    return addConditions(selectQuery, form);
}
项目:steve-plugsurfing    文件:TransactionRepositoryImpl.java   
/**
 * Difference from getInternalCSV:
 * Joins with CHARGE_BOX and OCPP_TAG tables, selects CHARGE_BOX_PK and OCPP_TAG_PK additionally
 */
@SuppressWarnings("unchecked")
private
SelectQuery<Record10<Integer, String, Integer, String, DateTime, String, DateTime, String, Integer, Integer>>
getInternal(TransactionQueryForm form) {

    SelectQuery selectQuery = ctx.selectQuery();
    selectQuery.addFrom(TRANSACTION);
    selectQuery.addJoin(CONNECTOR, TRANSACTION.CONNECTOR_PK.eq(CONNECTOR.CONNECTOR_PK));
    selectQuery.addJoin(CHARGE_BOX, CHARGE_BOX.CHARGE_BOX_ID.eq(CONNECTOR.CHARGE_BOX_ID));
    selectQuery.addJoin(OCPP_TAG, OCPP_TAG.ID_TAG.eq(TRANSACTION.ID_TAG));
    selectQuery.addSelect(
            TRANSACTION.TRANSACTION_PK,
            CONNECTOR.CHARGE_BOX_ID,
            CONNECTOR.CONNECTOR_ID,
            TRANSACTION.ID_TAG,
            TRANSACTION.START_TIMESTAMP,
            TRANSACTION.START_VALUE,
            TRANSACTION.STOP_TIMESTAMP,
            TRANSACTION.STOP_VALUE,
            CHARGE_BOX.CHARGE_BOX_PK,
            OCPP_TAG.OCPP_TAG_PK
    );

    return addConditions(selectQuery, form);
}
项目:steve-plugsurfing    文件:TransactionRepositoryImpl.java   
@SuppressWarnings("unchecked")
private SelectQuery addConditions(SelectQuery selectQuery, TransactionQueryForm form) {
    if (form.isTransactionPkSet()) {
        selectQuery.addConditions(TRANSACTION.TRANSACTION_PK.eq(form.getTransactionPk()));
    }

    if (form.isChargeBoxIdSet()) {
        selectQuery.addConditions(CONNECTOR.CHARGE_BOX_ID.eq(form.getChargeBoxId()));
    }

    if (form.isOcppIdTagSet()) {
        selectQuery.addConditions(TRANSACTION.ID_TAG.eq(form.getOcppIdTag()));
    }

    if (form.getType() == TransactionQueryForm.QueryType.ACTIVE) {
        selectQuery.addConditions(TRANSACTION.STOP_TIMESTAMP.isNull());
    }

    processType(selectQuery, form);

    // Default order
    selectQuery.addOrderBy(TRANSACTION.TRANSACTION_PK.desc());

    return selectQuery;
}
项目:steve-plugsurfing    文件:ReservationRepositoryImpl.java   
private void processType(SelectQuery selectQuery, ReservationQueryForm form) {
    switch (form.getPeriodType()) {
        case ACTIVE:
            selectQuery.addConditions(RESERVATION.EXPIRY_DATETIME.greaterThan(CustomDSL.utcTimestamp()));
            break;

        case FROM_TO:
            selectQuery.addConditions(
                    RESERVATION.START_DATETIME.greaterOrEqual(form.getFrom().toDateTime()),
                    RESERVATION.EXPIRY_DATETIME.lessOrEqual(form.getTo().toDateTime())
            );
            break;

        default:
            throw new SteveException("Unknown enum type");
    }
}
项目:daguerreo    文件:BasicJooqRepository.java   
private SelectQuery<R> getQuery(Sort sort) {
    SelectQuery<R> query = dsl.selectFrom(table).getQuery();
    // Do not sort if specified sort condition.
    if (sort == null) {
        return query;
    }
    for (Sort.Order order : sort) {
        // It's currently only allowed column name of lowercase.
        Field<?> field = table.field(name(LOWER_CAMEL.to(LOWER_UNDERSCORE, order.getProperty())));
        if (field == null) {
            // TODO Consider later that can't find the field which has sort condition.
            continue;
        }
        SortField<?> sortField;
        if (order.getDirection() == Sort.Direction.ASC) {
            sortField = field.asc();
        } else {
            sortField = field.desc();
        }
        query.addOrderBy(sortField);
    }
    return query;
}
项目:keywhiz    文件:SecretSeriesDAO.java   
public ImmutableList<SecretSeries> getSecretSeries(@Nullable Long expireMaxTime, Group group) {
  SelectQuery<Record> select = dslContext
      .select().from(SECRETS).join(SECRETS_CONTENT).on(SECRETS.CURRENT.equal(SECRETS_CONTENT.ID))
      .where(SECRETS.CURRENT.isNotNull()).getQuery();

  if (expireMaxTime != null && expireMaxTime > 0) {
    select.addOrderBy(SECRETS_CONTENT.EXPIRY.asc().nullsLast());
    long now = System.currentTimeMillis() / 1000L;
    select.addConditions(SECRETS_CONTENT.EXPIRY.greaterThan(now));
    select.addConditions(SECRETS_CONTENT.EXPIRY.lessOrEqual(expireMaxTime));
  }

  if (group != null) {
    select.addJoin(ACCESSGRANTS, SECRETS.ID.eq(ACCESSGRANTS.SECRETID));
    select.addJoin(GROUPS, GROUPS.ID.eq(ACCESSGRANTS.GROUPID));
    select.addConditions(GROUPS.NAME.eq(group.getName()));
  }
  List<SecretSeries> r = select.fetchInto(SECRETS).map(secretSeriesMapper);
  return ImmutableList.copyOf(r);
}
项目:keywhiz    文件:SecretSeriesDAO.java   
public ImmutableList<SecretSeries> getSecretSeriesBatched(int idx, int num, boolean newestFirst) {
  SelectQuery<Record> select = dslContext
      .select()
      .from(SECRETS)
      .join(SECRETS_CONTENT)
      .on(SECRETS.CURRENT.equal(SECRETS_CONTENT.ID))
      .where(SECRETS.CURRENT.isNotNull())
      .getQuery();
  if (newestFirst) {
    select.addOrderBy(SECRETS.CREATEDAT.desc());
  } else {
    select.addOrderBy(SECRETS.CREATEDAT.asc());
  }
  select.addLimit(idx, num);

  List<SecretSeries> r = select.fetchInto(SECRETS).map(secretSeriesMapper);
  return ImmutableList.copyOf(r);
}
项目:adjule    文件:JooqQuestionsDao.java   
@Override
public List<QuestionView> getQuestions(final QuestionsOptions options) {
    final Integer itemsPerPage = SecurityUtils.getItemsPerPage();
    final SelectQuery<Record> questionSelect = getQuestionSelect(options);

    if (options.isOwnOrPublic()) {
        questionSelect.addConditions(
                QUESTIONS.PRIVATE.eq(false).or(QUESTIONS.USER_ID.eq(getUserId(options.getCurrentUser())))
        );
    }

    if (StringUtils.isNotEmpty(options.getProblemCode())) {
        questionSelect.addConditions(QUESTIONS.TASK_ID.eq(getProblemId(options.getProblemCode())));
    }

    questionSelect.addOrderBy(QUESTIONS.QUESTION_ID.desc());
    questionSelect.addLimit(options.getPage() * itemsPerPage, itemsPerPage);
    return questionSelect.fetch(getQuestionMapper(QuestionContent.WITHOUT_CONTENT));
}
项目:cattle    文件:AuthDaoImpl.java   
@Override
public List<? extends ProjectMember> getProjectMembersByIdentity(long projectId, Set<Identity> identities) {
    Condition allMembers = DSL.falseCondition();
    for (Identity identity : identities) {
        allMembers = allMembers.or(PROJECT_MEMBER.EXTERNAL_ID.eq(identity.getExternalId())
                .and(PROJECT_MEMBER.EXTERNAL_ID_TYPE.eq(identity.getExternalIdType()))
                .and(PROJECT_MEMBER.REMOVED.isNull())
                .and(PROJECT_MEMBER.STATE.eq(CommonStatesConstants.ACTIVE))
                .and(PROJECT_MEMBER.PROJECT_ID.eq(projectId)));
    }
    SelectQuery<Record> query = create().selectQuery();
    query.addFrom(PROJECT_MEMBER);
    query.addConditions(allMembers);
    query.setDistinct(true);
    return query.fetchInto(PROJECT_MEMBER);
}
项目:cloud-cattle    文件:AbstractJooqResourceManager.java   
protected void addMappingJoins(SelectQuery<?> query, Table<?> toTable, SchemaFactory schemaFactory, String fromType, Table<?> from, String asName, MapRelationship rel) {
    Table<?> mappingTable = JooqUtils.getTableFromRecordClass(rel.getMappingType());
    /* We don't required the mapping type to be visible external, that's why we use the schemaFactory
     * from the objectManager, because it is the superset schemaFactory.
     */
    String mappingType = getObjectManager().getSchemaFactory().getSchemaName(rel.getMappingType());

    TableField<?, Object> fieldFrom = JooqUtils.getTableField(getMetaDataManager(), fromType, ObjectMetaDataManager.ID_FIELD);
    TableField<?, Object> fieldTo = JooqUtils.getTableField(getMetaDataManager(), mappingType, rel.getPropertyName());
    TableField<?, Object> fieldRemoved = JooqUtils.getTableField(getMetaDataManager(), mappingType, ObjectMetaDataManager.REMOVED_FIELD);

    org.jooq.Condition cond = fieldFrom.eq(fieldTo.getTable().field(fieldTo.getName())).and(fieldRemoved == null ? DSL.trueCondition() : fieldRemoved.isNull());
    query.addJoin(mappingTable, JoinType.LEFT_OUTER_JOIN, cond);

    fieldFrom = JooqUtils.getTableField(getMetaDataManager(), mappingType, rel.getOtherRelationship().getPropertyName());
    fieldTo = JooqUtils.getTableField(getMetaDataManager(), schemaFactory.getSchemaName(rel.getObjectType()), ObjectMetaDataManager.ID_FIELD);

    cond = fieldFrom.eq(fieldTo.getTable().asTable(asName).field(fieldTo.getName()));
    query.addJoin(toTable, JoinType.LEFT_OUTER_JOIN, cond);
}
项目:cloud-cattle    文件:AbstractJooqResourceManager.java   
protected void addSort(SchemaFactory schemaFactory, String type, Sort sort, SelectQuery<?> query) {
    if ( sort == null ) {
        return;
    }

    TableField<?, Object> sortField = JooqUtils.getTableField(getMetaDataManager(), type, sort.getName());
    if ( sortField == null ) {
        return;
    }

    switch (sort.getOrderEnum()) {
    case DESC:
        query.addOrderBy(sortField.desc());
    default:
        query.addOrderBy(sortField.asc());
    }
}
项目:cloud-cattle    文件:JooqObjectManager.java   
@SuppressWarnings("unchecked")
@Override
protected <T> List<T> getListByRelationshipMap(Object obj, MapRelationship rel) {
    Class<UpdatableRecord<?>> typeClass = JooqUtils.getRecordClass(schemaFactory, rel.getObjectType());

    String mappingType = schemaFactory.getSchemaName(rel.getMappingType());
    String fromType = schemaFactory.getSchemaName(rel.getObjectType());

    TableField<?, Object> fieldFrom = JooqUtils.getTableField(getMetaDataManager(), fromType, ObjectMetaDataManager.ID_FIELD);
    TableField<?, Object> mappingTo = JooqUtils.getTableField(getMetaDataManager(), mappingType, rel.getOtherRelationship().getPropertyName());
    TableField<?, Object> mappingOther = JooqUtils.getTableField(getMetaDataManager(), mappingType, rel.getPropertyName());
    TableField<?, Object> mappingRemoved = JooqUtils.getTableField(getMetaDataManager(), mappingType, ObjectMetaDataManager.REMOVED_FIELD);

    Table<?> table = JooqUtils.getTable(schemaFactory, typeClass);
    Table<?> mapTable = JooqUtils.getTable(schemaFactory, rel.getMappingType());

    SelectQuery<?> query = create().selectQuery();
    query.addFrom(table);
    query.addSelect(table.fields());
    query.addJoin(mapTable, fieldFrom.eq(mappingTo)
            .and(mappingRemoved == null ? DSL.trueCondition() : mappingRemoved.isNull())
            .and(mappingOther.eq(ObjectUtils.getId(obj))));

    return (List<T>)query.fetchInto(typeClass);
}
项目:dstack    文件:AbstractJooqResourceManager.java   
protected void addMappingJoins(SelectQuery<?> query, Table<?> toTable, SchemaFactory schemaFactory, String fromType, Table<?> from, String asName, MapRelationship rel) {
    Table<?> mappingTable = JooqUtils.getTableFromRecordClass(rel.getMappingType());
    String mappingType = schemaFactory.getSchemaName(rel.getMappingType());

    TableField<?, Object> fieldFrom = JooqUtils.getTableField(getMetaDataManager(), fromType, ObjectMetaDataManager.ID_FIELD);
    TableField<?, Object> fieldTo = JooqUtils.getTableField(getMetaDataManager(), mappingType, rel.getPropertyName());
    TableField<?, Object> fieldRemoved = JooqUtils.getTableField(getMetaDataManager(), mappingType, ObjectMetaDataManager.REMOVED_FIELD);

    org.jooq.Condition cond = fieldFrom.eq(fieldTo.getTable().field(fieldTo.getName())).and(fieldRemoved == null ? DSL.trueCondition() : fieldRemoved.isNull());
    query.addJoin(mappingTable, JoinType.LEFT_OUTER_JOIN, cond);

    fieldFrom = JooqUtils.getTableField(getMetaDataManager(), mappingType, rel.getOtherRelationship().getPropertyName());
    fieldTo = JooqUtils.getTableField(getMetaDataManager(), schemaFactory.getSchemaName(rel.getObjectType()), ObjectMetaDataManager.ID_FIELD);

    cond = fieldFrom.eq(fieldTo.getTable().asTable(asName).field(fieldTo.getName()));
    query.addJoin(toTable, JoinType.LEFT_OUTER_JOIN, cond);
}
项目:dstack    文件:AbstractJooqResourceManager.java   
protected void addSort(SchemaFactory schemaFactory, String type, Sort sort, SelectQuery<?> query) {
    if ( sort == null ) {
        return;
    }

    TableField<?, Object> sortField = JooqUtils.getTableField(getMetaDataManager(), type, sort.getName());
    if ( sortField == null ) {
        return;
    }

    switch (sort.getOrderEnum()) {
    case DESC:
        query.addOrderBy(sortField.desc());
    default:
        query.addOrderBy(sortField.asc());
    }
}
项目:dstack    文件:JooqObjectManager.java   
@SuppressWarnings("unchecked")
@Override
protected <T> List<T> getListByRelationshipMap(Object obj, MapRelationship rel) {
    Class<UpdatableRecord<?>> typeClass = JooqUtils.getRecordClass(schemaFactory, rel.getObjectType());

    String mappingType = schemaFactory.getSchemaName(rel.getMappingType());
    String fromType = schemaFactory.getSchemaName(rel.getObjectType());

    TableField<?, Object> fieldFrom = JooqUtils.getTableField(getMetaDataManager(), fromType, ObjectMetaDataManager.ID_FIELD);
    TableField<?, Object> mappingTo = JooqUtils.getTableField(getMetaDataManager(), mappingType, rel.getOtherRelationship().getPropertyName());
    TableField<?, Object> mappingOther = JooqUtils.getTableField(getMetaDataManager(), mappingType, rel.getPropertyName());
    TableField<?, Object> mappingRemoved = JooqUtils.getTableField(getMetaDataManager(), mappingType, ObjectMetaDataManager.REMOVED_FIELD);

    Table<?> table = JooqUtils.getTable(schemaFactory, typeClass);
    Table<?> mapTable = JooqUtils.getTable(schemaFactory, rel.getMappingType());

    SelectQuery<?> query = create().selectQuery();
    query.addFrom(table);
    query.addSelect(table.fields());
    query.addJoin(mapTable, fieldFrom.eq(mappingTo)
            .and(mappingRemoved == null ? DSL.trueCondition() : mappingRemoved.isNull())
            .and(mappingOther.eq(ObjectUtils.getId(obj))));

    return (List<T>)query.fetchInto(typeClass);
}
项目:Ultrastructure    文件:JobModelImpl.java   
private void addMask(SelectQuery<Record> selectQuery, UUID classifier,
                     UUID classification, TableField<?, UUID> field,
                     ExistentialDomain domain) {
    if (classifier.equals(WellKnownRelationship.ANY.id())) {
        if (log.isTraceEnabled()) {
            log.trace("Match ANY {}", field.getName());
        }
        return;
    }
    Condition condition;
    if (classifier.equals(WellKnownRelationship.SAME.id())) {
        condition = field.eq(classification);
        if (log.isTraceEnabled()) {
            log.trace("Match SAME {}", field.getName());
        }
    } else {
        condition = field.in(inferenceSubQuery(classifier, classification));
        if (log.isTraceEnabled()) {
            log.trace("Match on inferrred {}", field.getName());
        }
    }
    condition = condition.or(field.equal(getAnyId(domain)))
                         .or(field.equal(getSameId(domain)))
                         .or(field.equal(getNotApplicable(domain)));
    selectQuery.addConditions(condition);
}
项目:Ultrastructure    文件:JobModelImpl.java   
private void addServiceMask(MetaProtocolRecord metaProtocol, JobRecord job,
                            SelectQuery<Record> selectQuery) {
    if (metaProtocol.getServiceType()
                    .equals(WellKnownRelationship.SAME.id())) {
        selectQuery.addConditions(PROTOCOL.SERVICE.equal(job.getService()));
        if (log.isTraceEnabled()) {
            log.trace("Match SAME service");
        }
    } else {
        selectQuery.addConditions(PROTOCOL.SERVICE.in(inferenceSubQuery(metaProtocol.getServiceType(),
                                                                        job.getService())));
        if (log.isTraceEnabled()) {
            log.trace("Match inferred service");
        }
    }
}
项目:Ultrastructure    文件:JobModelImpl.java   
private void addStatusMask(MetaProtocolRecord metaProtocol, JobRecord job,
                           SelectQuery<Record> selectQuery) {
    if (metaProtocol.getStatus()
                    .equals(WellKnownRelationship.SAME.id())) {
        selectQuery.addConditions(PROTOCOL.STATUS.equal(job.getStatus()));
        if (log.isTraceEnabled()) {
            log.trace("Match on SAME status");
        }
    } else {
        selectQuery.addConditions(PROTOCOL.STATUS.in(inferenceSubQuery(metaProtocol.getStatus(),
                                                                       job.getService())));
        if (log.isTraceEnabled()) {
            log.trace("Match on inferred status");
        }
    }
}
项目:steve    文件:TransactionRepositoryImpl.java   
@SuppressWarnings("unchecked")
private
SelectQuery<Record8<Integer, String, Integer, String, DateTime, String, DateTime, String>>
getInternalCSV(TransactionQueryForm form) {

    SelectQuery selectQuery = ctx.selectQuery();
    selectQuery.addFrom(TRANSACTION);
    selectQuery.addJoin(CONNECTOR, TRANSACTION.CONNECTOR_PK.eq(CONNECTOR.CONNECTOR_PK));
    selectQuery.addSelect(
            TRANSACTION.TRANSACTION_PK,
            CONNECTOR.CHARGE_BOX_ID,
            CONNECTOR.CONNECTOR_ID,
            TRANSACTION.ID_TAG,
            TRANSACTION.START_TIMESTAMP,
            TRANSACTION.START_VALUE,
            TRANSACTION.STOP_TIMESTAMP,
            TRANSACTION.STOP_VALUE
    );

    return addConditions(selectQuery, form);
}
项目:steve    文件:TransactionRepositoryImpl.java   
/**
 * Difference from getInternalCSV:
 * Joins with CHARGE_BOX and OCPP_TAG tables, selects CHARGE_BOX_PK and OCPP_TAG_PK additionally
 */
@SuppressWarnings("unchecked")
private
SelectQuery<Record10<Integer, String, Integer, String, DateTime, String, DateTime, String, Integer, Integer>>
getInternal(TransactionQueryForm form) {

    SelectQuery selectQuery = ctx.selectQuery();
    selectQuery.addFrom(TRANSACTION);
    selectQuery.addJoin(CONNECTOR, TRANSACTION.CONNECTOR_PK.eq(CONNECTOR.CONNECTOR_PK));
    selectQuery.addJoin(CHARGE_BOX, CHARGE_BOX.CHARGE_BOX_ID.eq(CONNECTOR.CHARGE_BOX_ID));
    selectQuery.addJoin(OCPP_TAG, OCPP_TAG.ID_TAG.eq(TRANSACTION.ID_TAG));
    selectQuery.addSelect(
            TRANSACTION.TRANSACTION_PK,
            CONNECTOR.CHARGE_BOX_ID,
            CONNECTOR.CONNECTOR_ID,
            TRANSACTION.ID_TAG,
            TRANSACTION.START_TIMESTAMP,
            TRANSACTION.START_VALUE,
            TRANSACTION.STOP_TIMESTAMP,
            TRANSACTION.STOP_VALUE,
            CHARGE_BOX.CHARGE_BOX_PK,
            OCPP_TAG.OCPP_TAG_PK
    );

    return addConditions(selectQuery, form);
}
项目:steve    文件:TransactionRepositoryImpl.java   
@SuppressWarnings("unchecked")
private SelectQuery addConditions(SelectQuery selectQuery, TransactionQueryForm form) {
    if (form.isTransactionPkSet()) {
        selectQuery.addConditions(TRANSACTION.TRANSACTION_PK.eq(form.getTransactionPk()));
    }

    if (form.isChargeBoxIdSet()) {
        selectQuery.addConditions(CONNECTOR.CHARGE_BOX_ID.eq(form.getChargeBoxId()));
    }

    if (form.isOcppIdTagSet()) {
        selectQuery.addConditions(TRANSACTION.ID_TAG.eq(form.getOcppIdTag()));
    }

    if (form.getType() == TransactionQueryForm.QueryType.ACTIVE) {
        selectQuery.addConditions(TRANSACTION.STOP_TIMESTAMP.isNull());
    }

    processType(selectQuery, form);

    // Default order
    selectQuery.addOrderBy(TRANSACTION.TRANSACTION_PK.desc());

    return selectQuery;
}
项目:steve    文件:ReservationRepositoryImpl.java   
private void processType(SelectQuery selectQuery, ReservationQueryForm form) {
    switch (form.getPeriodType()) {
        case ACTIVE:
            selectQuery.addConditions(RESERVATION.EXPIRY_DATETIME.greaterThan(CustomDSL.utcTimestamp()));
            break;

        case FROM_TO:
            selectQuery.addConditions(
                    RESERVATION.START_DATETIME.greaterOrEqual(form.getFrom().toDateTime()),
                    RESERVATION.EXPIRY_DATETIME.lessOrEqual(form.getTo().toDateTime())
            );
            break;

        default:
            throw new SteveException("Unknown enum type");
    }
}
项目:steve-plugsurfing    文件:TransactionRepositoryImpl.java   
private void processType(SelectQuery selectQuery, TransactionQueryForm form) {
    switch (form.getPeriodType()) {
        case TODAY:
            selectQuery.addConditions(
                    date(TRANSACTION.START_TIMESTAMP).eq(date(CustomDSL.utcTimestamp()))
            );
            break;

        case LAST_10:
        case LAST_30:
        case LAST_90:
            DateTime now = DateTime.now();
            selectQuery.addConditions(
                    date(TRANSACTION.START_TIMESTAMP).between(
                            date(now.minusDays(form.getPeriodType().getInterval())),
                            date(now)
                    )
            );
            break;

        case ALL:
            break;

        case FROM_TO:
            selectQuery.addConditions(
                    TRANSACTION.START_TIMESTAMP.between(form.getFrom().toDateTime(), form.getTo().toDateTime())
            );
            break;

        default:
            throw new SteveException("Unknown enum type");
    }
}
项目:steve-plugsurfing    文件:OcppTagRepositoryImpl.java   
private void processBooleanType(SelectQuery selectQuery,
                                TableField<OcppTagRecord, Boolean> field,
                                OcppTagQueryForm.BooleanType type) {
    switch (type) {
        case ALL:
            break;

        default:
            selectQuery.addConditions(field.eq(type.getBoolValue()));
    }
}
项目:steve-plugsurfing    文件:UserRepositoryImpl.java   
@SuppressWarnings("unchecked")
private Result<Record7<Integer, Integer, String, String, String, String, String>> getOverviewInternal(UserQueryForm form) {
    SelectQuery selectQuery = ctx.selectQuery();
    selectQuery.addFrom(USER);
    selectQuery.addJoin(OCPP_TAG, JoinType.LEFT_OUTER_JOIN, USER.OCPP_TAG_PK.eq(OCPP_TAG.OCPP_TAG_PK));
    selectQuery.addSelect(
            USER.USER_PK,
            USER.OCPP_TAG_PK,
            OCPP_TAG.ID_TAG,
            USER.FIRST_NAME,
            USER.LAST_NAME,
            USER.PHONE,
            USER.E_MAIL
    );

    if (form.isSetUserPk()) {
        selectQuery.addConditions(USER.USER_PK.eq(form.getUserPk()));
    }

    if (form.isSetOcppIdTag()) {
        selectQuery.addConditions(includes(OCPP_TAG.ID_TAG, form.getOcppIdTag()));
    }

    if (form.isSetEmail()) {
        selectQuery.addConditions(includes(USER.E_MAIL, form.getEmail()));
    }

    if (form.isSetName()) {

        // Concatenate the two columns and search within the resulting representation
        // for flexibility, since the user can search by first or last name, or both.
        Field<String> joinedField = DSL.concat(USER.FIRST_NAME, USER.LAST_NAME);

        // Find a matching sequence anywhere within the concatenated representation
        selectQuery.addConditions(includes(joinedField, form.getName()));
    }

    return selectQuery.fetch();
}
项目:daguerreo    文件:BasicJooqRepository.java   
/**
 * {@inheritDoc}
 */
@Override
public List<E> findAll(Sort sort) {
    // TODO Throw exception if the index of the specified columns does not exist.
    SelectQuery<R> query = getQuery(sort);
    return query.fetch().map(mapper());
}
项目:daguerreo    文件:BasicJooqRepository.java   
/**
 * {@inheritDoc}
 */
@Override
public Page<E> findAll(Pageable pageable) {
    if (pageable == null) {
        return new PageImpl<>(findAll());
    }
    SelectQuery<R> query = getQuery(pageable);
    return new PageImpl<>(query.fetch().map(mapper()), pageable, count());
}
项目:tweetarchive    文件:TweetRepositoryImpl.java   
/**
 * Creates a query like
 * <pre>
 * WITH RECURSIVE cte AS (
 *      SELECT id, content FROM tweets WHERE id = ?
 *      UNION ALL
 *      SELECT t.id, t.content
 *      FROM cte c
 *      JOIN tweets t on t.in_reply_to_status_id = c.id
 * ) SELECT * FROM cte
 * </pre>
 *
 * @param id The id of the tweet starting the hierarchy, i.e. 726762141064286208
 * @return
 */
@Override
public List<TweetEntity> getTweetHierarchy(final long id) {
    final SelectQuery<Record> sqlGenerator = this.create
            .withRecursive("cte").as(
                select()
                    .from(TWEETS)
                    .where(TWEETS.ID.eq(id))
               .unionAll(
                select()
                    .from(name("cte"))
                    .join(TWEETS)
                        .on(TWEETS.IN_REPLY_TO_STATUS_ID .eq(field(name("cte", "id"), Long.class)))
                )
            )
            .select()
            .from(name("cte"))
            .orderBy(field(name("cte", TWEETS.CREATED_AT.getName())))
            .getQuery();

    // Retrieve sql with named parameter
    final String sql = sqlGenerator.getSQL(ParamType.NAMED);
    // and create actual hibernate query
    final Query query = this.entityManager.createNativeQuery(sql, TweetEntity.class);
    // fill in parameter
    sqlGenerator.getParams().forEach((n, v) -> query.setParameter(n, v.getValue()));
    // execute query
    return query.getResultList();
}
项目:adjule    文件:JooqProblemListDao.java   
@Override
public ProblemListView getProblems(@Nonnull final ProblemsOptions problemsOptions) {
    final Integer itemsPerPage = SecurityUtils.getItemsPerPage();

    final SelectQuery<Record> query = jooq.selectQuery();
    query.addSelect(TASKS.TASK_ID, TASKS.NAME, TASKS.CODE);
    query.addFrom(TASKS);

    if (!Strings.isNullOrEmpty(problemsOptions.getQuery())) {
        final String lowerQuery = problemsOptions.getQuery().toLowerCase();
        query.addConditions(TASKS.CODE.lower().contains(lowerQuery)
                                      .or(TASKS.NAME.lower().contains(lowerQuery)));
    }

    if (!Strings.isNullOrEmpty(problemsOptions.getAvailableForGroup())) {
        query.addConditions(TASKS.TASK_ID.notIn(
                jooq.select(CONTESTS_TASKS.TASK_ID)
                    .from(CONTESTS_TASKS)
                    .join(CONTESTS).on(CONTESTS.CONTEST_ID.eq(CONTESTS_TASKS.CONTEST_ID))
                    .where(CONTESTS.CODE.eq(problemsOptions.getAvailableForGroup()))
        ));
    }

    query.addOrderBy(TASKS.CODE, TASKS.NAME);

    query.addLimit(problemsOptions.getPage() * itemsPerPage, itemsPerPage);

    List<ProblemView> problems =
            query.fetch()
                 .map(record -> {
                     final ProblemView problem = new ProblemView();
                     problem.setCode(record.getValue(TASKS.CODE));
                     problem.setName(record.getValue(TASKS.NAME));
                     return problem;
                 });
    return new ProblemListView(problems);
}
项目:cattle    文件:JooqResourceListSupport.java   
public Object list(SchemaFactory schemaFactory, String type, Map<Object, Object> criteria, ListOptions options) {
    Class<?> clz = getClass(schemaFactory, type, criteria, true);
    if (clz == null) {
        return null;
    }

    /* Use core schema, parent may not be authorized */
    type = objectManager.getSchemaFactory().getSchemaName(clz);
    Table<?> table = JooqUtils.getTableFromRecordClass(clz);
    Sort sort = options == null ? null : options.getSort();
    Pagination pagination = options == null ? null : options.getPagination();

    if (table == null)
        return null;

    SelectQuery<?> query = create().selectQuery();
    query.addFrom(table);
    addSort(schemaFactory, type, sort, query);

    addConditions(schemaFactory, query, type, table, criteria);
    addLimit(schemaFactory, type, pagination, query);

    List<?> result = query.fetch();
    processPaginationResult(result, pagination);

    return result;
}
项目:cattle    文件:JooqResourceListSupport.java   
protected void addConditions(SchemaFactory schemaFactory, SelectQuery<?> query, String type, Table<?> table, Map<Object, Object> criteria) {
    org.jooq.Condition condition = JooqUtils.toConditions(metaDataManager, type, criteria);

    if (condition != null) {
        query.addConditions(condition);
    }
}
项目:cattle    文件:JooqResourceListSupport.java   
protected void addLimit(SchemaFactory schemaFactory, String type, Pagination pagination, SelectQuery<?> query) {
    if (pagination == null || pagination.getLimit() == null) {
        return;
    }

    int limit = pagination.getLimit() + 1;
    int offset = getOffset(pagination);
    query.addLimit(offset, limit);
}
项目:cattle    文件:JooqResourceListSupport.java   
protected void addSort(SchemaFactory schemaFactory, String type, Sort sort, SelectQuery<?> query) {
    if (sort != null) {
        TableField<?, Object> sortField = JooqUtils.getTableField(metaDataManager, type, sort.getName());
        if (sortField == null) {
            return;
        }

        switch (sort.getOrderEnum()) {
            case DESC:
                query.addOrderBy(sortField.desc());
                break;
            default:
                query.addOrderBy(sortField.asc());
        }
    }

    TableField<?, Object> idSort = JooqUtils.getTableField(metaDataManager, type, ObjectMetaDataManager.ID_FIELD);
    if (idSort == null) {
        return;
    }

    if (sort != null) {
        switch (sort.getOrderEnum()) {
            case DESC:
                query.addOrderBy(idSort.desc());
                break;
            default:
                query.addOrderBy(idSort.asc());
        }
    }
    else {
        query.addOrderBy(idSort.asc());
    }
}
项目:cloud-cattle    文件:AbstractJooqResourceManager.java   
protected Object listInternal(SchemaFactory schemaFactory, String type, Map<Object, Object> criteria, ListOptions options,
        Map<Table<?>,Condition> joins) {
    Class<?> clz = getClass(schemaFactory, type, criteria, true);
    if ( clz == null ) {
        return null;
    }

    /* Use core schema, parent may not be authorized */
    type = getObjectManager().getSchemaFactory().getSchemaName(clz);
    Table<?> table = JooqUtils.getTableFromRecordClass(clz);
    Sort sort = options == null ? null : options.getSort();
    Pagination pagination = options == null ? null : options.getPagination();
    Include include = options ==null ? null : options.getInclude();

    if ( table == null )
        return null;

    SelectQuery<?> query = create().selectQuery();
    MultiTableMapper mapper = addTables(schemaFactory, query, type, table, criteria, include, pagination, joins);
    addJoins(query, joins);
    addConditions(schemaFactory, query, type, table, criteria);
    addSort(schemaFactory, type, sort, query);
    addLimit(schemaFactory, type, pagination, query);

    List<?> result = mapper == null ? query.fetch() : query.fetchInto(mapper);

    processPaginationResult(result, pagination, mapper);

    return result;
}
项目:cloud-cattle    文件:AbstractJooqResourceManager.java   
protected void addJoins(SelectQuery<?> query, Map<Table<?>, Condition> joins) {
    if ( joins == null ) {
        return;
    }

    for ( Map.Entry<Table<?>, Condition> entry : joins.entrySet() ) {
        query.addJoin(entry.getKey(), JoinType.LEFT_OUTER_JOIN, entry.getValue());
    }
}
项目:cloud-cattle    文件:AbstractJooqResourceManager.java   
protected void addConditions(SchemaFactory schemaFactory, SelectQuery<?> query, String type, Table<?> table, Map<Object, Object> criteria) {
    org.jooq.Condition condition = JooqUtils.toConditions(getMetaDataManager(), type, criteria);

    if ( condition != null ) {
        query.addConditions(condition);
    }
}
项目:cloud-cattle    文件:AbstractJooqResourceManager.java   
protected void addLimit(SchemaFactory schemaFactory, String type, Pagination pagination, SelectQuery<?> query) {
    if ( pagination == null || pagination.getLimit() == null ) {
        return;
    }

    int limit = pagination.getLimit() + 1;
    int offset = getOffset(pagination);
    query.addLimit(offset, limit);
}
项目:dstack    文件:AbstractJooqResourceManager.java   
protected Object listInternal(SchemaFactory schemaFactory, String type, Map<Object, Object> criteria, ListOptions options,
        Map<Table<?>,Condition> joins) {
    Class<?> clz = getClass(schemaFactory, type, criteria, true);
    if ( clz == null ) {
        return null;
    }

    type = schemaFactory.getSchemaName(clz);
    Table<?> table = JooqUtils.getTableFromRecordClass(clz);
    Sort sort = options == null ? null : options.getSort();
    Pagination pagination = options == null ? null : options.getPagination();
    Include include = options ==null ? null : options.getInclude();

    if ( table == null )
        return null;

    SelectQuery<?> query = create().selectQuery();
    MultiTableMapper mapper = addTables(schemaFactory, query, type, table, criteria, include, pagination, joins);
    addJoins(query, joins);
    addConditions(schemaFactory, query, type, table, criteria);
    addSort(schemaFactory, type, sort, query);
    addLimit(schemaFactory, type, pagination, query);

    List<?> result = mapper == null ? query.fetch() : query.fetchInto(mapper);

    processPaginationResult(result, pagination, mapper);

    return result;
}
项目:dstack    文件:AbstractJooqResourceManager.java   
protected void addJoins(SelectQuery<?> query, Map<Table<?>, Condition> joins) {
    if ( joins == null ) {
        return;
    }

    for ( Map.Entry<Table<?>, Condition> entry : joins.entrySet() ) {
        query.addJoin(entry.getKey(), JoinType.LEFT_OUTER_JOIN, entry.getValue());
    }
}