com.scaleset.search.AbstractSearchDao Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scaleset-search Show documentation
Show all versions of scaleset-search Show documentation
Java object model for representing query requests in REST protocols.
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;
}
}