Ejemplo n.º 1
0
  @Override
  public Cursor<T> findAll(Query query, Class clazz) {
    SearchRequestBuilder builder = service.findAll(query, getIndex(), getType(), false);
    SearchHits h = service.executeBuilder(builder);
    if (h != null) {
      return new BlockCursor<T>(clazz, builder, 0, 100);
    }

    return null;
  }
Ejemplo n.º 2
0
  @Override
  public Cursor<T> findAll() {
    SearchRequestBuilder builder = service.findAllScroll(getIndex(), getType());
    SearchScrollRequestBuilder scroll = service.executeScroll(builder);
    if (builder != null) {
      try {
        return new ScrollCursor<T>(t, scroll);
      } catch (Exception e) {
        logger.log(Level.WARNING, "Failed to create new scroll.", e);
      }
    }

    return null;
  }
Ejemplo n.º 3
0
 @Override
 public T findById(String id) {
   String s = service.realTimeGet(getIndex(), getType(), id);
   if (s != null) {
     return mapping.get(s, t);
   } else {
     return null;
   }
 }
Ejemplo n.º 4
0
 @Override
 public OperationStatus write(WriteOperation builder, List<? extends T> t) {
   // TODO: need to gather operation results and return
   OperationStatus status = new OperationStatus();
   if (t.size() == 1) {
     service.index(
         getIndex(),
         getType(),
         mapping.get(t.get(0)),
         AnnotationHelper.getDocumentId(t.get(0), getIdField()));
   } else if (t.size() > 1) {
     List<String> list = new ArrayList<String>();
     for (T o : t) {
       list.add(mapping.get(o));
       // TODO: what do we do with null ids? bail with exception? Report the error with
       // OperationStatus?
     }
     service.bulkIndex(getIndex(), getType(), list.toArray(new String[list.size()]), getIdField());
   }
   status.setSucceeded(true);
   return status;
 }
Ejemplo n.º 5
0
 @Override
 public OperationStatus write(T... t) {
   // TODO: Need to gather results from index operation
   OperationStatus status = new OperationStatus();
   if (t.length == 1) {
     service.index(
         getIndex(),
         getType(),
         mapping.get(t[0]),
         AnnotationHelper.getDocumentId(t[0], getIdField()));
   } else if (t.length > 1) {
     List<String> list = new ArrayList<String>();
     for (T o : t) {
       list.add(mapping.get(o));
       // TODO: what do we do with null ids? bail with exception? Report the error with
       // OperationStatus?
     }
     service.bulkIndex(getIndex(), getType(), list.toArray(new String[list.size()]), getIdField());
   }
   status.setSucceeded(true);
   return status;
 }
Ejemplo n.º 6
0
 @Override
 public <T> T find(Query query, Class<T> clazz) {
   String s = service.getSingle(query, getIndex(), getType());
   return mapping.get(s, clazz);
 }
Ejemplo n.º 7
0
 @Override
 public T find(Query query) {
   String s = service.getSingle(query, getIndex(), getType());
   return mapping.get(s, t);
 }
Ejemplo n.º 8
0
 @Override
 public long count(Query query) {
   return service.count(query, getIndex(), getType());
 }
Ejemplo n.º 9
0
 @Override
 public long count() {
   return service.count(getIndex(), getType());
 }
Ejemplo n.º 10
0
 @Override
 public boolean exists() {
   return service.exists(getType(), getType());
 }
Ejemplo n.º 11
0
 @Override
 public Cursor<T> findAllById(Class<T> clazz, String... ids) {
   String[] json = service.realTimeMultiGet(getIndex(), getType(), ids);
   return new MultiGetCursor<T>(clazz, json);
 }
Ejemplo n.º 12
0
 @Override
 public <T> T findById(String id, Class<T> clazz) {
   String s = service.realTimeGet(getIndex(), getType(), id);
   return mapping.get(s, clazz);
 }