close

Filter

Elastic Social Manual / Version 2207

Table Of Contents

4.8 Known Limitations

This page describes known limitations of CoreMedia Elastic Social.

Using Query#skip for MongoDB Queries can be very costly

The MongoDB has the following text to this issue:

Unfortunately skip can be (very) costly and requires the server to walk from the beginning of the collection, or index, to get to the offset/skip position before it can start returning the page of data (limit). As the page number increases skip will become slower and more CPU intensive, and possibly IO bound, with larger collections. Range based paging provides better use of indexes but does not allow you to easily jump to a specific page.

Queries for content with interfaces which do not extend Model

In some cases you want to persist your objects, but you do not want to expose in your interface how you do it. For instance, a rating is persisted internally as a Model, but the interface does not extend the Model interface. Your interface and implementation for a Custom object would look like this:

public interface Custom {
}

public class CustomModelImpl implements Custom, Model {
}

Example 4.23. Custom interface


If you query for those Custom objects, you need to use implementation class which extends Model:

List<CustomModelImpl> impls = modelService.query("customModels", CustomModelImpl.class).fetch();
      

Example 4.24. Custom implementation


If you want to have a query result list you need to manually copy all query results to a new list:

public List<Custom> getCustoms() {
   List<CustomModelImpl> impls = modelService.query("customModels",
       CustomModelImpl.class).fetch();
   List<Custom> result = new ArrayList<Custom>(impls.size());
   for (Custom impl : impls) {
     ratings.add(impl);
   }
   return result;
}
      

Example 4.25. Get query result list


Non public properties

You might want to have properties which are part of the implementation, but not of the interface definition. For example, your interface and implementation might look like this:

public interface CustomModel extends Model {
}

public class CustomModelImpl implements CustomModel {
  private int level;

  public int getLevel() {
    return level;
  }

  public void setLevel(int level) {
    this.level = level;
  }
}
      

Example 4.26. Interface and implementation


If you have a service using this model, you want the service to define methods for the interface, not the implementation.

public class CustomModelService {
  public void doSomething(CustomModel model);
  }
}
      

Example 4.27. Model method definition


You cannot easily cast the model to its implementation class because the type is actually generated at runtime:

((CustomModelImpl) model).setLevel(5);
  // ClassCastException because the type is actually generated at runtime
      

Example 4.28. Casting of models


The best workaround for this is to use the setProperty method of the model using constants, which you should define in your implementation class CustomModelImpl:

model.setProperty(LEVEL_PROPERTY, 5)
      

Example 4.29. Set model properties


Overloaded Service methods

Every Service that offers a method which returns a Model or a bunch of Models has to offer this method in three variants to ensure a maximum of extensibility. This leads to a lot of code that may be hardly reused when implementing the method.

public interface CustomModel extends Model {
}
      

Example 4.30. Customize models


A typical implementation for the three method variants has to follow this pattern:

public class CustomModelServiceImpl implements CustomModelService {
  public List<CustomModel> getSomeModels() {
    Query<CustomModel> query = createQuery();
    return query.fetch();
  }

  public <T extends CustomModel> List<T> getSomeModels(
      Class<? extends T> type) {
    return getSomeModels(type, ModelService.NO_SUPER_TYPES);
  }

  public <T extends CustomModel> List<T> getSomeModels(
      Class<? extends T> type,
      List<Class<? extends Model>> superTypes) {
    Query<CustomModel> query = createQuery();
    return query.fetch(type, superTypes);
  }
}
      

Example 4.31. Custom model services


Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.