private AstSummarize generateTerm(ModelReference sourceModel, List<Source> group) { Map<String, ModelProperty> resolver = new HashMap<String, ModelProperty>(); List<AstPropertyFolding> foldings = new ArrayList<AstPropertyFolding>(); for (ModelProperty property : model.getProperties()) { Source source = property.getSource(); assert source.getDeclaring().equals(sourceModel); resolver.put(source.getName(), property); foldings.add( new AstPropertyFolding( null, AstBuilder.getDesciption("{0}({1})", source.getAggregator().name(), source.getName()), Arrays.asList( new AstAttribute[] { AstBuilder.getOriginalName(property.getName()), }), AstBuilder.toName(source.getAggregator()), AstBuilder.toName(source), AstBuilder.toName(property))); } List<AstSimpleName> grouping = new ArrayList<AstSimpleName>(); for (Source source : group) { ModelProperty property = resolver.get(source.getName()); assert property != null : source; grouping.add(AstBuilder.toName(property)); } return new AstSummarize( null, new AstModelReference(null, AstBuilder.toName(sourceModel)), new AstModelFolding(null, foldings), grouping.isEmpty() ? null : new AstGrouping(null, grouping)); }
private AstRecord generateTerm() { List<AstPropertyDefinition> properties = Lists.create(); for (ModelProperty property : model.getProperties()) { properties.add( new AstPropertyDefinition( null, AstBuilder.getDesciption("{0}", property.getName()), Arrays.asList( new AstAttribute[] { AstBuilder.getOriginalName(property.getName()), }), AstBuilder.toName(property), AstBuilder.toType(property.getType()))); } return new AstRecordDefinition(null, properties); }
/** 単純なテスト。 */ @Test public void simple() { TableModelDescription a = new TableModelBuilder("A") .add(null, "id", PropertyTypeKind.LONG) .add(null, "hoge", new StringType(255)) .toDescription(); TableModelDescription b = new TableModelBuilder("B") .add(null, "id", PropertyTypeKind.LONG) .add(null, "foo", new StringType(255)) .toDescription(); JoinedModelBuilder target = new JoinedModelBuilder("J", a, "a", b, "b"); target.on("a.id", "b.id"); target.add("id", "a.id"); target.add("hoge", "a.hoge"); target.add("bar", "b.foo"); JoinedModelDescription desc = target.toDescription(); assertThat(desc.getFromModel().getSimpleName(), is("A")); assertThat(desc.getJoinModel().getSimpleName(), is("B")); assertThat(desc.getFromCondition(), is(sources(a, "id"))); assertThat(desc.getJoinCondition(), is(sources(b, "id"))); List<ModelProperty> props = desc.getProperties(); assertThat(props.size(), is(3)); ModelProperty id = props.get(0); assertThat(id.getName(), is("id")); assertThat(id.getType().getKind(), is(PropertyTypeKind.LONG)); assertThat(id.getFrom(), is(source(a, "id"))); assertThat(id.getJoined(), is(source(b, "id"))); ModelProperty hoge = props.get(1); assertThat(hoge.getName(), is("hoge")); assertThat(hoge.getType().getKind(), is(PropertyTypeKind.STRING)); assertThat(hoge.getFrom(), is(source(a, "hoge"))); assertThat(hoge.getJoined(), is(nullValue())); ModelProperty bar = props.get(2); assertThat(bar.getName(), is("bar")); assertThat(bar.getType().getKind(), is(PropertyTypeKind.STRING)); assertThat(bar.getFrom(), is(nullValue())); assertThat(bar.getJoined(), is(source(b, "foo"))); }