All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.teamapps.pojo.template.UdbQuery.txt Maven / Gradle / Ivy

There is a newer version: 0.7.3
Show newest version
package {package};

import org.teamapps.universaldb.*;
import org.teamapps.universaldb.index.*;
import org.teamapps.universaldb.index.text.*;
import org.teamapps.universaldb.index.translation.*;
import org.teamapps.universaldb.index.bool.*;
import org.teamapps.universaldb.index.numeric.*;
import org.teamapps.universaldb.index.file.*;
import org.teamapps.universaldb.index.enumeration.*;
import org.teamapps.universaldb.index.reference.multi.*;
import org.teamapps.universaldb.index.reference.single.*;
import org.teamapps.universaldb.index.binary.*;
import org.teamapps.universaldb.pojo.*;
import org.teamapps.universaldb.pojo.template.*;
import org.teamapps.universaldb.transaction.*;
import org.teamapps.universaldb.record.*;
import org.teamapps.universaldb.query.*;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
{imports}

public class {udbQuery} extends AbstractUdbQuery implements {query} {

    public {udbQuery}() {
    }

	@Override
	public {query} fullTextFilter(TextFilter textFilter, String... fieldNames) {
    	and({udbType}.table.createFullTextFilter(textFilter, fieldNames));
		return this;
	}

	@Override
	public {query} parseFullTextFilter(String query, String... fieldNames) {
    	and({udbType}.table.createFullTextFilter(query, fieldNames));
		return this;
	}

{methods}
	@Override
	public {udbQuery} andOr({query} ... queries) {
	    AbstractUdbQuery[] abstractUdbQueries = Arrays.copyOf(queries, queries.length, AbstractUdbQuery[].class);
		andOr(abstractUdbQueries);
		return this;
	}

    @Override
    public {query} customFilter(Function<{type}, Boolean> customFilter) {
        Function filterFunction = id -> {
            return customFilter.apply({type}.getById(id));
        };
        and(new CustomEntityFilter(filterFunction));
        return this;
    }

	@Override
	public List<{type}> execute() {
        BitSet result = filter({udbType}.table.getRecordBitSet());
        return new EntityBitSetList<>({type}.getBuilder(), result);
	}

    @Override
    public {type} executeExpectSingleton() {
        BitSet result = filter({udbType}.table.getRecordBitSet());
        int id = result.nextSetBit(1);
        if (id < 0) {
            return null;
        } else {
            return {type}.getBuilder().build(id);
        }
    }

	@Override
    public List<{type}> execute(String sortFieldName, boolean ascending, String ... path) {
        BitSet result = filter({udbType}.table.getRecordBitSet());
        return {udbType}.sort(result, sortFieldName, ascending, path);
    }

    @Override
    public List<{type}> execute(int startIndex, int length, Sorting sorting) {
        if (sorting == null) {
            return execute().stream()
                    .skip(startIndex)
                    .limit(length)
                    .collect(Collectors.toList());
        } else {
            return execute(sorting.getSortFieldName(), sorting.getSortDirection().isAscending(), sorting.getSortFieldPath()).stream()
                    .skip(startIndex)
                    .limit(length)
                    .collect(Collectors.toList());
        }
    }

    @Override
    public String toString() {
        Filter filter = getFilter();
        if (filter == null) {
            return "EMPTY QUERY";
        } else {
            return filter.toString();
        }
    }
}







© 2015 - 2025 Weber Informatics LLC | Privacy Policy