/** * Fetches all {@link Locale}s for which {@link ContentSource}s * of the given {@link Provider} are available. * * @param providerId * @return a List (never null) with the {@link Locale}s. */ public List<Locale> getLocalesOfProvider(final int providerId) { final Result<Record1<String>> result = DSL.using(jooqConfig). select(TABLE.LOCALE). from(TABLE). where(TABLE.PROVIDER_ID.eq(providerId)). groupBy(TABLE.LOCALE). fetch(); final List<Locale> locales = new ArrayList<>(); for (final String localeStr : result.getValues(TABLE.LOCALE)) { locales.add(LocaleUtil.toLocale(localeStr)); } return locales; }
/** * Returns the user id for the given username. * @param username the username to find the {@link User}. * @return the id of the {@link User}. */ private long getIdForUsername(final String username) { final Record1<Long> idRecord = DSL.using(jooqConfig). select(TABLE.ID). from(TABLE). where(TABLE.USERNAME.eq(username)). fetchOne(); if(idRecord == null) { return 0; } return idRecord.getValue(TABLE.ID); }
/** * Checks if a {@link User} exists with the given value in the given field. * @return <code>true</code> if a {@link User} exists. */ @Override public boolean recordExists(final String fieldName, final Object value) { final Record1<Integer> count = DSL.using(jooqConfig). select(DSL.count()). from(TABLE). where(DSL.fieldByName(fieldName).eq(value)). fetchOne(); return count.getValue(0, int.class) > 0; }
/** * Returns the greatest news id. * Can be used to get the auto incremented value after a {@link News} was inserted. */ private long getLastId() { final Record1<Long> result = DSL.using(jooqConfig). select(TABLE_CONTENT.ID). from(TABLE_CONTENT). orderBy(TABLE_CONTENT.ID.desc()). limit(0, 1). fetchOne(); return result == null ? 0 : result.getValue(TABLE_CONTENT.ID); }
@Override public void updateTransaction(UpdateTransactionParams p) { // ------------------------------------------------------------------------- // Step 1: Update transaction table // // After update, a DB trigger sets the user.inTransaction field to 0 // ------------------------------------------------------------------------- ctx.update(TRANSACTION) .set(TRANSACTION.STOP_TIMESTAMP, p.getStopTimestamp()) .set(TRANSACTION.STOP_VALUE, p.getStopMeterValue()) .where(TRANSACTION.TRANSACTION_PK.equal(p.getTransactionId())) .and(TRANSACTION.STOP_TIMESTAMP.isNull()) .and(TRANSACTION.STOP_VALUE.isNull()) .execute(); // ------------------------------------------------------------------------- // Step 2: Set connector status back to "Available" again // ------------------------------------------------------------------------- SelectConditionStep<Record1<Integer>> connectorPkQuery = DSL.select(TRANSACTION.CONNECTOR_PK) .from(TRANSACTION) .where(TRANSACTION.TRANSACTION_PK.equal(p.getTransactionId())); insertConnectorStatus(connectorPkQuery, p.getStopTimestamp(), p.getStatusUpdate()); }
@Override public boolean isRegistered(String chargeBoxId) { Record1<Integer> r = ctx.selectOne() .from(CHARGE_BOX) .where(CHARGE_BOX.CHARGE_BOX_ID.eq(chargeBoxId)) .fetchOne(); return (r != null) && (r.value1() == 1); }
@Override public Optional<String> getOcppIdTag(String evcoId) { Record1<String> record = ctx.select(OCPP_TAG.ID_TAG) .from(PS_EVCO_ID) .join(OCPP_TAG).on(PS_EVCO_ID.OCPP_ID_TAG.eq(OCPP_TAG.ID_TAG)) .where(PS_EVCO_ID.EVCO_ID.eq(evcoId)) .fetchOne(); return getOptional(record); }
private static Optional<String> getOptional(Record1<String> record) { if (record == null) { return Optional.absent(); } else { return Optional.fromNullable(record.value1()); } }
@Override public String getOcppTagOfActiveTransaction(int transactionPK) { Record1<String> record = ctx.select(TRANSACTION.ID_TAG) .from(TRANSACTION) .where(TRANSACTION.TRANSACTION_PK.eq(transactionPK)) .and(TRANSACTION.STOP_TIMESTAMP.isNull()) .and(TRANSACTION.STOP_VALUE.isNull()) .fetchOne(); if (record == null) { return null; } return record.value1(); }
@Override public Optional<Integer> getSessionPkFromTransactionPk(int transactionPK) { Record1<Integer> record = ctx.select(PS_SESSION.PS_SESSION_PK) .from(PS_SESSION) .where(PS_SESSION.TRANSACTION_PK.eq(transactionPK)) .fetchOne(); if (record == null) { return Optional.absent(); } return Optional.fromNullable(record.value1()); }
@Override public boolean hasNoSession(String rfid) { Record1<Integer> record = ctx.selectOne() .from(PS_SESSION) .where(PS_SESSION.OCPP_TAG_PK.eq(ctx.select(OCPP_TAG.OCPP_TAG_PK) .from(OCPP_TAG) .where(OCPP_TAG.ID_TAG.eq(rfid)))) .and(PS_SESSION.TRANSACTION_PK.isNull()) .and(PS_SESSION.EVENT_STATUS.notEqual(SessionStatus.EXPIRED.name())) .fetchOne(); return record == null; }
@Override public boolean isExternal(String chargeBoxIdentity) { Record1<Integer> record = ctx.select(PS_CHARGEBOX.CHARGE_BOX_PK) .from(PS_CHARGEBOX) .join(CHARGE_BOX).on(CHARGE_BOX.CHARGE_BOX_PK.eq(PS_CHARGEBOX.CHARGE_BOX_PK)) .where(CHARGE_BOX.CHARGE_BOX_ID.eq(chargeBoxIdentity)) .and(PS_CHARGEBOX.IS_ENABLED.isTrue()) .fetchOne(); return record != null; }
@Override public Optional<Integer> getConnectorsNumber(String chargeBoxIdentity) { Record1<Integer> record = ctx.select(PS_CHARGEBOX.NUMBER_OF_CONNECTORS) .from(PS_CHARGEBOX) .join(CHARGE_BOX).on(CHARGE_BOX.CHARGE_BOX_PK.eq(PS_CHARGEBOX.CHARGE_BOX_PK)) .where(CHARGE_BOX.CHARGE_BOX_ID.eq(chargeBoxIdentity)) .fetchOne(); if (record == null) { return Optional.absent(); } else { return Optional.of(record.value1()); } }
@Override public boolean isPosted(String chargeBoxIdentity) { Record1<DateTime> dt = ctx.select(PS_CHARGEBOX.POST_TIMESTAMP) .from(PS_CHARGEBOX) .join(CHARGE_BOX).on(CHARGE_BOX.CHARGE_BOX_PK.eq(PS_CHARGEBOX.CHARGE_BOX_PK)) .where(CHARGE_BOX.CHARGE_BOX_ID.eq(chargeBoxIdentity)) .fetchOne(); return dt != null && dt.value1() != null; }
@Override public boolean isLocal(String rfid) { Record1<Integer> onlyLocal = ctx.selectOne() .from(OCPP_TAG) .leftOuterJoin(PS_OCPP_TAG) .on(OCPP_TAG.OCPP_TAG_PK.eq(PS_OCPP_TAG.OCPP_TAG_PK)) .where(PS_OCPP_TAG.OCPP_TAG_PK.isNull()) .and(OCPP_TAG.ID_TAG.eq(rfid)) .fetchOne(); return onlyLocal != null; }
@Override public boolean isExternal(String rfid) { Record1<Integer> externalAndActive = ctx.select(OCPP_TAG.OCPP_TAG_PK) .from(OCPP_TAG) .join(PS_OCPP_TAG).on(OCPP_TAG.OCPP_TAG_PK.eq(PS_OCPP_TAG.OCPP_TAG_PK)) .where(OCPP_TAG.ID_TAG.eq(rfid)) // since we mark the user as blocked/unblocked in the ocpp tag table based // on the response from PS (see PlugSurfingAuthenticator.verifyRfid()) // we need to check this constraint ! .and(OCPP_TAG.BLOCKED.isFalse()) .fetchOne(); return externalAndActive != null; }
@Override public int getConnectorPkFromTransactionPk(int transactionPK) { Record1<Integer> recordId = ctx.select(CONNECTOR.CONNECTOR_PK) .from(CONNECTOR) .join(TRANSACTION) .on(CONNECTOR.CONNECTOR_PK.eq(TRANSACTION.CONNECTOR_PK)) .where(TRANSACTION.TRANSACTION_PK.eq(transactionPK)) .fetchOne(); if (recordId == null) { throw new SteveException("No such PK for given transactionPK : %s", transactionPK); } return recordId.value1(); }
private List<Integer> getDiscoveredConnPks(Condition chargeBoxSelectCondition) { return ctx.selectDistinct(CONNECTOR.CONNECTOR_PK) .from(CONNECTOR) .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)) .where(chargeBoxSelectCondition) .and(CONNECTOR.CONNECTOR_ID.notEqual(0)) .fetch() .map(Record1::value1); }
/** * {@inheritDoc} */ @Override public Record1<Integer> key() { return (Record1) super.key(); }
/** * {@inheritDoc} */ @Override public Record1<String> key() { return (Record1) super.key(); }
/** * {@inheritDoc} */ @Override public Record1<Long> key() { return (Record1) super.key(); }