Search in sources :

Example 1 with Sorter

use of com.blazebit.persistence.view.Sorter in project blaze-persistence by Blazebit.

the class SorterTest method testAscendingNullFirst.

@Test
public void testAscendingNullFirst() {
    Sorter sorter = Sorters.sorter(true, true);
    verifySorter(sorter).orderBy(expression, true, true);
}
Also used : Sorter(com.blazebit.persistence.view.Sorter) Test(org.junit.Test)

Example 2 with Sorter

use of com.blazebit.persistence.view.Sorter in project blaze-persistence by Blazebit.

the class EntityViewSettingHelper method applyAttributeSorters.

private static <T, Q extends FullQueryBuilder<T, Q>> void applyAttributeSorters(EntityViewSetting<?, ?> setting, Q cb, String viewRoot, Set<String> fetches, ManagedViewTypeImplementor<?> entityViewRoot) {
    String name = entityViewRoot.getJavaType().getSimpleName();
    StringBuilder sb = null;
    for (Map.Entry<String, Sorter> attributeSorterEntry : setting.getAttributeSorters().entrySet()) {
        String attributeName = attributeSorterEntry.getKey();
        NavigableMap<String, AbstractMethodAttribute<?, ?>> recursiveAttributes = (NavigableMap<String, AbstractMethodAttribute<?, ?>>) entityViewRoot.getRecursiveAttributes();
        Map.Entry<String, AbstractMethodAttribute<?, ?>> entry = recursiveAttributes.floorEntry(attributeName);
        if (entry == null || !attributeName.startsWith(entry.getKey())) {
            throw new IllegalArgumentException("The attribute with the name '" + attributeName + "' couldn't be found on the view type '" + name + "'");
        }
        if (attributeName.length() != entry.getKey().length()) {
            throw new UnsupportedOperationException("No support yet for entity attribute filtering!");
        // // If we get here, the attribute type is a managed type and we can copy the rest of the parts
        // for (; i < parts.length; i++) {
        // type = jpaMetamodel.managedType(maybeUnmanagedType);
        // newSb.append('.');
        // newSb.append(parts[i]);
        // jpaAttribute = type.getAttribute(parts[i]);
        // maybeUnmanagedType = jpaAttribute.getJavaType();
        // }
        }
        Sorter sorter = attributeSorterEntry.getValue();
        if (sb == null) {
            sb = new StringBuilder(name.length() + attributeName.length() + 1);
        } else {
            sb.setLength(0);
        }
        String attributeExpression;
        if (fetches.isEmpty() || fetches.contains(attributeName)) {
            attributeExpression = buildAlias(sb, name, attributeName);
        } else {
            attributeExpression = buildMapping(sb, cb, viewRoot, recursiveAttributes, attributeName);
        }
        sorter.apply(cb, attributeExpression);
    }
}
Also used : NavigableMap(java.util.NavigableMap) Sorter(com.blazebit.persistence.view.Sorter) AbstractMethodAttribute(com.blazebit.persistence.view.impl.metamodel.AbstractMethodAttribute) HashMap(java.util.HashMap) Map(java.util.Map) NavigableMap(java.util.NavigableMap)

Example 3 with Sorter

use of com.blazebit.persistence.view.Sorter in project blaze-persistence by Blazebit.

the class SorterTest method testDescendingNullFirst.

@Test
public void testDescendingNullFirst() {
    Sorter sorter = Sorters.sorter(false, true);
    verifySorter(sorter).orderBy(expression, false, true);
}
Also used : Sorter(com.blazebit.persistence.view.Sorter) Test(org.junit.Test)

Example 4 with Sorter

use of com.blazebit.persistence.view.Sorter in project blaze-persistence by Blazebit.

the class SorterTest method testDescendingNullLast.

@Test
public void testDescendingNullLast() {
    Sorter sorter = Sorters.sorter(false, false);
    verifySorter(sorter).orderBy(expression, false, false);
}
Also used : Sorter(com.blazebit.persistence.view.Sorter) Test(org.junit.Test)

Example 5 with Sorter

use of com.blazebit.persistence.view.Sorter in project blaze-persistence by Blazebit.

the class SorterTest method testAscendingNullLast.

@Test
public void testAscendingNullLast() {
    Sorter sorter = Sorters.sorter(true, false);
    verifySorter(sorter).orderBy(expression, true, false);
}
Also used : Sorter(com.blazebit.persistence.view.Sorter) Test(org.junit.Test)

Aggregations

Sorter (com.blazebit.persistence.view.Sorter)5 Test (org.junit.Test)4 AbstractMethodAttribute (com.blazebit.persistence.view.impl.metamodel.AbstractMethodAttribute)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1