@Override public LocalLinkSqlDao get(String name, Config config, Map<String, String> runtimeParams) throws ConfigurationException { if (!config.getString("type").equals("sql")) { return null; } try { return new LocalLinkSqlDao( getConfigurator().get( WpDataSource.class, config.getString("dataSource")) ); } catch (DaoException e) { throw new ConfigurationException(e); } } }
@Override public Iterable<LocalLink> getLinks(Language language, int localId, boolean outlinks) throws DaoException{ // if (counter.incrementAndGet() % 1000 == 0) { // double mean = 1.0 * timer.get() / counter.get(); // System.out.println("counter is " + counter.get() + ", mean millis is " + mean); // } DSLContext context = getJooq(); // long start = System.currentTimeMillis(); try { TableField idField; if (outlinks){ idField = Tables.LOCAL_LINK.SOURCE_ID; } else { idField = Tables.LOCAL_LINK.DEST_ID; } Cursor<Record> result = context.select() .from(Tables.LOCAL_LINK) .where(Tables.LOCAL_LINK.LANG_ID.equal(language.getId())) .and(idField.equal(localId)) .fetchLazy(getFetchSize()); // long end = System.currentTimeMillis(); // timer.addAndGet(end - start); return buildLocalLinks(result, outlinks, context); } catch (RuntimeException e) { freeJooq(context); throw e; } }
@Override public LocalLink getLink(Language language, int sourceId, int destId) throws DaoException { DSLContext context = getJooq(); try { Result<Record> result = context.select(). from(Tables.LOCAL_LINK). where(Tables.LOCAL_LINK.LANG_ID.eq(language.getId())). and(Tables.LOCAL_LINK.SOURCE_ID.eq(sourceId)). and(Tables.LOCAL_LINK.DEST_ID.eq(destId)). fetch(); //Work-around to avoid pages that have multiple links to the same page Record record; if (result.isEmpty()){ record = null; } else { record = result.get(0); } return buildLocalLink(record, true); } catch (RuntimeException e) { freeJooq(context); throw e; } }
@Override public Iterable<LocalLink> get(DaoFilter daoFilter) throws DaoException { DSLContext context = getJooq(); try { Collection<Condition> conditions = new ArrayList<Condition>(); where(conditions). limit(daoFilter.getLimitOrInfinity()). fetchLazy(getFetchSize()); return new SimpleSqlDaoIterable<LocalLink>(result, context) { @Override freeJooq(context); throw e;
@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 Iterable<LocalLink> getLinks(Language language, int localId, boolean outlinks, boolean isParseable, LocalLink.LocationType locationType) throws DaoException{ DSLContext context = getJooq(); try { TableField idField; if (outlinks){ idField = Tables.LOCAL_LINK.SOURCE_ID; } else { idField = Tables.LOCAL_LINK.DEST_ID; } Cursor<Record> result = context.select() .from(Tables.LOCAL_LINK) .where(Tables.LOCAL_LINK.LANG_ID.equal(language.getId())) .and(idField.equal(localId)) .and(Tables.LOCAL_LINK.IS_PARSEABLE.equal(isParseable)) .and(Tables.LOCAL_LINK.LOCATION_TYPE.equal((short) locationType.ordinal())) .fetchLazy(getFetchSize()); return buildLocalLinks(result, outlinks, context); } catch (RuntimeException e) { freeJooq(context); throw e; } }