Manually create source records for the report. Agreggates cannot be provided as a column of a DataQuery result.

{@inheritDoc}
974573
public function sourceRecords($params = [], $sort = null, $limit = null)
    {
        $records = [];

        // Get the query to apply across all variants: looks at all subsites, translations, live stage only.
        $crossVariant = (function ($dataQuery) {
            $params = [
                'Subsite.filter' => false,
                'Versioned.mode' => 'stage',
                'Versioned.stage' => Versioned::LIVE,
            ];

            return $dataQuery->setDataQueryParam($params);
        });

        // Total.
        $records[] = [
            'Name' => _t(
                __CLASS__ . '.TotalPageCount',
                'Total live page count, across all translations and subsites'
            ),
            'Count' => $crossVariant(SiteTree::get())->count(),
        ];

        if (class_exists(Subsite::class)) {
            // Main site.
            $records[] = [
                'Name' => _t(__CLASS__ . '.PagesForMainSite', '- in the main site'),
                'Count' => $crossVariant(SiteTree::get())
                    ->filter(['SubsiteID' => 0])
                    ->count(),
            ];

            // Per subsite.
            $subsites = Subsite::get();
            foreach ($subsites as $subsite) {
                $records[] = [
                    'Name' => _t(
                        __CLASS__ . '.PagesForSubsite',
                        "- in the subsite '{SubsiteTitle}'",
                        ['SubsiteTitle' => $subsite->Title]
                    ),
                    'Count' => $crossVariant(SiteTree::get())
                        ->filter(['SubsiteID' => $subsite->ID])
                        ->count(),
                ];
            }
        }

        // Files.
        $records[] = [
            'Name' => _t(__CLASS__ . '.FileCount', 'File count'),
            'Count' => File::get()
                ->setDataQueryParam('Subsite.filter', false)
                ->filter(['ClassName:not' => Folder::class])
                ->count(),
        ];

        return ArrayList::create($records);
    }
1092557
public static function source(): RecordSource
    {
        /**
         * Container to be received via global scope.
         *
         * @var ContainerInterface $container
         */
        //Via global scope
        $container = self::staticContainer();

        if (empty($container)) {
            //Via global scope
            throw new ScopeException(sprintf(
                "Unable to get '%s' source, no container scope is available",
                static::class
            ));
        }

        return $container->get(ORMInterface::class)->source(static::class);
    }
937069
protected JRDataSource buildJRDataSource(Object dsCandidate) {
		if (dsCandidate == null)
			return null;

		if (dsCandidate instanceof JRDataSource)
			return (JRDataSource) dsCandidate;

		if (dsCandidate instanceof Collection)
			return new JRBeanCollectionDataSource((Collection) dsCandidate);

		if (dsCandidate instanceof ResultSet)
			return new JRResultSetDataSource((ResultSet) dsCandidate);

		if (dsCandidate.getClass().isArray())
			return new JRBeanArrayDataSource((Object[]) dsCandidate);


		throw new DJException("class " + dsCandidate.getClass().getName() + " is not supported " +
				"from the DynamicJasper WebWorK result type. Provide a JRDataSource implementation instead");
	}
1259409
@Override
    public <T> Producer<T> createProducer(final Bean<X> declaringBean, final Bean<T> bean, DisposalMethod<X, T> disposalMethod) {
        EnhancedAnnotatedField<T, X> enhancedField = getManager().getServices().get(MemberTransformer.class).loadEnhancedMember(field, getManager().getId());
        return new ProducerFieldProducer<X, T>(enhancedField, disposalMethod) {

            @Override
            public AnnotatedField<X> getAnnotated() {
                return field;
            }

            @Override
            public BeanManagerImpl getBeanManager() {
                return getManager();
            }

            @Override
            public Bean<X> getDeclaringBean() {
                return declaringBean;
            }

            @Override
            public Bean<T> getBean() {
                return bean;
            }
        };
    }
280574
@Override
    public void create(Collection<Bean> beans) throws AbortRuntimeException {
        init();
        Set<HBeanRow> beanRows = new HashSet<>();
        Map<HBeanRow, HBeanRow> refRows = new HashMap<>();
        Map<BeanId, Bean> beansMap = BeanUtils.uniqueIndex(beans);
        try {
            for (Bean bean : beans) {
                beanRows.add(new HBeanRow(bean, uids));
                for (BeanId ref : bean.getReferences()) {
                    Bean refBean = beansMap.get(ref);
                    HBeanRow row;
                    if (refBean == null) {
                        row = new HBeanRow(ref, uids);
                    } else {
                        row = new HBeanRow(refBean, uids);
                    }
                    refRows.put(row, row);
                }
            }
            table.getLazy(beanRows);
            throw Events.CFG303_BEAN_ALREADY_EXIST(beans.iterator().next().getId());
        } catch (HBeanNotFoundException e) {
            // ensure beans to be create does not exist
        }

        // ensure references exist either in memory or storage
        try {
            refRows = table.getLazyAsMap(refRows);
        } catch (HBeanNotFoundException e) {
            // only throw exception if the bean was not provided
            // as an argument to the create method.
            if (!idsFoundIn(beans, e)) {
                throw Events.CFG301_MISSING_RUNTIME_REF(e.getNotFound().iterator().next());
            }
            // make sure that references found in storage override the refRows
            for (HBeanRow row : e.getFound().keySet()) {
                refRows.put(row, row);
            }

        }
        // select the rows to update predecessors
        for (HBeanRow beanRow : beanRows) {
            for (HBeanRow refRow : beanRow.getReferenceRows()) {
                refRow = refRows.get(refRow);
                refRow.addPredecessor(beanRow);
            }
        }

        table.put(beanRows);
        table.put(Sets.newHashSet(refRows.values()));
    }
258391
public static <T> int createTable(ConnectionSource connectionSource, Class<T> dataClass) throws SQLException {
		Dao<T, ?> dao = DaoManager.createDao(connectionSource, dataClass);
		return doCreateTable(dao, false);
	}
166005
public <T> Evaluator<T> create(QueryMetadata metadata, List<? extends Expression<?>> sources,
            Expression<T> projection) {
        final CollQuerySerializer serializer = new CollQuerySerializer(templates);
        serializer.append("return ");
        if (projection instanceof FactoryExpression<?>) {
            serializer.append("(");
            serializer.append(ClassUtils.getName(projection.getType()));
            serializer.append(")(");
            serializer.handle(projection);
            serializer.append(")");
        } else {
            serializer.handle(projection);
        }
        serializer.append(";");

        Map<Object,String> constantToLabel = serializer.getConstantToLabel();
        Map<String, Object> constants = getConstants(metadata, constantToLabel);
        Class<?>[] types = new Class<?>[sources.size()];
        String[] names = new String[sources.size()];
        for (int i = 0; i < sources.size(); i++) {
            types[i] = sources.get(i).getType();
            names[i] = sources.get(i).toString();
        }

        // normalize types
        for (int i = 0; i < types.length; i++) {
            if (Primitives.isWrapperType(types[i])) {
                types[i] = Primitives.unwrap(types[i]);
            }
        }

        return factory.createEvaluator(serializer.toString(), projection.getType(), names,
                types, constants);
    }
123740
public function source(string $class): RecordSource
    {
        $source = $this->define($class, self::R_SOURCE_CLASS);

        if (empty($source)) {
            //Let's use default source
            $source = RecordSource::class;
        }

        $handles = $source::RECORD;
        if (empty($handles)) {
            //Force class to be handled
            $handles = $class;
        }

        return $this->getFactory()->make($source, [
            'class' => $handles,
            'orm'   => $this
        ]);
    }
1276244
private void generateDataSourceSingleThread(SQLiteDatabaseSchema schema, String dataSourceName) {
		// class DataSourceSingleThread
		String daoFactoryName = BindDaoFactoryBuilder.generateDaoFactoryName(schema);
		TypeSpec.Builder clazzBuilder = TypeSpec.classBuilder(DATA_SOURCE_SINGLE_THREAD_NAME)
				.addSuperinterface(TypeUtility.typeName(daoFactoryName));

		// _context field
		clazzBuilder.addField(FieldSpec.builder(SQLContextInSessionImpl.class, "_context", Modifier.PRIVATE).build());

		// constructor
		MethodSpec.Builder constructorBuilder = MethodSpec.constructorBuilder();
		constructorBuilder.addStatement("_context=new $T($L.this)", SQLContextInSessionImpl.class, dataSourceName);

		// all dao
		for (SQLiteDaoDefinition dao : schema.getCollection()) {
			TypeName daoImplName = BindDaoBuilder.daoTypeName(dao);

			// dao with external connections
			{
				String daoFieldName = extractDaoFieldNameForInternalDataSource(dao);
				MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("get" + dao.getName())
						.addModifiers(Modifier.PUBLIC).addJavadoc("\nretrieve dao $L\n", dao.getName())
						.returns(daoImplName);
				methodBuilder.beginControlFlow("if ($L==null)", daoFieldName);
				methodBuilder.addStatement("$L=new $T(this)", daoFieldName, daoImplName);
				methodBuilder.endControlFlow();
				methodBuilder.addStatement("return $L", daoFieldName);
				clazzBuilder.addMethod(methodBuilder.build());

				clazzBuilder.addField(FieldSpec.builder(daoImplName, daoFieldName, Modifier.PROTECTED).build());
			}
		}

		// constructor
		clazzBuilder.addMethod(constructorBuilder.build());

		// public SQLContext context()
		{
			MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("context").addModifiers(Modifier.PUBLIC)
					.returns(SQLContext.class);
			methodBuilder.addAnnotation(Override.class);
			methodBuilder.addStatement("return _context");
			clazzBuilder.addMethod(methodBuilder.build());
		}

		// onSessionOpened
		{
			MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("onSessionOpened")
					.addModifiers(Modifier.PROTECTED).returns(Void.TYPE);
			if (schema.hasLiveData()) {
				methodBuilder.addComment("support for live data");
				methodBuilder.addStatement("_context.onSessionOpened()");
			}

			clazzBuilder.addMethod(methodBuilder.build());
		}

		// onSessionClear
		{
			MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("onSessionClear")
					.addModifiers(Modifier.PROTECTED).returns(Void.TYPE);
			if (schema.hasLiveData()) {
				methodBuilder.addComment("support for live data");
				methodBuilder.addStatement("_context.onSessionOpened()");
			}

			clazzBuilder.addMethod(methodBuilder.build());
		}

		// onSessionClosed
		{
			MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("onSessionClosed")
					.addModifiers(Modifier.PROTECTED).returns(Void.TYPE);

			if (schema.hasLiveData()) {
				methodBuilder.addComment("support for live data");
				methodBuilder.addStatement("$T daosWithEvents=_context.onSessionClosed()",
						ParameterizedTypeName.get(Set.class, Integer.class));

				for (SQLiteDaoDefinition dao : schema.getCollection()) {

					String daoFieldName = extractDaoFieldNameForInternalDataSource(dao);
					if (dao.hasLiveData()) {
						methodBuilder.beginControlFlow("if ($L!=null && daosWithEvents.contains($L))", daoFieldName,
								dao.daoUidName);
						methodBuilder.addStatement("$L.invalidateLiveData()", daoFieldName);
						methodBuilder.endControlFlow();
					} else {
						methodBuilder.addComment("$S has no live data", daoFieldName);
					}
				}
			}

			clazzBuilder.addMethod(methodBuilder.build());
		}

		// build method bindToThread
		{
			MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("bindToThread").addModifiers(Modifier.PUBLIC)
					.returns(TypeUtility.typeName(DATA_SOURCE_SINGLE_THREAD_NAME));

			// methodBuilder.addStatement("_context.bindToThread()");
			methodBuilder.addStatement("return this");
			clazzBuilder.addMethod(methodBuilder.build());

			// build single thread daoFactory used in transaction
			classBuilder.addField(FieldSpec
					.builder(TypeUtility.typeName(DATA_SOURCE_SINGLE_THREAD_NAME), "_daoFactorySingleThread",
							Modifier.PROTECTED)
					.addJavadoc("Used only in transactions (that can be executed one for time\n")
					.initializer("new DataSourceSingleThread()").build());
		}
		
		// build transactions
		{
			SchemaUtility.generateTransaction(clazzBuilder, schema, false);
		}

		classBuilder.addType(clazzBuilder.build());

	}
1354631
public function CopyPropertyRecords($oField, $sourceRecordID)
    {
        if (!$this->isNewVariant() || 'shop_article_variants' != $oField->name) {
            parent::CopyPropertyRecords($oField, $sourceRecordID);
        }
    }
1055873
@Override
    public Row buildRow(final DefaultDataSet ds) {
        /** loop through each line in the file */
        while (true) {
            String line;
            try {
                line = fetchNextRecord(br, getQualifier(), getDelimiter());
            } catch (final IOException e) {
                throw new FPException("Error Fetching Record From File...", e);
            }

            if (line == null) {
                return null;
            }

            // check to see if the user has elected to skip the first record
            if (shouldSkipFirstRecord(line, ds)) {
                continue;
            }

            // TODO
            // seems like we may want to try doing something like this. I have my reservations because
            // it is possible that we don't get a "detail" id and this might generate NPE
            // is it going to create too much overhead to do a null check here as well???
            List<String> columns = ParserUtils.splitLine(line, getDelimiter(), getQualifier(), FPConstants.SPLITLINE_SIZE_INIT,
                    isPreserveLeadingWhitespace(), isPreserveTrailingWhitespace());
            final String mdkey = ParserUtils.getCMDKeyForDelimitedFile(getPzMetaData(), columns);
            final List<ColumnMetaData> cmds = ParserUtils.getColumnMetaData(mdkey, getPzMetaData());
            // DEBUG

            // Incorrect record length on line log the error. Line
            // will not be included in the dataset
            if (!validateColumns(ds, columns, cmds, line)) {
                continue;
            }

            return createRow(line, columns, mdkey);
        }
    }
559915
@Override
	public synchronized void createReport() throws IOException {
		if (reportLines.isEmpty()) {
			log.debug("No data to report. Skipping report generation.");
			return;
		}

		File reportFile = new File(archiveDir.get(), createFileName());

		log.debug("Writing report to file: {}", reportFile);

		String header = getHeaderLine();
		if (header != null) {
			reportLines.addFirst(header);
		}
		FileUtils.writeLines(reportFile, charset == null ? defaultCharset.name() : charset.name(), reportLines);

		reportLines.clear();
	}
245699
private DataSource preCreate(Long pipelineId, DbMediaSource dbMediaSource) {

        if (CollectionUtils.isEmpty(dataSourceHandlers)) {
            return null;
        }

        DataSource dataSource = null;
        for (DataSourceHanlder handler : dataSourceHandlers) {
            if (handler.support(dbMediaSource)) {
                dataSource = handler.create(pipelineId, dbMediaSource);
                if (dataSource != null) {
                    return dataSource;
                }
            }
        }
        return null;
    }
612017
public void mergeSourceData(Record recSource, Record recDest, boolean bFound)
    {
        for (int iFieldSeq = 0; iFieldSeq < recSource.getFieldCount(); iFieldSeq++)
        {
            BaseField fldSource = recSource.getField(iFieldSeq);
            BaseField fldDest = recDest.getField(fldSource.getFieldName());
            if (fldDest != null)
                if (!fldSource.isNull())
                    fldDest.moveFieldToThis(fldSource);
        }
    }
908942
ConstructorFunction<Void, RecordFactory> createRecordFactoryConstructor(final SerializationService serializationService) {
        return notUsedArg -> {
            switch (mapConfig.getInMemoryFormat()) {
                case BINARY:
                    return new DataRecordFactory(mapConfig, serializationService, partitioningStrategy);
                case OBJECT:
                    return new ObjectRecordFactory(mapConfig, serializationService);
                default:
                    throw new IllegalArgumentException("Invalid storage format: " + mapConfig.getInMemoryFormat());
            }
        };
    }
394461
protected function decorateSubreportsDataSource(): void
	{
		$builder = $this->getContainerBuilder();

		$subreports = $builder->findByTag(self::TAG_CACHE);
		foreach ($subreports as $service => $tag) {
			$serviceDef = $builder->getDefinition($service);

			// Validate datasource class
			if (!is_subclass_of((string) $serviceDef->getType(), DataSource::class)) {
				throw new AssertionException(sprintf(
					'Please use tag "%s" only on datasource (object %s found in %s).',
					self::TAG_CACHE,
					$serviceDef->getType(),
					$service
				));
			}

			// If cache.key is not provided, pick subreport name (fullname)
			if (!isset($tag['key'])) $tag['key'] = $serviceDef->getTag(self::TAG_SUBREPORT_DATASOURCE);

			// Validate cache scheme
			$this->validateConfig($this->scheme['tags'][self::TAG_CACHE], $tag, sprintf('%s', self::TAG_CACHE));

			// Wrap factory to cache
			$wrappedDef = $builder->addDefinition(sprintf('%s_cached', $service), $serviceDef);

			// Remove definition
			$builder->removeDefinition($service);

			// Add cached defition of datasource with wrapped original datasource
			$builder->addDefinition($service)
				->setFactory(CachedDataSource::class, [1 => $wrappedDef])
				->addSetup('setKey', [$tag['key']])
				->addSetup('setExpiration', [$tag['expiration']])
				->addTag(self::TAG_SUBREPORT_DATASOURCE, $wrappedDef->getTag(self::TAG_SUBREPORT_DATASOURCE));

			// Append cache tags to subreport introspection
			$subreportDef = $builder->getDefinition($wrappedDef->getTag(self::TAG_SUBREPORT_DATASOURCE));
			$introspection = $subreportDef->getTag(self::TAG_INTROSPECTION);
			$introspection['cache'] = ['datasource' => $tag];
			$subreportDef->addTag(self::TAG_INTROSPECTION, $introspection);
		}
	}
37376
@Bean
    public DataSource dataSource() throws SQLException {
        Preconditions.checkState(isValidConfiguration(), "The orchestration configuration is invalid, please choose one from Sharding rule and Master-slave rule.");
        return isShardingRule() ? createShardingDataSource() : createMasterSlaveDataSource();
    }