static Collection<? extends TableLike<?>> tables(final ColumnPermutation... columns) { return Arrays.stream(columns) .flatMap(columnPermutation -> columnPermutation.getColumnIdentifiers().stream()) .map(ColumnIdentifier::getTableIdentifier) .distinct() .map(DSL::name).map(DSL::table) .collect(toList()); }
@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())) .statusTimestamp(r.value4()) .status(r.value5()) .errorCode(r.value6()) .build() ); }
/** * A customized version of {@link ChargePointRepositoryImpl#getChargePointConnectorStatus()} * for this specific use case. */ @Override public List<ConnectorPostStatus> getChargePointConnectorStatus(String chargeBoxId) { // 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(CONNECTOR.CONNECTOR_PK, CONNECTOR_STATUS.STATUS) .from(CONNECTOR_STATUS) .join(CONNECTOR) .onKey() .join(CHARGE_BOX) .on(CHARGE_BOX.CHARGE_BOX_ID.eq(CONNECTOR.CHARGE_BOX_ID)) .join(PS_CHARGEBOX) .on(PS_CHARGEBOX.CHARGE_BOX_PK.eq(CHARGE_BOX.CHARGE_BOX_PK)) .join(t1) .on(CONNECTOR_STATUS.CONNECTOR_PK.equal(t1.field(t1Pk))) .and(CONNECTOR_STATUS.STATUS_TIMESTAMP.equal(t1.field(t1Max))) .where(CONNECTOR.CONNECTOR_ID.notEqual(0)) .and(CHARGE_BOX.CHARGE_BOX_ID.eq(chargeBoxId)) .fetch() .map(r -> buildStatus(r.value1(), r.value2())); }
public SelectBuilder<T> withJoinCondition(TableLike<?> table, Condition condition) { joinConditions.add(new JoinCondition(table, condition)); if (factory instanceof DefaultFieldFactory) { factory = new TableQualifiedFieldFactory(); } return this; }
public SelectBuilder<T> withLeftJoinCondition(TableLike<?> table, Condition condition) { joinConditions.add(new JoinCondition(table, condition, true)); if (factory instanceof DefaultFieldFactory) { factory = new TableQualifiedFieldFactory(); } return this; }
@Override protected TableLike<?> from() { return this.from; }
public JoinCondition(TableLike<?> table, Condition condition, boolean leftJoin) { this.table = table; this.condition = condition; this.leftJoin = leftJoin; }
public JoinCondition(TableLike<?> table, Condition condition) { this(table, condition, false); }
public TableLike<?> getTable() { return table; }