public static LanguageInfo getByLanguage(Language lang) { return LANGUAGE_INFOS[lang.getId() - 1]; } public static LanguageInfo getById(int langId) {
public long toLong() { long l = language.getId(); return (l << 32) | id; }
public int toInt() { // crazy scheme that breaks if languages "in the tail" get page ids that are too big // TODO: this could be smarter if (language.getId() > MAX_PACKED_LANGUAGE_ID) { throw new IllegalStateException("cannot pack language ids >= " + MAX_PACKED_LANGUAGE_ID + " into an int"); } if (id > MAX_PACKED_ID) { throw new IllegalStateException("cannot pack ids >= " + MAX_PACKED_ID + " into an int"); } return (language.getId() << 26) | id; }
public int hashCode(){ return (language.getId() + "_" + localId).hashCode(); //non-optimal }
public Collection<Short> getLangIds() { if (langs == null) { return null; } Set<Short> ids = new HashSet<Short>(); for (Language lang : langs) { ids.add(lang.getId()); } return ids; }
public Collection<Short> getLangIds() { if (langs == null) { return null; } Set<Short> ids = new HashSet<Short>(); for (Language lang : langs) { ids.add(lang.getId()); } return ids; }
public static long longHashCode(Language l, String title, NameSpace ns) { return longHashCode(l.getId(), title, ns.getArbitraryId()); }
/** * Returns true if and only if the page is valid within the * parameters of this DaoFilter. * @param page * @return */ public boolean isValidLocalPage(LocalPage page) { return page != null && (langIds == null || langIds.contains(page.getLanguage().getId())) && (nsIds == null || nsIds.contains(page.getNameSpace().getArbitraryId())) && (isRedirect == null || isRedirect == page.isRedirect()) && (isDisambig == null || isDisambig == page.isDisambig()); }
@Override public void save(Redirect redirect) throws DaoException { insert( redirect.getLanguage().getId(), redirect.getSourceId(), redirect.getDestId() ); }
public void save(LocalLink localLink, int sourceUnivId, int destUnivId, int algorithmId) throws DaoException { insert( localLink.getLanguage().getId(), localLink.getSourceId(), localLink.getDestId(), sourceUnivId, destUnivId, algorithmId ); }
@Override public void save(LocalCategoryMember member) throws DaoException { insert( member.getLanguage().getId(), member.getCategoryId(), member.getArticleId() ); }
@Override public void save(PageView view) throws DaoException { insert( view.getPageId().getLanguage().getId(), view.getPageId().getId(), view.getHour(), view.getViews() ); }
@Override public void save(PageView view) throws DaoException { insert( view.getPageId().getLanguage().getId(), view.getPageId().getId(), view.getHour(), view.getViews() ); }
@Override public void save(LocalLink localLink) throws DaoException { insert( localLink.getLanguage().getId(), localLink.getAnchorText(), localLink.getSourceId(), localLink.getDestId(), localLink.getLocation(), localLink.isParseable(), localLink.getLocType().ordinal() ); }
@Override public void save(LocalPage page) throws DaoException { insert( page.getLanguage().getId(), page.getLocalId(), page.getTitle().getCanonicalTitle(), page.getNameSpace().getArbitraryId(), page.isRedirect(), page.isDisambig() ); }
@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 Collection<Integer> getCategoryIds(Language language, int articleId) throws DaoException { DSLContext context = getJooq(); try { Result<Record> result = context.select(). from(Tables.CATEGORY_MEMBERS). where(Tables.CATEGORY_MEMBERS.ARTICLE_ID.eq(articleId)). and(Tables.CATEGORY_MEMBERS.LANG_ID.eq(language.getId())). fetch(); return extractIds(result, true); } finally { freeJooq(context); } }
@Override public RawPage getById(Language language, int rawLocalPageId) throws DaoException { DSLContext context = getJooq(); try { return buildRawPage(context. select(). from(Tables.RAW_PAGE). where(Tables.RAW_PAGE.PAGE_ID.eq(rawLocalPageId)). and(Tables.RAW_PAGE.LANG_ID.eq(language.getId())). fetchOne()); } finally { freeJooq(context); } }
@Override public Collection<Integer> getCategoryMemberIds(Language language, int categoryId) throws DaoException { DSLContext context = getJooq(); try { Result<Record> result = context.select(). from(Tables.CATEGORY_MEMBERS). where(Tables.CATEGORY_MEMBERS.CATEGORY_ID.eq(categoryId)). and(Tables.CATEGORY_MEMBERS.LANG_ID.eq(language.getId())). fetch(); return extractIds(result, false); } finally { freeJooq(context); } }