Package org.openhab.core.persistence

Examples of org.openhab.core.persistence.FilterCriteria


          if(hasStrategy(serviceName, config, GlobalStrategies.RESTORE)) {
            if(appliesToItem(config, item)) {
              PersistenceService service = persistenceServices.get(serviceName);
              if(service instanceof QueryablePersistenceService) {
                QueryablePersistenceService queryService = (QueryablePersistenceService) service;
                FilterCriteria filter = new FilterCriteria().setItemName(item.getName()).setPageSize(1);
                Iterable<HistoricItem> result = queryService.query(filter);
                Iterator<HistoricItem> it = result.iterator();
                if(it.hasNext()) {
                  HistoricItem historicItem = it.next();
                  GenericItem genericItem = (GenericItem) item;
View Full Code Here


   */
  static public HistoricItem historicState(Item item, AbstractInstant timestamp, String serviceName) {
    PersistenceService service = services.get(serviceName);
    if (service instanceof QueryablePersistenceService) {
      QueryablePersistenceService qService = (QueryablePersistenceService) service;
      FilterCriteria filter = new FilterCriteria();
      filter.setEndDate(timestamp.toDate());
      filter.setItemName(item.getName());
      filter.setPageSize(1);
      filter.setOrdering(Ordering.DESCENDING);
      Iterable<HistoricItem> result = qService.query(filter);
      if(result.iterator().hasNext()) {
        return result.iterator().next();
      } else {
        return null;
View Full Code Here

   */
  static public Date lastUpdate(Item item, String serviceName) {
    PersistenceService service = services.get(serviceName);
    if (service instanceof QueryablePersistenceService) {
      QueryablePersistenceService qService = (QueryablePersistenceService) service;
      FilterCriteria filter = new FilterCriteria();
      filter.setItemName(item.getName());
      filter.setOrdering(Ordering.DESCENDING);
      filter.setPageSize(1);
      Iterable<HistoricItem> result = qService.query(filter);
      if (result.iterator().hasNext()) {
        return result.iterator().next().getTimestamp();
      } else {
        return null;
View Full Code Here

   */
  static public HistoricItem previousState(Item item, boolean skipEqual, String serviceName) {
    PersistenceService service = services.get(serviceName);
    if (service instanceof QueryablePersistenceService) {
      QueryablePersistenceService qService = (QueryablePersistenceService) service;
      FilterCriteria filter = new FilterCriteria();
      filter.setItemName(item.getName());
      filter.setOrdering(Ordering.DESCENDING);

      filter.setPageSize(skipEqual ? 1000 : 1);
      int startPage = 0;
      filter.setPageNumber(startPage);

      Iterable<HistoricItem> items = qService.query(filter);
      while (items != null) {
        Iterator<HistoricItem> itemIterator = items.iterator();
        int itemCount = 0;
        while (itemIterator.hasNext()) {
          HistoricItem historicItem = itemIterator.next();
          itemCount++;
          if (!skipEqual || (skipEqual && !historicItem.getState().equals(item.getState()))) {
            return historicItem;
          }
        }
        if (itemCount == filter.getPageSize()) {
          filter.setPageNumber(++startPage);
          items = qService.query(filter);
        }
        else {
          items = null;
        }
View Full Code Here

  static private Iterable<HistoricItem> getAllStatesSince(Item item, AbstractInstant timestamp, String serviceName) {
    PersistenceService service = services.get(serviceName);
    if (service instanceof QueryablePersistenceService) {
      QueryablePersistenceService qService = (QueryablePersistenceService) service;
      FilterCriteria filter = new FilterCriteria();
      filter.setBeginDate(timestamp.toDate());
      filter.setItemName(item.getName());
      filter.setOrdering(Ordering.ASCENDING);
      return qService.query(filter);
    } else {
      logger.warn("There is no queryable persistence service registered with the name '{}'", serviceName);
      return Collections.emptySet();
    }
View Full Code Here

   
    if (query != null) {
      query.constrain(Db4oItem.class);
     
      if (filter==null) {
        filter = new FilterCriteria();
      }
      if (filter.getBeginDate()!=null) {
        query.descend("timestamp").constrain(filter.getBeginDate()).greater().equal();
      }
      if (filter.getEndDate()!=null) {
View Full Code Here

    if (label == null) {
      label = item.getName();
    }

    Iterable<HistoricItem> result;
    FilterCriteria filter;

    // Generate data collections
    Collection<Date> xData = new ArrayList<Date>();
    Collection<Number> yData = new ArrayList<Number>();
   
    // Declare state here so it will hold the last value at the end of the process
    org.openhab.core.types.State state = null;

    // First, get the value at the start time.
    // This is necessary for values that don't change often otherwise data will start
    // after the start of the graph (or not at all if there's no change during the graph period)
    filter = new FilterCriteria();
    filter.setEndDate(timeBegin);
    filter.setItemName(item.getName());
    filter.setPageSize(1);
    filter.setOrdering(Ordering.DESCENDING);
    result = service.query(filter);
    if(result.iterator().hasNext()) {
      HistoricItem historicItem = result.iterator().next();

      state = historicItem.getState();
      xData.add(timeBegin);
      yData.add(convertData(state));
    }

    // Now, get all the data between the start and end time
    filter.setBeginDate(timeBegin);
    filter.setEndDate(timeEnd);
    filter.setPageSize(Integer.MAX_VALUE);
    filter.setOrdering(Ordering.ASCENDING);
   
    // Get the data from the persistence store
    result = service.query(filter);
    Iterator<HistoricItem> it = result.iterator();
View Full Code Here

TOP

Related Classes of org.openhab.core.persistence.FilterCriteria

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.