private long getLatestTimestamp(DSLContext ctx) { return ctx.select(LATEST_TIMESTAMP) .from(TABLE) .where(DUMMY_COLUMN.eq(0)) .fetchOne(LATEST_TIMESTAMP); } }
@Override public byte[] getMetadataForTable(final TableReference tableRef) { return run(ctx -> { byte[] metadata = ctx .select(METADATA) .from(METADATA_TABLE) .where(TABLE_NAME.eq(tableRef.getQualifiedName())) .fetchOne(METADATA); return MoreObjects.firstNonNull(metadata, new byte[0]); }); }
@Override public Optional<T> getOptional(ID id) { Record record = getDSLContext().select().from(table).where(primaryKey.eq(id)).fetchOne(); return Optional.ofNullable(record).map(r -> r.into(entityClass)); }
@Override public ProjectMember getProjectMember(long id) { return create() .selectFrom(PROJECT_MEMBER) .where(PROJECT_MEMBER.ID.eq(id)).fetchOne(); }
@Override public Account findByUuid(String uuid) { return create() .selectFrom(ACCOUNT) .where(ACCOUNT.UUID.eq(uuid)) .fetchOne(); }
public SecretEntry get(UUID id) { try (DSLContext tx = DSL.using(cfg)) { return selectEntry(tx) .where(SECRETS.SECRET_ID.eq(id)) .fetchOne(SecretDao::toEntry); } }
protected Task getTask(String name) { return create() .selectFrom(TASK) .where(TASK.NAME.eq(name)) .fetchOne(); }
protected String get(String name) { return create() .select(DATA.VALUE) .from(DATA) .where(DATA.NAME.eq(name)) .fetchOne(DATA.VALUE); }
public UUID getOrgId(UUID id) { try (DSLContext tx = DSL.using(cfg)) { return tx.select(SECRETS.ORG_ID) .from(SECRETS) .where(SECRETS.SECRET_ID.eq(id)) .fetchOne(SECRETS.ORG_ID); } }
public UUID getProjectId(UUID repoId) { try (DSLContext tx = DSL.using(cfg)) { return tx.select(REPOSITORIES.PROJECT_ID) .from(REPOSITORIES) .where(REPOSITORIES.REPO_ID.eq(repoId)) .fetchOne(REPOSITORIES.PROJECT_ID); } }
private int countRunning(DSLContext tx, UUID prjId) { return tx.selectCount() .from(PROCESS_QUEUE) .where(PROCESS_QUEUE.PROJECT_ID.eq(prjId).and(PROCESS_QUEUE.CURRENT_STATUS.in(RUNNING_PROCESS_STATUSES))) .fetchOne(0, int.class); }
@Override public final <Z> P fetchOne(Field<Z> field, Z value) { R record = using(configuration) .selectFrom(table) .where(field.equal(value)) .fetchOne(); return mapper().map(record); }
@Override public Agent findNonRemovedByUri(String uri) { return create() .selectFrom(AGENT) .where( AGENT.URI.eq(uri) .and(AGENT.REMOVED.isNull())) .fetchOne(); }
@Override public Nic getPrimaryNic(Instance instance) { if ( instance == null ) { return null; } return create() .selectFrom(NIC) .where(NIC.INSTANCE_ID.eq(instance.getId()) .and(NIC.DEVICE_NUMBER.eq(0))) .fetchOne(); }
public UUID getId(UUID inventoryId, String queryName) { try(DSLContext tx = DSL.using(cfg)) { return tx.select(INVENTORY_QUERIES.QUERY_ID) .from(INVENTORY_QUERIES) .where(INVENTORY_QUERIES.QUERY_NAME.eq(queryName) .and(INVENTORY_QUERIES.INVENTORY_ID.eq(inventoryId))) .fetchOne(INVENTORY_QUERIES.QUERY_ID); } }
@Override public Account getAccountById(Long id) { return create() .selectFrom(ACCOUNT) .where( ACCOUNT.ID.eq(id) .and(ACCOUNT.STATE.ne(CommonStatesConstants.PURGED)) .and(ACCOUNT.REMOVED.isNull()) ).fetchOne(); }
@Override public Account getAccountById(Long id) { return create() .selectFrom(ACCOUNT) .where( ACCOUNT.ID.eq(id) .and(ACCOUNT.STATE.ne(CommonStatesConstants.PURGED)) .and(ACCOUNT.REMOVED.isNull()) ).fetchOne(); }
@Override public Instance getInstance(Agent agent) { return create() .selectFrom(INSTANCE) .where(INSTANCE.AGENT_ID.eq(agent.getId()) .and(INSTANCE.REMOVED.isNull()) .and(INSTANCE.STATE.notIn(InstanceConstants.STATE_ERROR, InstanceConstants.STATE_ERRORING, CommonStatesConstants.REMOVING))) .fetchOne(); }
@Override public Credential getCredential(String accessKey) { return create() .selectFrom(CREDENTIAL) .where(CREDENTIAL.KIND.eq(RegisterConstants.KIND_CREDENTIAL_REGISTRATION_TOKEN) .and(CREDENTIAL.PUBLIC_VALUE.eq(accessKey)) .and(CREDENTIAL.STATE.eq(CommonStatesConstants.ACTIVE)) .and(CREDENTIAL.REMOVED.isNull())) .fetchOne(); }
public boolean hasActiveProcess(DSLContext tx, Timestamp fromTime, Timestamp toTime) { int count = tx.selectCount() .from(PROCESS_QUEUE) .where(PROCESS_QUEUE.CREATED_AT.between(fromTime, toTime) .and(PROCESS_QUEUE.CURRENT_STATUS.notIn(ProcessStatus.FINISHED.name(), ProcessStatus.FAILED.name(), ProcessStatus.CANCELLED.name(), ProcessStatus.TIMED_OUT.name()))) .fetchOne(Record1::value1); return count > 0; }