@Override public void setFollowRedirects(boolean followRedirects) throws DaoException { if (followRedirects){ redirectSqlDao = new RedirectSqlDao(wpDs); } else { redirectSqlDao = null; } titlesToIds = null; }
@Override public void save(Language lang, int src, int dest) throws DaoException { save(new Redirect(lang, src, dest)); }
/** * 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 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); } }
@Override public void call(Record record) throws Exception { long hash = Title.longHashCode( record.getValue(Tables.LOCAL_PAGE.LANG_ID), record.getValue(Tables.LOCAL_PAGE.TITLE), record.getValue(Tables.LOCAL_PAGE.NAME_SPACE)); if (redirectSqlDao != null && record.getValue(Tables.LOCAL_PAGE.IS_REDIRECT)){ numRedirects.incrementAndGet(); Integer dest = redirectSqlDao.resolveRedirect( Language.getById(record.getValue(Tables.LOCAL_PAGE.LANG_ID)), record.getValue(Tables.LOCAL_PAGE.PAGE_ID)); if (dest != null) { numResolved.incrementAndGet(); synchronized (map) { map.put(hash, dest); } } } else { synchronized (map) { map.put(hash, record.getValue(Tables.LOCAL_PAGE.PAGE_ID)); } } if (map.size() % 500000 == 0) { LOG.info("built title cache entry " + map.size() + " of " + n); } } }, Integer.MAX_VALUE);
@Override public void save(Redirect redirect) throws DaoException { insert( redirect.getLanguage().getId(), redirect.getSourceId(), redirect.getDestId() ); }
@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 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); } }
protected LocalPage buildLocalPage(Record record, DaoFilter daoFilter) throws DaoException { if (record == null) { return null; } Language lang = Language.getById(record.getValue(Tables.LOCAL_PAGE.LANG_ID)); if (redirectSqlDao != null // either null or false // If true, we don't want to resolve redirects because they're all redirects && (daoFilter.isRedirect() == null || !daoFilter.isRedirect()) && record.getValue(Tables.LOCAL_PAGE.IS_REDIRECT)) { LocalPage page = getById(lang, redirectSqlDao.resolveRedirect( lang, record.getValue(Tables.LOCAL_PAGE.PAGE_ID))); if (daoFilter.isValidLocalPage(page)) { return page; } } Title title = new Title( record.getValue(Tables.LOCAL_PAGE.TITLE), true, LanguageInfo.getByLanguage(lang)); NameSpace nameSpace = NameSpace.getNameSpaceByArbitraryId(record.getValue(Tables.LOCAL_PAGE.NAME_SPACE)); return new LocalPage( lang, record.getValue(Tables.LOCAL_PAGE.PAGE_ID), title, nameSpace, record.getValue(Tables.LOCAL_PAGE.IS_REDIRECT), record.getValue(Tables.LOCAL_PAGE.IS_DISAMBIG) ); }
@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); } }
public LocalPageSqlDao(WpDataSource dataSource, boolean followRedirects) throws DaoException{ super(dataSource, INSERT_FIELDS, "/db/local-page"); if (followRedirects){ redirectSqlDao = new RedirectSqlDao(wpDs); } }
@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); } }
@Override public RedirectSqlDao get(String name, Config config, Map<String, String> runtimeParams) throws ConfigurationException { if (!config.getString("type").equals("sql")){ return null; } try { return new RedirectSqlDao( getConfigurator().get( WpDataSource.class, config.getString("dataSource")) ); } catch (DaoException e) { throw new ConfigurationException(e); } } }