public <U> ResultStream<U> selectAll() { // TODO: Decide between defaulting to using cursors or defaulting // to using lists. Cursor<Record> cursor; if (whereConditions != null) cursor = context.dsl.select().from(fromTables).where(whereConditions).fetchLazy(); else cursor = context.dsl.select().from(fromTables).fetchLazy(); RowReader<?>[] readerArray = tableReaders.toArray(new RowReader[tableReaders.size()]); RowReader<U> reader = tableReaders.size() == 1 ? (RowReader<U>)tableReaders.get(0) : new TupleRowReader<>(readerArray); return makeCursorStream(cursor, reader); }
public <U> ResultStream<U> select(Object lambda) { // Figure out which columns to return LambdaInfo select = LambdaInfo.analyze(context.metamodel, lambda); if (select == null) throw new IllegalArgumentException("Could not create convert Lambda into a query"); SelectTransform transform = new SelectTransform(context.metamodel, select); List<Table<?>> froms = new ArrayList<>(); froms.addAll(fromTables); ColumnExpressions<U> columns = transform.apply(froms); // Run the query now List<Field<?>> selectColumns = new ArrayList<>(); for (QueryPart col: columns.columns) selectColumns.add((Field<?>)col); Cursor<Record> cursor; if (whereConditions != null) cursor = context.dsl.select(selectColumns).from(froms).where(whereConditions).fetchLazy(); else cursor = context.dsl.select(selectColumns).from(froms).fetchLazy(); return makeCursorStream(cursor, columns.reader); }
@Override public <R extends Record> Cursor<R> fetchLazy(Table<R> table, Condition condition) { return selectFrom(table).where(condition).fetchLazy(); }
@Override public <R extends Record> Cursor<R> fetchLazy(Table<R> table, Condition condition) { return selectFrom(table).where(condition).fetchLazy(); }
@Override public int getNumViews(LocalId pageId, DateTime startDate, DateTime endDate) throws DaoException { DSLContext context = getJooq(); Timestamp startTime = new Timestamp(startDate.getMillis()); Timestamp endTime = new Timestamp(endDate.getMillis()); try { Cursor<Record> result = context.select(). from(Tables.PAGEVIEW). where(Tables.PAGEVIEW.LANG_ID.eq(pageId.getLanguage().getId())). and(Tables.PAGEVIEW.TSTAMP.between(startTime, endTime)). and(Tables.PAGEVIEW.PAGE_ID.eq(pageId.getId())). fetchLazy(getFetchSize()); int numViews = 0; for (Record record : result){ numViews += record.getValue(Tables.PAGEVIEW.NUM_VIEWS); } return numViews; } finally { freeJooq(context); } }
@Override public int getNumViews(LocalId pageId, DateTime startDate, DateTime endDate) throws DaoException { DSLContext context = getJooq(); Timestamp startTime = new Timestamp(startDate.getMillis()); Timestamp endTime = new Timestamp(endDate.getMillis()); try { Cursor<Record> result = context.select(). from(Tables.PAGEVIEW). where(Tables.PAGEVIEW.LANG_ID.eq(pageId.getLanguage().getId())). and(Tables.PAGEVIEW.TSTAMP.between(startTime, endTime)). and(Tables.PAGEVIEW.PAGE_ID.eq(pageId.getId())). fetchLazy(getFetchSize()); int numViews = 0; for (Record record : result){ numViews += record.getValue(Tables.PAGEVIEW.NUM_VIEWS); } return numViews; } finally { freeJooq(context); } }
@Override public TIntIntMap getAllViews(Language language, DateTime startDate, DateTime endDate) throws DaoException { DSLContext context = getJooq(); Timestamp startTime = new Timestamp(startDate.getMillis()); Timestamp endTime = new Timestamp(endDate.getMillis()); try { Cursor<Record> result = context.select(). from(Tables.PAGEVIEW). where(Tables.PAGEVIEW.LANG_ID.eq(language.getId())). and(Tables.PAGEVIEW.TSTAMP.between(startTime, endTime)). fetchLazy(getFetchSize()); TIntIntMap views = new TIntIntHashMap( gnu.trove.impl.Constants.DEFAULT_CAPACITY, gnu.trove.impl.Constants.DEFAULT_LOAD_FACTOR, -1, -1); for (Record record : result){ views.adjustOrPutValue( record.getValue(Tables.PAGEVIEW.PAGE_ID), record.getValue(Tables.PAGEVIEW.NUM_VIEWS), record.getValue(Tables.PAGEVIEW.NUM_VIEWS)); } return views; } finally { freeJooq(context); } }
@Override public TIntIntMap getAllViews(Language language, DateTime startDate, DateTime endDate) throws DaoException { DSLContext context = getJooq(); Timestamp startTime = new Timestamp(startDate.getMillis()); Timestamp endTime = new Timestamp(endDate.getMillis()); try { Cursor<Record> result = context.select(). from(Tables.PAGEVIEW). where(Tables.PAGEVIEW.LANG_ID.eq(language.getId())). and(Tables.PAGEVIEW.TSTAMP.between(startTime, endTime)). fetchLazy(getFetchSize()); TIntIntMap views = new TIntIntHashMap( gnu.trove.impl.Constants.DEFAULT_CAPACITY, gnu.trove.impl.Constants.DEFAULT_LOAD_FACTOR, -1, -1); for (Record record : result){ views.adjustOrPutValue( record.getValue(Tables.PAGEVIEW.PAGE_ID), record.getValue(Tables.PAGEVIEW.NUM_VIEWS), record.getValue(Tables.PAGEVIEW.NUM_VIEWS)); } return views; } finally { freeJooq(context); } }
where(conditions).fetchLazy(getFetchSize());
@Override public Map<Language, TIntIntMap> getAllUnivToLocalIdsMap(LanguageSet ls) throws DaoException { DSLContext context = getJooq(); try { Map<Language, TIntIntMap> map = new HashMap<Language, TIntIntMap>(); for (Language l : ls) { Cursor<Record> cursor = context.select() .from(Tables.UNIVERSAL_PAGE) .where(Tables.UNIVERSAL_PAGE.ALGORITHM_ID.eq(algorithmId)) .and(Tables.UNIVERSAL_PAGE.LANG_ID.eq(l.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.UNIVERSAL_PAGE.UNIV_ID), record.getValue(Tables.UNIVERSAL_PAGE.PAGE_ID)); } map.put(l, ids); } return map; } finally { freeJooq(context); } }
@Override public Map<Language, TIntIntMap> getAllLocalToUnivIdsMap(LanguageSet ls) throws DaoException { DSLContext context = getJooq(); try { Map<Language, TIntIntMap> map = new HashMap<Language, TIntIntMap>(); for (Language l : ls) { Cursor<Record> cursor = context.select() .from(Tables.UNIVERSAL_PAGE) .where(Tables.UNIVERSAL_PAGE.ALGORITHM_ID.eq(algorithmId)) .and(Tables.UNIVERSAL_PAGE.LANG_ID.eq(l.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.UNIVERSAL_PAGE.PAGE_ID), record.getValue(Tables.UNIVERSAL_PAGE.UNIV_ID)); } map.put(l, ids); } return map; } finally { freeJooq(context); } }
@Override public UniversalLinkGroup getInlinks(int destId) throws DaoException { DSLContext context = getJooq(); try { Cursor<Record> result = context.select(). from(Tables.UNIVERSAL_LINK). where(Tables.UNIVERSAL_LINK.UNIV_DEST_ID.eq(destId)). and(Tables.UNIVERSAL_LINK.ALGORITHM_ID.eq(algorithmId)). fetchLazy(getFetchSize()); return buildUniversalLinkGroup(result, false); } finally { freeJooq(context); } }
@Override public UniversalLinkGroup getOutlinks(int sourceId) throws DaoException { DSLContext context = getJooq(); try { Cursor<Record> result = context.select(). from(Tables.UNIVERSAL_LINK). where(Tables.UNIVERSAL_LINK.UNIV_SOURCE_ID.eq(sourceId)). and(Tables.UNIVERSAL_LINK.ALGORITHM_ID.eq(algorithmId)). fetchLazy(getFetchSize()); return buildUniversalLinkGroup(result, true); } finally { freeJooq(context); } }
@Override public TIntSet getOutlinkIds(int sourceId) throws DaoException{ DSLContext context = getJooq(); try { Cursor<Record> result = context.select(). from(Tables.UNIVERSAL_LINK). where(Tables.UNIVERSAL_LINK.UNIV_SOURCE_ID.eq(sourceId)). and(Tables.UNIVERSAL_LINK.ALGORITHM_ID.eq(algorithmId)). fetchLazy(getFetchSize()); TIntSet ids = new TIntHashSet(); for (Record record : result){ ids.add(record.getValue(Tables.UNIVERSAL_LINK.UNIV_DEST_ID)); } return ids; } 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 getOutlinkIds(int sourceId) throws DaoException { DSLContext context = getJooq(); try { Cursor<Record> result = context.select() .from(Tables.UNIVERSAL_SKELETAL_LINK) .where(Tables.UNIVERSAL_SKELETAL_LINK.SOURCE_ID.eq(sourceId)) .and(Tables.UNIVERSAL_SKELETAL_LINK.ALGORITHM_ID.eq(algorithmId)) .fetchLazy(getFetchSize()); TIntSet ids = new TIntHashSet(); for (Record record : result){ ids.add(record.getValue(Tables.UNIVERSAL_SKELETAL_LINK.DEST_ID)); } return ids; } finally { freeJooq(context); } }
@Override public TIntSet getInlinkIds(int destId) throws DaoException { DSLContext context = getJooq(); try { Cursor<Record> result = context.select() .from(Tables.UNIVERSAL_SKELETAL_LINK) .where(Tables.UNIVERSAL_SKELETAL_LINK.DEST_ID.eq(destId)) .and(Tables.UNIVERSAL_SKELETAL_LINK.ALGORITHM_ID.eq(algorithmId)) .fetchLazy(getFetchSize()); TIntSet ids = new TIntHashSet(); for (Record record : result){ ids.add(record.getValue(Tables.UNIVERSAL_SKELETAL_LINK.SOURCE_ID)); } return ids; } finally { freeJooq(context); } }
@Override public TIntSet getInlinkIds(int destId) throws DaoException{ DSLContext context = getJooq(); try { Cursor<Record> result = context.select(). from(Tables.UNIVERSAL_LINK). where(Tables.UNIVERSAL_LINK.UNIV_DEST_ID.eq(destId)). and(Tables.UNIVERSAL_LINK.ALGORITHM_ID.eq(algorithmId)). fetchLazy(getFetchSize()); TIntSet ids = new TIntHashSet(); for (Record record : result){ ids.add(record.getValue(Tables.UNIVERSAL_LINK.UNIV_SOURCE_ID)); } return ids; } finally { freeJooq(context); } }
@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 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; } }