@Override public Company findCompany(Integer pid) { logger.info("Finding Company by ID using JOOQ"); Company company = create. selectFrom(COMPANY) .where(COMPANY.PID.eq(pid)) .fetchOneInto(Company.class); logger.info("Found company: " + company); return company; }
@Override public Department findDepartment(Integer pid) { return create. selectFrom(DEPARTMENT) .where(DEPARTMENT.PID.eq(pid)) .fetchOneInto(Department.class); }
@Override public Employee findEmployee(Integer pid) { return create.selectFrom(EMPLOYEE).where(EMPLOYEE.PID.eq(pid)).fetchOneInto(Employee.class); }
@Override public Company findCompanyUsingSimpleStaticStatement(Integer pid) { Configuration configuration = create.configuration().derive(staticStatementSettings); return DSL.using(configuration) .selectFrom(COMPANY) .where(COMPANY.PID.eq(pid)) .fetchOneInto(Company.class); }
@Override public Long getRequestedVersion(Client client, String itemName) { return create() .select(CONFIG_ITEM_STATUS.REQUESTED_VERSION) .from(CONFIG_ITEM_STATUS) .where( CONFIG_ITEM_STATUS.NAME.eq(itemName) .and(targetObjectCondition(client))) .fetchOneInto(Long.class); }
@Override public boolean hasActiveHosts(Long accountId) { return create() .select(HOST.ID.count()) .from(HOST) .join(AGENT) .on(AGENT.ID.eq(HOST.AGENT_ID)) .where(HOST.ACCOUNT_ID.eq(accountId) .and(HOST.STATE.in(CommonStatesConstants.ACTIVATING, CommonStatesConstants.ACTIVE, CommonStatesConstants.UPDATING_ACTIVE) .and(AGENT.STATE.in(CommonStatesConstants.ACTIVATING, CommonStatesConstants.ACTIVE, AgentConstants.STATE_FINISHING_RECONNECT, AgentConstants.STATE_RECONNECTED)))) .fetchOneInto(Integer.class) > 0; }
@Override public Account getAccountByAccessKey(String accessKey) { return create() .select(ACCOUNT.fields()) .from(ACCOUNT) .join(CREDENTIAL) .on(CREDENTIAL.ACCOUNT_ID.eq(ACCOUNT.ID)) .where( CREDENTIAL.STATE.eq(CommonStatesConstants.ACTIVE) .and(CREDENTIAL.PUBLIC_VALUE.eq(accessKey)) .and(CREDENTIAL.KIND.eq(CredentialConstants.KIND_API_KEY)) .and(ACCOUNT.STATE.in(getActiveStates()))) .fetchOneInto(AccountRecord.class); }
@Override public Account getByUsername(String username) { try { return create() .select(ACCOUNT.fields()) .from(ACCOUNT) .join(CREDENTIAL) .on(CREDENTIAL.ACCOUNT_ID.eq(ACCOUNT.ID)) .where( ACCOUNT.STATE.in(getActiveStates()) .and(CREDENTIAL.STATE.eq(CommonStatesConstants.ACTIVE)) .and(CREDENTIAL.PUBLIC_VALUE.eq(username))) .and(CREDENTIAL.KIND.eq(CredentialConstants.KIND_PASSWORD)) .fetchOneInto(AccountRecord.class); } catch (InvalidResultException e) { throw new ClientVisibleException(ResponseCodes.CONFLICT, "MultipleOfUsername"); } }
@Override public Account getAccountByLogin(String publicValue, String secretValue, TransformationService transformationService) { Credential credential = create() .selectFrom(CREDENTIAL) .where( CREDENTIAL.STATE.eq(CommonStatesConstants.ACTIVE)) .and(CREDENTIAL.PUBLIC_VALUE.eq(publicValue) .and(CREDENTIAL.KIND.equalIgnoreCase(CredentialConstants.KIND_PASSWORD))) .fetchOne(); if (credential == null) { return null; } boolean secretIsCorrect = transformationService.compare(secretValue, credential.getSecretValue()); if (secretIsCorrect) { return create() .selectFrom(ACCOUNT).where(ACCOUNT.ID.eq(credential.getAccountId()) .and(ACCOUNT.STATE.in(getActiveStates()))) .fetchOneInto(AccountRecord.class); } else { return null; } }
.from(SQLITE_MASTER) .where(SQLiteMaster.NAME.eq(getName())) .fetchOneInto(String.class) .matches("(?s:.*\\b" + getName() + "\\b[^,]*(?i:\\bautoincrement\\b)[^,]*.*)");
@Override public Account getAccountByKeys(String access, String secretKey, TransformationService transformationService) { try { Credential credential = create() .selectFrom(CREDENTIAL) .where( CREDENTIAL.STATE.eq(CommonStatesConstants.ACTIVE)) .and(CREDENTIAL.PUBLIC_VALUE.eq(access)) .and(CREDENTIAL.KIND.in(SUPPORTED_TYPES.get())) .fetchOne(); if (credential == null) { return null; } if (transformationService.compare(secretKey, credential.getSecretValue())) { return create() .selectFrom(ACCOUNT).where(ACCOUNT.ID.eq(credential.getAccountId()) .and(ACCOUNT.STATE.in(getActiveStates()))) .fetchOneInto(AccountRecord.class); } else { return null; } } catch (InvalidResultException e) { throw new ClientVisibleException(ResponseCodes.CONFLICT, "MultipleKeys"); } }
@Override public Host getHost(Instance instance) { Condition cond = getInstanceHostConstraint(instance); try { return create() .selectDistinct(HOST.fields()) .from(HOST) .join(INSTANCE_HOST_MAP) .on(INSTANCE_HOST_MAP.HOST_ID.eq(HOST.ID)) .join(INSTANCE) .on(INSTANCE_HOST_MAP.INSTANCE_ID.eq(INSTANCE.ID)) .leftOuterJoin(SERVICE_EXPOSE_MAP) .on(INSTANCE.ID.eq(SERVICE_EXPOSE_MAP.INSTANCE_ID)) .where( INSTANCE_HOST_MAP.REMOVED.isNull() .and(HOST.REMOVED.isNull()) .and(INSTANCE.REMOVED.isNull()) .and(SERVICE_EXPOSE_MAP.REMOVED.isNull()) .and(SERVICE_EXPOSE_MAP.UPGRADE.isNull().or(SERVICE_EXPOSE_MAP.UPGRADE.eq(false))) .and(cond)) .fetchOneInto(HostRecord.class); } catch (InvalidResultException e) { throw new FailedToAllocate("Instances to allocate assigned to different hosts."); } }