public PageBuilder<Signon> findAllByPage(Pageable pageable) { SelectConditionStep<SignonRecord> where = dsl.selectFrom(SIGNON).where(); String sqlBeforePage = where.getSQL(ParamType.INLINED); where.limit(pageable.getPageSize()).offset(pageable.getOffset()); List<Signon> signons = where.fetchInto(Signon.class); return new PageBuilder<>(signons, pageable, sqlBeforePage, dsl); }
@Override public ChargePoint.Details getDetails(int chargeBoxPk) { ChargeBoxRecord cbr = ctx.selectFrom(CHARGE_BOX).where(CHARGE_BOX.CHARGE_BOX_PK.equal(chargeBoxPk)).fetchOne(); if (cbr == null) { throw new SteveException("Charge point not found"); } cbr.detach(); AddressRecord ar = addressRepository.get(ctx, cbr.getAddressPk()); return new ChargePoint.Details(cbr, ar); }
@Override public Result<ClassroomCourseTimetableInfoRecord> findByTieIdAndTeachTypeIdAndPage( ClassroomTimetableListVo classroomTimetableListVo, int tieId) { Condition a = Tables.CLASSROOM_COURSE_TIMETABLE_INFO .TIE_ID .eq((tieId)) .and( Tables.CLASSROOM_COURSE_TIMETABLE_INFO.TEACH_TYPE_ID.eq( classroomTimetableListVo.getTeachTypeId())); if (StringUtils.hasLength(classroomTimetableListVo.getTimetableInfoFileName())) { a = a.and( Tables.CLASSROOM_COURSE_TIMETABLE_INFO.TIMETABLE_INFO_FILE_NAME.like( "%" + classroomTimetableListVo.getTimetableInfoFileName() + "%")); } if (StringUtils.hasLength(classroomTimetableListVo.getTimetableInfoTerm())) { a = a.and( Tables.CLASSROOM_COURSE_TIMETABLE_INFO.TIMETABLE_INFO_TERM.like( "%" + classroomTimetableListVo.getTimetableInfoTerm() + "%")); } if (StringUtils.hasLength(classroomTimetableListVo.getClassroom())) { a = a.and( Tables.CLASSROOM_COURSE_TIMETABLE_INFO.CLASSROOM.like( "%" + classroomTimetableListVo.getClassroom() + "%")); } int pageNum = classroomTimetableListVo.getPageNum(); int pageSize = classroomTimetableListVo.getPageSize(); if (pageNum <= 0) { pageNum = 1; } Result<ClassroomCourseTimetableInfoRecord> record14s = create .selectFrom(Tables.CLASSROOM_COURSE_TIMETABLE_INFO) .where(a) .orderBy(Tables.CLASSROOM_COURSE_TIMETABLE_INFO.TIMETABLE_INFO_FILE_DATE.desc()) .limit((pageNum - 1) * pageSize, pageSize) .fetch(); return record14s; }
@SuppressWarnings("unchecked") public static <T extends UpdatableRecord<?>> T findById( DSLContext context, Class<T> clz, Object id) { if (id == null) return null; Table<?> table = getTableFromRecordClass(clz); if (table == null) return null; UniqueKey<?> key = table.getPrimaryKey(); if (key == null || key.getFieldsArray().length != 1) return null; TableField<?, Object> keyField = (TableField<?, Object>) key.getFieldsArray()[0]; /* Convert object because we are abusing type safety here */ Object converted = keyField.getDataType().convert(id); return (T) context.selectFrom(table).where(keyField.eq(converted)).fetchOne(); }
public boolean authenticate(String login, String password) { try { boolean userExist = true; if (login == null || password == null) { userExist = false; login = ""; password = ""; } AuthCredential p = AuthCredential.AUTH_CREDENTIAL; AuthCredentialRecord rs = context.selectFrom(p).where(p.LOGIN.equal(login)).fetchOne(); String digest, salt; if (rs != null) { digest = rs.getPassword(); salt = rs.getSalt(); if (digest == null || salt == null) { throw new RuntimeException("Database inconsistent Salt or Digested Password altered"); } } else { digest = "000000000000000000000000000="; salt = "00000000000="; userExist = false; } byte[] bDigest = base64ToByte(digest); byte[] bSalt = base64ToByte(salt); // Compute the new DIGEST byte[] proposedDigest = getHash(password, bSalt); boolean authenticated = Arrays.equals(proposedDigest, bDigest) && userExist; if (authenticated) { rs.setJwtToken(new BigInteger(130, new SecureRandom()).toString(32)); rs.store(); } return authenticated; } catch (IOException | NoSuchAlgorithmException e) { throw new RuntimeException("Authentication failed", e); } }