Search in sources :

Example 1 with JoinColumn

use of org.dotwebstack.framework.backend.postgres.model.JoinColumn in project dotwebstack-framework by dotwebstack.

the class JoinBuilderTest method createJoinColumns.

private List<JoinColumn> createJoinColumns() {
    JoinColumn joinColumnRefColumn = new JoinColumn();
    joinColumnRefColumn.setName("a_identifier");
    joinColumnRefColumn.setReferencedColumn("b_identifier");
    JoinColumn joinColumnRefField = new JoinColumn();
    joinColumnRefField.setName("c_identifier");
    joinColumnRefField.setReferencedField("otherIdentifier");
    return List.of(joinColumnRefColumn, joinColumnRefField);
}
Also used : JoinColumn(org.dotwebstack.framework.backend.postgres.model.JoinColumn)

Example 2 with JoinColumn

use of org.dotwebstack.framework.backend.postgres.model.JoinColumn in project dotwebstack-framework by dotwebstack.

the class JoinHelper method resolveJoinColumn.

private static JoinColumn resolveJoinColumn(JoinColumn joinColumn) {
    JoinColumn jc = new JoinColumn();
    jc.setName(joinColumn.getName());
    jc.setReferencedField(StringUtils.substringAfter(joinColumn.getReferencedField(), "."));
    jc.setReferencedColumn(joinColumn.getReferencedColumn());
    return jc;
}
Also used : JoinColumn(org.dotwebstack.framework.backend.postgres.model.JoinColumn)

Example 3 with JoinColumn

use of org.dotwebstack.framework.backend.postgres.model.JoinColumn in project dotwebstack-framework by dotwebstack.

the class FilterConditionBuilderTest method build_returnsCondition_forFieldPathWithMultipleItems.

@Test
void build_returnsCondition_forFieldPathWithMultipleItems() {
    var childObjectType = new PostgresObjectType();
    childObjectType.setTable("child_v");
    childObjectType.setFields(Map.of("child_id", new PostgresObjectField()));
    var joinColumns = new ArrayList<JoinColumn>();
    var joinColumn = new JoinColumn();
    joinColumn.setName("parent_id");
    joinColumn.setReferencedColumn("child_id");
    joinColumns.add(joinColumn);
    var parentField = new PostgresObjectField();
    parentField.setJoinColumns(joinColumns);
    parentField.setObjectType(new PostgresObjectType());
    parentField.setTargetType(childObjectType);
    var childField = new PostgresObjectField();
    childField.setColumn("child_column");
    Map<String, Object> values = Map.of("eq", "foo");
    var filterCriteria = ObjectFieldFilterCriteria.builder().filterType(FilterType.EXACT).fieldPath(List.of(parentField, childField)).value(values).build();
    var condition = build(filterCriteria);
    assertThat(condition, notNullValue());
    assertThat(condition.toString(), equalTo("exists (\n" + "  select 1\n" + "  from \"child_v\" \"x1\"\n" + "  where (\n" + "    \"x1\".\"parent_id\" = \"x1\".\"child_id\"\n" + "    and \"x1\".\"child_column\" = 'foo'\n" + "  )\n" + ")"));
}
Also used : PostgresObjectType(org.dotwebstack.framework.backend.postgres.model.PostgresObjectType) JoinColumn(org.dotwebstack.framework.backend.postgres.model.JoinColumn) PostgresObjectField(org.dotwebstack.framework.backend.postgres.model.PostgresObjectField) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with JoinColumn

use of org.dotwebstack.framework.backend.postgres.model.JoinColumn in project dotwebstack-framework by dotwebstack.

the class JoinHelperTest method createJoinConditions_returnsListCondition.

@Test
void createJoinConditions_returnsListCondition() {
    var context = new Context();
    context.setFields(Map.of("arg", mock(ContextField.class)));
    var contextCriteria = ContextCriteria.builder().name("test").context(context).values(Map.of("arg", "val")).build();
    Table<Record> junctionTable = findTable("table1", contextCriteria);
    Table<Record> referencedTable = findTable("table2", contextCriteria);
    JoinColumn joinColumn = mock(JoinColumn.class);
    when(joinColumn.getName()).thenReturn("arg");
    List<JoinColumn> joinColumns = List.of(joinColumn);
    when(joinColumn.getReferencedField()).thenReturn("any");
    PostgresObjectType objectType = mock(PostgresObjectType.class);
    PostgresObjectField field = mock(PostgresObjectField.class);
    when(field.getColumn()).thenReturn("arg");
    when(objectType.getField(any(String.class))).thenReturn(field);
    var result = createJoinConditions(junctionTable, referencedTable, joinColumns, objectType);
    assertThat(result, notNullValue());
    assertThat(result.toString(), is("\"table1_test_ctx({0})\".\"arg\" = \"table2_test_ctx({0})\".\"arg\""));
}
Also used : Context(org.dotwebstack.framework.core.model.Context) JoinColumn(org.dotwebstack.framework.backend.postgres.model.JoinColumn) PostgresObjectType(org.dotwebstack.framework.backend.postgres.model.PostgresObjectType) PostgresObjectField(org.dotwebstack.framework.backend.postgres.model.PostgresObjectField) Record(org.jooq.Record) Test(org.junit.jupiter.api.Test)

Example 5 with JoinColumn

use of org.dotwebstack.framework.backend.postgres.model.JoinColumn in project dotwebstack-framework by dotwebstack.

the class JoinHelper method resolveReferencedField.

public static JoinColumn resolveReferencedField(JoinColumn joinColumn, PostgresObjectType objectType) {
    if (StringUtils.isNotBlank(joinColumn.getReferencedField())) {
        JoinColumn result = new JoinColumn();
        result.setName(joinColumn.getName());
        result.setReferencedColumn(objectType.getField(joinColumn.getReferencedField()).getColumn());
        return result;
    }
    return joinColumn;
}
Also used : JoinColumn(org.dotwebstack.framework.backend.postgres.model.JoinColumn)

Aggregations

JoinColumn (org.dotwebstack.framework.backend.postgres.model.JoinColumn)7 Test (org.junit.jupiter.api.Test)4 ConstraintValidatorContext (javax.validation.ConstraintValidatorContext)2 PostgresObjectField (org.dotwebstack.framework.backend.postgres.model.PostgresObjectField)2 PostgresObjectType (org.dotwebstack.framework.backend.postgres.model.PostgresObjectType)2 ArrayList (java.util.ArrayList)1 Context (org.dotwebstack.framework.core.model.Context)1 Record (org.jooq.Record)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1