Package com.asakusafw.compiler.flow

Examples of com.asakusafw.compiler.flow.DataClass


        if (downstream.size() == 1) {
            FragmentNode succ = downstream.iterator().next();
            return succ.getName();
        }

        DataClass model = environment.getDataClasses().load(type);
        if (model == null) {
            throw new IllegalStateException(type.toString());
        }
        Type dataType = importer.toType(model.getType());

        SimpleName cacheName = names.create("cache");
        FieldDeclaration cache = factory.newFieldDeclaration(
                null,
                new AttributeBuilder(factory)
                    .Private()
                    .toAttributes(),
                dataType,
                cacheName,
                model.createNewInstance(dataType));

        SimpleName argumentName = names.create("arg");
        List<Statement> statements = Lists.create();
        Iterator<FragmentNode> iter = downstream.iterator();
        while (iter.hasNext()) {
            FragmentNode node = iter.next();
            if (iter.hasNext()) {
                statements.add(model.assign(cacheName, argumentName));
                statements.add(new ExpressionBuilder(factory, node.getName())
                    .method(FlowElementProcessor.RESULT_METHOD_NAME, cacheName)
                    .toStatement());
            } else {
                statements.add(new ExpressionBuilder(factory, node.getName())
                    .method(FlowElementProcessor.RESULT_METHOD_NAME, argumentName)
                    .toStatement());
            }
        }

        MethodDeclaration result = factory.newMethodDeclaration(
                null,
                new AttributeBuilder(factory)
                    .annotation(importer.toType(Override.class))
                    .Public()
                    .toAttributes(),
                factory.newBasicType(BasicTypeKind.VOID),
                factory.newSimpleName(FlowElementProcessor.RESULT_METHOD_NAME),
                Collections.singletonList(factory.newFormalParameterDeclaration(
                        Models.toType(factory, model.getType()),
                        argumentName)),
                statements);

        return factory.newClassInstanceCreationExpression(
                null,
View Full Code Here


        ShuffleKey keyInfo = desciption.getKeyInfo();

        Type inputType = input.getDescription().getDataType();

        DataClassRepository dataClasses = environment.getDataClasses();
        DataClass source = dataClasses.load(inputType);
        DataClass target = dataClasses.load(desciption.getOutputType());
        if (source == null) {
            error("データクラス{0}は定義されていません", inputType);
        }
        if (target == null) {
            error("データクラス{0}は定義されていません", desciption.getOutputType());
        }
        if (source == null || target == null) {
            return null;
        }

        List<ShuffleModel.Term> terms = Lists.create();
        for (String name : keyInfo.getGroupProperties()) {
            int termId = terms.size() + 1;
            DataClass.Property property = target.findProperty(name);
            if (property == null) {
                error("データクラス{0}にはプロパティ{1}が定義されていません", target, name);
                continue;
            }
            terms.add(new ShuffleModel.Term(
                    termId,
                    property,
                    ShuffleModel.Arrangement.GROUPING));
        }
        for (ShuffleKey.Order order : keyInfo.getOrderings()) {
            int termId = terms.size() + 1;
            DataClass.Property property = target.findProperty(order.getProperty());
            if (property == null) {
                error("データクラス{0}にはプロパティ{1}が定義されていません",
                        target,
                        order.getProperty());
                continue;
View Full Code Here

        FlowElementPortDescription input = context.getInputPort(Extend.ID_INPUT);
        FlowElementPortDescription output = context.getOutputPort(Extend.ID_OUTPUT);
        DataObjectMirror cache = context.createModelCache(output.getDataType());
        context.setOutput(cache.get());

        DataClass sourceType = loadChecked(input);
        DataClass sinkType = loadChecked(output);
        if (sourceType == null || sinkType == null) {
            return;
        }

        context.add(cache.createReset());
        Expression inputObject = context.getInput();
        Expression outputObject = cache.get();
        for (DataClass.Property sourceProperty : sourceType.getProperties()) {
            Property sinkProperty = sinkType.findProperty(sourceProperty.getName());
            if (sinkProperty == null) {
                getEnvironment().error(
                        "{0}において、{2}.{3}に対応するプロパティが{1}に定義されていません",
                        context.getOperatorDescription().getName(),
                        sinkType,
View Full Code Here

            }
        }
    }

    private DataClass loadChecked(FlowElementPortDescription port) {
        DataClass resolved = getEnvironment().getDataClasses().load(port.getDataType());
        if (resolved == null) {
            getEnvironment().error(
                    "型{0}を解決できませんでした",
                    port.getDataType());
        }
View Full Code Here

        FlowElementPortDescription joinedPort = context.getOutputPort(MasterJoin.ID_OUTPUT_JOINED);
        FlowElementPortDescription missedPort = context.getOutputPort(MasterJoin.ID_OUTPUT_MISSED);

        DataObjectMirror resultCache = context.createModelCache(joinedPort.getDataType());
        DataClass outputType = getEnvironment().getDataClasses().load(joinedPort.getDataType());
        List<Statement> process = Lists.create();
        process.add(resultCache.createReset());

        Joined annotation = TypeUtil.erase(joinedPort.getDataType()).getAnnotation(Joined.class);
        Set<String> saw = Sets.create();
        for (Joined.Term term : annotation.terms()) {
            DataClass inputType = getEnvironment().getDataClasses().load(term.source());
            Expression input;
            if (term.source().equals(context.getInputPort(MasterJoin.ID_INPUT_MASTER).getDataType())) {
                input = masterAnalyzer.getGetRawMasterExpression();
            } else {
                input = context.getProcessInput(tx);
            }
            for (Joined.Mapping mapping : term.mappings()) {
                if (saw.contains(mapping.destination())) {
                    continue;
                }
                saw.add(mapping.destination());
                Property sourceProperty = inputType.findProperty(mapping.source());
                Property destinationProperty = outputType.findProperty(mapping.destination());
                process.add(destinationProperty.createSetter(
                        resultCache.get(),
                        sourceProperty.createGetter(input)));
            }
View Full Code Here

        FlowElementPortDescription input = context.getInputPort(Project.ID_INPUT);
        FlowElementPortDescription output = context.getOutputPort(Project.ID_OUTPUT);
        DataObjectMirror cache = context.createModelCache(output.getDataType());
        context.setOutput(cache.get());

        DataClass sourceType = loadChecked(input);
        DataClass sinkType = loadChecked(output);
        if (sourceType == null || sinkType == null) {
            return;
        }

        context.add(cache.createReset());
        Expression inputObject = context.getInput();
        Expression outputObject = cache.get();
        for (DataClass.Property sinkProperty : sinkType.getProperties()) {
            Property sourceProperty = sourceType.findProperty(sinkProperty.getName());
            if (sourceProperty == null) {
                getEnvironment().error(
                        "{0}において、{2}.{3}に対応するプロパティが{1}に定義されていません",
                        context.getOperatorDescription().getName(),
View Full Code Here

            }
        }
    }

    private DataClass loadChecked(FlowElementPortDescription port) {
        DataClass resolved = getEnvironment().getDataClasses().load(port.getDataType());
        if (resolved == null) {
            getEnvironment().error(
                    "型{0}を解決できませんでした",
                    port.getDataType());
        }
View Full Code Here

    }

    private DataClass toDataClass(FlowElementInput input) {
        assert input != null;
        Type runtime = input.getDescription().getDataType();
        DataClass type = getEnvironment().getDataClasses().load(runtime);
        if (type == null) {
            getEnvironment().error(
                    "型{0}の解析に失敗しました",
                    runtime);
            return new DataClass.Unresolved(getEnvironment().getModelFactory(), runtime);
View Full Code Here

        return type;
    }

    private List<Property> toJoinKey(FlowElementInput input) {
        assert input != null;
        DataClass dataClass = toDataClass(input);
        ShuffleKey key = input.getDescription().getShuffleKey();
        assert key != null;
        List<Property> results = Lists.create();
        for (String name : key.getGroupProperties()) {
            Property property = dataClass.findProperty(name);
            if (property == null) {
                getEnvironment().error(
                        "型{0}にプロパティ{1}が見つかりませんでした",
                        dataClass,
                        name);
View Full Code Here

    @Override
    public DataClass load(Type type) {
        Precondition.checkMustNotBeNull(type, "type");
        LOG.debug("Resolving {} as a data model", type);
        for (DataClassRepository repository : repositories) {
            DataClass dataClass = repository.load(type);
            if (dataClass != null) {
                return dataClass;
            }
        }
        return null;
View Full Code Here

TOP

Related Classes of com.asakusafw.compiler.flow.DataClass

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.