final FieldList getSelect1() { if (getSelect0().isEmpty()) { FieldList result = new SelectFieldList(); // [#109] [#489]: SELECT * is only applied when at least one table // from the table source is "unknown", i.e. not generated from a // physical table. Otherwise, the fields are selected explicitly if (knownTableSource()) { for (TableLike<?> table : getFrom()) { for (Field<?> field : table.asTable().fields()) { result.add(field); } } } // The default is SELECT 1, when projections and table sources are // both empty if (getFrom().isEmpty()) { result.add(one()); } return result; } return getSelect0(); }
@Override public List<ConnectorStatus> getChargePointConnectorStatus() { // Prepare for the inner select of the second join Field<Integer> t1Pk = CONNECTOR_STATUS.CONNECTOR_PK.as("t1_pk"); Field<DateTime> t1Max = DSL.max(CONNECTOR_STATUS.STATUS_TIMESTAMP).as("t1_max"); TableLike<?> t1 = ctx.select(t1Pk, t1Max) .from(CONNECTOR_STATUS) .groupBy(CONNECTOR_STATUS.CONNECTOR_PK) .asTable("t1"); return ctx.select( CHARGE_BOX.CHARGE_BOX_PK, CONNECTOR.CHARGE_BOX_ID, CONNECTOR.CONNECTOR_ID, CONNECTOR_STATUS.STATUS_TIMESTAMP, CONNECTOR_STATUS.STATUS, CONNECTOR_STATUS.ERROR_CODE) .from(CONNECTOR_STATUS) .join(CONNECTOR) .onKey() .join(CHARGE_BOX) .on(CHARGE_BOX.CHARGE_BOX_ID.eq(CONNECTOR.CHARGE_BOX_ID)) .join(t1) .on(CONNECTOR_STATUS.CONNECTOR_PK.equal(t1.field(t1Pk))) .and(CONNECTOR_STATUS.STATUS_TIMESTAMP.equal(t1.field(t1Max))) .orderBy(CONNECTOR_STATUS.STATUS_TIMESTAMP.desc()) .fetch() .map( r -> ConnectorStatus.builder() .chargeBoxPk(r.value1()) .chargeBoxId(r.value2()) .connectorId(r.value3()) .timeStamp(DateTimeUtils.humanize(r.value4())) .status(r.value5()) .errorCode(r.value6()) .build()); }
SelectQueryImpl(Configuration configuration, TableLike<? extends R> from, boolean distinct) { super(configuration); this.distinct = distinct; this.select = new SelectFieldList(); this.from = new TableList(); this.condition = new ConditionProviderImpl(); this.connectBy = new ConditionProviderImpl(); this.connectByStartWith = new ConditionProviderImpl(); this.groupBy = new QueryPartList<GroupField>(); this.having = new ConditionProviderImpl(); this.orderBy = new SortFieldList(); this.limit = new Limit(); if (from != null) { this.from.add(from.asTable()); } this.forUpdateOf = new FieldList(); this.forUpdateOfTables = new TableList(); }
@Override public final void addFrom(Collection<? extends TableLike<?>> f) { for (TableLike<?> provider : f) { getFrom().add(provider.asTable()); } }