@Override @Deprecated public final Field<Integer> count() { return DSL.count(this); }
private static final AggregateFunction<?> parseCountIf(ParserContext ctx) { if (parseFunctionNameIf(ctx, "COUNT")) { parse(ctx, '('); boolean distinct = parseSetQuantifier(ctx); if (parseIf(ctx, '*') && parse(ctx, ')')) if (distinct) return countDistinct(); else return count(); QualifiedAsterisk asterisk = parseQualifiedAsteriskIf(ctx); List<Field<?>> fields = (asterisk == null) ? distinct ? parseFields(ctx) : Collections.<Field<?>>singletonList(parseField(ctx)) : null; parse(ctx, ')'); if (distinct) if (fields == null) return countDistinct(asterisk); else if (fields.size() > 0) return countDistinct(fields.toArray(EMPTY_FIELD)); else return countDistinct(fields.get(0)); else if (fields == null) return count(asterisk); else return count(fields.get(0)); } return null; }
@Override @Deprecated public final Field<Integer> count() { return DSL.count(this); }
/** * Get the count(*) function. */ @Support public static AggregateFunction<Integer> count() { return count(org.jooq.impl.Function.ASTERISK); }
@Override @Deprecated public final WindowPartitionByStep<Integer> countOver() { return DSL.count(this).over(); }
@Override @Deprecated public final WindowPartitionByStep<Integer> countOver() { return DSL.count(this).over(); }
@Override public final SelectSelectStep<Record1<Integer>> selectCount() { return new SelectImpl(configuration, this).select(count()); }
/** * Get the count(*) function. */ @Support @Transition( name = "COUNT(*)" ) public static AggregateFunction<Integer> count() { return count(field("*", Integer.class)); }
@Override public SelectSelectStep<Record1<Integer>> selectCount() { return new SelectImpl(configuration(), null).select(count()); }
boolean is84() { if (is84 == null) { // [#2916] Window functions were introduced with PostgreSQL 9.0 try { create(true) .select(count().over()) .fetch(); is84 = true; } catch (DataAccessException e) { is84 = false; } } return is84; }
static boolean test(DataSource datasource, DSLContexts context) { try (Connection conn = datasource.getConnection()) { DSLContext dsl = context.get(conn); return dsl.select(count()).from(ZIPKIN_DEPENDENCIES).fetchAny().value1() > 0; } catch (DataAccessException e) { if (e.sqlState().equals("42S02")) { LOG.warning("zipkin_dependencies doesn't exist, so pre-aggregated dependencies are not " + "supported. Execute mysql.sql located in this jar to add the table"); return false; } problemReading(e); } catch (SQLException | RuntimeException e) { problemReading(e); } return false; }
@Override public boolean canCreate(Long hostId, String event) { if (!ContainerEventConstants.EVENT_START.equals(event)) { return true; } Record1<Integer> count = create().select(DSL.count()) .from(CONTAINER_EVENT) .where(CONTAINER_EVENT.HOST_ID.eq(hostId) .and(CONTAINER_EVENT.STATE.notEqual(CommonStatesConstants.CREATED))) .fetchAny(); return count.value1() < MAX_EVENTS.get(); }
public Map<ProcessStatus, Integer> getStatistics() { try (DSLContext tx = DSL.using(cfg)) { return tx.select(PROCESS_QUEUE.CURRENT_STATUS, count(asterisk())).from(PROCESS_QUEUE) .groupBy(PROCESS_QUEUE.CURRENT_STATUS) .fetchMap(r -> ProcessStatus.valueOf(r.value1()), r -> r.value2()); } }
public Map<String, List<ProjectProcesses>> processByOrgs(int maxProjectRows, Set<UUID> orgIds, Set<ProcessStatus> processStatuses, Timestamp fromUpdatedAt) { Set<String> statuses = processStatuses.stream().map(Enum::name).collect(Collectors.toSet()); try (DSLContext tx = DSL.using(cfg)) { WindowRowsStep<Integer> rnField = rowNumber().over().partitionBy(V_PROCESS_QUEUE.ORG_NAME).orderBy(V_PROCESS_QUEUE.ORG_NAME); SelectHavingStep<Record4<String, String, Integer, Integer>> a = tx.select(V_PROCESS_QUEUE.ORG_NAME, V_PROCESS_QUEUE.PROJECT_NAME, count(), rnField) .from(V_PROCESS_QUEUE) .where(V_PROCESS_QUEUE.ORG_ID.in(orgIds) .and(V_PROCESS_QUEUE.CURRENT_STATUS.in(statuses)) .and(V_PROCESS_QUEUE.LAST_UPDATED_AT.greaterOrEqual(fromUpdatedAt))) .groupBy(V_PROCESS_QUEUE.ORG_NAME, V_PROCESS_QUEUE.PROJECT_NAME); Result<Record3<String, String, Integer>> r = tx.select(a.field(0, String.class), a.field(1, String.class), a.field(2, Integer.class)) .from(a) .where(a.field(rnField).lessOrEqual(maxProjectRows)) .fetch(); Map<String, List<ProjectProcesses>> result = new HashMap<>(); r.forEach(i -> { String orgName = i.value1(); String projectName = i.value2(); int count = i.value3(); result.computeIfAbsent(orgName, (k) -> new ArrayList<>()).add(new ProjectProcesses(projectName, count)); }); return result; } } }
@Override public PageResult<Tag> page(PageResult<Tag> page) { return dao.fetch(page, e -> { return e.select(Fields.all(C_TAG.fields(), DSL.count(C_ARTICLE_TAG.ARTICLE_ID).as("articleCount"))).from(C_TAG,C_ARTICLE_TAG) .where(C_TAG.ID.eq(C_ARTICLE_TAG.TAG_ID)) .groupBy(C_ARTICLE_TAG.TAG_ID); }, Tag.class); } }
/** * Finds the total number of rows in the table * * @return number of records in table */ private int getRecordsCount(Object lowerBoundKey) throws SQLException { Condition condition = DSL.trueCondition(); if (getWhereCondition() != null) { condition = condition.and(getWhereCondition()); } if (isPollerPartition && lowerBoundKey != null) { condition = andLowerBoundKeyCondition(condition, lowerBoundKey); } int recordsCount = dslContext.select(DSL.count()).from(getTableName()).where(condition).fetchOne(0, int.class); return recordsCount; }
public List<Catalog> findAllDetail() { return dao.execute(e -> { return e.select(Fields.all(C_CATALOG.fields(), DSL.count(C_ARTICLE.ID).as("articleCount"))).from(C_ARTICLE) .leftJoin(C_CATALOG).on(C_CATALOG.ID.eq(C_ARTICLE.CATALOG_ID)) .where(C_ARTICLE.STATUS.eq(Article.STATUS_PUBLISH)) .groupBy(C_CATALOG.ID) .orderBy(C_CATALOG.SORT).fetch(r -> { return dao.mapperEntityEx(r, Catalog.class); }); }); } }
@Override public ListDocument list(String tableName, Params params) { ArrayList<Record> records = new ArrayList<>(); ReflectedTable table = reflection.getTable(tableName); includer.addMandatoryColumns(table, reflection, params); ArrayList<Field<?>> columnNames = columns.getNames(table, true, params); Condition condition= filters.getCombinedConditions(table, params); ArrayList<SortField<?>> columnOrdering = ordering.getColumnOrdering(table, params); int count = 0; ResultQuery<org.jooq.Record> query; if (!pagination.hasPage(params)) { int size = pagination.getResultSize(params); query = dsl.select(columnNames).from(table).where(condition).orderBy(columnOrdering); if (size != -1) { query = ((SelectLimitStep<org.jooq.Record>) query).limit(size); } } else { int offset = pagination.getPageOffset(params); int limit = pagination.getPageSize(params); count = (int) dsl.select(DSL.count()).from(table).where(condition).fetchOne(0); query = dsl.select(columnNames).from(table).where(condition).orderBy(columnOrdering).limit(offset, limit); } for (org.jooq.Record record : query.fetch()) { records.add(Record.valueOf(record.intoMap())); } includer.addIncludes(tableName, records, reflection, params, dsl); return new ListDocument(records.toArray(new Record[records.size()]), count); }
@Override public Integer getCurrentScale(long serviceId) { return create() .select(DSL.count()) .from(INSTANCE) .join(SERVICE_EXPOSE_MAP) .on(SERVICE_EXPOSE_MAP.INSTANCE_ID.eq(INSTANCE.ID) .and(SERVICE_EXPOSE_MAP.SERVICE_ID.eq(serviceId)) .and(SERVICE_EXPOSE_MAP.STATE.in(CommonStatesConstants.ACTIVATING, CommonStatesConstants.ACTIVE, CommonStatesConstants.REQUESTED)) .and(SERVICE_EXPOSE_MAP.UPGRADE.eq(false)) .and(INSTANCE.STATE.notIn(CommonStatesConstants.PURGING, CommonStatesConstants.PURGED, CommonStatesConstants.REMOVED, CommonStatesConstants.REMOVING, InstanceConstants.STATE_ERROR, InstanceConstants.STATE_ERRORING))) .and(SERVICE_EXPOSE_MAP.DNS_PREFIX.isNull()) .fetchOne(0, Integer.class); }
private void createIndexTableIfNotExists(DSLContext dsl) { boolean tableExists = dsl.select(DSL.count()) .from("information_schema.tables") .where( DSL.field("table_schema").eq(colSchema.getName()) .and(DSL.field("table_name").eq(toroIndexTable.getName())) ) .fetchOne(0, int.class) > 0; if (!tableExists) { Name tableName = DSL.name(colSchema.getName(), toroIndexTable.getName()); dsl.execute( databaseInterface.createIndexesTableStatement( dsl.render(tableName), toroIndexTable.nameColumn.getName(), toroIndexTable.indexColumn.getName() ) ); } }