@Override public int getCount(DaoFilter daoFilter) throws DaoException{ DSLContext context = getJooq(); try { Collection<Condition> conditions = new ArrayList<Condition>(); if (daoFilter.getLangIds() != null) { conditions.add(Tables.REDIRECT.LANG_ID.in(daoFilter.getLangIds())); } return context.select(). from(Tables.REDIRECT). where(conditions). fetchCount(); } finally { freeJooq(context); } }
/** * Generally this method should not be used. * @param daoFilter a set of filters to limit the search * @return * @throws DaoException */ @Override public Iterable<Redirect> get(DaoFilter daoFilter) throws DaoException { DSLContext context = getJooq(); try { Collection<Condition> conditions = new ArrayList<Condition>(); if (daoFilter.getLangIds() != null) { conditions.add(Tables.REDIRECT.LANG_ID.in(daoFilter.getLangIds())); } Cursor<Record> result = context.select(). from(Tables.REDIRECT). where(conditions). limit(daoFilter.getLimitOrInfinity()). fetchLazy(getFetchSize()); return new SimpleSqlDaoIterable<Redirect>(result, context) { @Override public Redirect transform(Record r) { return buildRedirect(r); } }; } catch (RuntimeException e) { freeJooq(context); throw e; } }
@Override public boolean isRedirect(Language lang, int id) throws DaoException { DSLContext context = getJooq(); try { Record record = context.select().from(Tables.REDIRECT) .where(Tables.REDIRECT.SRC_PAGE_ID.equal(id)) .and(Tables.REDIRECT.LANG_ID.equal(lang.getId())) .fetchOne(); return (record != null); } finally { freeJooq(context); } }
@Override public Integer resolveRedirect(Language lang, int id) throws DaoException { DSLContext context = getJooq(); try { Record record = context.select().from(Tables.REDIRECT) .where(Tables.REDIRECT.SRC_PAGE_ID.equal(id)) .and(Tables.REDIRECT.LANG_ID.equal(lang.getId())) .fetchOne(); if (record == null){ return null; } return record.getValue(Tables.REDIRECT.DEST_PAGE_ID); } finally { freeJooq(context); } }
@Override public TIntIntMap getAllRedirectIdsToDestIds(Language lang) throws DaoException { DSLContext context = getJooq(); try { Cursor<Record> cursor = context.select(). from(Tables.REDIRECT). where(Tables.REDIRECT.LANG_ID.equal(lang.getId())). fetchLazy(getFetchSize()); TIntIntMap ids = new TIntIntHashMap( gnu.trove.impl.Constants.DEFAULT_CAPACITY, gnu.trove.impl.Constants.DEFAULT_LOAD_FACTOR, -1, -1); for (Record record : cursor){ ids.put(record.getValue(Tables.REDIRECT.SRC_PAGE_ID), record.getValue(Tables.REDIRECT.DEST_PAGE_ID)); } return ids; } finally { freeJooq(context); } }
@Override public TIntSet getRedirects(LocalPage localPage) throws DaoException { DSLContext context = getJooq(); try { Result<Record> result = context.select(). from(Tables.REDIRECT). where(Tables.REDIRECT.DEST_PAGE_ID.eq(localPage.getLocalId())). and(Tables.REDIRECT.LANG_ID.eq(localPage.getLanguage().getId())). fetch(); TIntSet ids = new TIntHashSet(); for (Record record : result){ ids.add(record.getValue(Tables.REDIRECT.SRC_PAGE_ID)); } return ids; } finally { freeJooq(context); } }