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

com.scaleset.search.AbstractSearchDao Maven / Gradle / Ivy

There is a newer version: 0.24.0
Show newest version
package com.scaleset.search;

import java.util.ArrayList;
import java.util.List;

public abstract class AbstractSearchDao implements GenericSearchDao {

    public void close() {
    }

    @Override
    public void delete(T entity) throws Exception {
        throw new UnsupportedOperationException();
    }

    @Override
    public void deleteByKey(K id) throws Exception {
        throw new UnsupportedOperationException();
    }

    @Override
    public void deleteByQuery(Query query) throws Exception {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean exists(K id) throws Exception {
        boolean result = findById(id) != null;
        return result;
    }

    @Override
    public T findOne(String q) throws Exception {
        T result = null;
        Query query = new QueryBuilder(q).limit(1).build();
        Results results = search(query);
        if (!results.getItems().isEmpty()) {
            result = results.getItems().get(0);
        }
        return result;
    }

    @Override
    public long count(String q) throws Exception {
        // hack for now.  eventually use ES search api.
        Query query = new QueryBuilder(q).limit(0).build();
        Results results = search(query);
        long result = results.getTotalItems();
        return result;
    }

    @Override
    public T save(T entity) throws Exception {
        throw new UnsupportedOperationException();
    }

    @Override
    public List saveBatch(List entities) throws Exception {
        List results = new ArrayList<>();
        for (T entity : entities) {
            save(entity);
            results.add(entity);
        }
        return results;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy