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

org.meridor.perspective.sql.QueryPart Maven / Gradle / Ivy

There is a newer version: 1.3.4.1
Show newest version
package org.meridor.perspective.sql;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public interface QueryPart {
    
    String getSql();
    
    List getParameters();
    
    default Optional getPreviousPart() {
        return Optional.empty();
    }

    default List getParts() {
        List queryParts = new ArrayList<>();
        if (getPreviousPart().isPresent()) {
            QueryPart prevQueryPart = getPreviousPart().get();
            queryParts.addAll(prevQueryPart.getParts());
        }
        queryParts.add(this);
        return queryParts;
    }

    default Query getQuery() {
        String sql = getParts().stream()
                .map(QueryPart::getSql)
                .collect(Collectors.joining());
        List parameters = getParts().stream()
                .flatMap(p -> p.getParameters().stream())
                .collect(Collectors.toList());
        Query query = new Query();
        query.setSql(sql);
        List parametersEntity = new ArrayList<>();
        parametersEntity.addAll(parameters);
        query.setParameters(parametersEntity);
        return query;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy