private <T extends CountStats> T getCountStats(final TableImpl table, final TableField<? extends Record, Timestamp> createdField, final T countStats) { final Field<Integer> totalField = DSL.selectCount().from(table).asField(); final Field<Integer> last7daysField = DSL.selectCount() .from(table) .where(createdField.ge(DSL.currentTimestamp().minus(7))) .asField(); final Field<Integer> last30daysField = DSL.selectCount() .from(table) .where(createdField.ge(DSL.currentTimestamp().minus(30))) .asField(); return jooq.select(totalField, last7daysField, last30daysField) .fetchOne() .map(r -> { countStats.setTotal(r.getValue(totalField)); countStats.setLast7days(r.getValue(last7daysField)); countStats.setLast30days(r.getValue(last30daysField)); return countStats; }); }
int personCmd(String[] args) throws IllegalArgumentException { CmdType type = checkCmd(args); String[] field_name = new String[1]; int[] ids = new int[1]; TableImpl<PersonsRecord> table = Persons.PERSONS; TableField<PersonsRecord, Integer>[] pkey = new TableField[1]; pkey[0] = Persons.PERSONS.PERSON_ID; Object[] out_args = prepareArgs(table.fields().length, type, args, ids, field_name, true); if (out_args != null) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); java.util.Date parsed; try { parsed = format.parse(out_args[3].toString()); } catch (ParseException e) { parsed = new java.util.Date(); } out_args[3] = new java.sql.Date(parsed.getTime()); PassportRecord passport = new PassportRecord(); passport.setSerialNumber(Integer.parseInt(out_args[8].toString())); passport.setId(Integer.parseInt(out_args[9].toString())); out_args[8] = null; // photo out_args[9] = passport; } // person add 123 123 123 2016-01-01 M adsads asdasd adasd 5716 478596 1 // person update 9 123 123 123 2016-01-01 M adsads asdasd adasd 5718 478596 1 // person delete 36 return doCommand(table, pkey, type, ids, field_name[0], out_args, true); }
<R extends UpdatableRecord, F extends TableField<R, Integer>> int generalCmd(TableImpl<R> table, F[] pkey, boolean skipId, String[] args) { CmdType type = checkCmd(args); String[] field_name = new String[1]; int[] ids = new int[pkey.length]; Object[] out_args = prepareArgs(table.fields().length, type, args, ids, field_name, skipId); return doCommand(table, pkey, type, ids, field_name[0], out_args, skipId); }
public static void resetSequence(final DSLContext jooq, final Sequence<Long> sequence, final TableImpl table) { jooq.alterSequence(sequence) .restartWith(jooq.selectCount().from(table).fetchOne(0, long.class) + 1) .execute(); }
int sellLogCmd(String[] args) { CmdType type = checkCmd(args); String[] field_name = new String[1]; int[] ids = new int[1]; TableImpl<SellLogRecord> table = SellLog.SELL_LOG; TableField<SellLogRecord, Integer>[] pkey = new TableField[1]; pkey[0] = SellLog.SELL_LOG.LOG_ID; Object[] out_args = prepareArgs(table.fields().length, type, args, ids, field_name, true); // sell_log add 9 1 100 if (out_args != null) { out_args[0] = Integer.parseInt(out_args[0].toString()); out_args[1] = Integer.parseInt(out_args[1].toString()); out_args[2] = Integer.parseInt(out_args[2].toString()); if (out_args[3] != null) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); java.util.Date parsed; try { parsed = format.parse(out_args[3].toString()); } catch (ParseException e) { parsed = new java.util.Date(); } out_args[3] = new java.sql.Date(parsed.getTime()); } else { out_args[3] = new java.sql.Date(Calendar.getInstance().getTimeInMillis()); } if (type == CmdType.ADD) { AddSellLog add = new AddSellLog(); add.setPId((int) out_args[0]); add.setShId((int) out_args[1]); add.setInAmount((int) out_args[2]); add.setDate((java.sql.Date) out_args[3]); return add.execute(ctx.configuration()); } else { UpdateSellLog upd = new UpdateSellLog(); upd.setPId((int) out_args[0]); upd.setShId((int) out_args[1]); upd.setInAmount((int) out_args[2]); upd.setInDate((Date) out_args[3]); return upd.execute(ctx.configuration()); } } return doCommand(table, pkey, type, ids, field_name[0], out_args, true); }